Search code examples
rtime-seriesperformanceanalytics

Times series charting using chart.CumReturns


I'm trying to do a very simple calculation using chart.CumReturns function. Somehow, the result looks utterly odd. It can't be right. Can someone point out the error?

data <- structure(list(Date = structure(c(15005, 15033, 15064, 15093, 
15125, 15155, 15184, 15217, 15247, 15278, 15308, 15338, 15370, 
15399, 15429, 15460, 15491, 15520, 15552, 15583, 15611, 15644, 
15674, 15705, 15736, 15764, 15793, 15825, 15856, 15884, 15917, 
15947, 15978, 16009, 16038, 16070, 16101, 16129, 16160, 16190, 
16220, 16251, 16282, 16311, 16343, 16374, 16402, 16435, 16465, 
16493, 16525, 16555, 16584, 16616, 16647, 16678, 16708, 16738, 
16769, 16800, 16829, 16860, 16878), class = "Date"), close = c(28.31, 
28.9, 27.95, 28.91, 28.85, 27.57, 26.86, 24.16, 22.94, 24.62, 
24.26, 24.77, 25.81, 26.88, 26.58, 26.17, 24.64, 25.51, 26.52, 
27, 27.11, 27.33, 27.94, 28.3, 29.11, 29.39, 29.67, 30.2, 30.9, 
28.82, 30.39, 30.22, 31.31, 32.57, 32.87, 32.91, 32.41, 34.04, 
33.64, 34.22, 35.23, 34.57, 34.03, 34.66, 34.4, 33.89, 35.04, 
34.25, 36.98, 39.48, 40.02, 40.08, 40.73, 38.5, 40.14, 36.78, 
34.91, 37.83, 38.81, 36.9, 34.28, 33.56, 34.13)), .Names = c("Date", 
"close"), row.names = c(NA, -63L), class = "data.frame")

library(PerformanceAnalytics)
x <- xts(data$close, order.by = data$Date)
chart.CumReturns(x)

Oddly, I had to use order.by = to convert the data to xts. The chart looks just not right. The return skyrockets towards the end. But everywhere else is flat.

Where is the mistake?


Solution

  • chart.CumReturns requires returns not prices, you need to convert those prices to returns.

    e.g.

    returns <- Return.calculate(x)
    chart.CumReturns(returns)