Files
MT5-PY-AI-Tbot/separate_codes/create_benchmark_model.py
T
Ash 1e16b161c4 feat: Add MT5 trading bot project files
This commit includes the initial project files for the MT5 trading bot. It includes:

- MQL5 scripts for exporting data and for the trading EAs.

- Python scripts for model development and for creating a benchmark model.

- ONNX models for the trading EAs.

- A file with all the code concatenated.

- A directory with the separate code files.
2025-10-23 23:02:10 +01:00

34 lines
1.1 KiB
Python

import pandas as pd
from sklearn.linear_model import LogisticRegression
import skl2onnx
from skl2onnx.common.data_types import FloatTensorType
# Load the data
raw_price_df = pd.read_csv("raw_price_data.csv")
# Feature Engineering
raw_price_df["feature_price_change"] = raw_price_df["Close"].diff()
# Target Engineering
raw_price_df["y_target_direction"] = (raw_price_df["Close"].shift(-1) > raw_price_df["Close"]).astype(int)
# Drop rows with NaN values
raw_price_df.dropna(inplace=True)
# Separate features and target
X = raw_price_df[['feature_price_change']]
y = raw_price_df['y_target_direction']
# Create and train the logistic regression model
log_reg_model = LogisticRegression()
log_reg_model.fit(X, y)
# Convert the model to ONNX format
initial_type = [('float_input', FloatTensorType([None, 1]))]
onnx_model = skl2onnx.convert_sklearn(log_reg_model, initial_types=initial_type)
# Save the ONNX model
with open("benchmark_logistic_model.onnx", "wb") as f:
f.write(onnx_model.SerializeToString())
print("Model successfully exported to benchmark_logistic_model.onnx")