Preface |
|
ix | |
|
1 Python and Algorithmic Trading |
|
|
1 | (16) |
|
|
1 | (6) |
|
Python Versus Pseudo-Code |
|
|
2 | (1) |
|
|
3 | (2) |
|
Pandas and the DataFrame Class |
|
|
5 | (2) |
|
|
7 | (4) |
|
Python for Algorithmic Trading |
|
|
11 | (2) |
|
|
13 | (1) |
|
|
13 | (2) |
|
|
14 | (1) |
|
|
14 | (1) |
|
|
14 | (1) |
|
Machine and Deep Learning |
|
|
15 | (1) |
|
|
15 | (1) |
|
References and Further Resources |
|
|
15 | (2) |
|
|
17 | (28) |
|
Conda as a Package Manager |
|
|
19 | (8) |
|
|
19 | (3) |
|
Basic Operations with Conda |
|
|
22 | (5) |
|
Conda as a Virtual Environment Manager |
|
|
27 | (3) |
|
|
30 | (6) |
|
Docker Images and Containers |
|
|
31 | (1) |
|
Building a Ubuntu and Python Docker Image |
|
|
31 | (5) |
|
|
36 | (7) |
|
RSA Public and Private Keys |
|
|
38 | (1) |
|
Jupyter Notebook Configuration File |
|
|
38 | (2) |
|
Installation Script for Python and Jupyter Lab |
|
|
40 | (1) |
|
Script to Orchestrate the Droplet Set Up |
|
|
41 | (2) |
|
|
43 | (1) |
|
References and Further Resources |
|
|
44 | (1) |
|
3 Working with Financial Data |
|
|
45 | (36) |
|
Reading Financial Data From Different Sources |
|
|
46 | (6) |
|
|
46 | (1) |
|
Reading from a CSV File with Python |
|
|
47 | (2) |
|
Reading from a CSV File with pandas |
|
|
49 | (1) |
|
Exporting to Excel and JSON |
|
|
50 | (1) |
|
Reading from Excel and JSON |
|
|
51 | (1) |
|
Working with Open Data Sources |
|
|
52 | (3) |
|
|
55 | (10) |
|
Retrieving Historical Structured Data |
|
|
58 | (4) |
|
Retrieving Historical Unstructured Data |
|
|
62 | (3) |
|
Storing Financial Data Efficiently |
|
|
65 | (12) |
|
Storing DataFrame Objects |
|
|
66 | (4) |
|
|
70 | (5) |
|
Storing Data with SQLite3 |
|
|
75 | (2) |
|
|
77 | (1) |
|
References and Further Resources |
|
|
78 | (1) |
|
|
78 | (3) |
|
4 Mastering Vectorized Backtesting |
|
|
81 | (42) |
|
Making Use of Vectorization |
|
|
82 | (6) |
|
|
83 | (2) |
|
Vectorization with pandas |
|
|
85 | (3) |
|
Strategies Based on Simple Moving Averages |
|
|
88 | (10) |
|
|
89 | (8) |
|
Generalizing the Approach |
|
|
97 | (1) |
|
Strategies Based on Momentum |
|
|
98 | (9) |
|
|
99 | (5) |
|
Generalizing the Approach |
|
|
104 | (3) |
|
Strategies Based on Mean Reversion |
|
|
107 | (4) |
|
|
107 | (3) |
|
Generalizing the Approach |
|
|
110 | (1) |
|
Data Snooping and Overfitting |
|
|
111 | (2) |
|
|
113 | (1) |
|
References and Further Resources |
|
|
113 | (2) |
|
|
115 | (1) |
|
|
115 | (3) |
|
Momentum Backtesting Class |
|
|
118 | (2) |
|
Mean Reversion Backtesting Class |
|
|
120 | (3) |
|
5 Predicting Market Movements with Machine Learning |
|
|
123 | (52) |
|
Using Linear Regression for Market Movement Prediction |
|
|
124 | (15) |
|
A Quick Review of Linear Regression |
|
|
125 | (2) |
|
The Basic Idea for Price Prediction |
|
|
127 | (2) |
|
|
129 | (3) |
|
Predicting Future Returns |
|
|
132 | (2) |
|
Predicting Future Market Direction |
|
|
134 | (1) |
|
Vectorized Backtesting of Regression-Based Strategy |
|
|
135 | (2) |
|
Generalizing the Approach |
|
|
137 | (2) |
|
Using Machine Learning for Market Movement Prediction |
|
|
139 | (14) |
|
Linear Regression with scikit-learn |
|
|
139 | (2) |
|
A Simple Classification Problem |
|
|
141 | (5) |
|
Using Logistic Regression to Predict Market Direction |
|
|
146 | (4) |
|
Generalizing the Approach |
|
|
150 | (3) |
|
Using Deep Learning for Market Movement Prediction |
|
|
153 | (13) |
|
The Simple Classification Problem Revisited |
|
|
154 | (2) |
|
Using Deep Neural Networks to Predict Market Direction |
|
|
156 | (6) |
|
Adding Different Types of Features |
|
|
162 | (4) |
|
|
166 | (1) |
|
References and Further Resources |
|
|
166 | (1) |
|
|
167 | (8) |
|
Linear Regression Backtesting Class |
|
|
167 | (3) |
|
Classification Algorithm Backtesting Class |
|
|
170 | (5) |
|
6 Building Classes for Event-Based Backtesting |
|
|
175 | (26) |
|
|
177 | (5) |
|
Long-Only Backtesting Class |
|
|
182 | (3) |
|
Long-Short Backtesting Class |
|
|
185 | (5) |
|
|
190 | (1) |
|
References and Further Resources |
|
|
190 | (1) |
|
|
191 | (10) |
|
|
191 | (3) |
|
Long-Only Backtesting Class |
|
|
194 | (3) |
|
Long-Short Backtesting Class |
|
|
197 | (4) |
|
7 Working with Real-Time Data and Sockets |
|
|
201 | (22) |
|
Running a Simple Tick Data Server |
|
|
203 | (3) |
|
Connecting a Simple Tick Data Client |
|
|
206 | (2) |
|
Signal Generation in Real Time |
|
|
208 | (3) |
|
Visualizing Streaming Data with Plotly |
|
|
211 | (6) |
|
|
211 | (1) |
|
|
212 | (2) |
|
Three Sub-Plots for Three Streams |
|
|
214 | (1) |
|
|
215 | (2) |
|
|
217 | (1) |
|
References and Further Resources |
|
|
218 | (1) |
|
|
218 | (5) |
|
|
218 | (1) |
|
|
219 | (1) |
|
Momentum Online Algorithm |
|
|
219 | (1) |
|
Sample Data Server for Bar Plot |
|
|
220 | (3) |
|
|
223 | (26) |
|
|
227 | (2) |
|
|
229 | (1) |
|
Retrieving Historical Data |
|
|
230 | (6) |
|
Looking Up Instruments Available for Trading |
|
|
230 | (1) |
|
Backtesting a Momentum Strategy on Minute Bars |
|
|
231 | (3) |
|
Factoring In Leverage and Margin |
|
|
234 | (2) |
|
Working with Streaming Data |
|
|
236 | (1) |
|
|
237 | (2) |
|
Implementing Trading Strategies in Real Time |
|
|
239 | (5) |
|
Retrieving Account Information |
|
|
244 | (2) |
|
|
246 | (1) |
|
References and Further Resources |
|
|
247 | (1) |
|
|
247 | (2) |
|
|
249 | (16) |
|
|
251 | (1) |
|
|
251 | (5) |
|
|
252 | (2) |
|
|
254 | (2) |
|
|
256 | (7) |
|
Retrieving Historical Data |
|
|
257 | (2) |
|
Retrieving Streaming Data |
|
|
259 | (1) |
|
|
260 | (2) |
|
|
262 | (1) |
|
|
263 | (1) |
|
References and Further Resources |
|
|
264 | (1) |
|
10 Automating Trading Operations |
|
|
265 | (44) |
|
|
266 | (11) |
|
Kelly Criterion in Binomial Setting |
|
|
266 | (6) |
|
Kelly Criterion for Stocks and Indices |
|
|
272 | (5) |
|
ML-Based Trading Strategy |
|
|
277 | (14) |
|
|
278 | (7) |
|
|
285 | (2) |
|
|
287 | (3) |
|
Persisting the Model Object |
|
|
290 | (1) |
|
|
291 | (5) |
|
Infrastructure and Deployment |
|
|
296 | (1) |
|
|
297 | (2) |
|
Visual Step-by-Step Overview |
|
|
299 | (5) |
|
Configuring Oanda Account |
|
|
299 | (1) |
|
|
300 | (1) |
|
Setting Up the Python Environment |
|
|
301 | (1) |
|
|
302 | (1) |
|
|
302 | (2) |
|
|
304 | (1) |
|
|
304 | (1) |
|
References and Further Resources |
|
|
305 | (1) |
|
|
305 | (4) |
|
Automated Trading Strategy |
|
|
305 | (3) |
|
|
308 | (1) |
Appendix. Python, NumPy, matplotlib, pandas |
|
309 | (42) |
Index |
|
351 | |