$ cat methodology.md
Technical foundations of the Rebel Terminal analysis engine.
Conformal Prediction
Instead of giving you a single number ("BTC will be at $70k"), we are building toward giving you a range ("BTC will be between $58k and $82k") with a statistical coverage property. When the live engine ships, a 90% interval will be designed to contain the true value about 90% of the time. Current figures are illustrative samples.
Conformal prediction is the framework we are building toward: a distribution-free method for constructing prediction sets with finite-sample coverage properties. Given a calibration set {(X_i, Y_i)}_{i=1}^n and a new test point X_{n+1}, the conformal prediction set C(X_{n+1}) satisfies P(Y_{n+1} ∈ C(X_{n+1})) ≥ 1 - α under the exchangeability assumption. No parametric distributional assumptions are required. Our roadmap includes three methods — StandardCP, MondrianCP, and CQR. No conformal model is currently in production; all figures shown are illustrative samples.
P(Y_{n+1} ∈ C(X_{n+1})) ≥ 1 - α[1] Vovk, V., Gammerman, A., & Shafer, G. (2005). Algorithmic Learning in a Random World. Springer.
[2] Romano, Y., Patterson, E., & Candès, E. (2019). "Conformalized Quantile Regression." NeurIPS.
[3] Barber, R.F., Candès, E.J., Ramdas, A., & Tibshirani, R.J. (2021). "Predictive Inference with the Jackknife+." Annals of Statistics.
Coverage Methods
Our roadmap includes three methods for different data types. StandardCP covers most cases. MondrianCP is designed to give separate coverage for each market regime (expansion vs contraction). CQR is designed for cases where uncertainty varies — wider intervals when volatility is high, tighter when it's calm.
StandardCP: Split conformal with nonconformity scores s_i = |Y_i - μ̂(X_i)| for regression or 1 - π̂_y(X_i) for classification. The prediction set includes all labels y where the score is below the (1-α)(1+1/n) quantile of calibration scores. MondrianCP: Group-conditional conformal that partitions the calibration set by regime labels (EXPANSION/CONTRACTION/TRANSITION) and computes per-group thresholds. is designed to provide coverage properties within each group, not just marginally (roadmap). CQR: Trains quantile regressors at levels α/2 and 1-α/2, then conformally calibrates the residuals, designed to provide finite-sample coverage (roadmap), producing intervals that adapt to local variance.
[1] Mondrian Conformal Predictors: Vovk, V. (2013). "Conditional Validity of Inductive Conformal Predictors." JMLR Workshop.
[2] CQR: Romano, Y., Patterson, E., & Candès, E. (2019). NeurIPS.
Hamilton Filter (Detrending)
Economic data has long-term trends that obscure cyclical patterns. The Hamilton filter removes the trend using a regression-based approach, leaving behind the cyclical signal we care about — the liquidity cycle. Unlike the popular HP filter, it doesn't create artificial cycles at the endpoints of the data.
The Hamilton filter regresses Y_t on Y_{t-h} (typically h=24 months) to extract the cyclical component as the residual: ε_t = Y_t - β̂₀ - β̂₁Y_{t-h}. This avoids the spurious cycle artifacts and endpoint instability of the Hodrick-Prescott filter. The residuals preserve the spectral properties of the underlying cyclical dynamics without introducing phase shifts.
ε_t = Y_t - β̂₀ - β̂₁·Y_{t-h}[1] Hamilton, J.D. (2018). "Why You Should Never Use the Hodrick-Prescott Filter." Review of Economics and Statistics, 100(5), 831-843.
Lomb-Scargle Periodogram (Cycle Detection)
After detrending, we need to find the dominant cycle frequency — how long does a full liquidity cycle take? The Lomb-Scargle method detects periodic patterns even when data points aren't evenly spaced (common with economic data). It tells us the cycle length, where we are in it (peak, trough, recovery, contraction), and how confident we should be in that classification.
The Lomb-Scargle periodogram estimates spectral power P(ω) at angular frequency ω from unevenly sampled data. We apply it to Hamilton-filtered residuals to identify the dominant cycle frequency. The fitted sinusoid f(t) = A·sin(ωt + φ) parameterizes the cycle position into four quadrants: TROUGH (φ ∈ [π, 3π/2)), RECOVERY (φ ∈ [3π/2, 2π)), PEAK (φ ∈ [0, π/2)), CONTRACTION (φ ∈ [π/2, π)). R² of the sinusoidal fit quantifies cycle regularity.
P(ω) = (1/2){[Σ(Y_i - Ȳ)cos(ω(t_i - τ))]² / Σcos²(ω(t_i - τ)) + [Σ(Y_i - Ȳ)sin(ω(t_i - τ))]² / Σsin²(ω(t_i - τ))}[1] Lomb, N.R. (1976). "Least-squares frequency analysis of unequally spaced data." Astrophysics and Space Science, 39, 447-462.
[2] Scargle, J.D. (1982). "Studies in astronomical time series analysis." Astrophysical Journal, 263, 835-853.
Net Supply-Demand (Net S-D)
Net S-D answers one question: is there more liquidity entering the system (bullish) or leaving it (bearish)? We take supply indicators (Fed balance sheet, M2 money supply, bank reserves) and subtract demand indicators (Treasury issuance, reverse repo absorption). The result is a single number — positive means liquidity is expanding, negative means it's tightening.
Net S-D is a composite z-score: z(supply) - z(demand). Supply components (e.g., Fed total assets, M2, bank reserves) are individually z-scored over a trailing window and averaged. Demand components (e.g., Treasury general account, RRP facility balance) are similarly z-scored, optionally sign-inverted, and averaged. The composite is computed monthly from 1998–present. Year-over-year changes in Net S-D drive regime classification: sustained positive ΔNet S-D → EXPANSION, sustained negative → CONTRACTION, ambiguous → TRANSITION.
[1] Howell, M. (2020). Capital Wars: The Rise of Global Liquidity. Springer.
Regime Detection
Markets operate in three states: expansion (liquidity growing, risk assets rising), contraction (liquidity shrinking, risk assets falling), and transition (mixed signals, regime is changing). We detect the current regime from Net S-D changes and historical patterns. Since 2006, we've identified 98 regime transitions with clear patterns in how BTC and other assets behave in each state.
Regime labels are assigned based on year-over-year ΔNet S-D with hysteresis thresholds to prevent chattering. The classification uses a 3-state model: EXPANSION (ΔNet S-D > +σ for ≥3 consecutive months), CONTRACTION (ΔNet S-D < -σ for ≥3 consecutive months), TRANSITION (otherwise). On our roadmap, MondrianCP would leverage these regime labels for group-conditional conformal inference, designed to provide coverage properties stratified by market state. Regime durations range from 4 to 36 months historically.
[1] Hamilton, J.D. (1989). "A New Approach to the Economic Analysis of Nonstationary Time Series." Econometrica, 57(2), 357-384.
Regime Nowcast (Tier-0)
The regime nowcast is the one model actually running in production: it reads the latest macro snapshot and outputs probabilities over four regimes (expansion, late cycle, contraction, early recovery) that sum to 1. When the database has no snapshot, the UI says so instead of guessing.
GET /api/quant/regime-nowcast serves the current m02-nowcast snapshot (Σpᵢ = 1 enforced by DB CHECK). The Quant Lab regime tab renders the distribution with a staleness chip; hit-rates in GET /api/signal/hit-rate score the nowcast timeline against realized forward returns with Wilson 95% CIs.
Backtesting Protocol
We don't just test our models on the data they were trained on — that would be cheating. We use temporal cross-validation: train on past data, predict the future, measure how often our intervals contain the true value. We enforce a strict rule that training data never overlaps with test data chronologically, mimicking real-world deployment. Our coverage target is 90% ± 5pp (the 85-95% acceptance band the slot classifier enforces).
Temporal cross-validation with purged groups: fold boundaries are determined by time-sorted indices with a gap buffer equal to the forecast horizon. Within each fold, the model is trained on data before the purge boundary and evaluated on data after it. Coverage is measured as the fraction of test points whose true value falls within the conformal prediction set. We target 90% coverage (α=0.10) with an acceptance band of [85%, 95%]. Slots are classified as ON_TARGET (85-95%), OVERCOVERING (>95%), or UNDERCOVERING (<85%).
[1] de Prado, M.L. (2018). Advances in Financial Machine Learning. Wiley. (Chapter 7: Cross-Validation in Finance)
[2] Arlot, S. & Celisse, A. (2010). "A survey of cross-validation procedures for model selection." Statistics Surveys, 4, 40-79.
Why Macro Matters for Active Traders
Day traders and swing traders often dismiss macro data as "too slow." But macro regime detection acts as a directional filter — in expansion regimes, long setups historically have a 68% hit rate vs 47% in contraction. The VIX z-score provides a timely risk management overlay. Net S-D trend gives directional bias. You don't need to trade the macro signal directly — use it to size positions, filter entries, and manage risk.
Macro regime context improves intraday alpha through three mechanisms: (1) Directional bias: BTC 12-month returns average +127% in EXPANSION vs -31% in CONTRACTION regimes since 2015, providing a statistical prior for trade direction. (2) Volatility regime: VIX z-score > 1.5 correlates with 2.3x average true range expansion, affecting position sizing and stop placement. (3) Correlation regime: Cross-asset correlations shift significantly between regimes (BTC-SPX correlation: +0.62 in contraction vs +0.21 in expansion), affecting portfolio hedging and pair trades.
Data Sources & Freshness
We track 9 FRED series with data in the current snapshot (see /data/fred-series-manifest.json for per-series row counts; us2y, ffr, and ism are empty in this snapshot). Market data (BTC, ETH, S&P 500, VIX, Gold, DXY) comes from Yahoo Finance. The snapshot is frozen at March 2026 — a FRED refresh job is on the roadmap to unfreeze it.
The FRED refresh map covers 11 series ids (WALCL, M2SL, WTREGEN, RRPONTSYD, TOTRESNS, DGS5, SOFR, BAMLH0A0HYM2, BAMLC0A0CAA, NAPM, VIXCLS); 9 carry data in the March-2026 snapshot. Market data from Yahoo Finance covers 8 core assets at daily resolution. Derived features include z-scores (trailing 36-month window), year-over-year changes, Hamilton-filtered residuals, and Lomb-Scargle cycle parameters.
Rebel Standard Library (SDK)
The Rebel Standard Library (`rebel`) is a native Python SDK built into the Workspace environment. It allows you to interface directly with the Rebel Terminal UI, pushing your custom Python calculations onto interactive charts or deploying them as permanent modules in the Intelligence Hub.
The `rebel` module is automatically injected into the PYTHONPATH of the secure execution environment. Methods: • `rebel.plot(name: str, values: list, color: str)`: Emits a standard JSON payload (`{"overlay_chart": ...}`) intercepted by the frontend Terminal. Maps the vector to the active conformal prediction chart using the global timeline. • `rebel.promote_to_hub(slot: str, name: str, values: list, regime: str, confidence: float)`: Extends the plot payload with `promote_to_hub: True` and a target `slot` (L5-L12). The frontend intercepts this to dynamically populate the `FormulaDataContext`, persisting the module via `localStorage` to survive page navigation to `/intelligence`.
from rebel import rebel\nrebel.promote_to_hub(slot="L5", ...)