Skip to content

Instantly share code, notes, and snippets.

@quantra-go-algo
Created August 24, 2021 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quantra-go-algo/329ca3a81327dbae55b9dad609f77add to your computer and use it in GitHub Desktop.
Save quantra-go-algo/329ca3a81327dbae55b9dad609f77add to your computer and use it in GitHub Desktop.
Getting data
####################################################
## 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