Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Difference between nancov and corr2cov with NaNs

Status
Not open for further replies.

sssu

Computer
Joined
Apr 28, 2004
Messages
2
Location
AU
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!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top