首页 > 解决方案 > 如何在 R 中计算 maxDrawdown

问题描述

我在 PerformanceAnalytics 包中使用 maxDrawdown 函数

我选择了一个日期列和一个类型双列来绘制这些时期的 maxdrawdown。

例如

   period            p/l
 2020-11-02         12.34
 2020-11-02         34.32
 2020-11-03         -0.23
  ...                ..

我已经运行了代码

maxDrawdown(select(Data,dt,pl))

但返回此错误:

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'. 

标签: ranalytics

解决方案


也许:

library(xts)
x <- xts(Data$pl, Data$date)
maxDrawdown(x)

推荐阅读