Computing simple and log returns

Returns measure the rate of change of (stock) prices. The advantage of using returns is that returns are dimensionless, so we can easily compare the returns of different financial securities. In contrast, the price of financial assets alone doesn't tell us much. In this chapter, we calculate daily returns because our data is sampled daily. With small adjustments, you should be able to apply the same analysis on different time frames.

In fact, there are various types of returns. For the purpose of basic analysis, we only need to know about simple (7.1) and log(arithmic) returns (7.2), as given by the following equations:

Computing simple and log returns

Actually these types of returns can easily be converted – from simple to log returns and back. Log returns are the ones you should prefer if you are given the choice, because they are easier to compute.

How to do it...

  1. The imports are as follows:
    import dautil as dl
    import ch7util
    import matplotlib.pyplot as plt
  2. Download data for the S&P 500 index:
    ohlc = dl.data.OHLC()
    sp500 = ohlc.get('^GSPC')['Adj Close']
    rets = sp500[1:]/sp500[:-1] - 1
  3. Plot the simple and log returns:
    _, ax = plt.subplots()
    cp = dl.plotting.CyclePlotter(ax)
    cp.plot(sp500.index, rets, label='Simple')
    cp.plot(sp500.index[1:], ch7util.log_rets(sp500), label='Log')
    ax.set_title('Simple and Log Returns')
    ax.set_xlabel('Date')
    ax.set_ylabel('Return')
    ax.legend(loc='best')

Refer to the following screenshot for the end result (the values of simple and log returns are very close):

How to do it...

The code for this recipe is in the simple_log_rets.ipynb file in this book's code bundle.

See also

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset