Comparison of two quotation charts with non-linear distortions on the X-axis - page 5

 
alsu: The mql code will probably not be long))

here seems to be the source code http://www.bytefish.de/blog/dynamic_time_warping

 
Well yes, it's short, but that's in the simplest version, and there are a few other improvements regarding the speed of the algorithm and consideration of constraints...
 
This one has implemented support for data dimensions up to and including 3, plus a lower bound estimation method and associated candidate path test (as I understand it, this is much cheaper than full DTW for dimensions >1, where the main method becomes a TK-complete problem and leads to exponential solution times)
 
There is an article about DTW on the Habrahabra site http://habrahabr.ru/blogs/algorithm/135087/, it seems to be very clear, but I can't figure out how to use DTW for OHLC, can anyone explain it to me?
 
IgorM:
There's an article about DTW on the Habrahabra site http://habrahabr.ru/blogs/algorithm/135087/, it seems to be very clear, but I can't figure out how to use DTW for OHLC, can anyone explain it to me?

Is it already done for one price?
 
Integer: Has it worked for one price yet?

It didn't work, it's not a problem to port the DTW source to mql, somehow:

//+------------------------------------------------------------------+
// create cost matrix
#define costmaxM 100
#define costmaxN 100
double cost[costmaxM][costmaxN];
int costM,costN; // текущая размерность cost
//+------------------------------------------------------------------+
double dist(double x, double y){
   return(MathSqrt(MathPow((x - y), 2)));
}
//+------------------------------------------------------------------+
int dtw(double &t1[],double &t2[]) {
// возвращаемое значение -1 ошибка
// +1 массив cost[][] заполнен правильно        
                int i,j;
                costM = ArraySize(t1);
                costN = ArraySize(t2);
                if(costM>=costmaxM || costN>=costmaxN)return(-1);

                cost[0][0] = dist(t1[0], t2[0]);
                // calculate first row
                for(i = 1; i < costM; i++)
                        cost[i][0] = cost[i-1][0] + dist(t1[i], t2[0]);
                // calculate first column
                for(j = 1; j < costN; j++)
                        cost[0][j] = cost[0][j-1] + dist(t1[0], t2[j]);
                // fill matrix
                for(i = 1; i < costM; i++)
                        for(j = 1; j < costN; j++)
                                cost[i][j] = MathMin(cost[i-1][j],MathMin(cost[i][j-1], cost[i-1][j-1])) + dist(t1[i],t2[j]);
 
return(1);//            return cost[m-1][n-1];
}
//+------------------------------------------------------------------+
The problem is that I don't understand how to use it, all I've understood is that with DTW you can fit different time periods (BP) to the same scale for subsequent analysis, but how... - don't understand
 
IgorM:

It didn't work, the DTW source itself is easy to port to mql, somehow:

the problem is that I don't understand how to use this, all I've understood is that with DTW you can fit different time sections (BPs) to the same scale for later analysis, but how... - don't understand


Tried it. Not sure how to use it either. Output should be either transformation path or transformed data. Let's say cost[][] is a distance matrix. But it gives a path with a return (if we look for the minimum value in each column), the condition "1. Monotonicity - the path never returns, i.e.: both indexes, i and j, which are used in the sequence, never decrease." Also, the path does not reach the opposite corner. In general, I don't really understand the meaning of all these manipulations with numbers when filling the cost[][] array - first the distances are simply counted and then they are added.

If we need to count distances between each element t1 and each element t2, then why should we perform so many calculations, if we need to fulfill condition "1. Monotonicity - the path never returns, that is: both indexes, i and j, used in the sequence, never decrease"?



.

 

DTW is completely unsuitable for the task at hand. DTW is used to recognize speech (words) in a real-time audio stream as follows (roughly):

  1. There is a pattern (word) - a sequence of data, of length N.
  2. There is an audio stream - a sequence of data, of length M >> N.
  3. From the audio stream the outermost pieces of data, of different length are selected (roughly).
  4. Each chunk is compared with a template by DTW.
  5. If the maximum DTW exceeds a certain threshold, it is considered that a word has been spoken.

So DTW is just a criterion for comparing two sequences of different length. Nothing more.

To search for words in audio history, DTW is not suitable at all, because it is very resource-intensive. For example, finding out how many times a word was said in the last hour, using DTW, is nearly impossible.

A quick solution to this problem is to use a fast algorithm to calculate Pearson's QC. In doing so, the DTW is converted each time by a ZigZag with different input parameters. Such an algorithm is very easy to parallelize and will work almost in real time when implemented using GPU.

Another question is why do we need it? No one has solved this task on a serious level. But I'm almost sure that after having solved it, there will be one more nail in the coffin of pattern theory's soundness.

The theory of patterns, as well as Elliott waves and Fibo is not a technocratic level of thinking.

 
hrenfx:

The DTW is totally unsuited to the task at hand...

Let's show you a working DTW first, then we can discuss what it fits and what it doesn't.
 

Something I made up myself, but I don't know, it's nonsense.

The yellow line, that's the orange one stretched over the red one.