Book Image

Mastering Pandas for Finance

By : Michael Heydt
Book Image

Mastering Pandas for Finance

By: Michael Heydt

Overview of this book

Table of Contents (16 chapters)
Mastering pandas for Finance
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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  0.85225
   2011-02-26      NaN      NaN
   [373 rows x 2 columns]

At the end of our run of this strategy, we can see that we have made a profit. We now...