Newbie question whats np.log (logarithm) used to calculate / indicate?
Newbie question whats np.log (logarithm) used to calculate / indicate?
The 'np.log' method returns the natural log of a given parameter ( see the numpy docs https://docs.scipy.org/doc/numpy/reference/generated/numpy.log.html )
This is often used to get log returns rather than arithmetic returns. A problem with 'arithmetic' returns is they cannot be added or averaged. Consider the case of a -10% return followed by a +10%. The net return is not 0%. However log(1-.1) + log(1+.1) (ie the log returns) gives -.105+.095 = -.01 which is a small loss and is correct. See this post for some more info https://www.quantopian.com/posts/log-normal-return-built-in-factor .
I believe the question is in regard to this algorithm https://www.quantopian.com/posts/long-only-mean-reversion-for-robinhood-users-100000-percent-returns . The code used in the algorithm and shown below gets the log return.
arithmetic_returns = prices/prices.shift(1) - 1
log_returns = np.log(1+arithmetic_returns)
# or...
log_returns = np.log(prices/prices.shift(1))