You should be able to find the covariance by passing the second through 60th rows of your data into the cov
function (covariance_matrix = cov(data(2:end,:))
), as per this documentation. Hope that helps!
Covariance for elements in a matrix - Matlab
-
29-09-2022 - |
Question
I'm struggling here as it's my first attempt with Matlab...
I have data that looks like this:
The first row has stockID number and the 60 rows in each column contain the stock's returns.
I am trying to calculate the variance for each stock as well as a covariance matrix in Matlab. I am stuck because I do not know how to identify each column as its StockID. Should each column be its own variable? If so, how would I do this automatically as I have about 1,000 stocks...? Is there then a way to create a cov. matrix for each stock without manually entering in each variable, i.e. not do this: cov(10801, 12032, 13439, .....) ?
Thanks so much for the help!
La solution
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow