The Claude Quant PlaybookDownload ebookDownload ebook

Value at risk (VaR)

intermediateRisk and portfolio4 of 13

Value at risk is a loss threshold: with confidence c, you will not lose more than this over the horizon. This version assumes normal returns with zero mean, so VaR is a fixed number of standard deviations of the P&L.

Build a trading system with Claude.Download ebook

01The formula

the loss that is exceeded only on the worst 1 − c of days
the confidence level, such as 95% or 99%
the standard normal quantile for c: 1.645 for 95%, 2.326 for 99%
daily volatility of the portfolio's returns
the horizon in days
the portfolio value

02See it move

03Where it is used

04Why traders use it

It turns a whole book of positions into one money number that anyone can understand: on a bad day, this is roughly what we could lose. That makes it the common language of risk limits.

05Worked example

A $1,000,000 portfolio with daily volatility 1.5% has a 99.0% one-day VaR of $34,895, or 3.49% of its value. The quantile used is z = 2.326, and a loss beyond VaR should happen about once every 100 trading days.

06How it is built

  1. Model the P&L over days as normal with mean 0 and standard deviation (volatility grows with the square root of time).
  2. Find the point that leaves of the probability in the left tail: standard deviations, with .
  3. Multiply back to money: .
  4. Check it by backtesting: the share of days with losses above VaR should be close to .

07The common mistake

Reading VaR as the most you can lose. It says nothing about how big the loss is on the days it is exceeded, and real returns have fatter tails than the normal curve, so those days can be far worse. Expected shortfall fills that gap.

08In Python and LaTeX

import numpy as np
from scipy.stats import norm
V, sigma, c, h = 1_000_000, 0.015, 0.99, 1
VaR = norm.ppf(c) * sigma * np.sqrt(h) * V
print(round(VaR))  # 34895
\text{VaR}_c = z_c\,\sigma\sqrt{h}\;V, \qquad z_c = N^{-1}(c)

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.