Which machine learning or deep learning model(has to be supervised learning) will be best suited for recognizing patterns in financial markets ?

What I mean by pattern recognition in financial market : Following Image shows how a sample pattern (i.e. Head and shoulder) looks like:

Image 1:

Prototype of Head and Shoulder Pattern

And Following Image shows how it actually forms in real chart events:

Image 2:

Head and Shoulder in real chart events

What I'm trying to do is: Any pattern similar to Image 1 can be defined as Head and Shoulder Pattern but in a Chart (Price Chart) it will not form as clearly as Image 1. Image 2 is the sample of Head and Shoulder Pattern form in Chart (Price Chart). As it seems in Image 2, it can not be identified as Head and Shoulder Pattern by normal algorithms or analysis (Because there are a lot of highers and low forming a lot of structure, which can easily mislead into a lot of shoulders or head or any other structures). I'm expecting to train machine to recognize the Head and Shoulder Pattern when similar (as Image 2) pattern is formed.

Thank you for your time.

Let me know if I'm taking it to wrong way. I only have beginners knowledge on Machine Learning.

  • 1
    $\begingroup$ So you want a binary classifier (bearish vs. bullish)? Hang out here: quant.stackexchange.com $\endgroup$
    – Emre
    Jan 16 '17 at 18:49
  • $\begingroup$ My intention was to recognize above pattern in chart. Data used in chart can be any type of data (in example it is stock market data). I should have used more clean picture of chart. $\endgroup$ Jan 16 '17 at 19:42
  • $\begingroup$ @SurajNeupane The question is a bit unclear, please elaborate more. based on what you have mentioned, I'm thinking you can create features on a moving window and treat it as a supervised classification problem. $\endgroup$
    – iratzhash
    Jan 16 '17 at 19:56
  • $\begingroup$ I Apologize if I mislead you. I have elaborated more on the topic. Let me know if it is still unclear, I will think of another way to explain. $\endgroup$ Jan 17 '17 at 7:28
  • $\begingroup$ Did you succeed in this project? Interested to know where this ended up. $\endgroup$ Feb 10 at 14:29

These are some suggestions that might be useful.

  1. The data on the curve are bumpier than the roads in my country. So I think you should start by smoothing the curve. There are many smoothing filters like from the simplest median smoothing to Local Regression models like LOESS. There are some parameters to tweak. Take a look at the example.
  2. Finding the local maxima. Python's numpy has an implementation for this and this should help.

My idea is to basically smooth till you get your head and shoulders i.e., three maxima.

Warning: Smoothing though reduces the amount of noise (not in literal noise sense) on the curve, it tends to shift the curve from its original position to represent it.

A sample Python implementation will be like

from statsmodels.nonparametric.smoothers_lowess import lowess
import numpy as np
from scipy.signal import argrelextrema
import matplotlib.pyplot as plt
sample_points =  np.array([1,2.3,3.5,3,4.5,5,2.25,33.3,5,6.7,7.3,56.0,70.1,4.2,5.4,6.2,4.4,100,2.9,45,10,3.4,4.8,50,2.3,3.45,5.5,6.7,7.9,8.7,6.1])
for i in np.arange(0,0.5,0.05):
    # i in the loop is the percentage of data points we are inputing for the loess regression. Wiki atricle explains it, I guess
    filtered = lowess(sample_points,range(len(sample_points)), is_sorted=True, frac=i, it=0)
    maxima = argrelextrema(filtered[:,1], np.greater)
    if len(maxima[0]) == 3:

I hope this kind of gives the direction of where you might need some checking.

  • $\begingroup$ sample_points = np.array([1,2.3,3.5,3,4.5,5,2.25,33.3,5,6.7,7.3,56.0,70.1,4.2,5.4,6.2,4.4,100,2.9,45,10,3.4,4.8,50,2.3,3.45,5.5,6.7,7.9,8.7,6.1]) plt.plot(lowess(sample_points,range(len(sample_points)), is_sorted=True, frac=0.2, it=0),'b-'); plt.show(); This is very close to the pattern. I wanted to train this pattern so when it actually appear in chart, it will be recognized. Is that possible ? $\endgroup$ Jan 18 '17 at 15:36
  • $\begingroup$ @SurajNeupane Yes, That can be done by Dynamic Time Warping. But since there is no specific pattern on when your left and right shoulder and they might occur at any time point on the curve, I suggested finding maxima after smoothing. $\endgroup$ Jan 18 '17 at 16:00

You should look at a classifier based on Dynamic Time Warping (DTW) distance. DTW is a method that calculates an optimal match between two given sequences (e.g. time series). It has been used in a supervised learning setup, in particular it has been reported to achieved state of the art results, when used in a nearest neighbour classifier.


Have you seen this thesis? The author uses DTW to identify a collection of chart patterns.


It would seem you could mimic the pattern using percentages. About how high does the two shoulders come within the peak?(head) should the two shoulders be even what is even? Perfect or do give slight difference what is this slight difference. Finding the answer may come after studying charts to see what the percentages of successful patterns were. Then mimicking this.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.