【问题标题】:Drawdowns- Performance Analytics error--- Factor and Numeric亏损-绩效分析错误---因子和数字
【发布时间】:2013-11-29 06:24:49
【问题描述】:

文本文件中的一些数据:

date,p
2013-11-14,0.001
2013-11-13,-0.005
2013-11-12,0.001

library(PerformanceAnalytics)
stuff<-read.csv("C:stuffexample.txt")
str(stuff)

'data.frame':   3 obs. of  2 variables:
 $ date: Factor w/ 3 levels "2013-11-12","2013-11-13",..: 3 2 1
 $ p   : num  0.001 -0.005 0.001

想要对数据使用性能分析:

AverageDrawdown(stuff)

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

table.Drawdowns(box)

Error in checkData(R[, 1, drop = FALSE]) : 
  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'. 

如何修复错误?

【问题讨论】:

    标签: r performanceanalytics


    【解决方案1】:

    您需要遵循错误中给出的建议。您应该在 data.frame 中有日期的行名和只有数据:

    row.names(stuff) <- levels(stuff$date)[stuff$date]
    stuff2 <- stuff[, 'p', drop=FALSE]
    
    AverageDrawdown(stuff2)
    

    这是未经测试的,因为您没有提供可重现的示例...

    【讨论】:

      猜你喜欢
      • 2013-02-02
      • 2015-09-05
      • 1970-01-01
      • 2017-04-29
      • 1970-01-01
      • 2010-12-24
      • 1970-01-01
      • 2021-06-09
      • 2010-10-15
      相关资源
      最近更新 更多