I'm an engineer with minimal to zero knowledge about economical topics, please be patient with me if the following question makes no sense or is too basic ...

Currently I'm working through the "Python Data Science Handbook" of Jake van der Plas. In the chapter about time series data there are several examples with financial numbers, in particular stock rates.

In one example he calculates the ROI out of a series of stock rates:

from pandas_datareader import data

# data_source google won't work anymore, use yahoo
goog = data.DataReader('GOOG', start='2004', end='2016',
goog = goog.asfreq('D', method='pad')
ROI = 100 * (goog.tshift(-365) / goog - 1)
plt.ylabel('% Return on Investment');

So, he divides data from one year ago with the current data, plus 1, times 100 (to get it into percent values).

For my understanding, the central formular is (with $f_0$ for the data from one year ago and $f_1$ for the current data):

$\frac{f_0}{f_1} - 1 \equiv \frac{f_0}{f_1} - \frac{f_1}{f_1} \equiv \frac{f_0 - f_1}{f_1} $

What I found when googling for ROI are especically the definitions from Wikipedia:

return on investment = Net income / Investment


return on investment = (gain from investment – cost of investment) / cost of investment


return on investment = (revenue − cost of goods sold) / cost of goods sold

Although the latter both definitions come quite close to the formular above, I'm unable to see the relationship between stock rates used in the data of the code example and the words used in the definitons from Wikipedia.

Can anyone help me to understand this a bit better, with a brief explanation or a hint where to continue reading on this topic?

Thanks and cheers Wolfgang

  • $\begingroup$ I'm not certain his maths is exactly right, but I assume that he is working out the return on buying a stock and keeping it for a year, i.e. $f_0$ = "cost of investment" and $f_1$ = "gain from investment" in the second WP definition you give. I would have thought $\frac{f_1 - f_0}{f_0}$ made more sense -- could it be a typo? $\endgroup$ – Dan Nov 8 '19 at 16:50

I agree with Dan it is likely a typo.

Some definitions (using your notations)

Investment : $f_0$

Investment one year later : $f_1$

Net income : $f_1 - f_0$

ROI: $-1 + \frac{f_1}{f_0}$

It follows that the correct code should be

ROI = (goog/goog.tshift(-365) -1)*100
| improve this answer | |
  • $\begingroup$ Putting aside that multiplying by $100$ boils down to considering that a percentage is a unit/constant, which is not to me. I mean: $0.01=1\%=10^{-2}$. But he does so probably only for the plot. $\endgroup$ – keepAlive Nov 10 '19 at 10:55

To understand the return formula, think of it this way: ROI is the effect/effort - 1. If you invest 100 dollars today, which is your effort, and one year later you have 105 dollars (effect), you get a 5% payoff.

| improve this answer | |

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.