iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🐈

Building Machine Learning Models for the richmanbtc Tutorial

に公開
2022/03/10

Note: Only covering the creation of the learning model.

Data preprocessing and backtesting will not be covered.

Essential Books for Botters

  • The Reality of Botters Revealed by an SS-Class Trader with a Daily Income of 3 Million Yen

https://amzn.to/3hUFlfm
This is the well-known book by richmanbtc.
It was the book that clearly led me down the path of becoming a botter, when I was only vaguely thinking about making money through cryptocurrency trading.

I think it's great for people considering becoming a botter as you can learn about the general aspects such as the advantages and target areas of being a botter.

  • Techniques to Win at Kaggle

https://amzn.to/3MD6iCf
A book recommended by richmanbtc. It said to read it whenever you get stuck.
I had moments where I thought "???" while performing data preprocessing or creating learning models.
Reading this at those times helped clear things up.

My Past Articles

The process of a humanities student with no machine learning experience becoming a botter through richmanBTC's tutorial

https://zenn.dev/flutternyumon/articles/4fa5f97b0c4ba3

I didn't quite understand richmanbtc's Force Entry Price, so I tried summarizing it in my own way

https://zenn.dev/flutternyumon/articles/17fffff306fd79

richmanbtc tutorial: Flow up to ground truth data creation

https://zenn.dev/flutternyumon/articles/14c4888a3d4ea4

Operational Concept

The idea is: "If we predict y_buy and y_sell and trade only when the predicted value is positive, we should be able to win."
A prediction model for each of y_buy and y_sell is required.

By the way, I wrote about the creation of y_buy and y_sell in detail in the following article:
https://zenn.dev/flutternyumon/articles/14c4888a3d4ea4

Differences from the Production Model

The production model is trained on the entire dataset.
On the other hand, in this tutorial, a production model trained on all data cannot be used because of the relationship with the test data.
Therefore, we create and use a tutorial model trained by excluding a certain period.

About OOS (Out-of-sample) Predicted Values

OOS refers to the test data. In this tutorial, the training data and test data are divided by time periods.
OOS predicted values are the predicted values for the test data.

The reason for calculating with OOS is to make conditions as close to production as possible.
When running in production, you must handle data that was not used for training (future data).

Cross-validation (CV) is used.
Cross-validation involves splitting the training and test data and evaluating the model created with the training data on the test data.

There are various splitting methods, and they need to be chosen based on the use case.
Richmanbtc uses K-Fold Cross-Validation (KFold).

cv_indicies = list(KFold().split(df))
# Splitting based on the number of samples in df.

Then, the OOS predicted values are calculated.
Richmanbtc uses a custom-made my_cross_val_predict function.

It's almost the same process as sklearn's cross_val_predict, but since that can only be used when the input and output sizes are the same, this custom version was created to allow for different input and output sizes.

# Calculate OOS predicted values
def my_cross_val_predict(estimator, X, y=None, cv=None):
    y_pred = y.copy()
    y_pred[:] = np.nan
    for train_idx, val_idx in cv:
        estimator.fit(X[train_idx], y[train_idx])
        y_pred[val_idx] = estimator.predict(X[val_idx])
    return y_pred

Called from here:

df['y_pred_buy'] = my_cross_val_predict(model, df[features].values, df['y_buy'].values, cv=cv_indicies)

df['y_pred_sell'] = my_cross_val_predict(model, df[features].values, df['y_sell'].values, cv=cv_indicies)

Using cv=cv_indicies to pass the KFold values.

Source

richmanbtc's GitHub: "https://github.com/richmanbtc/mlbot_tutorial"

Discussion