I am currently trying to create a Risk Return Scatter plot using the following code

chart.RiskReturnScatter(performance[x:y, portfolio.list], Rf = rf, main = "", cex.axis = 1.5, cex.lab = 1.5)

the performance[x:y, portfolio.list] dataframe is formatted as:

             HR Muni Bond HR Taxable Bond Composite Portfolio
2017-12-31           NA          -0.006       -0.0025071641
2018-03-31           NA          -0.003       -0.0012671892
2018-06-30           NA           0.007        0.0028773074
2018-09-30           NA          -0.001       -0.0004108567

I modified my code to replace the NA's with zeros thinking that this would correct the error:

chart.RiskReturnScatter(performance[x:y, portfolio.list][is.na(performance[x:y, portfolio.list])]<-0,Rf=rf,main="", cex.axis = 1.5, cex.lab = 1.5)

Nope, that didn't fix the issue. I received the following error: "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'."

I went back to the drawing board and added tk_xts to coerce the dataframe back to the xts format using this code:

chart.RiskReturnScatter(tk_xts(performance[x:y, portfolio.list][is.na(performance[x:y, portfolio.list])]<-0, by 1),Rf=rf,main="", cex.axis = 1.5, cex.lab = 1.5)

I think I am up to strike 3. I now get this error: "Error in xts::xts(data, ...) : order.by requires an appropriate time-based object"

I am not sure where to proceed next. Basically, what is the best way to handle NA's in PerformanceAnalytics? Any suggestions are greatly appreciated.

Thank you.

  • $\begingroup$ Make sure your index is a proper date object with as.Date() and see if that fixes the issue. Usually "order.by requires an appropriate time-based object" means that the index isn't the right kind of date object that xts expects to receive. $\endgroup$ – Jared Marks Nov 14 '18 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.