Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement