sssu
Computer
- Apr 28, 2004
- 2
Can somebody explain the difference?
I have a set of returns (with NaN Values) and I want to create a covariance matrix. I have the option of two functions (When I have NaN values in my returns they yield different results- Can you explain why?). Here is an example:
This is a sample returns matrix
X=[[2; 9; 1; 0.2], [4; 5; NaN; 0.5],[0.2; 5; 8; NaN]]
1. Using the covariance function
nancov(X,'pairwise')
ans =
16.2767 8.8167 0.3000
8.8167 5.5833 2.4000
0.3000 2.4000 15.4800
2. Using corr2cov
Convert standard deviation and correlation to covariance
ExpCovariance = corr2cov(ExpSigma, ExpCorrC)
corr2cov(nanstd(X), corrcoef(X,'rows','pairwise'))
ans =
16.2767 7.6511 0.2777
7.6511 5.5833 9.2968
0.2777 9.2968 15.4800
Can anyone explain why these two fucntions- which should yield the same result- actually display a different covariance matrix?
Thank you!!!!
Much appreciated!!!!!
I have a set of returns (with NaN Values) and I want to create a covariance matrix. I have the option of two functions (When I have NaN values in my returns they yield different results- Can you explain why?). Here is an example:
This is a sample returns matrix
X=[[2; 9; 1; 0.2], [4; 5; NaN; 0.5],[0.2; 5; 8; NaN]]
1. Using the covariance function
nancov(X,'pairwise')
ans =
16.2767 8.8167 0.3000
8.8167 5.5833 2.4000
0.3000 2.4000 15.4800
2. Using corr2cov
Convert standard deviation and correlation to covariance
ExpCovariance = corr2cov(ExpSigma, ExpCorrC)
corr2cov(nanstd(X), corrcoef(X,'rows','pairwise'))
ans =
16.2767 7.6511 0.2777
7.6511 5.5833 9.2968
0.2777 9.2968 15.4800
Can anyone explain why these two fucntions- which should yield the same result- actually display a different covariance matrix?
Thank you!!!!
Much appreciated!!!!!