O'Reilly logo

Mastering pandas for Finance by Michael Heydt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Cumulative returns and the result of the strategy

We now have all the weekly returns based upon our strategy. We can calculate the overall net percentage return of the investments at the end by applying the cumulative product of 1 + base.ret0 (the return of each week) and then subtracting 1 from the cumulative product:

In [23]:
   base['cumret0'] = (1 + base.ret0).cumprod() - 1
   base['cumret1'] = (1 + base.ret1).cumprod() - 1
   base[['cumret0', 'cumret1']]

Out[23]:
               cumret0  cumret1
   GoogleWE                    
   2004-01-10  0.00000  0.00000
   2004-01-17  0.00000  0.00000
   2004-01-24  0.00000  0.00000
   2004-01-31 -0.00760 -0.00760
   2004-02-07  0.00515  0.00515
   ...             ...      ...
   2011-01-29  2.70149  0.84652
   2011-02-05  2.73394  0.86271
   2011-02-12  2.71707  0.85430
 2011-02-19 2.72118 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required