Algorithmic Trading Python

LSTM Long Regression Strategy for Algorithmic Trading

After my first video on LSTM’s long strategy on algorithmic trading, i got a feedback to try out the regression instead of classification. In this tutorial, i will show the result of experiment with LSTM regression loing strategy. I also found that the rolling scaling has a big impact on the performance. Increasing the rolling window seem to increase more trades in the testing data.
The first few steps are identical to my previous video, so I will not repeat there here.
I have increased  the rolling scaling window to 8 months to take in account of the non-stationary nature of the time series. Let me know if this make sense. 
Since this is the regression model, my target is not categorical labels of 1 and 0, but instead my target is the next day returns.
To change to a regression model, i change the output layer to a linear activation function and the loss function to mse. 
I trained the model with 200 epochs and got a decent loss vs epochs curve showing the LSTM model is learning from the data. 
I compute the signal to be taking a long position  if the predicted return is positive and no position if the predicted return is negative. 
I am able to get a lot more trades in the training and testing dataset.
I have a comparable equity curve as compared to bnh benchmark. The Sharpe ratio has improved to 0.89 and a max drawdown of -49%. 

The code can be downloaded below
https://github.com/tertiarycourses/Algorithmic-Trading/blob/main/lstm-long-regression-strategy.ipynb

Recommended trading platforms

MooMoo https://j.moomoo.com/00i5px

Recommended courses on Algorithmic Trading

1. Basic Algorithmic Trading with Python
https://www.tertiarycourses.com.sg/python-algorithmic-trading-course.html https://www.tertiarycourses.com.my/python-quantitative-analysis-and-algorithmic-trading-malaysia.html
https://www.tertiarycourses.com.gh/python-quantitative-analysis-and-algorithmic-trading-ghana.html

2. Machine Learning for Algorithmic Trading
https://www.tertiarycourses.com.sg/machine-learning-for-algorithmic-trading.html https://www.tertiarycourses.com.my/machine-learning-for-algorithmic-trading-malaysia.html https://www.tertiarycourses.com.gh/machine-learning-for-algorithmic-trading-ghana.html

Other training courses from Tertiary Courses

https://www.tertiarycourses.com.sg/
https://www.tertiarycourses.com.my/
https://www.tertiarycourses.com.gh/

June 12, 2022