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

 
mytarmailS:

1) You may be right, but this net is able to learn by itself how to make decisions, it is not the usual classification without a teacher, and therefore it is possible to realize the concept I told about long ago - you can teach it not as a standard target in the form of buy-sel-buy or 00011101011, but in a more abstract way - for example to simply put conditions like: Net! I don't care how you trade there, but I want your profit to be at least 1% of the drawdown 0.5% and it will look for the rules, combinations to solve this problem. If I'm wrong somewhere and have said some nonsense then correct me for my own good.)

Right, didn't think about that, everything is correct. Then it is better to give the neural network a condition to maximize the sharpe ratio (or recovery factor), and make in R something like a simple forex tester on real quotes to test the model to evaluate the evolution. But a miracle will not happen by itself, the problem of retraining will remain, the data must still be divided into training and test samples, and crossvalidations must be performed for the final estimation of the model during its evolution. How to work with sharpe ratio at crossvalidation I could not think up quickly, in my opinion it will not be possible to remove random bars in the test sample, because it is not the accuracy of each bar that is important, but the continuous trade itself, with all drawdowns, spreads and commissions for each new trade.

Alexey Burnakov:

They seem to be preparing a package for R. We should take note of it.

I have the package already, but I don't know how many percent it is ready, for now on githab. Here's a simpler example, a continuation of the article. They teach the network to extract the root.

http://gekkoquant.com/2016/07/17/rneat-square-root-neural-net-trained-using-augmenting-topologies-simple-example/

I will finish it later:

I did an example classification of irises, code in atachment (the model could not classify, I replaced all classes with numbers for regression, and rounded the results to the nearest numeric levels. Probably could have been done somehow easier).
For training I took only 50% of the data, on validation success of 95%, quite good. Judging by the graph the model even removed the first predictor itself.

Forex is more complicated than Iris :) The result there will be much worse.

I also noticed that parts 3 and 4 of the article use different functions to train the model.
Part 3 is for modeling some dynamic processes, for example the model can watch the forex chart and open/close trades in real time.
Part 4 is simply to train the model on ready examples and predict the result

Files:
 
Dr.Trader:

1) Right, didn't think about it, everything is correct. Then it is better to give the neural network a condition to maximize sharpe ratio (or recovery factor), and make R something like a simple forex tester on real quotes

2) I also noticed that parts 3 and 4 of the article use different functions to train the model.
Part 3 is to simulate some dynamic processes, for example the model can watch the forex chart and open/close trades in real time.
Part 4 is just to train the model on ready examples and predict the result

1) Absolutely right! That's exactly what I meant, the profit / drawdown is just an example, I thought about taking the recovery factor, but the sharpe is basically no worse

2) You're right, in 4th article the author has already created something like a package, by all "R" standards, it's just a model - a target vector - prediction through "predict" - but this approach won't suit us, because all functions are already hidden in the package... We need to deal with the source code and write everything for yourself, that's why I said that help to understand as here everything is much more complicated than with the "ready-made package with examples to it" I think that even the functions from Part 3 will not be enough for what we need. So it would be just fabulous if we all got involved

 
mytarmailS:

1) Absolutely right! That's exactly what I meant, the profit/loss is just an example, I was thinking of taking the recovery factor, but the sharpe is basically no worse

2) You're right, in 4th article the author has already created something like a package, by all "R" standards, that's as much as possible just have model - have target vector - make forecast with "predict" - but this very approach won't suit us, because all functions are already hidden in the package... We need to deal with the source code and write everything for yourself, that's why I said that help to understand as here everything is much more complicated than with the "ready-made package with examples to it" I think that even the functions from Part 3 will not be enough for what we need. So it would be fabulous if we all got involved

Who's going to teach you other than yourselves? Why don't you get the source code? Study it. And also about the differentiability of the function. You need to feed some kind of smooth function into the network. And you will tell us - and we will give you our advice.
 
Alexey Burnakov:
You need to feed some smooth function into the network. Tell us about it ), and we'll give you our advice.

Forgive me for interfering, but not only smooth, but also normalized.

So that the NS never goes beyond its known areas.

Something like this.

 

I can't understand, why are they clinging to these networks?

After all, went beyond the wretched packages to the expanse of the R! But no, old sins keep dragging and dragging ...

Take caret, for example. Not only there are a hundred and fifty models there, but also a bunch of useful preprocessing and prediction functions...

So no, nets and nets...

 
SanSanych Fomenko:

I can't understand, why are they clinging to these networks?

After all, went beyond the wretched packages to the expanse of the R! But no, old sins keep dragging and dragging ...

Take caret, for example. Not only there are a hundred and fifty models there, but also a bunch of useful preprocessing and prediction functions...

So, no, nets and nets...

So, show us your caret and a hundred and fifty models in action! :)

 
Vadim Shishkin:

So show us your caret and a hundred and fifty models in action! :)

By the way, I myself use caret and get satisfactory results on forex.

Here is an example of code from my experiments:

####
##########
############## start experiment
##########
####

library(caret)
library(gbm)
library(doParallel)

        
# tuning GBM - перебор параметров обучения по сетке
gbmGrid <- expand.grid(interaction.depth = seq(from = 3, to = 9, by = 2)
                  , n.trees = seq(from = 600, to = 1200, by = 300)
                  , shrinkage = seq(from = 0.01, to = 0.02, by = 0.005)
                  , n.minobsinnode = seq(from = 30, to = 60, by = 30))

######################
# start training cycle - ввод основных переменных и массива для результатов

validating_arr <- data.frame()
max_best_models <- 1
counter <- 1
max_inputs <- 15
max_cv_folds <- 5
max_bag_fract <- 1
distributions <- c('gaussian', 'laplace')
start <- Sys.time()
        
for (best_inp_num in seq(from = 3, to = max_inputs, by = 3)){
        
        for (cv_folds in 2:max_cv_folds){
                
                for (bag_frac in seq(from = 0.2, to = max_bag_fract, by = 0.2)){

#########################
# prepare training scheme - параметры caret
                                        gbmControl <- trainControl(method = 'cv'
                                                                      , number = cv_folds
                                                                      , verboseIter = F
                                                                      , returnData = F
                                                                      , returnResamp = 'all'
                                                                      , savePredictions = 'none'
                                                                      , summaryFunction = mymetrics
                                                                      , search = 'grid'
                                                                      , allowParallel = T)

########################
# initiate paralleling
                        cores <- 4 #detectCores()
                        cl <- makePSOCKcluster(cores)
                        registerDoParallel(cl)
                        
                        # train the model - обучение моделей с кроссвалидацией. Используется GBM.
                        best_models <- train(training[, ncol(training)] ~.
                                                , data = training[, 1:(ncol(training) - 1)]
                                                , method = 'gbm'
                                                , distribution = distributions[2]
                                                , bag.fraction = bag_frac
                                                , metric = 'mae_improve'
                                                , maximize = T
                                                , trControl = gbmControl
                                                , tuneGrid = gbmGrid)
                        
                        # stop paralleling
                        stopCluster(cl)
                        
                        # summarize the model - сохранение n лучших моделей
                        best_models_arr <- as.data.frame(cbind(best_models[[4]][1]
                                                                    , best_models[[4]][2]
                                                                    , best_models[[4]][3]
                                                                    , best_models[[4]][4]
                                                                    , best_models[[4]][5]
                                                                    , best_models[[4]][6]
                                                                    , best_models[[4]][7]
                                                                    , best_models[[4]][8]))
                        
                        rm(best_models)
                        
                        best_models_arr_ordered <- best_models_arr[order(best_models_arr$mae_improve, decreasing = T), ]

# далее - обучение лучших моделей и их валидация


 
Thank you. :)
 
SanSanych Fomenko:

I can't understand, why are they clinging to these networks?

After all, went beyond the wretched packages to the expanse of the R! But no, old sins keep dragging and dragging ...

Take caret, for example. Not only there are a hundred and fifty models there, but also a bunch of useful preprocessing and prediction functions...

So, no, nets and nets...

Usually a library can either do much but average, or one thing with good quality. Caret is the first case, it's easy to test dozens of models and compare results, but it's hard to improve something for your task. I've run into huge difficulties when selecting predictors according to my rules - caret can simulated annealing to enumerate them (and genetics), but can't just take my fitness function for estimation. I have to create a new model for caret with training, validation, and fitness functions; but caret will still control training and test data samples by its own rules, with its own crossvalidations.
It is easier for me to take GA or GenSA package for enumerating predictors and write just one fitness function that will both create a model and cross-validation according to the rules I need.

The neuron is not worse than the forest, my results with it are in the plus, or in the worst case just without losing the deposit. Due to different algorithms, neuronka will prefer different predictors than forest, but all predictor selection rules are completely the same as for the forest.

It will take you a couple of minutes to transfer the neuronc to mt5 EA (save weights from R into csv and read them into the EA). The forest in mt5 will be much more difficult to transfer, that is why I prefer neuronc.

 

I experimented with RNeat a little more, and came to the conclusion that it cannot be worked with the same way as with conventional neural networks.

1) unlike conventional models, RNeat training does not use raw data. The model is sort of randomly generated, improved, and only at the end is tested on the raw data. Usually models use raw data, build their logic on it, and then use validation sampling to see if the model's logic is correct, or if it has just memorized the raw examples. Unlike the others, RNeat isn't capable of memorizing the raw data at all, for it doesn't know about it, all the model knows is the desired results and how close it is to them.

2) crossvalidation will not help improve fronttest results. We all seem to agree that it is possible to train a regular model, run a couple of crossvalidations, and somehow handle the errors on all samples for the final fitness score of the model. Since RNeat does not know the raw data, it does not matter for it what sample the data is in - training or test, it will adjust its logic to the desired result in any case. Theoretically it will "learn" (more precisely mutate :) ) on all samples that are used in the fitness function. All you can do is train the model to the desired accuracy, and hope that it is not over-trained, quite a risky approach for forex. Crossvalidation can be used only after training, as final estimation of possible result in fronttest, and in no case this validation sample should be used inside fitness function.

Reason: