‘sI am new to R and even more to ts objects. I try to use the package PerformanceAnalytics on a vector from a dataframe (df).
I have the following data frame:
row.names Date PnL
1 22 1992-01-02 -1.751133e-02
2 23 1992-01-03 -1.586737e-02
3 24 1992-01-06 -2.898982e-02
I tried:
TestS=SharpeRatio.annualized(df[,"PnL"],Rf=0,scale=252)
TestS=SharpeRatio.annualized(as.ts(df[,"PnL"]),Rf=0,scale=252)
It returns respectively the error in the object and:
Error in checkData(R, method = “xts”) :
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’
dput(df[,"PnL")=0.00994504296273811, 0.00156467225423175, 0.00976137048829638, etc.
dputdf[,"Date")=8036, 8037, 8040, 8041,etc.
The package’s help says the function works on vector. I don’t have any NA, and therefore I don’t see why it does not work.
First, you need to convert your data frame to an
xtsobject:Then you can do:
Or whatever else you need to do.