YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
Trading GRU Regression Model for XAUUSD
This is a PyTorch GRU model trained to predict price change percentages for XAUUSD (Gold Futures).
Model Details
- Architecture: GRU with 3 layers, 128 hidden units, batch normalization, dropout
- Input: 50 timesteps of 16 technical indicators (standardized)
- Output: Predicted price change percentage (regression)
- Training Data: XAUUSD historical data from 2010-2023
- Loss: Mean Squared Error (MSE)
- Optimizer: Adam with L2 regularization
- Multi-Year Backtest Performance: 99.88% compounded return (19.98% average annual) across 2019-2024
Features Used
- Close, Volume, RSI_14, SMA_5, SMA_20, EMA_5, EMA_20
- MACD, MACD_Signal, MACD_Diff
- BB_Upper, BB_Lower, BB_Middle
- ATR_14, OBV, ROC_12
Usage
import torch
from sklearn.preprocessing import StandardScaler
class TradingLSTM(nn.Module):
def __init__(self):
super(TradingLSTM, self).__init__()
self.gru = nn.GRU(input_size=16, hidden_size=128, num_layers=3, batch_first=True, dropout=0.3)
self.fc1 = nn.Linear(128, 64)
self.fc2 = nn.Linear(64, 32)
self.fc3 = nn.Linear(32, 1)
self.dropout = nn.Dropout(0.4)
self.relu = nn.ReLU()
self.batch_norm1 = nn.BatchNorm1d(128)
self.batch_norm2 = nn.BatchNorm1d(64)
def forward(self, x):
gru_out, _ = self.gru(x)
x = gru_out[:, -1, :]
x = self.batch_norm1(x)
x = self.relu(self.fc1(x))
x = self.batch_norm2(x)
x = self.dropout(x)
x = self.relu(self.fc2(x))
x = self.dropout(x)
x = self.fc3(x)
return x
model = TradingLSTM()
model.load_state_dict(torch.load('trading_regression.pth'))
model.eval()
# Prepare input sequence (50, 16) and scale with StandardScaler
# Predict price change percentage
prediction = model(sequence) # e.g., 0.0167 = 1.67% expected change
Trading Strategy
- Buy when predicted change > 0.001 (0.1% expected increase)
- Sell when predicted change < -0.001 (0.1% expected decrease)
- Close positions when predictions reverse
- Tested across 5 years (2019-2024) with consistent profitability
Disclaimer
This model is for educational purposes only. Trading involves significant risk. Past performance does not guarantee future results.
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support