Research methodology tooling¶
The tradedesk.research package automates two checks on a candidate
strategy:
- Walk-forward harness — runs a 2yr-train / 6mo-OOS rolling loop and reports IS Sharpe, OOS Sharpe, OOS/IS degradation ratio, and per-year drawdown on the chained OOS curve.
- Correlation gate — given a candidate's daily PnL and the daily PnL of
existing strategies (sleeves), computes the pairwise Pearson correlation
matrix and flags any sleeve at or above a threshold (default 0.6,
set with
threshold).
Both tools sit on top of the existing event-driven backtest runner; no new market-data plumbing is introduced.
Walk-forward harness¶
import asyncio
from datetime import date
from pathlib import Path
from tradedesk.research import WalkForwardSpec, run_walk_forward
def factory(client, window, phase):
# phase is "train" or "oos" — fit on train, freeze on oos
return build_my_strategy(client, fit_window=window if phase == "train" else None)
spec = WalkForwardSpec(
portfolio_factory=factory,
instrument="EURUSD",
period="HOUR",
cache_dir=Path("/data/marketdata"),
symbol="EURUSD",
date_from=date(2018, 1, 1),
date_to=date(2024, 1, 1),
)
report = asyncio.run(run_walk_forward(spec=spec, out_dir=Path("/tmp/wf")))
print(report.is_sharpe, report.oos_sharpe, report.degradation_ratio)
Window cadence is configurable via train_window and oos_window
(defaults: 730 days train, 183 days OOS). Windows step forward by
oos_window so the OOS slices are contiguous — you get continuous
coverage for the chained drawdown calculation.
When out_dir is supplied, every window writes its IS and OOS run
artefacts under {out_dir}/{train_from}_{oos_to}/{is|oos}/ for later
inspection.
End-to-end script: docs/examples/research_walk_forward.py.
Correlation gate¶
from tradedesk.research import correlation_gate, daily_pnl_from_csv
candidate_pnl = daily_pnl_from_csv("trades_candidate.csv")
sleeves = {
"fx_meanrev": daily_pnl_from_csv("live/fx_meanrev.csv"),
"dax_breakout": daily_pnl_from_csv("live/dax_breakout.csv"),
}
result = correlation_gate("my_candidate", candidate_pnl, sleeves)
if result.fails_gate:
raise SystemExit(f"correlation kill: {result.flagged}")
The gate accepts daily PnL as a dict[date, float]. Helpers exist for the
three input shapes researchers actually have to hand:
| Source | Helper |
|---|---|
Reconstructed RoundTrip objects from a backtest |
daily_pnl_from_round_trips |
| Raw fill-row dicts | daily_pnl_from_trade_rows |
| A trade-log CSV on disk | daily_pnl_from_csv |
Days where either series is silent are dropped, not zero-filled — silent
days carry no information about co-movement and would dilute the
correlation. Sleeves with fewer than min_overlap_days (default 20) of
shared trading days are reported in skipped_sleeves and excluded from
the kill check.
End-to-end script: docs/examples/research_correlation_gate.py.