Want to test it yourself? Hereβs a Python snippet using XGBoost + Leverage for crypto trading.
python
CopyEdit
import pandas as pd
import numpy as np
import xgboost as xgb
from binance.shopper import Consumer
from sklearn.model_selection import train_test_split
# Load historic BTC information
df = pd.read_csv('btc_data.csv')# Characteristic Engineering
df['price_change'] = df['Close'].pct_change()
df['rsi'] = ta.momentum.RSIIndicator(df['Close']).rsi()
df['macd'] = ta.development.MACD(df['Close']).macd()
df.dropna(inplace=True)# Put together coaching information
X = df[['price_change', 'rsi', 'macd']]
y = (df['price_change'].shift(-1) > 0).astype(int) # 1 if value goes up, 0 if down
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)# Prepare XGBoost Mannequin
mannequin = xgb.XGBClassifier()
mannequin.match(X_train, y_train)# Predict next-hour value motion
df['prediction'] = mannequin.predict(X)# Apply 2x Leverage Buying and selling Technique
df['trade'] = np.the place(df['prediction'] == 1, 2, -2) # 2x leverage for lengthy, -2 for brief# Calculate returns
df['returns'] = df['trade'] * df['price_change']
cumulative_returns = (1 + df['returns']).cumprod()print("Ultimate Portfolio Worth:", cumulative_returns.iloc[-1] * 10000)