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

Generating order signals


In the trading strategy that we will define, we want to be able to decide whether there is enough movement in the volume of searches on debt to go and execute a trade in the market that will make us a profit. The paper defines this threshold as though there is a higher search volume at the end of a Google Trends week than in the previous three-week average of the search volume, and then we will go short. If there is a decline, we will go long the following week.

The first thing we will need to do is reorganize our data by moving the GoogleWE dates into the index. We are going to make our decisions based upon these week-ending dates and use the Close price in an associated record as the basis for our trade as that price represents the Close price at the beginning of the next week. We also drop the DJIAClose column as it is redundant with Close:

In [18]:
   base = final.reset_index().set_index('GoogleWE')
   base.drop(['DJIAClose'], inplace=True, axis=1)
   base[:3...