我正在尝试根据股票df2
的数据帧计算最差的亏损。
> head(df2[3:19])
.SXTR .SXNR .SXMR .SXAR .SX3R .SX6R .SXFR .SXOR .SXDR .SX4R ...
2000-01-03 223.93 489.04 586.38 306.56 246.81 385.36 403.82 283.78 455.39 427.43 ...
2000-01-04 218.90 474.05 566.15 301.13 239.24 374.64 390.41 275.93 434.92 414.10 ...
2000-01-05 215.88 464.20 542.29 298.22 239.55 373.26 383.48 272.54 430.05 406.33 ...
2000-01-06 218.18 470.82 529.33 300.69 249.75 377.26 383.48 272.47 434.15 417.91 ...
2000-01-07 220.10 478.87 531.65 306.50 255.17 381.19 390.23 273.76 447.02 428.54 ...
2000-01-10 223.01 484.07 581.82 310.84 252.75 387.74 393.75 278.76 453.80 431.81 ...
运行它时,会得到一系列NA。
maxDrawdown(df2[3:19], weights = NULL, geometric = TRUE, invert = TRUE)
.SXTR .SXNR .SXMR .SXAR .SX3R .SX6R .SXFR .SXOR .SXDR .SX4R .SXRR
Worst Drawdown NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
.SXER .SXKR .SX7R .SX8R .SXIR .SXPR
Worst Drawdown NaN NaN NaN NaN NaN NaN
因此,我尝试使用in this question发布的方法仅考虑非Nas的行,但没有考虑。
> maxDrawdown(complete.cases(df2[2:19]), weights = NULL, geometric = TRUE, invert = TRUE)
Error in checkData(R) :
The data cannot be converted into a time series. If you are trying to pass in names from a data object with one column, you should use the form 'data[rows, columns, drop = FALSE]'. Rownames should have standard date formats, such as '1985-03-15'.