Download verify_long_term.py from SurgeSoftwareSolutions/intraday-btc-model-11yr: direct link, hf CLI and curl.
- Browser
- Download file 3.08 kB
-
https://huggingface.co/SurgeSoftwareSolutions/intraday-btc-model-11yr/resolve/main/verify_long_term.py
- Command line
-
hf download hf://SurgeSoftwareSolutions/intraday-btc-model-11yr/verify_long_term.py
-
curl -L -o verify_long_term.py https://huggingface.co/SurgeSoftwareSolutions/intraday-btc-model-11yr/resolve/main/verify_long_term.py
3.08 kB
| """ | |
| Final Verification: Best Long-Term Model | |
| ---------------------------------------- | |
| Timeframe: Daily (11 Years: 2014-2025) | |
| Strategy: Aggressive Trend Following (MA 10/50) | |
| Leverage: 3x | |
| Stop Loss: 4.0 ATR | |
| """ | |
| import pandas as pd | |
| import numpy as np | |
| import sys | |
| import os | |
| import matplotlib.pyplot as plt | |
| sys.path.append(os.path.dirname(os.path.abspath(__file__))) | |
| import config | |
| from core.backtester import Backtester | |
| def verify_long_term(): | |
| print("\n" + "="*70) | |
| print("VERIFYING LONG-TERM STRATEGY (11 Years)") | |
| print("="*70) | |
| # Load Daily Data | |
| data_file = os.path.join(config.DATA_DIR, "btc_daily_2014_2025.csv") | |
| df = pd.read_csv(data_file) | |
| df['timestamp'] = pd.to_datetime(df['timestamp']) | |
| df.set_index('timestamp', inplace=True) | |
| print(f" Period: {df.index[0].date()} to {df.index[-1].date()}") | |
| print(f" Bars: {len(df):,}") | |
| # Indicators (MA 10/50) | |
| df['ema_fast'] = df['close'].ewm(span=10, adjust=False).mean() | |
| df['ema_slow'] = df['close'].ewm(span=50, adjust=False).mean() | |
| # ATR | |
| high = df['high'] | |
| low = df['low'] | |
| close = df['close'] | |
| tr = pd.concat([ | |
| high - low, | |
| (high - close.shift()).abs(), | |
| (low - close.shift()).abs() | |
| ], axis=1).max(axis=1) | |
| df['atr'] = tr.rolling(14).mean() | |
| # Signals | |
| signals = pd.Series(0, index=df.index) | |
| signals[df['ema_fast'] > df['ema_slow']] = 1 | |
| signals[df['ema_fast'] < df['ema_slow']] = -1 | |
| # Parameters | |
| # 4.0 ATR Stop is very wide | |
| avg_atr_pct = (df['atr'] / df['close']).mean() # Approx 4-5% | |
| stop_dist = avg_atr_pct * 4.0 # ~16-20% Stop | |
| print(f" Stop Distance: ~{stop_dist*100:.1f}%") | |
| # Backtest | |
| class DummySignal: | |
| def get_params(self): return {"model": "LongTerm_Daily"} | |
| backtester = Backtester( | |
| data=df, | |
| features=df, | |
| signals=signals, | |
| signal_model=DummySignal(), | |
| e_base=1000.0, | |
| leverage=3.0, # 3x Leverage | |
| risk_fraction=0.50, # Risk 50% of equity per trade (Aggressive) | |
| # With 20% stop, rho=0.5 => Size = 2.5x Equity | |
| stop_distance=stop_dist, | |
| tp_distance=stop_dist * 5.0, | |
| d_max=0.90, | |
| commission=0.001, | |
| slippage=0.0001, | |
| verbose=True | |
| ) | |
| results = backtester.run() | |
| m = results['metrics'] | |
| print("\n" + "="*70) | |
| print("✅ FINAL RESULTS (11 Years)") | |
| print("="*70) | |
| print(f"Initial Equity: $1,000") | |
| print(f"Final Equity: ${m['total_equity']:,.0f}") | |
| print(f"Total Return: {m['total_return_pct']:,.0f}%") | |
| print(f"CAGR: {(m['total_equity']/1000)**(1/11) - 1:.1%}") | |
| print(f"Max Drawdown: {m['max_drawdown_pct']:.1f}%") | |
| print(f"Sharpe Ratio: {m['sharpe_ratio']:.2f}") | |
| print(f"Trades: {m['num_trades']}") | |
| backtester.save_results(config.REPORTS_DIR) | |
| if __name__ == "__main__": | |
| verify_long_term() | |