Skip to content
Skills Library
Finance & accounting · Analysis

dynamic-position-sizing-based-on-realized-volatility

/dynamic-position-sizing-based-on-realized-volatility

Use when a fixed percentage-of-capital rule leaves risk far higher in volatile regimes than calm ones; scales size inversely to realised volatility to hold an ex-ante risk budget constant. It cannot anticipate a gap.

Licence
Apache-2.0
Last repository change
14.09.2026

Assessment and security

90/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content25 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
6
Scripts
2
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 14.09.2026, without references to retired models or APIs.

Licence

Apache-2.0, otwarta: można używać i zmieniać, z zachowaniem licencji i informacji o zmianach.

What to check before installing
  • 2 scripts in this package. Review them before installing, as Claude may execute them.

Scripts: scripts/realized_vol_sizer.py, scripts/test_realized_vol_sizer.py

What it does and when to use it

Use when a fixed percentage-of-capital rule leaves risk far higher in volatile regimes than calm ones; scales size inversely to realised volatility to hold an ex-ante risk budget constant. It cannot anticipate a gap.

Original author description

Use when a fixed percentage-of-capital rule leaves risk far higher in volatile regimes than calm ones; scales size inversely to realised volatility to hold an ex-ante risk budget constant. It cannot anticipate a gap.

How it works

  1. When to Use
  2. When NOT to Use
  3. Prerequisites
  4. Workflow
  5. Common Pitfalls
  6. Verification
  7. Related Skills
Original SKILL.md headings · 68 lines, 928 words
SKILL.md preview
---
name: dynamic-position-sizing-based-on-realized-volatility
description: >-
  Use when a fixed percentage-of-capital rule leaves risk far higher in volatile regimes
  than calm ones; scales size inversely to realised volatility to hold an ex-ante risk
  budget constant. It cannot anticipate a gap.
license: Apache-2.0
metadata:
  domain: algorithmic-trading
  subdomain: risk-management
  tags: risk-management, volatility-targeting, realized-volatility, position-sizing, riskmetrics-ema, vol-scaling
  brokers_frameworks: "Realized Volatility Position Sizer; Python NumPy"
  version: "2.0.0"
  author: algo-trading-skills-contributors
---

## When to Use

Invoke this skill when executing trend-following, mean-reversion, or multi-asset strategies where static capital allocation ($X\%$ per trade) leads to unintentional risk concentration during high-volatility market regimes. Volatility targeting scales position size inversely to annualized realized volatility $\sigma_{\text{realized}}$, so a strategy consumes a constant *ex-ante* risk budget (e.g. $15\%$ target annualized volatility) whether the VIX is at $12$ or $45$.

## When NOT to Use

- **As a stop-loss, drawdown control, or gap protection.** The scalar is set from volatility *already realized*. It cannot anticipate a jump, and a position sized on calm data is full-size when the gap arrives. Pair it with an independent circuit breaker.
- **On a return history shorter than the estimator's effective window.** A $\lambda = 0.94$ EWMA consumes ~74 daily returns at a 1% tolerance (RiskMetrics Table 5.7). Below that the estimate mostly reflects the arbitrary seed, so the sizer raises rather than sizing.
- **On intraday bars without changing `annualization_factor`.** The default 252 is daily. Feeding 5-minute bars while leaving it at 252 understates volatility by roughly $\sqrt{78}$ and oversizes the position ~9×. The frequency cannot be inferred from a list of floats — you must set it.
- **As portfolio construction.** This sizes one asset at a time. Summing independently vol-targeted positions does not produce a vol-targeted portfolio; see `correlation-aware-exposure-limits`.
- **When the constraint is liquidity or lot size rather than volatility** — see `liquidity-adjusted-position-sizing` and `minimum-fill-size-and-lot-rounding-logic`.

## Prerequisites

- Return series $r_t$ **ending at the last completed observation before the bar being sized**, sampled at one consistent frequency.
- `annualization_factor` = observations per year for that frequency (252 for daily bars).
- Target annualized volatility $\sigma_{\text{target}}$ (e.g. $0.15 = 15\%$).
- Estimator choice: RiskMetrics EWMA ($\lambda = 0.94$ daily, $0.97$ monthly) or simple rolling sample standard deviation.

## Workflow

1. **Estimate Realized Volatility**:
   - EWMA (RiskMetrics Eq. 5.3): $\sigma_t^2 = \lambda \sigma_{t-1}^2 + (1 - \lambda) r_t^2$, using raw squared returns — RiskMetrics centres on zero, not on the sample mean.
   - Annualize: $\sigma_{\text{ann}} = \sqrt{F} \times \sigma_t$, where $F$ is observations per year.
   - **Decision point — check the history length before trusting the number.** `required_ewma_observations(λ, tolerance)` gives the effective window ($\lambda=0.94 \Rightarrow 74$ at 1%). A shorter history is not a noisy estimate, it is largely the seed; the sizer raises instead of returning one.
   - **Decision point — the two estimators are not interchangeable.** EWMA assumes a zero mean; the rolling estimator subtracts the sample mean and applies the $(n-1)$ correction. They disagree on identical data. Pick one per strategy; do not compare their outputs or switch mid-backtest.

2. **Compute Volatility Scalar**:
   $$\text{Scalar} = \frac{\sigma_{\text{target}}}{\max(\sigma_{\text{floor}}, \sigma_{\text{ann}})}$$
   - **Decision point — if `vol_floor_binding` is true**, the size was set by the floor, not by measured volatility. That is a deliberate leverage brake on an abnormally quiet series, not a volatility reading; do not report it as one.

3. **Apply Min/Max Multiplier Bounds**:
   $$\text{FinalScalar} = \text{clip}(\text{Scalar}, \text{MinScalar}, \text{MaxScalar})$$

4. **Calculate Volatility-Adjusted Allocation**:
   $$\text{CapitalAllocation} = \text{BaseCapital} \times \text{FinalScalar}$$
   - Share count is **floored**, never rounded up, so the position cannot exceed the risk budget.

> Full procedure: see `references/workflows.md`.
> Standards reference: see `references/standards.md`.
> Printable pre-flight checklist: see `assets/checklist.md`.

## Common Pitfalls

- **Sizing on corrupt data**: a single `NaN` in the return series collapses a naive variance calculation to zero, which the volatility floor then converts into the *maximum* leverage scalar — the largest possible position produced by the worst possible data. Reject non-finite returns before estimating; never let them reach the estimator.
- **Silently sizing with no data**: returning the target volatility as a fallback yields a scalar of exactly $1.0$ — a full-size position justified by nothing. Absent or too-short history must raise, not default.
- **Including the current bar's return**: the volatility used to size period $t$ must be built from returns through $t-1$ (RiskMetrics Eq. 5.37). Including the bar being sized leaks its outcome into the size and flatters every backtest.
- **Mismatched annualization**: intraday returns annualized with 252 understate volatility by $\sqrt{\text{bars per day}}$, producing a position several times larger than intended.
- **Reporting the floored volatility as realized volatility**: when the floor binds it is a sizing guard, not a measurement; conflating the two overstates a genuinely quiet asset's risk in every downstream report.
- **Lagged Volatility Response During Crashing Markets**: a 60-day simple estimator reacts too slowly during a sudden crash, leaving positions oversized. Faster $\lambda$ reacts sooner but consumes less data — the trade-off is explicit in RiskMetrics Table 5.7.
- **Hyper-Leveraging in Ultra-Quiet Regimes**: allowing the scalar to reach $10\times$ during abnormally low vol without enforcing a `MaxScalar` cap.
- **Assuming the floor caps leverage**: with $\sigma_{\text{target}}=15\%$ and $\sigma_{\text{floor}}=5\%$ the floor permits a raw scalar of $3.0$, so with `MaxScalar` $=2.0$ it is the *cap*, not the floor, that binds. Set both deliberately.

## Verification

- Instantiate `RealizedVolPositionSizer(target_annualized_vol=0.15, min_scalar=0.20, max_scalar=2.00, vol_floor=0.05)`. Feed an alternating $\pm d$ return series with $d = 0.60/\sqrt{252}$ (100 observations, exactly 60% annualized): verify `realized_annualized_vol` $= 0.60$, `bounded_vol_scalar` $= 0.25$, and `adjusted_capital_usd` $= \$25{,}000$ on $\$100{,}000$ base. Repeat at 4% annualized: verify the raw scalar is $3.0$ (floor-bound, not $3.75$), clipped to the $2.0$ cap, with `vol_floor_binding` true.
- Verify `required_ewma_observations(0.94, 0.01) == 74` and `(0.97, 0.01) == 151`, reproducing RiskMetrics Table 5.7.
- Negative checks: an empty history, a 1-element history, a 73-element history at $\lambda=0.94$, a `NaN` return, and a negative `base_capital_usd` must each raise.
- Run `python -m unittest discover -s skills/dynamic-position-sizing-based-on-realized-volatility/scripts` and confirm 100% pass rate.

## Related Skills

- `correlation-aware-exposure-limits`
- `liquidity-adjusted-position-sizing`
- `value-at-risk-var-live-monitoring`
- `kill-switch-and-drawdown-circuit-breakers`
Files in this package (6)
  • SKILL.md 7 KB
  • assets/checklist.md 2 KB
  • references/standards.md 3 KB
  • references/workflows.md 3 KB
  • scripts/realized_vol_sizer.py 15 KB
  • scripts/test_realized_vol_sizer.py 16 KB

Versions

The database has no other skills named dynamic-position-sizing-based-on-realized-volatility.

Database snapshot: 13.11.2026 · package version 861e45f365e0 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100sizing
    Turns an expected return and a risk estimate into a position size using fractional Kelly, a volatility target, and a maximum weight. Use when asked how large a position should be, how to size or scale a strategy, what the Kelly fraction is, or how to bring a position to a target volatility.
  • 100position-sizing
    Use when deciding how large a position to take. Covers fixed-fractional risk, volatility-based sizing, the Kelly criterion and why to fractionalize it, and portfolio concentration limits. Trigger on "how much should i put in this trade", "how many shares should i buy", "should i…
  • 95garch-method
    Volatility forecasting and position sizing via walk-forward GARCH(1,1). Use whenever the user asks about volatility forecasts, position sizing, "how much should I put on", vol targeting, risk throttling, storm/calm regimes, or wants to test whether vol-targeted sizing improves…
  • 100position-sizer
    Calculate risk-based position sizes for long stock trades. Use when user asks about position sizing, how many shares to buy, risk per trade, Kelly criterion, ATR-based sizing, fractional-share sizing, or portfolio risk allocation. Supports stop-loss distance calculation,…
  • 95ml4t-position-sizing
    Convert signals to position sizes using volatility targeting and risk budgets. Use when scaling trade size relative to conviction and portfolio risk.
  • 100nixtla-market-risk-analyzer
    Analyzes market risk by calculating VaR, volatility, drawdown, and position sizing. Use when assessing investment risk, managing portfolios, or determining position sizes. Trigger with "analyze market risk", "calculate portfolio risk", "determine position size".

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.