Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Catalyst — Real-Time Streaming Alpha Decay & Feature Drift Monitor

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.

Architecture

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.

How the decay logic works

For each strategy, the engine keeps a rolling window of the last N=50 trades:

  1. Rolling IC — Spearman rank correlation between predicted_return and realized_return_5m over the window.
  2. t-statistic — t = IC · sqrt(N - 2) / sqrt(1 - IC² + ε). |t| < 1.96 means the IC is no longer significant at the 95% confidence level.
  3. Feature drift (KS test) — the first fully-populated window of input_volatility per strategy is frozen as the "backtest norm" baseline; every subsequent window is KS-tested against it. p < 0.05 means 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.

Setup

cd catalyst-alpha-decay
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

Run

From the repository root (catalyst-alpha-decay/):

uvicorn backend.main:app --reload --port 8000

On 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.

API

  • GET /health — service liveness check.
  • GET /api/metrics/summary — current SystemState: 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 watch WARNING/PAUSED states trigger live. Calling it again on the same strategy reverts it to normal, for repeatable demos.
  • WS /ws/metrics — streams every DecayMetrics JSON object as it's computed (roughly one message per strategy per 500ms tick). Fan-out is handled by an asyncio.Lock-guarded connection manager, so any number of clients can subscribe concurrently.

Quick demo

# 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/summary

Within 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.

Frontend integration

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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages