r - Error: order.by requires an appropriate time-based object PerformanceAnalytics -
'I'm new to R and more than ts objects I use dataframe (DF) to display analytics on vector Try
I have the following data frames:
row.names Date PnL 1 22 1992-01-02 -1.751133e-02 2 23 1992-01-03 -1.586737 E-02 3 24 1992-01-06 -2.898982-02
I tried:
tests = SharpeRatio.nualized (df [, "pnl "], RF = 0, scale = 252) TestS = Sharperateo.Unulized (as.ts (df [," PnL "]), RF = 0, scale = 252)
Returns the error in the object, and:
Error in the checkdata (R, method = "extents"): Data can not be converted to a time series. If you are trying to pass through a name in a column from a data object, then you should use 'data [rows, columns, drop = falls]'. Rownames should have a standard date format, such as '1985-03-15'
dput (df [, "PnL") = 0.00994504296273811, 0.00156467225423175, 0.00976137048829638, etc. Dputdf [, "Date") = 8036, 8037, 8040, 8041, etc.
The Package Help says that the function works on vector. I have no NA, and so I do not know why this does not work.
First of all, you have to change your data frame in the xts
object :
dfx = xts (df $ PnL, order.by = as.Date (df $ date)))
Then you can do this :
TestS = SharpeRatio.annualized (dfx, Rf = 0, scale = 252)
Or whatever you need to do.
Comments
Post a Comment