rggplot2financequantmodperformanceanalytics

R chart.RollingPerformance stock price unable to output correct y axis


This is my code for reading in a bunch of ETFs. I tried using a chart.RollingPerformance for the return of the ETFs but cant seem to output the display with the correct y axis?

I read in the data with these:

mystocks <- new.env(hash=TRUE)
getSymbols(c("QQQ", "XBI", "VYM", "VOO"), env=mystocks, from ="2016-01-04", to ="2020-10-22")
etf <- do.call(cbind,eapply(mystocks, Cl))
str(etf)
head(etf)
An ‘xts’ object on 2016-01-04/2020-10-21 containing:
  Data: num [1:1210, 1:4] 184 185 182 178 176 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:4] "VOO.Close" "QQQ.Close" "XBI.Close" "VYM.Close"
  Indexed by objects of class: [Date] TZ: UTC
  xts Attributes:  
List of 2
 $ src    : chr "yahoo"
 $ updated: POSIXct[1:1], format: "2020-10-23 15:38:16"

           VOO.Close QQQ.Close XBI.Close VYM.Close
2016-01-04    184.31    109.50     67.83     65.95
2016-01-05    184.64    109.31     67.22     66.28
2016-01-06    182.30    108.26     64.35     65.41
2016-01-07    177.86    104.87     61.82     64.00
2016-01-08    175.97    104.01     60.51     63.28
2016-01-11    175.99    104.33     57.14     63.35

I plot with the following with these code. I have attached the picture for reference.

etf_returns_discrete = Return.calculate(etf, method = c("discrete"))
etf_returns_log = Return.calculate(etf, method = c("log"))

charts.RollingPerformance(etf_returns_discrete,
                          Rf=.03/12, 
                          main="Rolling 12-Month Performance",
                          legend.loc="topleft")

Here is the link to the photo

Thanks in advance!!


Solution

  • This happens, because the default value for width = 12 in charts.RollingPerformance and you are using daily returns. As you are annualizing returns using only 12 days, you get annualized returns of >100% sometime. If you use roughly a year (252 business days), you'll get the desired result. Just change your call to charts.RollingPerformance to this:

    charts.RollingPerformance(R = etf_returns_discrete,
                              width = 252,
                              Rf = 0,
                              "Rolling 12-Month Performance")