1
$\begingroup$

Suppose that you want to calculate the single period return. Let p0 be the initial price and p1 be the final price over the period.

The most common formula is

(p1 - p0) / p0

But I also sometimes see people use

(p1 / p0) - 1

Algebraically, both forms are equivalent. However, when you are writing computer code, is there any difference?

From a performance perspective, both forms involve 1 division and 1 subtraction, so they should have similar performance. (Perhaps the first form only needs 3 registers while the second needs 4?)

From an accuracy perspective, is there any difference? Does one form have lower floating point error than the other? Assume that a 64 bit floating point type is being used (e.g. numpy float64 or Java double).

I am not sure whether the language used matters, but if you think it might, I now typically use Python (Pandas), R, or Java. And if I am using Pandas or R, the return is usually calculated as a vector operation.

$\endgroup$
5
  • $\begingroup$ Hi: there's no difference. the more important issue is whether you want to include compounding ( you're calculating the simple return ) and this question depends on the timescale of your returns. See this for a discussion of simple returns versus compounded. en.wikipedia.org/wiki/Rate_of_return $\endgroup$ – mark leeds Feb 11 at 18:13
  • $\begingroup$ @mark leeds: I am well aware of the effect of compounding, geometric returns versus arithmetic returns, etc. But your comment is worth stating, thanks. $\endgroup$ – HaroldFinch Feb 11 at 18:31
  • 1
    $\begingroup$ The question needs be clarified with respect to which datatypes are used in the above calculation. BigDecimal vs double vs float make a difference. If the former, precision limit matters. Prices are often typed as decimal numbers. $\endgroup$ – Sergei Rodionov Feb 11 at 18:55
  • 2
    $\begingroup$ On a calculator I prefer -1+P1/P0= simply because it requires the fewest keystrokes. $\endgroup$ – noob2 Feb 11 at 20:50
  • 1
    $\begingroup$ Or don’t subtract the 1 at all. This might be an option in your code as well:) $\endgroup$ – Bob Jansen Feb 12 at 20:11
5
$\begingroup$

The language would matter but if performance is an issue you would want to make sure that the code is optimal. Optimized assembly code for a single return calculation looks like this (on Godbolt):

method1(double, double):
        divsd   xmm0, xmm1
        subsd   xmm0, QWORD PTR .LC0[rip]
        ret
method2(double, double):
        subsd   xmm0, xmm1
        divsd   xmm0, xmm1
        ret
.LC0:
        .long   0
        .long   1072693248

The number of instructions and registers used is the same. I don't know whether there is a difference between applying subsd on two register or one register and one value from the data segment. All compilers behave more or less the same so I guess this is a quick way to subtract 1.

The Godbolt link also contains vectorized code, this code is quite similar and from a quick check seems to use the same amount of registers (xmm0, xmm1, xmm2 and loop accounting registers).

For financial purposes double numbers are precise enough. The rounding differences you might encounter in return calculations are negligible, smaller than 1e-10 for all reasonable numbers. It's much more important to get the correct data. But even if you have the correct data, any noise in the data such as bid-ask spreads would swamp the floating point error. Floating point errors blow up when you divide. It's probably a bad idea by divide returns in any case because they can easily be 0.

To conclude

I wouldn't worry about this. Performance differences will be negligible and if they are not you should measure both. The floating point error shouldn't hurt, much better to focus on getting good data.

$\endgroup$
1
  • 1
    $\begingroup$ great answer, thanks! $\endgroup$ – HaroldFinch Feb 12 at 2:02
1
$\begingroup$

Any difference would be negligible. On the other hand, there are statistical advantages when calculating the log return. Remember that the log return is simply the log difference of the value / price from one day to the next. Log returns have some more favorable properties for statistical analysis than the simple net returns as shown by Quigley and Ramsey (2008), such as stationarity and ergodicity.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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