Spaces:
Running
Running
File size: 1,127 Bytes
b1f38ad | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | """
Train HMM Model for Live Trading
Run this script once to generate the hmm_model.pkl file
"""
from strategy import train_models_and_backtest
# Train HMM model using recent BTC data
print("Training HMM model for live trading...")
print("=" * 60)
result = train_models_and_backtest(
ticker="BTC-USD",
start_date="2024-01-01", # Backtest period
end_date="2024-12-14", # Today
short_window=12,
long_window=26,
n_states=3
)
if "error" in result:
print(f"❌ Error: {result['error']}")
else:
print("\n" + "=" * 60)
print("✅ Model training complete!")
print("\nBacktest Results:")
print(f" Strategy Return: {result['metrics']['strategy_return']}")
print(f" Buy & Hold Return: {result['metrics']['buy_hold_return']}")
print(f" Sharpe Ratio: {result['metrics']['sharpe_ratio']}")
print(f" Max Drawdown: {result['metrics']['max_drawdown']}")
print(f" Win Rate: {result['metrics']['win_rate']}")
print(f" Total Trades: {result['metrics']['total_trades']}")
print("\n📁 Model saved to: backend/hmm_model.pkl")
print(" Ready for live trading!")
|