Drawdowns- Performance Analytics error— Factor and Numeric

自闭症网瘾萝莉.ら 提交于 2019-12-11 06:51:28

问题


Some data in a text file:

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

Want to use Performance Analytics on the data:

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

How do I fix errors?


回答1:


You need to follow the advice given in the error. You should have row names of dates and only data in your data.frame:

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

AverageDrawdown(stuff2)

This is untested since you did not provide a reproducible example though...



来源:https://stackoverflow.com/questions/20008212/drawdowns-performance-analytics-error-factor-and-numeric

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!