# Calculating and interpreting cumulative returns is R

I have buy and sell signals,and accordingly, I artificially generate a signal series,for which,I assign 1 to every buy and -1 to every sell:

library(xts)
require(TTR)
close_series=rnorm(20,100,10)
date=seq(as.Date("2000/1/1"), as.Date("2000/1/20"), "days")
close_xts=xts(close_series,date)

x.points.sell=c(3,6,12,20)
sell.points=index(close_xts[x.points.sell])

signal<- xts(rep(NA,length(close_xts)),index(close_xts))
signal[sell.points]<--1
signal<-na.locf(signal)
returns <- ROC(close_xts,type="discrete")*signal
returns[is.na(returns)]<- 0
eq <- exp(cumsum(returns))


This is giving me returns that seem to be too good to be true,I am not able to understand the fundamental methodology on the basis of which these cumulative returns show such huge figures.Can anyone please help me to understand this?

• Help us: we need library(xts) and where can we find the function ROC? – Ric Dec 18 '13 at 12:56
• I don't know at the moment what ROC does, but there you spedicy discrete and in the last line you apply logic for log-returns. – Ric Dec 18 '13 at 12:58
• @SBS Probably there is a require(TTR) missing. ROC() calculates discrete returns and you convert back with the exponential. You should correct that. Further more, if you model the price directly, try to reduce the sigma. You could also try something like seq(100,100.95,by=0.05) just to get started... – vanguard2k Dec 18 '13 at 15:35
• @Richard,i have edited my post so as to include packages TTR and xts.. – SBS Dec 19 '13 at 4:07