Understanding AI Pattern Recognition for Trading

Understanding AI Pattern Recognition for Trading

Pattern Detection

Let's open this discussion with the following question: How can you detect patterns in trade data and use these to automate decisions for trading? Traditionally traders have used indicators and patterns in a price time series to find trading opportunities through technical analysis of stock charts. New deep learning methods have made it possible to extract complex relationships in the price and volume movements that are differentiated from some of these traditional methods and can provide advantageous new signals. Traders look for price patterns that signal changes in the market's trend, and then execute trades based on these signals. AI can process vast amount of data to recognize patterns and trends that can inform trading decisions which a human might not be able to detect. AI is transforming many areas especially with automation, and some places have already started to incorporate these new techniques into their platforms.

There are a plethora of patterns that can be programmatically defined and identified including Head and Shoulders, Cup and Handle, Double Top/Bottom, and Triangle that indicate bullish or bearish market sentiments. You can write a machine learning program to find these patterns on a price series and report how often the market had a swing in a positive or negative direction and the size of that movement, and the duration of that trend for a swing style strategy.


You can generate a frequency report of how often these patterns were detected, but need to determine which do a better job at predicting trends in a positive or negative direction. I offer a few illustrations in the slide below.



Back Testing

A back-test is a way to consolidate indicators together into a strategy with buy and sell signals. In this rather simplistic example below, I will discuss how you can add a pattern into a back-test.

  • Identify the pattern: Identify and define the pattern you want to test including candlestick formations, price relationships and any relevant time frame considerations.
  • Translate pattern into code: Write code that can recognize the pattern within the historical data by checking for specific price conditions across multiple candlesticks. You can write code for several patterns and test them all for which are more performant.
  • Set entry and exit conditions: Determine how you will enter the trade and when you will exit dependent on the price action. For example, you can automate a stop-loss conditions in case the market move against you, or profit taking when you are in the money.
  • Implement in your back-testing platform: Some trading platforms have built-in functions to id candlestick patterns or allow custom coding to implement your pattern recognition logic. I will discuss some of these later, but packages like Quantstrat provides a generic infrastructure to model and backtest signal-based quantitative strategies on trade data allowing for a more custom approach. https://github.com/braverock/quantstrat
  • Considerations:

  1. "Pattern reliability" Not all patterns are equally reliable, so it is important to analyze historical data to assess the pattern's accuracy in predicting price movements in your asset's class over a considerable amount of time to see the accuracy of the pattern.
  2. "Execution" Back testing platforms often assume you will get execution after a pattern signal, but that is far from the case in production, subject to matching algorithms and queue allocations like FIFO.

Back Testing -- A Simple Example

Bullish Engulfing pattern -- A bullish engulfing pattern happens when the current candlestick's real body completely engulfs the previous candlestick's body, with the current candle closing higher than the previous candle's high, and opening lower than the previous candle's low. Here is a visual of the pattern:

You can add this signal as a buy event with a profit taking condition to see cumulative P&L, drawdowns including max drawdown, and other factors like Sharpe Ratio. During algo trading back-testing, a higher Sharpe Ratio indicates that a strategy is providing more return per unit of risk, making it a crucial metric for comparing different strategies or pattern indicators. There are various visuals and reports that are available to see the buy and sell events in your historical data:


New Methods: Increasing Pattern Complexity and LSTM for Price Predictions

In recent years, LSTMs have been proposed as alternative ways to create price predictions on stock price series data with ongoing research on their effectiveness. A "lagged LSTM price prediction" refers to using a Long Short-Term Memory (LSTM) neural network to predict future prices of a financial asset by incorporating past price data at specific lagged time intervals as input into the model, allowing it to capture complex relationships and trends within the time series data. This has been a controversial topic, so I discuss how this is done on a high level and some initial first readings.

Lag Feature engineering: Before feeding data to the LSTM, the historical data is transformed into lagged features, meaning you create new features by shifting the original price data by a certain number of time steps (for example, daily and weekly shifts). Those that are familiar with ARIMA models might be familiar with how to create these, and you can compare to see which one performed better.

Why LSTM?

  • Handle sequential data and solve the vanishing gradient problem known in other neural nets and retain information that it saw previously. In this way, LSTMs have the potential to learn long term dependencies within sequential data making them capable of capturing the intricate relationships and patterns between lagged price points.
  • Capturing complex patterns. LSTMs can identify non-linear relationships and complex patterns that are stored in an elaborate neural net leading to detecting new complex patterns that humans can detect. These are similar to the neural nets that can do facial recognition, and can process many features of your face all at once.

Businesses that are Incorporating Pattern Detection for Day Traders

Many places are incorporating AI and sophisticated methods for pattern detection and algo development which is making it easier to develop strategies, and evaluate results. Some examples are provided below.

Tickeron -- AI powered stock forecast tools -- https://tickeron.com

Trendspider -- Train predictive AI-based trading models -- https://trendspider.com

Meet Composer -- Build trading algorithms with AI, backtest them, then execute—all in one platform. https://www.composer.trade/

Enjoy and happy back-testing. I have a presentation from which some of the images are taken on this that breaks this into simple and easier to understand ideas. Ask for more info.





要查看或添加评论,请登录

Helena Ristov的更多文章

社区洞察

其他会员也浏览了