my attempt:
De [esta respuesta] [4] intenté de esta respuesta:
dr_df = cbind(df[-1,1],apply(df[,-1],2,function(x) diff(x)/head(x,-1)))
Que devuelve:
> head(dr_df)
SX5P SX5E SXXP SXXE SXXF SXXA
[1,] 6209 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000
[2,] 6210 -0.005303226 -0.010035301 -0.002295795 -0.007912355 -0.006424638 0.004488850
[3,] 6213 0.001297202 0.007344861 0.003027734 0.008179959 0.007800472 -0.003027245
[4,] 6214 0.005220951 0.004441575 0.005554214 0.005983773 0.006517975 0.004916136
[5,] 6215 0.006817713 -0.003513166 0.006003842 -0.002318782 -0.002124861 0.015683453
[6,] 6216 -0.004595435 -0.013101262 -0.003103366 -0.011014551 -0.009531535 0.005949851
DK5F DKXF
[1,] 0.0000000000 0.0000000000
[2,] 0.0036574404 0.0038133008
[3,] 0.0035823477 0.0001519526
[4,] 0.0039234391 0.0036463081
[5,] -0.0007969471 0.0021192855
[6,] -0.0098164026 -0.0087613293
Lo que parece bastante bueno, pero no entiendo el código: / Y cuando intento crear la matriz de covarianza, tengo algunos problemas:
> cov(dr_df[2:8])
Error in cov(dr_df[2:8]) : supply both 'x' and 'y' or a matrix-like 'x'
> cov(dr_df)
SX5P SX5E SXXP SXXE SXXF SXXA DK5F DKXF
9886513 NA NA NA NA NA NA NA NA
SX5P NA NA NA NA NA NA NA NA NA
SX5E NA NA NA NA NA NA NA NA NA
SXXP NA NA NA NA NA NA NA NA NA
SXXE NA NA NA NA NA NA NA NA NA
SXXF NA NA NA NA NA NA NA NA NA
SXXA NA NA NA NA NA NA NA NA NA
DK5F NA NA NA NA NA NA NA NA NA
DKXF NA NA NA NA NA NA NA NA NA