0

I'm trying to calculate variance from covariance matrix and the proportions of each stocks. Here's my code:

for num in range(9):

result_table2.iloc[num]['Expected Return'] = arith_mean.dot(result_table1.iloc[num])
for num in range(9):

result_table2.iloc[num]['Standard Deviation'] = (result_table1.iloc[num])@V.values

The first one worked and the second one failed result_table1: enter image description here result_table2: enter image description here covariance matrix: enter image description here

pupupyguy
  • 33
  • 4
  • 1
    Please include the relevant code as text and example of input and desired output (maybe calculate a small case manually) – Caridorc Jan 26 '23 at 02:52
  • 1
    Maybe replace `std` by `var` in whatever you did in the last step... but is difficult to say without your actual code. See [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). – Ignatius Reilly Jan 26 '23 at 03:00
  • @Caridorc Hi, I just added my code, hope it works better! – pupupyguy Jan 26 '23 at 03:04
  • "How to calculate variance from covariance matrix in python?" This is `x'Cx` where x[i] are the amounts (or fractions) in instrument i and C is the covariance matrix. – Erwin Kalvelagen Jan 26 '23 at 08:51

0 Answers0