The Claude Quant PlaybookDownload ebookDownload ebook

EWMA volatility

intermediateTime series6 of 8

A running volatility estimate that weights recent returns most. Each day the old estimate fades by λ and today's squared return is mixed in.

Build a trading system with Claude.Download ebook

01The formula

the variance estimate after day t (its square root is the volatility)
the decay: how much weight yesterday's estimate keeps, typically 0.94 for daily data
the return on day t
the weight on today's squared return

02See it move

03Where it is used

04Why traders use it

Volatility changes, and a plain average over a year reacts far too slowly when it does. EWMA is one line of code, needs no fitting, and catches regime changes.

05Worked example

True daily volatility jumps from 1.0% to 2.5% on day 125. With λ = 0.94, the highlighted estimate reads 2.60% ten days after the jump and 2.46% on the last day, against a true 2.50%. The weights halve every 11.2 days.

06How it is built

  1. Unroll the recursion: , a weighted average of past squared returns.
  2. The weights add up to 1 and halve every days.
  3. After a jump in true variance from to , the expected estimate days later is .
  4. Lower λ means faster reaction but a noisier estimate: its relative error is about .

07The common mistake

Treating λ as a law of nature. It is a choice between speed and noise; a value tuned for daily equity returns can be far too slow for intraday data or too jumpy for monthly data.

08In Python and LaTeX

import numpy as np
lam = 0.94
rng = np.random.default_rng(7)
r = np.r_[0.01 * rng.standard_normal(125), 0.025 * rng.standard_normal(125)]
v = 0.01**2
for x in r: v = lam * v + (1 - lam) * x * x
print(round(np.log(0.5) / np.log(lam), 2))  # 11.2 days: the weight half-life
last = np.sqrt(v)  # near the true 2.5%; differs by sample
\hat\sigma_t^2 = \lambda\,\hat\sigma_{t-1}^2 + (1 - \lambda)\,r_t^2

09Where it fits

Rather not code the maths yourself? Describe your trading idea and let AI build the bot.

Build a bot with AgenKit

The worked example and the model run the same code, so every number matches. Models simplify markets on purpose. This is education, not financial advice.