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

 
Maxim Dmitrievsky #:
I specifically answered your specific question - in any one you want. That's your own business. It's even strange why I was asked. It had nothing to do with the topic I was interested in.

Hmm, you've reported here in the thread about uplift models, which are an evolution of A-B testing. So, the method is designed to estimate the impact when the target changes from the new impact. So it's obvious to me that the starting point of the influence of the predictor being sought should be set. Here I wanted to hear your thoughts on this issue. Including the reason why you think it is not important.

 
Maxim Dmitrievsky #:
Why call masterpieces rubbish? I offered you free of charge, including on your superlatives, just like Alexei. But I was sent to the kodobazu. And now he, the complainer, runs around calling me names.

Who's the complainer? Who's calling me names?

If it's me, the accusations are baseless. I will spend my energies to remove the undesirables, in fairness, only if it is necessary to achieve my goals.

I offered to give the predictor values for verification, as it is quick.

I wrote earlier that I use predictors in large numbers on data from ZZ, I even described the gist of it. It is counterproductive to rewrite it in python.

 
Aleksey Vyazmikin #:

Thanks for the article!

Translated it, read it.

Can you help me translate the algorithm in the form of formulas into a more understandable language? And I will try to write the code of this method of building a tree.

There, in the article, on page 10, there is an implementation in the form of pseudocode. On the penultimate page, in the appendix, there are references to the implementation in the R language and to the data used in the article.

How, in general terms, do you implement decision trees in mql5? Through arrays or templates?

 
Aleksey Vyazmikin #:

Hmm, you have reported here in the thread about uplift models, which are an evolution of A-B testing. So, the method is designed to estimate the influence when the target changes from the new influence. So it is obvious to me that the starting point of the influence of the predictor being sought should be set. Here I wanted to hear your thoughts on this issue. Including the reason why you think it is unimportant.

Samples in randomised experiments are determined randomly. The very beginning of the book.

There is the opening of trades at random and the corresponding result on the control group, and there is a model built on another subsample, the test group. We need to determine the effect of using such a model, whether it is positive for the control group. If so, then aplift the model in one of the suggested ways.

By simply testing on new data, you can't determine the effect because there is often bias in the data. Therefore, the formula is two summands ATE + Bias. You can go even further and define CATE, that is on a case by case basis, and select only those that are better treated, the rest ignore/skip in trading.

In Sanych's terms, looking for the stationary in the non-stationary.
 
Aleksey Vyazmikin #:

Who's the complainer? Who's calling names?

If it's about me, the accusations are baseless. I will spend my energies to eliminate the undesirable, in fairness, only if it is necessary to achieve my goals.

I offered to give the predictor values for verification as it is quick.

I wrote earlier that I use predictors in large numbers on data from ZZ, I even described the gist of it. Rewriting this to python is counterproductive.

You complain and call me names like a child
And in a small amount of everything is productive?)
 
def R_learner():
    dataset = get_prices()
    dataset = labeling(dataset)

    data = dataset[dataset.index < FORWARD].copy()
    data['treatment'] = data['labels'].apply(lambda x: np.random.choice([0, 1], p=[0.2, 0.8])) // случайно выбрал элементы для лечения


    X = data[data['treatment'] == 1]
    X = X[X.columns[1:-2]]
    X_t = data[data['treatment'] == 0]
    X_t = X_t[X_t.columns[1:-2]]

    y = data[data['treatment'] == 1]
    y = y[y.columns[-2]]
    y_t = data[data['treatment'] == 0]
    y_t = y_t[y_t.columns[-2]]

    treat_m = CatBoostClassifier(iterations=1000,
                                depth=6,
                                custom_loss=['Accuracy'],
                                eval_metric='Accuracy',
                                verbose=False,
                                use_best_model=True,
                                task_type='CPU')
    treat_m.fit(X, y, eval_set=(X_t, y_t),
                    early_stopping_rounds=50, plot=False) // обучил модель на этих примерах, остальные попали в валидацию

    data['y_t'] = [x[0] < 0.5 for x in treat_m.predict_proba(data[data.columns[1:-2]])] // теперь метки классов - это предсказания обученной модели
    data['y_t'] = data['y_t'].astype(float)
    
    # perform residualisation
    debias_m = CatBoostClassifier(iterations = 5,
                                    max_depth = 1,
                                    early_stopping_rounds = 2,
                                    verbose = False) // эта модель определяет смещение в оценках тритмента
    denoise_m = CatBoostClassifier(iterations = 5,
                                    max_depth = 1,
                                    early_stopping_rounds = 2,
                                    verbose = False) // эта модель определяет смещение в оценках целевой

    t_diff = data['treatment'] - cross_val_predict(debias_m, 
                                                data[data.columns[1:-3]], 
                                                data[data.columns[-2]], 
                                                method='predict_proba', cv=5)[:, 0] // определяем тритмент эффект

    y_diff =  data['y_t'] - cross_val_predict(denoise_m, 
                                                data[data.columns[1:-3]], 
                                                data[data.columns[-1]], 
                                                method='predict_proba', cv=5)[:, 0] // определяем байес

    # create the weights
    w = t_diff ** 2 // новые веса для модели
    # create the transformed target
    y_debias = (y_diff / t_diff).apply(lambda x: 1 if x > 0.0 else 0) // новые метки без смещения

    data['weights'] = w
    data['y_debias'] = y_debias
    data = data.drop(['labels', 'treatment', 'y_t'], axis=1)


    X = data[data.columns[1:-2]]
    y = data[data.columns[-2:]]

    train_X, test_X, train_y, test_y = train_test_split(
            X, y, train_size=0.5, test_size=0.5, shuffle=True)

    train_data = Pool(
        data=train_X,
        label=train_y[train_y.columns[1]],
        weight=train_y[train_y.columns[0]] // добавляем веса к обучению
    )

    eval_data = Pool(
        data=test_X,
        label=test_y[test_y.columns[1]],
        weight=test_y[test_y.columns[0]]
    )

    # learn final model with train and validation subsets
    model = CatBoostClassifier(iterations=1000,
                                depth=6,
                                learning_rate=0.1,
                                custom_loss=['Accuracy'],
                                eval_metric='Accuracy',
                                verbose=False,
                                use_best_model=True,
                                task_type='CPU')

    model.fit(X= train_data, eval_set=eval_data,
                early_stopping_rounds=50, plot=False) // учим новую модель с обесшумленными метками и дополнительными весами

    return model

This approach does not work well on new data. Apparently because I did a poor job of defining what should be a tritent and in relation to what :)

the idea of R-learner is taken from here
 
Maxim Dmitrievsky #:

This approach does not work well on new data. Apparently because I did a poor job of defining what should be a tritent and in relation to what :)

the idea of R-learner is taken from here

The article uses very important knowledge about inputs - elasticity of supply-demand. Hence the persistent odour of over fitting.

We don't have such fundamental quote data, moreover, it's likely that elasticity doesn't work: the price of an asset can vary from zero to sky-high.

The code you have posted, as well as the causal approach itself, will be of value only after running it in the MKL-5 tester, and necessarily with a forward.

 

Even adjusted for elasticity, it didn't work at all on the new data. It stayed fine on the traine, though.

The reasons are being determined...

Because it may have worked, but not in the way you'd like it to work


 
Maxim Dmitrievsky #:

Even adjusted for elasticity, it didn't work at all on the new data. Although it stayed fine on the traine.

The reasons are being established...

Because it may have worked, but not in the way you'd like it to work


The graphs don't show clear cause and effect like air temperature and --> buying ice cream.
 
Forester #:
There is no obvious cause and effect in the graphs, like air temperature and --> buying ice cream.

The tritment is how you influence the system. That's where the impact of price changes (your impact) on sales is considered.

I influenced the directions of transactions by training the model. Lerner showed me that this does nothing ) but it didn't fix anything either.