Skip to main content
skill CX Codex

volatility-modeling · agiprolabs — Claude Code skill: what it does, how to install

Estimates crypto volatility, constructs volatility cones, and forecasts regimes via GARCH and EWMA. Useful for position sizing and stop placement.

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

What volatility-modeling does

This skill implements volatility estimators tailored for crypto assets. It covers standard close-to-close deviation, range-based Parkinson, and OHLC-based Garman-Klass and Yang-Zhang methods. For forecasting, it includes RiskMetrics EWMA and GARCH(1,1) models. Annualized calculations rely on 365 trading days rather than standard equity calendars.

The skill outlines steps to build volatility cones across lookback windows to spot whether current levels sit above historical percentiles. It also groups market dynamics into clear volatility regimes, from low-volatility ranges to crisis periods with liquidation cascades. Implementing the reference scripts requires Python with numpy, while the ATR stop logic relies on talib.

Keep in mind that Garman-Klass assumes zero drift and struggles with opening gaps, which makes Yang-Zhang a safer choice when tokens display sporadic trading gaps.

What it helps with

  • select a historical volatility estimator for daily or OHLC price data
  • forecast future asset variance using EWMA or GARCH(1,1)
  • construct volatility cones to identify historical percentile extremes
  • classify market conditions into regimes to adjust position sizing

Example prompts for the agent

  • Calculate Garman-Klass volatility for daily BTC OHLC data.
  • Construct a volatility cone for ETH across windows of 5, 10, 20, 60, and 120 days.
  • Forecast asset variance using the GARCH(1,1) model.

How to install volatility-modeling

1Skills CLI (Vercel)

npx skills add agiprolabs/claude-trading-skills --skill volatility-modeling -a claude-code

2Manually: put the files in place

~/.claude/skills/volatility-modeling/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/volatility-modeling/

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

Questions about volatility-modeling

How to install volatility-modeling in Claude Code?

Run npx skills add agiprolabs/claude-trading-skills --skill volatility-modeling -a claude-code in your terminal.

Which estimators does volatility-modeling include?

It covers Close-to-Close, Parkinson, Garman-Klass, Yang-Zhang, along with EWMA and GARCH(1,1) forecasting models.

What dependencies are required to run the code snippets?

The formulas and estimation routines rely on Python with numpy. Calculating ATR stops also requires talib.

Source text

SKILL.md · MIT
---
name: volatility-modeling
description: Volatility estimation, forecasting, and regime classification using GARCH, EWMA, realized volatility, and volatility cones
---

# Volatility Modeling

Volatility — the magnitude of price fluctuations — is arguably the single most
important quantity in trading.  It drives position sizing, stop placement, option
pricing, and regime detection.  This skill covers estimation, forecasting, and
practical application of volatility in crypto markets.

## Why Volatility Matters

| Use Case | How Volatility Is Used |
|---|---|
| **Position sizing** | Scale position inversely with vol so each trade risks a consistent dollar amount |
| **Stop placement** | ATR-based stops widen in high-vol regimes, tighten in low-vol |
| **Strategy selection** | Mean-reversion works in low vol; momentum works in high vol |
| **Risk budgeting** | Vol-target portfolios maintain constant portfolio-level risk |
| **Regime detection** | Vol regime shifts signal changing market dynamics |
| **Option pricing** | Implied vs realized vol gap creates trading opportunities |

## Types of Volatility

### Historical (Realized) Volatility
Computed from observed past returns.  The most common and directly measurable
form.  Multiple estimators exist with different statistical efficiency.

### Implied Volatility
Derived from option prices via Black-Scholes or similar models.  Limited in
crypto DeFi where liquid options markets are sparse, but available on Deribit
for BTC/ETH.

### Forecast Volatility
Predicted future volatility from models like EWMA or GARCH.  Used for
forward-looking position sizing and risk budgets.

---

## Estimation Methods

### 1. Close-to-Close (Standard Deviation of Log Returns)

The simplest estimator.  Compute the standard deviation of log returns and
annualize.

```python
import numpy as np

log_returns = np.log(closes[1:] / closes[:-1])
vol_daily = np.std(log_returns, ddof=1)
vol_annual = vol_daily * np.sqrt(365)  # crypto trades 365 days
```

- **Pros**: Simple, widely understood.
- **Cons**: Uses only close prices — ignores intraday range.

### 2. Parkinson (High-Low Range)

Uses the daily high-low range, which is ~5x more statistically efficient than
close-to-close.

```python
hl_ratio = np.log(highs / lows)
vol_parkinson = np.sqrt(np.mean(hl_ratio**2) / (4 * np.log(2))) * np.sqrt(365)
```

- **Pros**: More efficient, captures intraday moves.
- **Cons**: Downward bias with discrete sampling; ignores close-to-close jumps.

### 3. Garman-Klass (OHLC)

The most efficient single-day OHLC estimator.

```python
hl = np.log(highs / lows)
co = np.log(closes / opens)
gk = np.mean(0.5 * hl**2 - (2 * np.log(2) - 1) * co**2)
vol_gk = np.sqrt(gk) * np.sqrt(365)
```

- **Pros**: Best efficiency among OHLC estimators.
- **Cons**: Assumes no drift; sensitive to opening gaps.

### 4. Yang-Zhang

Combines overnight (close-to-open) and open-to-close components.  Handles
gaps properly.  Less relevant for 24/7 crypto but useful for tokens with
sporadic trading.

### 5. EWMA (Exponentially Weighted Moving Average)

RiskMetrics approach — no parameters to estimate beyond λ.

```python
lam = 0.94  # RiskMetrics default for daily
ewma_var = np.zeros(len(returns))
ewma_var[0] = returns[0] ** 2
for t in range(1, len(returns)):
    ewma_var[t] = lam * ewma_var[t - 1] + (1 - lam) * returns[t - 1] ** 2
vol_ewma = np.sqrt(ewma_var) * np.sqrt(365)
```

- λ = 0.94 for daily data (RiskMetrics).
- λ = 0.97 for weekly data.
- Higher λ → smoother, slower reaction to new information.

### 6. GARCH(1,1)

The workhorse autoregressive volatility model.  Captures volatility clustering.

```
σ²_t = ω + α · r²_{t-1} + β · σ²_{t-1}
```

- **ω**: long-run variance weight.
- **α**: reaction to recent shock (typically 0.05–0.15 for crypto).
- **β**: persistence (typically 0.80–0.90 for crypto).
- **α + β < 1**: stationarity constraint.
- **Long-run variance**: ω / (1 − α − β).

Estimated via maximum likelihood.  See `references/estimators.md` for details.

---

## Volatility Cones

Volatility cones show the percentile distribution of realized volatility at
different lookback windows, revealing whether current vol is historically
high or low.

### Construction
1. Get 1+ years of daily data.
2. For each lookback window (5, 10, 20, 60, 120 days):
   - Compute rolling realized volatility.
   - Extract percentiles: 5th, 25th, 50th, 75th, 95th.
3. Plot percentiles vs window length — the "cone" shape.
4. Overlay current realized vol at each window.

### Interpretation
- **Current vol > 75th percentile**: historically elevated — expect mean reversion.
- **Current vol < 25th percentile**: historically compressed — expect expansion.
- **Cone narrowing at longer windows**: vol mean-reverts over longer horizons.

See `references/volatility_cones.md` for full methodology and worked examples.

---

## Crypto Volatility Characteristics

Crypto vol differs from traditional assets in important ways:

| Characteristic | Detail |
|---|---|
| **Level** | 50–150% annualized is typical; TradFi equities are 15–25% |
| **Clustering** | Strong — high-vol days cluster together |
| **Weekday patterns** | Weekend vol often lower but weekend gaps can be large |
| **Volume correlation** | Vol and volume are positively correlated |
| **Regime dependence** | Bull market vol ≠ bear market vol; ranges are different |
| **Mean reversion** | Vol mean-reverts more reliably than price |
| **Tail risk** | Fat tails — more extreme moves than normal distribution predicts |

### Regime Classification by Volatility

| Regime | Annualized Vol Range | Characteristics |
|---|---|---|
| Low vol | < 40% | Range-bound, mean reversion works |
| Normal vol | 40–80% | Trending possible, balanced strategies |
| High vol | 80–120% | Strong trends or sharp reversals |
| Crisis vol | > 120% | Liquidation cascades, reduced position size |

---

## Volatility Forecasting

### EWMA Forecast
Simple and effective.  The current EWMA variance estimate *is* the 1-step
forecast.  Multi-step forecasts are flat (same as 1-step).

### GARCH Forecast
GARCH produces a term structure of variance forecasts:

```
σ²_{t+h} = V_L + (α + β)^h · (σ²_t − V_L)
```

Where V_L = ω / (1 − α − β) is the long-run variance.

- Short-horizon forecasts reflect current conditions.
- Long-horizon forecasts converge to long-run variance.
- The speed of convergence depends on α + β (persistence).

See `scripts/vol_forecast.py` for a working implementation.

---

## Practical Applications

### Position Sizing with Volatility
```python
# Vol-target position sizing
target_vol = 0.02  # 2% daily portfolio vol target
current_vol = 0.05  # 5% daily asset vol (annualized ~95%)
weight = target_vol / current_vol  # = 0.40 → 40% allocation
```

See the `position-sizing` skill for complete integration.

### ATR-Based Stop Placement
```python
atr_14 = talib.ATR(highs, lows, closes, timeperiod=14)
stop_distance = 2.0 * atr_14[-1]  # 2x ATR stop
stop_price = entry_price - stop_distance  # for longs
```

### Vol-Regime Strategy Selection
```python
vol_percentile = current_vol_percentile(token, window=30)
if vol_percentile < 25:
    strategy = "mean_reversion"
elif vol_percentile > 75:
    strategy = "momentum_breakout"
else:
    strategy = "balanced"
```

---

## Files

### References
| File | Description |
|---|---|
| `references/estimators.md` | Full derivations and details for all volatility estimators |
| `references/volatility_cones.md` | Cone construction methodology and interpretation guide |

### Scripts
| File | Description |
|---|---|
| `scripts/estimate_volatility.py` | Multi-estimator volatility computation with cone analysis |
| `scripts/vol_forecast.py` | EWMA and GARCH forecasting with term structure output |

---

## Related Skills

- **`regime-detection`** — Classify market regimes using volatility as a key input.
- **`position-sizing`** — Scale positions inversely with volatility.
- **`risk-management`** — Portfolio-level vol targeting and risk budgets.
- **`pandas-ta`** — ATR and Bollinger Bands are volatility-based indicators.
- **`custom-indicators`** — Build crypto-specific volatility indicators.

---

## Dependencies

```bash
uv pip install pandas numpy scipy
```

Optional for live data:
```bash
uv pip install httpx
```

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

Similar skills

Everything for Finance and business →

volatility-modeling by other authors comes first.

From the same set52

trading-visualization Builds trading charts: candlesticks, equity curves, drawdowns, correlation heatmaps and return distributions. Useful when you need to review a strategy or put together a report. CX Codex +1 508installs exit-strategies Provides systematic exit rules, ATR stop-loss logic, and trailing stop strategies for crypto and Solana trading. Useful for automating disciplined position management. CX Codex +1 505installs strategy-framework Gives you one template for writing a trading strategy down: entry and exit rules, position sizing, risk limits, performance criteria. Useful when the idea exists but the document does not. CX Codex +1 500installs backtrader A skill that teaches your agent to write backtests with the Python backtrader framework: bar-by-bar execution, bracket orders, commission and slippage. CX Codex +1 498installs ta-lib Provides C-optimized technical analysis with 150+ indicators and 61 candlestick patterns via TA-Lib. Essential for high-performance trading pipelines on large price datasets. CX Codex +1 493installs vectorbt Runs vectorized backtests for trading strategies using NumPy and pandas array operations. It executes parameter grid searches and analyzes portfolio risk. CX Codex +1 492installs whale-tracking Tracks large Solana wallets on-chain: accumulation, distribution and smart money signals before they show up in price. CX Codex +1 493installs mean-reversion Statistical toolkit for mean-reversion trading strategies. Validates stationarity with ADF and Hurst tests, calculates half-life, and generates z-score trade signals. CX Codex +1 490installs

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