Created
August 24, 2021 12:19
-
-
Save quantra-go-algo/329ca3a81327dbae55b9dad609f77add to your computer and use it in GitHub Desktop.
Getting data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#################################################### | |
## Fetch data from yfinance | |
## 3-year daily data for Coca-Cola, SPY, Pepsi, and USD index | |
end1 = datetime.date(2021, 7, 28) | |
start1 = end1 - pd.Timedelta(days = 365 * 3) | |
ko_df = yf.download("KO", start = start1, end = end1, progress = False) | |
spy_df = yf.download("SPY", start = start1, end = end1, progress = False) | |
pep_df = yf.download("PEP", start = start1, end = end1, progress = False) | |
usdx_df = yf.download("DX-Y.NYB", start = start1, end = end1, progress = False) | |
#################################################### | |
## Calculate log returns for the period based on Adj Close prices | |
ko_df['ko'] = np.log(ko_df['Adj Close'] / ko_df['Adj Close'].shift(1)) | |
spy_df['spy'] = np.log(spy_df['Adj Close'] / spy_df['Adj Close'].shift(1)) | |
pep_df['pep'] = np.log(pep_df['Adj Close'] / pep_df['Adj Close'].shift(1)) | |
usdx_df['usdx'] = np.log(usdx_df['Adj Close'] / usdx_df['Adj Close'].shift(1)) | |
#################################################### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment