Skip to Content
Learn Algorithmic Trading
book

Learn Algorithmic Trading

by Sebastien Donadio, Sourav Ghosh
November 2019
Beginner content levelBeginner
394 pages
10h 31m
English
Packt Publishing
Content preview from Learn Algorithmic Trading

Naive trading strategy

In this section, we will implement a naive strategy based on the number of times a price increases or decreases. This strategy is based on the historical price momentum. Let's have a look at the code:

def naive_momentum_trading(financial_data, nb_conseq_days):     signals = pd.DataFrame(index=financial_data.index)     signals['orders'] = 0     cons_day=0     prior_price=0     init=True     for k in range(len(financial_data['Adj Close'])):         price=financial_data['Adj Close'][k]         if init:             prior_price=price             init=False         elif price>prior_price:             if cons_day<0:                 cons_day=0             cons_day+=1         elif price<prior_price:             if cons_day>0:                 cons_day=0             cons_day-=1         if cons_day==nb_conseq_days:             signals['orders'][k]=1         elif cons_day == -nb_conseq_days:             signals['orders'][k]=-1 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

High-Frequency Trading: A Practical Guide to Algorithmic Strategies and Trading Systems

High-Frequency Trading: A Practical Guide to Algorithmic Strategies and Trading Systems

Irene Aldridge
Developing High-Frequency Trading Systems

Developing High-Frequency Trading Systems

Sebastien Donadio, Sourav Ghosh, Romain Rossier

Publisher Resources

ISBN: 9781789348347Supplemental Content