Tuesday, 13 November 2012

Time series similarity

One of the things I have been working on in the last months are time series similarity algorithms. Why? In principle, most trading systems use past data to enter a trade. So for instance you use 5 technical indicators to enter the market. Or maybe you are using classical technical analysis: double top/bottom or head and shoulders as entry signals... Basically, you are trying to find chart patterns that occurred in the past and produced more profit then loss.

My idea is: let's take last X prices. And look in all the history for a given instrument what were the most similar X prices  in the past and what happened in the next Y prices. For example:
  • Let's look at last 500 open prices on 1 minute chart
  • Find the most similar 500 open prices in the historical data
  • Check whether the price risen or fallen in the next 200 bars
Of course the challenge is: how to find the most similar piece of data from the past. My initial idea was rather trivial: take two data series and calculate an euclidean distance in each data point. If all the distances would be the same it would mean that the series are identical. However this approach wouldn't be very robust in presence of noise or for time shifted data... 

So I implemented an algorithm called Dynamic Time Warping. It is a rather simple approach to determining time series similarity, but it gives good results for vast variety of different classes of time series data. I will not write about the algorithm itself, as it is well described in Internet. I tried two things (not going into calculation details):
  1. Finding one most similar pattern from the past. 
  2. Finding many similar patterns and seeing whether there was a consistent behavior in directly subsequent data.
When I created a simple trading system leveraging above as an entry signal results were confusing in both cases. Some combinations of input parameters  were profitable, but small modification of the parameters resulted in no profit at all...  I done all the tests on EURUSD 2006-2011 1-minute and 5-minute data which is very consistent in its characteristics. Of course I was normalizing each data point by subtracting mean  and dividing by the standard deviation of a given probe.

As for now I am parking this idea, even though I believe there is a lot of value in it... But to further explore it I would need to spent much more time to implement other similarity algorithms:
  • more precise on varied datasets,
  • much faster in calculation. 
If you want to spend some time on this, I would suggest continue reading here: http://www.eecs.umich.edu/db/files/sigmod07timeseries.pdf

No comments:

Post a Comment