Take the 2-minute tour ×
Quantitative Finance Stack Exchange is a question and answer site for finance professionals and academics. It's 100% free, no registration required.

I feel like I'm missing something fundamental here, but I can't shake the feeling that these two series should be equivalent.

/edit: there is also dailyReturn(Cl(SPY)). I've seen all 3 of these methods used to calculate stock returns on various blogs, and I'm wondering which is 'correct.' They all give slightly different results...

/edit2: and there is also Delt(Cl(SPY)), which seems to be equivalent to ClCl(SPY)

share|improve this question

2 Answers 2

up vote 3 down vote accepted

TTR::ROC calculates log returns by default. quantmod::ClCl uses quantmod::Delt, which calculates arithmetic returns by default.

ROC(Cl(SPY), type="discrete") should match ClCl(SPY). Which is 'correct' depends on your purpose.

share|improve this answer
1  
What I want to do is generate a series of returns that I can modify with a simple -1/1 trading system, and then pass to PerformanceAnalytics::charts.PerformanceSummary to plot my equity, returns, and drawdowns. –  Zach Apr 27 '11 at 22:42

To expand on what Joshua has already stated, here is a truncated parameter list of similar functions, along with the package to which they belong.

quantmod::Delt(x1,type = c("arithmetic", "log"))
quantmod::periodReturn(x, type='arithmetic') # log would be "log"
TTR::ROC(x, type=c("continuous", "discrete"))
PerformanceAnalytics::CalculateReturns(prices, method=c("compound","simple"))

Your choice are simple returns, which are (today's_close - yesterday's_close) / yesterday's_close, or log returns, which are log(today's_close) - log(yesterday's_close), or, equivalently, log(today's_close / yesterday's_close). If you decide on simple returns, you must multiply returns to get the total return at the end of a period. With log returns you get to add them. This is preferred when your vector may have zeroes in it for obvious reasons. If you have a simple 1 or -1 signal, then you're only going to have a zero in the beginning, or an NA depending on which function you choose. But once you have a system that goes flat, or signals a 0, then you will have some trouble with simple returns.

Simple returns are referred to as arithmetic, discrete or simple in the above functions. The log returns are alternately referred to as log, continuous or compound.

The Delt function is sort of an artifact and has been updated with the dailyReturn function. Here is a snapshot of what each function generates on the first two lines of a trading system. Notice also that some have their defaults set to simple returns and others have default set to log returns. Each function allows you to change the default.

            SLV.Close    Delt   dailyReturn          ROC  CalculateReturns
2010-01-04  17.23          NA   0.000000000           NA                NA
2010-01-05  17.51 0.016250725   0.016250725  0.016120096       0.016120096

Remember that once you convert your returns to a log return, you need to un-convert it to get simple returns again, and this is accomplished by simply applying exp(log_return).

My recent blog post about this topic may be of interest to you. http://www.milktrader.net/2011/04/chop-slice-and-dice-your-returns-in-r.html

share|improve this answer
1  
Thanks for the information. Which type of returns does PerformanceAnalytics expect when calculating things like sharpe ratio or charting equity? –  Zach Apr 28 '11 at 15:40
1  
log returns are not "simply log(simple_returns)." Log return = log(today's_close) - log(yesterday's_close), or, equivalently, log(today's_close / yesterday's_close). PerformanceAnalytics defaults to log returns. –  user508 Apr 29 '11 at 2:49
    
@user508 I copied and pasted your correction into my answer. Thanks. Also, I checked it to make sure it's correct and it is. –  Milktrader May 1 '11 at 12:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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