Chapter 1: Algorithmic Trading Fundamentals 7

Why are we trading? 8

Basic concepts regarding the modern trading setup 8

Market sectors 9

Asset classes 10

Basics of what a modern trading exchange looks like 12

Understanding algorithmic trading concepts 13

Exchange order book 14

Exchange matching algorithm 14

FIFO matching 15

Pro-rata matching 15

Limit order book 16

Exchange market data protocols 16

Market data feed handlers 17

Order types 17

IOC – Immediate Or Cancel 17

GTD – Good Till Day 17

Stop orders 17

Exchange order entry protocols 18

Order entry gateway 18

Positions and profit and loss (PnL) management 18

From intuition to algorithmic trading 19

Why do we need to automate trading? 19

Evolution of algorithmic trading – from rule-based to AI 20

Components of an algorithmic trading system 22

Market data subscription 23

Limit order books 23

Signals 24

Signal aggregators 24

Execution logic 24

Position and PnL management 25

Risk management 26

Backtesting 26

Why Python? 27

Choice of IDE – Pycharm or Notebook 28

Section 2: Trading Signal Generation and Strategies

Chapter 2: Deciphering the Markets with Technical Analysis 39

Designing a trading strategy based on trend- and momentum-based

indicators 40

Support and resistance indicators 40

Creating trading signals based on fundamental technical analysis 47

Simple moving average 47

Implementation of the simple moving average 48

Exponential moving average 49

Implementation of the exponential moving average 51

Absolute price oscillator 53

Implementation of the absolute price oscillator 53

Moving average convergence divergence 55

Implementation of the moving average convergence divergence 56

Bollinger bands 59

Implementation of Bollinger bands 60

Relative strength indicator 62

Implementation of the relative strength indicator 63

Standard deviation 66

Implementing standard derivatives 66

Momentum 68

Implementation of momentum 69

Implementing advanced concepts, such as seasonality, in trading

instruments 71

Summary 79

Chapter 3: Predicting the Markets with Basic Machine Learning 80

Understanding the terminology and notations 81

Exploring our financial dataset 84

Creating predictive models using linear regression methods 87

Ordinary Least Squares 87

Regularization and shrinkage – LASSO and Ridge regression 93

Decision tree regression 94

Creating predictive models using linear classification methods 95

K-nearest neighbors 95

Support vector machine 98

Section 3: Algorithmic Trading Strategies

Chapter 4: Classical Trading Strategies Driven by Human Intuition 102

Creating a trading strategy based on momentum and trend

following 103

Examples of momentum strategies 104

Python implementation 104

Dual moving average 104

Naive trading strategy 107

Turtle strategy 109

Creating a trading strategy that works for markets with reversion

behavior 111

Examples of reversion strategies 112

Creating trading strategies that operate on linearly correlated

groups of trading instruments 112

Summary 130

Chapter 5: Sophisticated Algorithmic Strategies 131

Creating a trading strategy that adjusts for trading instrument

volatility 132

Adjusting for trading instrument volatility in technical indicators 132

Adjusting for trading instrument volatility in trading strategies 133

Volatility adjusted mean reversion trading strategies 134

Mean reversion strategy using the absolute price oscillator trading signal 134

Mean reversion strategy that dynamically adjusts for changing volatility 144

Trend-following strategy using absolute price oscillator trading signal 148

Trend-following strategy that dynamically adjusts for changing volatility 153

Creating a trading strategy for economic events 155

Economic releases 156

Economic release format 157

Electronic economic release services 157

Economic releases in trading 158

Understanding and implementing basic statistical arbitrage trading

strategies 161

Basics of StatArb 161

Lead-lag in StatArb 162

Adjusting portfolio composition and relationships 162

Infrastructure expenses in StatArb 163

StatArb trading strategy in Python 164

StatArb data set 164

Defining StatArb signal parameters 166

Defining StatArb trading parameters 167

Quantifying and computing StatArb trading signals 168

StatArb execution logic 172