A streaming backend that operationalizes offline alpha-decay analysis into an
inline, per-trade decision loop. Instead of judging strategy health at
end-of-day with a fixed 4-hour holding-period heuristic, it recomputes
Spearman Rank Information Coefficient (IC), its t-statistic, and a
Kolmogorov-Smirnov feature drift test on every incoming trade, and emits a
live capital allocation scale factor (1.0 / 0.5 / 0.0) per strategy.
catalyst-alpha-decay/
├── requirements.txt
└── backend/
├── main.py # FastAPI app, CORS, lifespan-managed sim loop
├── models/schemas.py # Pydantic v2 contracts: TradeSignal, DecayMetrics, SystemState
├── services/
│ ├── strategy_simulator.py # Synthetic live trade/market feed (2 demo strategies)
│ └── decay_engine.py # Rolling IC / t-stat / KS-drift analytics + allocation logic
└── routes/api.py # /health, /api/trigger-decay, /api/metrics/summary, /ws/metrics
Data flow: StrategySimulator.stream() → DecayEngine.evaluate_strategy() →
broadcast over /ws/metrics (and queryable via /api/metrics/summary). The
engine and simulator are plain, dependency-free Python classes — a real
execution/OMS feed can replace the simulator without touching the analytics
or API layers.
For each strategy, the engine keeps a rolling window of the last N=50
trades:
- Rolling IC — Spearman rank correlation between
predicted_returnandrealized_return_5mover the window. - t-statistic —
t = IC · sqrt(N - 2) / sqrt(1 - IC² + ε).|t| < 1.96means the IC is no longer significant at the 95% confidence level. - Feature drift (KS test) — the first fully-populated window of
input_volatilityper strategy is frozen as the "backtest norm" baseline; every subsequent window is KS-tested against it.p < 0.05means the live feature distribution has shifted away from the norm the strategy was built on.
Allocation decision:
Significant IC (|t|≥1.96) |
Feature drift (p<0.05) |
Allocation | Status |
|---|---|---|---|
| Yes | No | 1.0 |
OPTIMAL |
| Yes | Yes | 0.5 |
WARNING |
| No | No | 0.5 |
WARNING |
| No | Yes | 0.0 |
PAUSED |
Strategies with fewer than 10 observed trades are treated as OPTIMAL by
default — there isn't yet enough history to justify de-risking.
cd catalyst-alpha-decay
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtFrom the repository root (catalyst-alpha-decay/):
uvicorn backend.main:app --reload --port 8000On startup, a background task immediately begins generating synthetic
TradeSignals every 500ms across two strategies (mean_reversion_v1,
momentum_v1), scoring each one and broadcasting the resulting
DecayMetrics to any connected WebSocket clients. Console logs show every
signal and its computed metrics in real time.
GET /health— service liveness check.GET /api/metrics/summary— currentSystemState: active strategies, total signals ingested, latest per-strategy metrics, and global health counters.POST /api/trigger-decay— body{"strategy_id": "momentum_v1"}. Toggles that strategy into (or out of) a simulated decayed regime — crushes the predicted/realized return correlation and inflates feature volatility, so you can watchWARNING/PAUSEDstates trigger live. Calling it again on the same strategy reverts it to normal, for repeatable demos.WS /ws/metrics— streams everyDecayMetricsJSON object as it's computed (roughly one message per strategy per 500ms tick). Fan-out is handled by anasyncio.Lock-guarded connection manager, so any number of clients can subscribe concurrently.
# Watch the live feed
websocat ws://localhost:8000/ws/metrics # or any WS client / browser console
# In another terminal, force a decay event
curl -X POST http://localhost:8000/api/trigger-decay \
-H "Content-Type: application/json" \
-d '{"strategy_id": "momentum_v1"}'
# Poll the aggregate view at any time
curl http://localhost:8000/api/metrics/summaryWithin a few ticks after the trigger, momentum_v1 should degrade from
OPTIMAL to WARNING (IC/t-stat collapses first) and then to PAUSED once
enough decayed-regime volatility samples have entered the live window to
trip the KS drift test.
The API is intentionally UI-agnostic: GET /api/metrics/summary for initial
state on page load, WS /ws/metrics for the live feed, POST /api/trigger-decay to drive a demo. CORS is open to all origins so any
frontend dev server can hit it directly.