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

 

Maxim Dmitrievsky:

Three weeks left until my finish line with the NS :))) either the grail or screw them. Place your bets :))

At first it would be nice to hear the odds of winning. Nobody just takes orders here ;)

 

I urgently needed to find the minimum of a smooth function, so I decided to first compare different packages on what is faster. For the test I took the Rastrigin function (the most difficult function to optimize according to some professors).

Rastrigin <- function(x){
  return(sum(x^2 - 10 * cos(2 * pi * x)) + 10 * length(x))
}


I took it for the test with 4 parameters:

~ w^2 - 10 * cos(2 * pi * w)  +  x^2 - 10 * cos(2 * pi * x)  +  y^2 - 10 * cos(2 * pi * y)  +  z^2 - 10 * cos(2 * pi * z)   +  10 * 4


Derivatives:

2 * w + 10 * (sin(2 * pi * w) * 2 * pi
2 * x + 10 * (sin(2 * pi * x) * 2 * pi
2 * y + 10 * (sin(2 * pi * y) * 2 * pi
2 * z + 10 * (sin(2 * pi * z) * 2 * pi


I compared packages GenSA, lbfgs, lbfgsb3, n1qn1 and various methods in the standard function optim()

Results:
package, number of fitness (and gradient) function calls, parameters found, and the final result where the search stops.

n1qn1 fitness function calls: 448 ; parameters = 3.90227 e-18 3.90227 e-18 3.90227 e-18 3.90227 e-18 ; result = 0 
lbfgs fitness function calls: 14 ; parameters = -1.891749 e-10 -1.891749 e-10 -1.891749 e-10 -1.891749 e-10 ; result = 0 
lbfgsb3 fitness function calls: 12 ; parameters = -7.542216 e-15 -7.542216 e-15 -7.542216 e-15 -7.542216 e-15 ; result = 0 
GenSA fitness function calls: 66582 ; parameters = 1.517382 e-11 -5.657816 e-12 -2.292922 e-11 -3.257902 e-12 ; result = 0 
optim Nelder-Mead fitness function calls: 253 ; parameters = -2.981633 3.988813 0.9902444 -2.980489 ; result = 34.8497 
optim BFGS fitness function calls: 49 ; parameters = 8.731115 e-16 8.731115 e-16 8.731166 e-16 8.731157 e-16 ; result = 0 
optim CG fitness function calls: 918 ; parameters = 0.9949586 0.9949586 0.9949586 0.9949586 ; result = 3.979836 
optim L-BFGS-B fitness function calls: 81 ; parameters = 8.526118 e-13 8.526118 e-13 8.526118 e-13 8.526118 e-13 ; result = 0 
optim SANN fitness function calls: 10000 ; parameters = 750.3075 745.0596 743.626 753.8133 ; result = 2239327 

The first three functions (n1qn1, lbfgs, lbfgsb3) use an analytically found gradient.

The result = 0 is ideal, the further away from zero the worse.

We can see that knowing the derivatives is very good, lbfgsb3 has reached the perfect result for 12 calls of the fitness functions.
Of those defining the gradient numerically the best was standard function optim with the method BFGS, 49 calls of the fitness function.

The conclusion is that derivatives are very good. Ideally we could find derivatives for all weights for neuronkey and put it into lbfgsb3 instead of backprops.
But all this test result refers only to smooth functions in which you can find derivatives for all parameters. If you have function parameters randomly change the result even at the slightest change - genetics, GenSA, and other stochastic algorithms are better there.

I attached a file with the code, you can test it on your functions.

Files:
n1qn1.txt  4 kb
 

I wonder if such a series can be predicted by some kind of arima, or is it enough to work on the return to the average... managed to achieve impressively stable results (cointegration diagram), working returns more than 2 spreads


 

A return to the average can even be traded with a wand. But how can we determine where the average price is if the average shifts along with the trend? (The question is rhetorical - no way).

 
Dr. Trader:

A return to the average can even be traded with a wand. But how can we determine where the average price is if the average shifts along with the trend? (The question is rhetorical - you can't).

The average here is 0, it's a neutral strategy

we should use statistics to work out further) what is shifted there in the black box

In short, almost finished 2 nd strategy of the 3 planned (the results of the first have already written, not knocked)

if this one does not work - the last one will be left )

and this will be the end of the MO

 
Maxim Dmitrievsky:

I wonder if such a series can be predicted by some arima, or it is enough to work on returning to the average... I managed to achieve impressively stable results (cointegration diagram), working returns more than 2 spreads


Cointegration is a term and has nothing to do with your picture.

The feasibility of arim is determined by several tests, the main one being arch, which determines if there is an arch effect in the time series. If there is no arch-effect, which is about 20%, then trade, but... On the history, because this part has already been passed or almost passed or...

 
SanSanych Fomenko:

Cointegration is a term and has nothing to do with your picture.

The possibility of applying the arym is determined by several tests, the main one being the arch, which determines the presence of the arch effect in the time series. If the arch-effect is absent, and it's about 20%, then trade, but... on the history, since this section has already been passed or almost passed or...

let's 3rd time the definition of cointegration ... what is it and why doesn't it apply to my picture? :)

this is a picture already from the test site, I do not consider the history at all, everything is always perfect there

or what this thread is about - development of strategies on IR or analysis of different R functions, i think i'm the only one who has posted any results for a few months :)

 
Maxim Dmitrievsky:

The average here is 0, it's a market neutral strategy

Do you want the green chart itself to trade? Then I see, at first I thought it was an indicator for trading on eurusd.

First we need to figure out - is it a random process or does it have memory like normal time series.

If it has a memory, then the mashka and arima may be useful.
But if the graph is completely random, you need models for Markovian processes. I'm not good at it, but Alexander said something about Wiener model, you can start with it, for example.

 
Maxim Dmitrievsky:

let's 3rd time the definition of cointegration...what is it and why doesn't it apply to my picture? :)

This picture is already from the test plot, I do not consider it on the history at all, everything is always perfect there

There are at least two time series in cointegration.

But that's not all.

These series are not stationary.

But that's not all.

These nonstationary series must be connected in such a way that the result is stationary.

Trade decisions are made based on this STATIONARY series which guarantees the very possibility to make a forecast.

 
Dr. Trader:

Do you want to trade the green chart itself? Then I see, at first I thought it was an indicator for trading on eurusd.

First we need to figure out if it is a random process, or if it has a memory like normal time series.

If it has memory - then both mash and arima can come in handy.
But if the graph is completely random, then you need models for Markov processes. I'm not good at it, but Alexander said something about Wiener model, you can start with it, for example.

So, we need to determine if it has a memory... it is determined by its tails, isn't it?

Reason: