When comparing the performance of financial assets like Bitcoin, ETFs, and stocks, which was the most profitable asset since 2010?
In this tutorial, we explain how to download, process, and report on the performance of financial assets using Python.
The report is inspired by Charlie Bilello’s analyses.
Data
We define the list of tickers for the assets to analyze.
tickers = ['BTC-USD', 'QQQ', 'IWF', 'SPY', ...]
We download daily historical price movements using the
yfinance
library, which downloads data from Yahoo
Finance.
import yfinance as yf
df = yf.download(tickers)
Questions
- How to download historical price data for multiple financial assets?
- How to calculate the annual cumulative return of each asset?
- Why is it necessary to group data for cumulative calculations?
- How to select the last day of cumulative return in each year?
- How to identify the maximum and minimum return values in each year?
- How to calculate the percentage of positive returns for each asset?