consider the following problem i am trying to find the monthly covariance matrix given daily data. i have the following codeimport datetime
import pandas as pd
import yfinance as yf
import numpy as np
tickers = ['AAPL', 'AMZN', 'XOM']
start_date1 = datetime.date(2010, 1, 2)
end_date1 = datetime.date(2019, 12, 31)
daily_data1 = yf.download(tickers, start=start_date1, end=end_date1) # definere datasættet
daily_data1 = daily_data1['Adj Close'].dropna()
frames = [v for _, v in daily_data1.groupby(pd.Grouper(freq='M'))]
for month in frames:
cov_matrix = (month.pct_change().apply(lambda x: np.log(1 + x)).cov())
so i think i would multiply the cov_matrix with the length of the given month by i am unsure if its that easy so multiply the cov_matrix*len(month)? if someone could confirm it. Thanks in advance
daily_data1.resample('M').last()
will give you the last day of each month for the correspondingdaily_data1
dataframe. Now transform said monthly data to returns and compute the (rolling) covariance matrix on that data. $\endgroup$