BYBIT:BNBUSDT.P   BNBUSDT Perpetual Contract
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score

# Load historical OHLCV data
data = pd.read_csv('historical_data.csv')

# Preprocess data
data = data.dropna()
data = np.log(data / data.shift(1))
data = (14 + np.arange(len(data))) / (14 + np.arange(len(data))) * data.rolling(window=14).mean()
data, data, data = data.rolling(window=20).apply(lambda x: np.percentile(x, 80), raw=True), data.rolling(window=20).mean(), data.rolling(window=20).apply(lambda x: np.percentile(x, 20), raw=True)
data = np.sign(data - data.shift(1))

# Feature engineering
data = data.rolling(window=50).mean()
data = data.rolling(window=200).mean()

# Model training
X = data.drop(columns=)
y = data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
model = RandomForestClassifier(n_estimators=100, random_state=42)
model.fit(X_train, y_train)

# Model evaluation
y_pred = model.predict(X_test)
print('Accuracy:', accuracy_score(y_test, y_pred))
print('Precision:', precision_score(y_test, y_pred))
print('Recall:', recall_score(y_test, y_pred))
print('F1-score:', f1_score(y_test, y_pred))

# Prediction
next_candle_stick_color = model.predict(X_test.iloc.values.reshape(1, -1)))
print('Next candle stick color:', 'up' if next_candle_stick_color == 1 else 'down')

Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.