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:
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.
import dautil as dl import ch7util import matplotlib.pyplot as plt
ohlc = dl.data.OHLC() sp500 = ohlc.get('^GSPC')['Adj Close'] rets = sp500[1:]/sp500[:-1] - 1
_, 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):
The code for this recipe is in the simple_log_rets.ipynb
file in this book's code bundle.