Machine learning in trading: theory, models, practice and algo-trading - page 253

 

From the "interesting things" column ))

DTW algorithm

Imagine that you need to find some equal parts of the price in the series, but since the price is not stationary of course because of this property the size of these parts will be different, how to be in this case?

I know two possible solutions - interpolation and dwt algorithm, I'm playing with the last one very closely now

про dwt - https://ru.wikipedia.org/wiki/%D0%90%D0%BB%D0%B3%D0%BE%D1%80%D0%B8%D1%82%D0%BC_%D0%B4%D0%B8%D0%BD%D0%B0%D0%BC%D0%B8%D1%87%D0%B5%D1%81%D0%BA%D0%BE%D0%B9_%D1%82%D1%80%D0%B0%D0%BD%D1%81%D1%84%D0%BE%D1%80%D0%BC%D0%B0%D1%86%D0%B8%D0%B8_%D0%B2%D1%80%D0%B5%D0%BC%D0%B5%D0%BD%D0%BD%D0%BE%D0%B9_%D1%88%D0%BA%D0%B0%D0%BB%D1%8B

I won't bother with formulas as I don't know them myself, I won't bother with words either, I'll just give commented code for anyone to be able to reproduce...

So this code solved the problem:

We have a certain pattern, let's call it "main pattern" of size (length) 8 points (the number is just an odd number)

I need to find patterns similar to the main pattern, but their dimension is 5 and 13 points (the figures are taken from the junk)

The result is in the picture

ч

How it can be used, and whether it is possible at all is an open question, I think that I have successfully applied it, but you need to remember that all this is just a tool for implementing your idea, but not the idea itself ...

I will post the code below

Алгоритм динамической трансформации временной шкалы — Википедия
  • ru.wikipedia.org
Алгоритм динамической трансформации временно́й шкалы (DTW-алгоритм, от англ.  ) — алгоритм, позволяющий найти оптимальное соответствие между временными последовательностями. Впервые применен в распознавании речи, где использован для определения того, как два речевых сигнала представляют одну и ту же исходную произнесённую фразу. Впоследствии...
Files:
zzz.txt  4 kb
 

In simple terms, the whole point of the code is this:

library(dtw)

X <- rnorm(10)
Y <- rnorm(20)

my.dtw <- dtw(X ,Y)

my.dtw$distance

where

my.dtw$distance
[1] 14.17198

it is a measure of proximity (Euclidean distance), the smaller it is, the greater the proximity of X and Y

 
mytarmailS:

In simple terms, the whole point of the code is this:

library(dtw)

X <- rnorm(10)
Y <- rnorm(20)

my.dtw <- dtw(X ,Y)

my.dtw$distance

where

my.dtw$distance
[1] 14.17198

it is a measure of proximity (Euclidean distance), the smaller it is, the greater the proximity of X and Y

Just in case: If the proximity measure = 1, then the second row is obtained from the first by distortion?
 
SanSanych Fomenko:
Just in case: If the proximity measure = 1, then the second row is obtained from the first by distortion?

Usually when one wants to change the proximity between two rows, the rule is that these rows must be the same length

dtw can measure the proximity of two rows with different dimensions, of course it will distort the row to find the correct proximity value

 

mytarmailS:

We have a pattern, let's call it "main pattern" size (length) of 8 points (the figure from junk)

I need to find patterns similar to the main pattern, but their dimension is 5 and 13 points (the figures are taken at random)

It was in the same thread, pg. 130.

In brief, the classical DTW algorithm compares two segments of fixed length n and m respectively, fills the array [1...n, 1...m] and takes the result of the calculation from cell [n, m]. If you want some segment to be random (floating) in length - for example n=8 and m takes values from 5 to 13 - you fill array 8*13 and take the minimum result from cells [8,5] to [8,13] divided by the path length.

It turns out that the Russian wikipedia rewrote the whole article during this time, and I did not know. In the English article, nothing has changed and the pseudocode remains, which makes it easier to understand the principle of the algorithm.

 
Vizard_:

Approach #4)) But did not enter the "first hundred" club (133) (0.68705), getting punched in the face by nerds-assholes)))


Wow, that's awesome!!!
 
Awl Writer:

It was in the same thread, pg. 130.

In short, in the classic DTW algorithm .....................

Or you can do it another way, just stupidly interpolate all the arbitrary sections to a single size, and then just measure the correlation or Euclidean...

 

Hi all!

I ask for help and propose to unite in efforts to create some algorithm called "polyharmonic approximation" - this is a very deep and clever approximation of a function in the context of the family of algorithms "MSUA" why I think so I will voice later with explanations and possibly pictures

ссылка https://ru.wikipedia.org/wiki/%D0%9C%D0%B5%D1%82%D0%BE%D0%B4_%D0%B3%D1%80%D1%83%D0%BF%D0%BF%D0%BE%D0%B2%D0%BE%D0%B3%D0%BE_%D1%83%D1%87%D1%91%D1%82%D0%B0_%D0%B0%D1%80%D0%B3%D1%83%D0%BC%D0%B5%D0%BD%D1%82%D0%BE%D0%B2

excerpt from the link

Обычно степень полинома опорной функции выбирается не выше {\displaystyle N-1} N-1, где {\displaystyle N} N - количество точек выборки. Часто бывает достаточно использовать в качестве опорных функции полиномы второй степени. В таком случае на каждом шаге итерации степень результирующего полинома удваивается.

Вместо полинома Колмогорова-Габора можно использовать ряды Фурье. Их имеет смысл применять, если в исходных данных наблюдается периодичность (например, уровень воды в реках, температура воздуха, объём осадков). Полученная в таком случае модель будет полигармонической [1].

===================================================

Also a link to one of the many books on this wonderful method those "MSUA"

The book has very strong ideas and is easy to read (until the formulas start) IVERY highly recommend readinghttps://www.gmdh.net/articles/theory/bookNoiseIm.pdf

===================================================

also some commentary confirming that polyharmonic approximation is the right direction in preprocessing data for MO

excerpt of comment

...................................…Следующим шагом была новая модель: к цене закрытия применяем фильтр низких частот (я использовал фильтр Батерворта 2-го порядка), применяем полиномиально-гармоническую аппроксимацию, преобразуем A*cos(wx)+B*sin(wx) к виду M*sin(wx+f) и в качестве вторичных признаков берем M и f.
…. И вот с такой моделью мне удалось построить сеть, которая имела очень хорошие обобщающие свойства: новые данные почти все правильно распознавала........................

link to the original sourcehttp://www.kamynin.ru/archives/4917

 
mytarmailS:

It looks complicated, and there is no certainty about the result, I'll pass.
R has GMDH package ("MGUA" in English).

By the way, in Numerai I also finished the model to logloss <0.69
0.68930
But from somewhere came out a hundred people with results 0.4-0.5, some hell, now to the prizes is like the moon.

Reason: