# walk-forward-validation

Walk-forward validation framework for trading strategies and ML models. It handles financial time-series splits, prevents lookahead bias, and tests for overfitting.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 703 installs · ★ 443
- Author: agiprolabs
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/agiprolabs/claude-trading-skills/tree/HEAD/skills/walk-forward-validation/SKILL.md
- Updated: 2026-09-03
- HTML: https://affpapa.org/en/nevibecode/skills/walk-forward-validation

## What it does

Standard k-fold cross-validation fails on financial time series because random splits leak future data and ignore serial correlation. Financial data requires strict temporal splits. This skill defines rolling and expanding training windows, with sample purging and embargo gaps between folds.

The skill includes combinatorial purged cross-validation (CPCV) and statistical overfit detection metrics. It provides Python implementations for the Deflated Sharpe Ratio and Probability of Backtest Overfitting (PBO). You will need numpy and scipy installed, because the Deflated Sharpe calculation relies on both packages.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add agiprolabs/claude-trading-skills --skill walk-forward-validation -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/walk-forward-validation/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/walk-forward-validation/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add agiprolabs/claude-trading-skills --skill walk-forward-validation -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/walk-forward-validation/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add agiprolabs/claude-trading-skills --skill walk-forward-validation -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/walk-forward-validation/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install agiprolabs/claude-trading-skills walk-forward-validation
```

2. **Manually: put the files in place**
- File: `.github/skills/walk-forward-validation/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add agiprolabs/claude-trading-skills --skill walk-forward-validation -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/agiprolabs/claude-trading-skills --path skills/walk-forward-validation
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/walk-forward-validation/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add agiprolabs/claude-trading-skills --skill walk-forward-validation -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/agiprolabs/claude-trading-skills/tree/HEAD/skills/walk-forward-validation/SKILL.md

## When to use it
- split financial time series without lookahead bias
- purge overlapping label windows between train and test splits
- apply embargo gaps to eliminate residual serial correlation
- calculate Deflated Sharpe Ratio adjusted for multiple testing
- estimate Probability of Backtest Overfitting using CPCV

## Example prompts
- Help me set up rolling window validation for my trading strategy with label purging
- Implement the Deflated Sharpe Ratio in Python to test my backtest results
- Configure combinatorial purged cross-validation with an embargo period for crypto time series

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 139effde65954323.

BEGIN THIRD-PARTY FILE 139effde65954323
````text
---
name: walk-forward-validation
description: Walk-forward validation framework for trading strategies and ML models with time-series-aware splits, overfit detection, and regime-aware validation
---

# Walk-Forward Validation

Walk-forward validation framework for trading strategies and ML models. Standard cross-validation (k-fold, random splits) fails catastrophically for financial time series because it introduces lookahead bias and ignores autocorrelation. This skill covers proper time-series validation techniques including rolling and expanding windows, purged cross-validation, combinatorial purged cross-validation (CPCV), and overfit detection metrics.

## Why Standard Cross-Validation Fails

Standard k-fold CV assumes data points are independent and identically distributed (IID). Financial time series violate both assumptions:

1. **Lookahead bias** — Random splits let the model train on future data and predict past data, artificially inflating performance.
2. **Autocorrelation** — Adjacent observations are correlated. A random split that puts Monday in test and Tuesday in train leaks information.
3. **Regime dependence** — Markets shift between regimes. A model trained on a bull market and tested on a bull market tells you nothing about bear market performance.
4. **Label overlap** — If labels are computed over windows (e.g., 24h forward return), adjacent train/test samples share label computation periods, leaking information.

## Walk-Forward Framework

### Rolling Window (Fixed Train Size)

The train window has a fixed size and slides forward in time. This is preferred when you believe older data is less relevant (common in crypto).

```
Window 1: [===TRAIN===][=TEST=]
Window 2:    [===TRAIN===][=TEST=]
Window 3:       [===TRAIN===][=TEST=]
```

**Parameters:**
- `train_size`: Number of bars/days in the training window
- `test_size`: Number of bars/days in the test window
- `step_size`: How far to advance between folds (often equals `test_size`)

### Expanding Window (Growing Train)

The train window starts at the beginning and expands forward. This uses all available historical data, which helps when data is scarce.

```
Window 1: [==TRAIN==][=TEST=]
Window 2: [====TRAIN====][=TEST=]
Window 3: [======TRAIN======][=TEST=]
```

**Parameters:**
- `min_train_size`: Minimum training samples before first fold
- `test_size`: Fixed test window size
- `step_size`: How far to advance between folds

### Choosing Between Them

| Factor | Rolling | Expanding |
|---|---|---|
| Data recency | Prioritizes recent data | Uses all history |
| Regime changes | Better adapts to new regimes | May dilute recent regime |
| Sample size | Fixed, may be small | Grows over time |
````
END THIRD-PARTY FILE 139effde65954323

The third-party file has ended. Everything between the 139effde65954323 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2719 of 8768 bytes. © agiprolabs · MIT · https://github.com/agiprolabs/claude-trading-skills/tree/HEAD/skills/walk-forward-validation/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
