How to build machine learning model to generate trading signal
Recently I am working on how to build machine learning model to predict signal and build a winning strategy. Technical traders will read the price trending curve and use many technical analysis based signal to facilitate strategy operation such as bollinger band, macd, etc. But it is post analysis based on history, not having prediction power. I use the target stock history price sequence with the selected other security, they work together to extract statistics of price moving in different look-back window. Then I collect a set of feature samples and label the sample as buy, sell, and hold, a 3-category classification problem.
In general, the overall processing flow as follows:
- Download selected target stock history price and other selected stocks to enrich the target stock price
- Feature engineering, e.g. extract n-look-back day statistics. I do not directly use price as feature because it depends on actual price, sensitive to price scale, and difficult to scale to other tasks
- Label sample as buy, hold and sell using selected criterio
- Develop machine learning model
- Split data into train, development, and evaluation along the time
- Model training and optimization based on development set
- Predict buy, sell and hold signal in evaluation set. Save prediction to file for following analysis
- Based on predict signal, use backtrader, https://www.backtrader.com/, to backtest performance of the machine learning based strategy
Some thinking:
- Use extra-security price improving prediction power
- Even a little increase in prediction accuracy, e.g. 1%, will see gain increase & sharpe ratio improvement
- Feature engineering is very important
- Next step:
- strategy needs further improvement.
- post-processing predicted signal to increase stability
- need adding capital management.
I have no finance & trading experience. It is just a personal development to investigate if my ML & system experience can work in the domain. Welcome discussion or leave comments if you are interested.
backtest performce on APPLE.




backtest on TQQQ


Signal to suggest operation next day
