0

I am calculating a log return series for a study on financial data.

By the laws of logarithms log(p_t/p_t-1) is the same as log(p_t) - log(p_t-1).

I calculate two different series that should be the same...

r = log(price(2:end)) - log(price(1:(end - 1)));

r1 = log(price(2:end))./price(1:(end - 1));

Out of curiosity I decided to check:

r1 == r

and I get a TON of 0's in the result array.

Is there some reason for this? These two should be absolutely equivalent. I wouldn't think weird floating point things would be a problem here, and if they were a problem they'd effect both vectors equally.

What is going on here?

1 Answers1

0

Your parentheses are wrong in the second equation, but you will still get floating point differences.

r = log(price(2:end)) - log(price(1:(end - 1)));

r1 = log(price(2:end)./price(1:(end - 1)));
Alex
  • 75
  • 9