Skip to content

Instantly share code, notes, and snippets.

@julian-west
Created September 7, 2019 16:54
Show Gist options
  • Save julian-west/c88bcf7639dbcc1cb1d147155e8d33e0 to your computer and use it in GitHub Desktop.
Save julian-west/c88bcf7639dbcc1cb1d147155e8d33e0 to your computer and use it in GitHub Desktop.
# create empty dataframe for log returns information
log_returns_df = pd.DataFrame()
# calculate log returns of each asset
# loop through each column in dataframe and and calculate the daily log returns
# add log returns column to new a dataframe
for col in raw_asset_prices_df.columns:
# dates are given in reverse order so need to set diff to -1.
log_returns_df[col] = np.log(raw_asset_prices_df[col]).diff(-1)
#check output of log returns dataframe
log_returns_df.head()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment