Tag Archives: Machine learning

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

Learn a metric oriented classifier

Objective function is the mathematical formulation of how to estimate classifier parameters. The classical objective function is derived from maximal log-likelihood function on training samples for the proposed classifier. Classifier parameters are estimated by solving the objective function. But log-likelihood is not directly related to performance metric, e.g. training on likelihood, and preferred evaluation metric maybe F1, accuracy or ranking. This criteria gap between training and evaluating causes the classifier trained on log-likelihood is not optimal for F1 , classification error or ranking. This is the intention of our work on MFoM based classifier learning. Updated the work on https://aisengtech.com/project#mfom. Hereafter MFoM, there are many research papers on learning classifier for specified metric in research community, in which learn-to-rank is most famous, and learn-to-rank is now a core module for modern search engine.