residual-edge-analyzer
tradermonty/claude-trading-skills
Separate strategy returns into baseline exposure and residual alpha using returns-based OLS attribution with HAC inference and rolling stability analysis.
What is residual-edge-analyzer?
Isolates independent alpha in a strategy return series by comparing it against predeclared baseline factors (market, equal-weight, momentum, sector, or custom) using OLS regression with Newey-West standard errors. Use this after backtesting to audit whether apparent outperformance survives explicit baseline comparison, to explain drawdown sources, or to gate strategy deployment on attribution quality.
- Runs returns-based OLS attribution with HAC/Newey-West inference against primary and alternate baseline models
- Computes annualized alpha, residual edge ratio, and rolling stability across predeclared time windows
- Validates input contract: unique ISO dates, finite returns >-100%, identical frequency and cost basis, point-in-time universe membership where required
- Produces auditable JSON artifact and Markdown report with four diagnostic statuses: RESIDUAL_EDGE, BASELINE_EXPLAINED, RESIDUAL_FRAGILE, INSUFFICIENT_EVIDENCE
- Breaks down active returns by predeclared regimes and flags multicollinearity (VIF) and residual autocorrelation
- Requires predeclared baseline selection, cost basis, analysis scope, and universe data; marks undeclared fields as REVIEW_REQUIRED
How to install residual-edge-analyzer
npx skills add https://github.com/tradermonty/claude-trading-skills --skill residual-edge-analyzer- Python 3.9 or later
- CSV file with ISO dates, strategy returns, and all baseline returns on identical rows with identical frequency and cost basis
- JSON configuration file specifying baseline selection (predeclared), cost basis (gross or net), analysis scope (out_of_sample, live, or in_sample), and universe data provenance
How to use residual-edge-analyzer
- 1.State the claimed independent edge in one sentence and select a primary baseline (plausible simple copy of strategy) plus at least one alternate baseline model
- 2.Prepare CSV with ISO date column, strategy return column, and baseline return columns; validate unique dates, finite returns >-100%, and identical frequency
- 3.Create JSON config declaring baseline_selection, strategy_return_basis, baseline_return_basis, analysis_scope, and universe_data; mark as not_applicable if field does not apply rather than leaving blank
- 4.Run: 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
- 5.Inspect primary and sensitivity-model status, annualized alpha and HAC t-stat, residual edge ratio, rolling stability, VIF, and active-return regime breakdown in JSON output
- 6.Send baseline-choice and stability findings back to backtest-expert; pass regime failures to signal-postmortem; hand evidence only (never position changes) to trade-performance-coach
Use cases
- Evaluate whether backtest or out-of-sample returns contain independent alpha beyond a market or equal-weight baseline
- Diagnose whether a strategy drawdown originated from baseline exposure loss or strategy-specific behavior failure
- Gate live trading deployment by confirming residual edge stability across rolling windows and alternate baseline models
- Audit sensitivity of attribution results when baseline choice is uncertain or when strategy operates across multiple regimes
- Quantitative traders and portfolio managers evaluating strategy robustness after backtesting
- Risk analysts and compliance teams requiring auditable alpha attribution before live deployment
- Researchers comparing strategy performance across multiple factor models and market regimes
residual-edge-analyzer FAQ
Residual edge ratio = annualized alpha / annualized residual volatility. It measures alpha per unit of strategy-specific risk. Do not compute Sharpe from raw OLS residuals because an intercept model makes residual mean zero by construction.
Use residual-edge-analyzer for returns-based analysis when you have a dated return series. Use Brinson attribution when you have historical holdings, benchmark weights, and constituent returns; Brinson decomposes allocation and selection effects, not alpha vs. baseline.
Results fail one or more robustness gates (rolling stability, multicollinearity, autocorrelation), change across declared baseline models, or rolling analysis is unavailable or incomplete. Investigate sensitivity before treating residual edge as confirmed.
No. In-sample results are subject to overfitting. Use out-of-sample or live analysis scope for decision-grade verdicts. In-sample findings require out-of-sample confirmation.
Critical provenance, cost-basis, sample size, or multicollinearity warnings exist; rolling evidence is unavailable; or no alternate baseline was tested. Resolve warnings and rerun before using for deployment decisions.
Full instructions (SKILL.md)
Source of truth, from tradermonty/claude-trading-skills.
name: residual-edge-analyzer description: 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.
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 the input contract.
- 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: predeclaredstrategy_return_basisandbaseline_return_basis: bothgrossor bothnetanalysis_scope:out_of_sample,live, orin_sampleuniverse_data:point_in_time,current_constituents, ornot_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.
Related skills
More from tradermonty/claude-trading-skills and the wider catalog.

scenario-analyzer
Analyze 18-month investment scenarios from news headlines with dual-agent review.

sector-analyst
Analyze sector rotation patterns and market cycle positioning from CSV data without API keys.

signal-postmortem
Record and analyze post-trade outcomes to track signal quality and feed improvement feedback to edge pipeline.

skill-designer
Generate Claude CLI prompts to auto-create complete skills from structured idea specifications.

skill-idea-miner
Mine Claude Code session logs to extract and score skill idea candidates for your weekly pipeline.

skill-integration-tester
Validate multi-skill workflows and inter-skill data contracts before release.