nd edition
Python for finance and algorithmic trading
Lucas INGLESE
Disclaimer: I am not authorized by any financial authority to give investment advice. This book is for educational purposes only. I disclaim all responsibility for any loss of capital on your part. Moreover, 78.18% of private investors lose money trading CFD. Using the information and instructions in this work is at your own risk. Suppose any code samples or other technologies this work contains or describes are subject to open-source licenses or the intellectual property rights of others. In that case, your responsibility is to ensure that your use thereof complies with such licenses and rights. This book is not intended as financial advice. Please consult a qualified professional if you require financial advice. Past performance is not indicative of future performance.
WARNINGS: Any partial or complete reproduction without the author's consent may result in legal action.
A question to ask the author? Section 1.3 "Join the community
Table of contents
Why should you read this book?
The financial sector is undergoing significant restructuring. Traders and portfolio managers are increasingly becoming financial data scientists. Banks, hedge funds, and fintech are automating their investments by integrating machine learning and deep learning algorithms into their decision-making process. This book presents the benefits of portfolio management, statistics, and machine learning applied to live trading with MetaTrader 5.
Part 1 is dedicated to portfolio management, risk management, and back testing. These chapters will allow us to understand how to combine strategies and which metrics to look at to understand the strategy robustness.
Part 2 discusses statistical predictive models . We will discuss the statistical arbitrage and autoregressive moving average (ARMA) model and introduce the classification algorithms through logistic regression.
Part 3 gives us an understanding of Machine Learning and Deep Learning predictive models . We will see these algorithms using trading strategies example: Support Vector Machines (SVM), decision tree, random forest, ensemble methods, Artificial Neural Network (ANN), Recurrent Neural Network (RNN), Recurrent Convolutional Neural Network (RCNN)
The book ends with a concrete project from A to Z: Importing data from your broker, creating a portfolio of trading strategies, deployment in live trading, or using a screener.
Who am I?
I am Lucas, an independent quantitative trader specializing in Machine learning and data science and the founder of Quantreo, an algorithmic trading E-learning website ( www.quantreo.com ).
I graduated in mathematics and economics from the University of Strasbourg (France). I already help more than 56.000 students through my online courses and YouTube channel dedicated to algorithmic trading.
I have a quantitative trading approach, combining predictive models, financial theory, and stochastic calculus.
To show you some realistic results, you can see the profit of my last portfolio of strategies in live trading: 2.5% of return for a 0.6% drawdown without leverage in 1 month and a half.
Figure 1: My last live trading signal on BullTrading
You can see one of my last signals on BullTrading (bulltrading.be), a copy trader platform. This strategy is based on machine learning and quantitative analysis (the same as in the book).
Chapter 1: Read me
1.1. Find the code
All the resources in the book are available on the GitHub repository ( https://github.com/Quantreo/2nd-edition-BOOK-AMAZON-Python-for-Finance-and-Algorithmic-Trading ). If there is an issue with this link or something else related to the code, contact us using the contact page www.quantreo.com .
Before reading this book, you should download Jupyter Notebook using Anaconda Navigator ( https://www.anaconda.com ). In Chapter 01, you can find a notebook that installs all the necessary libraries for the book. All the additional readings can be found on the README.md file on the repository Github.
1.2. Join our community
Follow us on social media to obtain the latest algorithmic trading information, tips, and ready-to-use strategies. Moreover, join the discord forum of the community to ask any questions about the book to read it easily!
Linktree QRCODE
Chapter 2: Prerequisites
This chapter discusses the necessary prerequisites to understand this book thoroughly. First, we will discuss some math, statistics, algebra, and optimization basics. Then, the leading financial theories and the Python basics are mandatory to implement our trading strategies.
2.1. Mathematical prerequisites
This section aims to detail many mathematical terms and concepts necessary for the book's whole comprehension. However, it is not complete math for the finance course. We will cover some introductory algebra, statistics, and optimization.
2.1.1. Algebra
Algebra is a significant field to know when we work in finance. Indeed, we will work with matrices all the time because it is the heart of algebra. Thus, it is required to understand the basics about them.
There are many theories about matrices in math, more complex than others, but for us, it will be straightforward: a matrix will be a set of data. Let us see an example of a matrix A with shape ( n,m ), where m is the number of columns and n is the number of rows in the matrix.
We can imagine that matrix A with a shape of (3,2) will give us the daily return of some assets. Usually, the rows will be the days, and the columns represent the assets. Thus, the matrix has two assets and three daily returns for each.
There are many essential operations that we can apply to a matrix. Let us see some of them:
- Addition : we need matrices with the same shape to add them. Then, we must add matrix A's coefficients to matrix B's coefficients, one by one. Let us take an example to explain.
- Subtraction : We need matrices with the same shape to add them. Then, we must subtract the coefficients of matrix A from the coefficients of matrix B, one by one. Let us take an example to explain.
- Scalar multiplication : We multiply each coefficient by the scalar (just a number). Let us take an example to explain.
The three previous operations are the basic operations between matrices but exist more complex operations like inverse, comatrix, and transpose. Thankfully, we only need to know the transpose matrix for the rest of this book. Suppose each matrix coefficient is noted where is the row number and
Next page