Skip to main content
skill CX Codex

residual-edge-analyzer — Claude Code skill: how to install

The skill separates strategy returns into declared baseline exposure and residual edge using OLS regression. It acts as a quality gate after backtesting.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add tradermonty/claude-trading-skills --skill residual-edge-analyzer -a claude-code
Open on GitHub

What residual-edge-analyzer does

The skill tests whether strategy performance survives direct comparison with predeclared baseline models. It applies intercept OLS regression with HAC/Newey-West standard errors to attribute returns between common market factors and residual alpha. This identifies whether a drawdown stems from baseline movements or strategy decisions.

Execution requires Python 3.9+ and the analyze_residual_edge.py script. The workflow expects a single CSV file with ISO dates and finite returns above -100%, along with a JSON configuration file. Summary metrics like CAGR or Sharpe ratio cannot replace a dated return series. Without chronological observations, the run halts immediately.

Results are written to JSON and Markdown reports with one of four statuses: RESIDUAL_EDGE, BASELINE_EXPLAINED, RESIDUAL_FRAGILE, or INSUFFICIENT_EVIDENCE. Incomplete declarations or multicollinearity flags force a REVIEW_REQUIRED state. The skill shares findings with other agents and never modifies trading orders directly.

What it helps with

  • Separate strategy returns into baseline exposure and residual alpha
  • Identify whether drawdowns come from market exposure or model logic
  • Verify return stability across rolling windows after backtesting
  • Check sensitivity against alternative baseline asset models

Example prompts for the agent

  • Analyze the return series in reports/strategy_returns.csv using reports/residual_edge_config.json.
  • Run residual-edge-analyzer to verify strategy alpha against the primary baseline.
  • Generate a residual edge attribution report in reports/residual_edge_report.md.

How to install residual-edge-analyzer

1Skills CLI (Vercel)

npx skills add tradermonty/claude-trading-skills --skill residual-edge-analyzer -a claude-code

2Manually: put the files in place

~/.claude/skills/residual-edge-analyzer/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/residual-edge-analyzer/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about residual-edge-analyzer

How to install residual-edge-analyzer in Claude Code?

Install it by running npx skills add tradermonty/claude-trading-skills --skill residual-edge-analyzer -a claude-code.

What does residual-edge-analyzer do?

It separates trading strategy returns into benchmark exposure and residual edge using OLS attribution with HAC standard errors. It outputs JSON and Markdown reports to evaluate whether alpha is genuine.

What inputs are required for residual-edge-analyzer?

You need Python 3.9+, a CSV file containing ISO dates with returns greater than -100%, and a matching JSON configuration contract. The tool cannot evaluate summary statistics without periodic dated returns.

Source text

SKILL.md · MIT
---
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](https://github.com/tradermonty/claude-trading-skills/blob/main/skills/residual-edge-analyzer/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

```bash
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:

1. primary and sensitivity-model status;
2. annualized alpha and HAC t-stat;
3. residual edge ratio and residual autocorrelation;
4. rolling alpha stability;
5. VIF for multi-factor models;
6. 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.

© tradermonty · MIT · tradermonty/claude-trading-skills

Similar skills

Everything for Finance and business →

From the same set73

stockbee-episodic-pivot-analyzer Evaluates Day 1 Episodic Pivot setups using Stockbee criteria. It pairs corporate catalysts with volume shocks and opening range price expansion. CX Codex +1 2,600installs fxmacrodata-calendar Pulls official FXMacroData release dates so a trade plan can pause entries ahead of CPI, NFP or a central-bank decision. CX Codex +1 2,500installs contrarian-setup-gate Synthesizes COT crowding, news-reaction failure, and weekly price action reports into one actionable trade setup status. Useful before sizing contrarian positions. CX Codex +1 2,500installs news-reaction-failure-analyzer Tests whether a crowded speculative position failed to benefit from favorable news. It handles step two of the COT contrarian process. CX Codex +1 2,500installs cot-contrarian-detector Runs a screen over CFTC futures markets to show where large speculators have piled onto one side. Useful when you want a starting point for a contrarian look. CX Codex +1 2,500installs futures-position-sizer Calculates contract-based futures position sizes from entry, stop-loss, and account risk budgets using verified specs. Runs completely offline via Python with no API keys. CX Codex +1 2,500installs manifoldbt-backtester Runs a declarative strategy spec over OHLCV bars with the manifoldbt engine and returns the eight metrics an evaluator scores. CX Codex +1 1,700installs us-undervalued-growth-screener Screens NYSE, Nasdaq and NYSE American stocks for undervalued-growth setups and returns a ranked report with a run audit. CX Codex +1 1,600installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor