Course Name: Quantitative Portfolio Management, Section No: 2, Unit No: 6, Unit type: Notebook
Hi there,
I noticed that the following two methods for calculating covariance each gives a different result. Can you help to explain why?
price_returns.cov() * 252
cov_msft_googl = np.cov(
price_returns['MSFT'], price_returns['GOOGL'], bias=True)*252
Many thanks,
Ryan
The reason for the difference in the np.cov() method and DataFrame.cov() is the normalisation.
In both cases, the default normalisation is False (bias = False) and is done by N-1.
where N is the number of observations given.
When you change to bias=True, then normalisation is done by N.
Instead of this line of code:
cov_msft_googl = np.cov(
price_returns['MSFT'], price_returns['GOOGL'], bias=True)*252
Use this:
cov_msft_googl = np.cov(
price_returns['MSFT'], price_returns['GOOGL'], bias=False)*252
You will get the same result using both np.cov() and DataFrame.cov() method.