This question is a continuation of this one.
My goal is to find the turning points in stock price data.
So far I:
Tried differentiating the smoothed price set, with the help of Dr. Andrew Burnett-Thompson using the centered five-point method, as explained here.
I use the EMA20 of tick data for smoothing the data set.
For each point on the chart I get the 1st derivative (dy/dx). I create a second chart for the turning points. Each time the dy/dx is between [-some_small_value] and [+some_small_value] - I add a point to this chart.
The problems are: I don't get the real turning points, I get something close. I get too much or too little points - depening on [some_small_value]
I tried a second method of adding a point when dy/dx turns from negative to positive, which also creates too many points, maybe because I use EMA of tick data (and not of 1 minute closing price)
A third method is to divide the data set into slices of n points, and to find the minimum and maximum points. This works fine (not ideal), but it's lagging.
Anyone has a better method?
I attached 2 pictures of the output (1st derivative and n points min/max)
You could take the second derivative into account, meaning you should additionally (to your first derivative) evaluate (y_{i-1} + y_{i+1} - 2y_i) / (dx)²
. If this is above a certain threshold you have a maximum, if it is below you have a minimum and else you can discard it. This should throw out a lot of points that you keep using your method of finding extrema (y' = 0
), because this condition is also valid for saddle points.