# Quantmod: what's the difference between ROC(Cl(SPY)) and ClCl(SPY)

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)

-

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.

-
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).