Skip to content
All library documents

Handling Missing Returns and Time-Series Input in PerformanceAnalytics

Article Quant Q&A · Author: UTexas80

Summary

The document describes a user’s attempt to create a risk-return scatter plot from quarterly portfolio returns that include missing values. Replacing missing entries with zero does not resolve the problem: the assignment expression passed to the plotting function produces an unsuitable input, followed by errors about converting the data to a time series and finding an appropriate date index.

The post raises a practical question about preparing missing observations for PerformanceAnalytics, but it contains no accepted answer or demonstrated fix. Its example suggests that both the data structure and date index matter when passing returns to the plotting function; it does not establish that zero-filling is a sound treatment for missing returns. Readers should treat this as an unresolved troubleshooting question, not as guidance on a validated imputation method.

Key ideas

  • The post concerns a risk-return scatter plot built from portfolio return data with missing observations.
  • Replacing missing values with zero did not solve the plotting problem.
  • The attempted assignment altered the input structure and led to time-series conversion errors.
  • The document provides no confirmed fix or evidence supporting a particular missing-data treatment.

Tags

Full text
# Issue with chart.RiskReturnScatter in performance analytics, need finite 'ylim' values error


# Issue with chart.RiskReturnScatter in performance analytics, need finite 'ylim' values error












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.

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.