| Overall Statistics |
|
Total Orders 378 Average Win 1.90% Average Loss -0.87% Compounding Annual Return 14.739% Drawdown 14.200% Expectancy 1.062 Start Equity 100000 End Equity 565810.82 Net Profit 465.811% Sharpe Ratio 0.838 Sortino Ratio 0.786 Probabilistic Sharpe Ratio 18.009% Loss Rate 35% Win Rate 65% Profit-Loss Ratio 2.19 Alpha 0.054 Beta 0.312 Annual Standard Deviation 0.095 Annual Variance 0.009 Information Ratio -0.008 Tracking Error 0.129 Treynor Ratio 0.254 Total Fees $2903.13 Estimated Strategy Capacity $15000000.00 Lowest Capacity Asset SHY SGNKIKYGE9NP Portfolio Turnover 5.82% Drawdown Recovery 471 |
from AlgorithmImports import *
class BitcoinTelegrapher(QCAlgorithm):
def initialize(self) -> None:
self.set_start_date(2014, 1, 2)
self.set_end_date(2026, 8, 6)
self.set_cash(100_000)
self.settings.free_portfolio_value_percentage = 0.05
# Add the two ETFs we'll trade.
qqq = self.add_equity("QQQ", Resolution.DAILY)
shy = self.add_equity("SHY", Resolution.DAILY)
# Add some BTCUSD indicators to classify the market regime.
btc = self.add_crypto("BTCUSD", Resolution.DAILY, Market.BITFINEX)
self.settings.automatic_indicator_warm_up = True
btc.sma = self.sma(btc, 50)
btc.roc = self.roc(btc, 20)
# Rebalance the portfolio at the start of each week.
self.schedule.on(
self.date_rules.week_start(qqq),
self.time_rules.at(8, 0),
# Trading rule: When BTCUSD is rising, hold QQQ. Otherwise, hold SHY.
lambda: self.set_holdings(qqq if btc.price > btc.sma.current.value and btc.roc.current.value > 0 else shy, 1, True)
)# region imports
from AlgorithmImports import *
# endregion
SPEC = """# Strategy: Bitcoin Telegrapher (BTC Momentum -> Nasdaq Gate)
Napkin-simple: ONE leading indicator (Bitcoin's medium-term trend), ONE traded asset (QQQ), ONE risk gate. Long/flat only, no portfolio-construction module, no shorting, no leverage, no options.
## One-Sentence Thesis
Own Nasdaq growth equities (QQQ) only while Bitcoin is in a positive medium-term trend (BTC close above its 50-day SMA AND its 20-day ROC positive); stand in cash/SHY the moment crypto risk-appetite rolls over.
## Economic Rationale
- Crypto is the highest-frequency expression of global risk appetite and dollar liquidity. Bitcoin trades 24/7 - nights, weekends, holidays - no circuit breakers, no market close, a deeply leveraged derivatives complex (perps/futures 50-100x). It reprices global risk-on/off funding-stress conditions immediately and continuously, well before the regular-session equity tape can react.
- Lead-lag into growth equities: Nasdaq/growth is a high-beta claim on the same global-liquidity/risk cycle, but it reprices only during the normal session through slower flow/positioning channels. A sustained multi-day BTC downtrend flags deteriorating risk conditions (deleveraging cascades, dollar-funding stress, retail flight) that propagate into tech/growth with a delay. The edge is harvesting that slower repricing while crypto's faster tape tells us when to step aside.
## Assets & Universe
- Traded asset (the only one we actually buy/sell): QQQ (Invesco QQQ Trust - Nasdaq-100, deeply liquid).
- Signal input: BTCUSD daily closes (LEAN crypto data). Signal-only; we never trade Bitcoin itself.
- Cash refuge: SHY (iShares 1-3 Year Treasury Bond ETF) - treated as plain cash.
- Fixed 2-3 symbol universe (QQQ + BTCUSD + SHY) - no universe-selection code.
## Data & Indicators
- Daily resolution for BTCUSD and QQQ. Matches a multi-week-to-month holding horizon; no intraday data.
- TWO built-in indicators on BTCUSD, both native LEAN, no custom math:
1. SMA(50) - medium-term regime (Bitcoin close above its 50-day simple moving average).
2. ROC(20) - 20-day rate of change on the close, short-term momentum confirmation.
## Signal Logic & Holding Horizon
1. Weekly (Monday at the open, via a weekly schedule), compute signals from prior-day closes (no look-ahead).
2. Risk-ON (BTC close > SMA(50) AND ROC(20, BTC) > 0): long QQQ, target ~100% of the portfolio.
3. Risk-OFF (either condition fails): sell QQQ, hold 100% SHY (or cash).
4. Rebalance weekly on the regime state. Position holds weeks-to-months; turnover is low (a handful of regime switches per year).
5. Long/flat only - no shorting, no leverage, no options.
## Risk Management
- Position is all-or-nothing long-and-flat. No leverage, no shorting, no options.
- The regime switch is itself the risk control: it mechanically removes exposure when Bitcoin's trend turns down.
## How to Backtest Honestly
- Period: 2014-01 to present (earliest clean intersection of exchange-traded BTCUSD and QQQ history; verify BTC data reach before ~2014 and do not trust thin years). Start cash $100k, daily resolution.
- Realistic costs: 5-10 bps slippage on QQQ (SPY-style). Turnover is low (roughly 2-6 round trips per year), so cost drag is small but must be modeled.
- No look-ahead: compute the ratio/indicators from prior-day closes, place the QQQ order at the next market open.
- Walk-forward / parameter sensitivity: confirm edge survives neighboring SMA/ROC windows.
## KILL condition
Net-of-cost risk-adjusted performance (Sharpe, max drawdown) of the gated long-QQQ strategy must justify the gate vs a simple long-only buy-and-hold QQQ over the same period. If the Bitcoin gate adds no timing value over just holding QQQ, the idea is dead. The honest win condition is risk-adjusted (lower/fewer drawdowns at comparable return per unit vol), not beating buy-and-hold QQQ on raw cumulative return during pure bull regimes.
## Failure Regimes / Weaknesses
- In a sustained QQQ bull with choppy-sideways BTC, whipsaw churn can bleed via crossing the SMA (mitigated by the ROC confirm).
- Fails materially when: (1) crypto-specific shocks decouple BTC from equities (exchange collapses, regulatory crackdowns, halving/ETF-flow idiosyncrasy, or crypto's own bear, e.g. 2022 USDT/LUNA-type cascades) drive BTC down without propagating to equities -> the gate goes flat and misses fine equity tape; (2) growth rallies while crypto stagnates (a decorrelation regime) -> we are wrongly parked in cash; (3) liquidity-driven crashes fall together faster than the weekly rebalance exit (the 2020-03 archetype) - the gate cannot protect against a same-weekend risk-off gap; (4) early-period BTC data is thin/noisy - results before ~2016 are unreliable.
- Biggest structural flaw: BTC and QQQ are both risk-on assets in the same global-liquidity complex. The timing is real but it is risk-appetite momentum, not an independent return harvest. Do NOT expect to beat buy-and-hold QQQ on raw cumulative return during pure bull regimes.
## LEAN / Framework Fit
- Classic event-driven API is the right fit (fixed signal asset + 1-ETF trade, weekly schedule): Initialize + a weekly schedule callback, SetHoldings/MarketOrder on QQQ, built-in SMA(50) and ROC(20) indicators on BTCUSD.
- AddCrypto("BTCUSD", ...) for the signal, AddEquity("QQQ") for the traded asset, AddEquity("SHY") for the cash refuge.
"""