Residual Edge Analyzer
Overview
Test whether a strategy's apparent performance survives explicit comparison with
predeclared baseline return series. Produce an auditable JSON artifact and a concise
Markdown report without fetching data or changing trading exposure.
Treat this as a falsification gate after backtest-expert, not as trade authorization.
Prerequisites
- Use Python 3.9+.
- Prepare one CSV containing an ISO date, strategy return, and every baseline return on
the same row.
- Prepare a JSON specification following
references/input-contract.md.
- Supply actual period returns. Do not substitute CAGR, Sharpe, cumulative P&L, or other
summary metrics.
Workflow
1. Define the question before inspecting results
State the claimed independent edge in one sentence. Select a primary baseline that is a
plausible simple copy of the strategy, then select at least one alternate baseline model.
Record these declarations in the config:
baseline_selection: predeclared
strategy_return_basis and baseline_return_basis: both gross or both net
analysis_scope: out_of_sample, live, or in_sample
universe_data: point_in_time, current_constituents, or not_applicable
Every declaration is mandatory for a decision-grade verdict. Omitting one is treated as
undeclared, not as benign, and drops the report to REVIEW_REQUIRED. not_applicable
exists so that a baseline with no universe membership can be declared explicitly rather
than left blank.
Do not choose a baseline because it gives the preferred residual result.
2. Validate the return-series contract
Require:
- unique ISO dates;
- finite numeric returns greater than -100%;
- identical frequency and cost basis across strategy and baselines;
- point-in-time membership for same-universe equal-weight or momentum baselines;
- regime labels defined independently of the loss periods being explained.
Stop if the input lacks a dated strategy return series. Report summary-only input as
insufficient rather than inventing observations.
3. Run the analyzer
python3 skills/residual-edge-analyzer/scripts/analyze_residual_edge.py \
--input reports/strategy_returns.csv \
--config reports/residual_edge_config.json \
--output-json reports/residual_edge_report.json \
--output-markdown reports/residual_edge_report.md
The script runs the predeclared primary model and all sensitivity models in one execution.
It uses an intercept OLS model and HAC/Newey-West standard errors. It reports the residual
edge ratio as annualized alpha divided by annualized residual volatility; do not calculate
a Sharpe ratio from raw OLS residual mean because an intercept makes that mean zero.
4. Interpret the evidence
Use the four statuses as diagnostic labels:
RESIDUAL_EDGE: alpha, residual edge ratio, and rolling stability clear configured
thresholds.
BASELINE_EXPLAINED: baseline R-squared is high while residual evidence is weak.
RESIDUAL_FRAGILE: results fail one or more robustness gates or change across declared
baseline models. Also use this status when rolling analysis is disabled, unavailable,
incomplete, or no sensitivity model was supplied.
INSUFFICIENT_EVIDENCE: the sample is below the configured minimum.
Read decision_eligibility separately. A statistically interesting result remains
REVIEW_REQUIRED when critical provenance, cost-basis, sample, or multicollinearity
warnings exist, when rolling evidence is unavailable, or when no alternate baseline was
tested.
Inspect:
- primary and sensitivity-model status;
- annualized alpha and HAC t-stat;
- residual edge ratio and residual autocorrelation;
- rolling alpha stability;
- VIF for multi-factor models;
- active-return breakdown across predeclared regimes.
5. Hand off findings
- Send baseline-choice, OOS, and stability findings back to
backtest-expert.
- Send recurring residual failure regimes to
signal-postmortem.
- Pass only evidence and operating constraints to
trade-performance-coach.
- Never change position size, exposure, or orders automatically.
Boundaries
- Do not call this holdings-based contribution analysis. Brinson allocation, selection,
and interaction effects require historical holdings, benchmark weights, and constituent
returns.
- Do not claim stock-selection alpha from a market-index-only baseline.
- Do not build equal-weight baselines from current constituents and label them
point-in-time.
- Do not interpret in-sample residual edge as confirmed alpha.
- Do not mine many regime definitions after seeing losses. Predeclare a small set and
confirm findings out of sample.
- Do not assume high R-squared makes a strategy worthless; capacity, tail behavior, costs,
and implementation value require separate evidence.
Resources
scripts/analyze_residual_edge.py — deterministic CSV-to-JSON/Markdown analyzer.
references/input-contract.md — CSV/config contract and runnable example.
references/methodology.md — statistical definitions, interpretation, and limitations.
1---2name: residual-edge-analyzer3description: Separate a strategy return series into declared baseline exposure and residual edge with returns-based OLS attribution, HAC inference, rolling stability, alternate-baseline sensitivity, and regime breakdowns. Use when evaluating whether backtest, out-of-sample, or live returns contain independent alpha beyond market, equal-weight, momentum, sector, or user-supplied factor returns; when explaining whether a drawdown came from baseline exposure or strategy-specific behavior; or when a strategy needs an attribution quality gate after backtesting. Do not use for holdings-based Brinson attribution, feature-level Shapley explanations, or analysis from summary metrics without a dated return series.4---5
6# Residual Edge Analyzer
7
8## Overview
9
10Test whether a strategy's apparent performance survives explicit comparison with
11predeclared baseline return series. Produce an auditable JSON artifact and a concise
12Markdown report without fetching data or changing trading exposure.
13
14Treat this as a falsification gate after `backtest-expert`, not as trade authorization.
15
16## Prerequisites
17
18- Use Python 3.9+.
19- Prepare one CSV containing an ISO date, strategy return, and every baseline return on
20 the same row.
21- Prepare a JSON specification following
22 [references/input-contract.md](references/input-contract.md).
23- Supply actual period returns. Do not substitute CAGR, Sharpe, cumulative P&L, or other
24 summary metrics.
25
26## Workflow
27
28### 1. Define the question before inspecting results
29
30State the claimed independent edge in one sentence. Select a primary baseline that is a
31plausible simple copy of the strategy, then select at least one alternate baseline model.
32
33Record these declarations in the config:
34
35- `baseline_selection: predeclared`
36- `strategy_return_basis` and `baseline_return_basis`: both `gross` or both `net`
37- `analysis_scope`: `out_of_sample`, `live`, or `in_sample`
38- `universe_data`: `point_in_time`, `current_constituents`, or `not_applicable`
39
40Every declaration is mandatory for a decision-grade verdict. Omitting one is treated as
41undeclared, not as benign, and drops the report to `REVIEW_REQUIRED`. `not_applicable`
42exists so that a baseline with no universe membership can be declared explicitly rather
43than left blank.
44
45Do not choose a baseline because it gives the preferred residual result.
46
47### 2. Validate the return-series contract
48
49Require:
50
51- unique ISO dates;
52- finite numeric returns greater than -100%;
53- identical frequency and cost basis across strategy and baselines;
54- point-in-time membership for same-universe equal-weight or momentum baselines;
55- regime labels defined independently of the loss periods being explained.
56
57Stop if the input lacks a dated strategy return series. Report summary-only input as
58insufficient rather than inventing observations.
59
60### 3. Run the analyzer
61
62```bash
63python3 skills/residual-edge-analyzer/scripts/analyze_residual_edge.py \
64 --input reports/strategy_returns.csv \
65 --config reports/residual_edge_config.json \
66 --output-json reports/residual_edge_report.json \
67 --output-markdown reports/residual_edge_report.md
68```
69
70The script runs the predeclared primary model and all sensitivity models in one execution.
71It uses an intercept OLS model and HAC/Newey-West standard errors. It reports the residual
72edge ratio as annualized alpha divided by annualized residual volatility; do not calculate
73a Sharpe ratio from raw OLS residual mean because an intercept makes that mean zero.
74
75### 4. Interpret the evidence
76
77Use the four statuses as diagnostic labels:
78
79- `RESIDUAL_EDGE`: alpha, residual edge ratio, and rolling stability clear configured
80 thresholds.
81- `BASELINE_EXPLAINED`: baseline R-squared is high while residual evidence is weak.
82- `RESIDUAL_FRAGILE`: results fail one or more robustness gates or change across declared
83 baseline models. Also use this status when rolling analysis is disabled, unavailable,
84 incomplete, or no sensitivity model was supplied.
85- `INSUFFICIENT_EVIDENCE`: the sample is below the configured minimum.
86
87Read `decision_eligibility` separately. A statistically interesting result remains
88`REVIEW_REQUIRED` when critical provenance, cost-basis, sample, or multicollinearity
89warnings exist, when rolling evidence is unavailable, or when no alternate baseline was
90tested.
91
92Inspect:
93
941. primary and sensitivity-model status;
952. annualized alpha and HAC t-stat;
963. residual edge ratio and residual autocorrelation;
974. rolling alpha stability;
985. VIF for multi-factor models;
996. active-return breakdown across predeclared regimes.
100
101### 5. Hand off findings
102
103- Send baseline-choice, OOS, and stability findings back to `backtest-expert`.
104- Send recurring residual failure regimes to `signal-postmortem`.
105- Pass only evidence and operating constraints to `trade-performance-coach`.
106- Never change position size, exposure, or orders automatically.
107
108## Boundaries
109
110- Do not call this holdings-based contribution analysis. Brinson allocation, selection,
111 and interaction effects require historical holdings, benchmark weights, and constituent
112 returns.
113- Do not claim stock-selection alpha from a market-index-only baseline.
114- Do not build equal-weight baselines from current constituents and label them
115 point-in-time.
116- Do not interpret in-sample residual edge as confirmed alpha.
117- Do not mine many regime definitions after seeing losses. Predeclare a small set and
118 confirm findings out of sample.
119- Do not assume high R-squared makes a strategy worthless; capacity, tail behavior, costs,
120 and implementation value require separate evidence.
121
122## Resources
123
124- `scripts/analyze_residual_edge.py` — deterministic CSV-to-JSON/Markdown analyzer.
125- `references/input-contract.md` — CSV/config contract and runnable example.
126- `references/methodology.md` — statistical definitions, interpretation, and limitations.