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:

date=seq(as.Date("2000/1/1"), as.Date("2000/1/20"), "days")


signal<- xts(rep(NA,length(close_xts)),index(close_xts)) 
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?

  • $\begingroup$ Help us: we need library(xts) and where can we find the function ROC? $\endgroup$
    – Richi Wa
    Commented Dec 18, 2013 at 12:56
  • 1
    $\begingroup$ 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. $\endgroup$
    – Richi Wa
    Commented Dec 18, 2013 at 12:58
  • $\begingroup$ @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... $\endgroup$
    – vanguard2k
    Commented Dec 18, 2013 at 15:35
  • $\begingroup$ @Richard,i have edited my post so as to include packages TTR and xts.. $\endgroup$
    – SBS
    Commented Dec 19, 2013 at 4:07

2 Answers 2


enter image description here

This is the equity line i got after i repeated your code. how is this good ? may be you have run with only one set of numbers. any ways here are a few things you can do to come closer to reality :

  1. take the close prices as lognormal distribution instead of a normal distribution.
  2. you are adding up the returns later on. this is only right if you have logarithmic differences instead of simple differences.
  3. run the same simulation with a lot of samples to get a distribution and then decide if it is good or bad.
  4. the fluctuations you will see in the equity line is because you have provided a huge value for the standard deviation.

Time Series Returns Summary

You can use the PerformanceAnalytics package , and get the following charts, Cumulative Returns, Daily Returns as well as Drawdown for understanding the time series.

Code: library("PerformanceAnalytics")

charts.PerformanceSummary( ROC(eq, n = 1, type = "discrete"), main = "Returns (PerformanceAnalytice::charts.PerformanceSummary)" )


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.