Skip to content
TotalFinance

Measure value at risk

Historical or parametric VaR and expected shortfall on your own returns, with the loss tail and drawdowns drawn.

Run it

Live, in your browser. Nothing leaves this page.

Local

One value per line, optionally with a date column. Returns are decimals: −0.012 means −1.2%.

Synthetic volatility shock (seed 99, not market data), daily simple returns

249 returns · 2025-01-03 → 2025-12-17

Synthetic
Preview rows
datereturn
2025-01-03-0.00114
2025-01-060.002647
2025-01-070.001502
… 244 more rows …
2025-12-160.01141
2025-12-17-0.013693
95%

decimal · 0.95 = 95%

252

for annualized volatility · 252 daily, 52 weekly, 12 monthly

Change any input; everything updates.

Value at risk · 95.00%
2.29%
one-period loss, as a decimal
Expected shortfall
3.53%
mean loss beyond VaR
Annualized volatility
23.79%
252 periods per year
Maximum drawdown
16.59%
98 periods peak to trough
Observations
249
returns
Distribution of one-period returnsThe shaded tail holds the returns at or below −VaR. Expected shortfall is the average of that tail. Synthetic volatility shock (seed 99, not market data), daily simple returns.
  • Observations
  • Loss tail
ES 3.53%VaR 2.29%Zero
Show data (26 rows)
FromToNumber of periods
-6.70%-6.21%1
-6.21%-5.72%0
-5.72%-5.23%1
-5.23%-4.74%0
-4.74%-4.26%1
-4.26%-3.77%1
-3.77%-3.28%2
-3.28%-2.79%3
-2.79%-2.30%4
-2.30%-1.82%7
-1.82%-1.33%7
-1.33%-0.84%30
-0.84%-0.35%29
-0.35%0.14%42
0.14%0.62%46
0.62%1.11%31
1.11%1.60%20
1.60%2.09%6
2.09%2.58%10
2.58%3.06%1
3.06%3.55%1
3.55%4.04%2
4.04%4.53%2
4.53%5.01%0
5.01%5.50%1
5.50%5.99%1
Drawdown of the compounded return pathDecline from the running peak of an investment that earns these returns in order.
Show data (249 rows)
PeriodDrawdown
1-0.11%
2-0.00%
3-0.00%
4-0.03%
5-0.20%
6-0.00%
7-0.81%
8-0.00%
9-0.25%
10-0.00%
11-1.62%
12-0.00%
13-0.00%
14-0.00%
15-0.00%
16-0.00%
17-0.00%
18-0.00%
19-0.00%
20-0.95%
21-0.98%
22-0.21%
23-0.58%
24-2.57%
25-3.25%
26-3.25%
27-3.35%
28-3.27%
29-3.01%
30-1.15%
31-1.33%
32-1.02%
33-1.04%
34-0.51%
35-0.73%
36-0.00%
37-0.00%
38-1.35%
39-1.12%
40-0.62%
41-0.27%
42-0.88%
43-2.15%
44-2.54%
45-2.55%
46-1.36%
47-2.24%
48-1.19%
49-0.77%
50-1.74%
51-2.74%
52-2.82%
53-3.47%
54-2.32%
55-3.18%
56-5.36%
57-5.43%
58-4.90%
59-4.14%
60-3.32%
61-1.91%
62-1.77%
63-2.73%
64-1.24%
65-1.34%
66-0.86%
67-0.65%
68-0.59%
69-0.41%
70-0.00%
71-0.00%
72-0.58%
73-0.63%
74-0.31%
75-1.29%
76-0.69%
77-0.69%
78-0.90%
79-0.33%
80-0.00%
81-0.53%
82-0.78%
83-1.43%
84-2.32%
85-3.34%
86-2.26%
87-3.18%
88-3.05%
89-2.49%
90-3.50%
91-2.44%
92-2.47%
93-1.91%
94-1.68%
95-2.42%
96-1.22%
97-1.76%
98-0.79%
99-0.00%
100-0.00%
101-0.92%
102-0.00%
103-0.10%
104-0.20%
105-0.57%
106-0.85%
107-1.45%
108-0.65%
109-1.30%
110-1.87%
111-1.44%
112-2.56%
113-3.45%
114-3.52%
115-2.59%
116-2.26%
117-1.98%
118-3.54%
119-4.25%
120-6.67%
121-8.05%
122-10.17%
123-8.06%
124-9.91%
125-8.24%
126-6.13%
127-5.92%
128-12.22%
129-6.96%
130-4.77%
131-2.77%
132-1.83%
133-6.04%
134-1.97%
135-3.27%
136-3.09%
137-6.37%
138-7.23%
139-6.37%
140-7.76%
141-7.67%
142-6.99%
143-7.53%
144-5.14%
145-5.68%
146-5.00%
147-6.59%
148-4.46%
149-6.97%
150-9.58%
151-8.43%
152-8.19%
153-7.32%
154-5.87%
155-5.91%
156-6.24%
157-6.53%
158-5.78%
159-4.72%
160-8.35%
161-5.54%
162-5.08%
163-4.61%
164-5.80%
165-7.67%
166-10.50%
167-9.60%
168-8.75%
169-8.79%
170-8.97%
171-8.81%
172-9.54%
173-7.61%
174-7.01%
175-7.72%
176-8.01%
177-7.37%
178-6.37%
179-5.69%
180-6.13%
181-8.65%
182-7.96%
183-4.38%
184-3.47%
185-4.70%
186-5.13%
187-6.06%
188-6.72%
189-7.91%
190-9.05%
191-7.69%
192-8.01%
193-8.03%
194-12.93%
195-11.76%
196-14.41%
197-14.02%
198-13.66%
199-13.74%
200-16.59%
201-12.09%
202-13.03%
203-13.96%
204-12.93%
205-13.56%
206-15.46%
207-15.94%
208-15.33%
209-11.53%
210-10.08%
211-9.69%
212-10.07%
213-9.65%
214-9.35%
215-6.01%
216-5.10%
217-3.87%
218-3.65%
219-3.29%
220-3.02%
221-2.43%
222-1.14%
223-2.11%
224-1.92%
225-0.76%
226-0.00%
227-0.00%
228-1.19%
229-2.45%
230-1.64%
231-0.00%
232-0.00%
233-0.48%
234-2.65%
235-3.41%
236-3.36%
237-2.93%
238-2.56%
239-3.85%
240-3.92%
241-2.59%
242-3.59%
243-4.69%
244-4.60%
245-2.69%
246-4.73%
247-4.35%
248-3.25%
249-4.58%

Assumptions & conventions

What the calculation assumed, echoed by the library rather than hidden.

valueAtRisk.conventionsVersion
0.0.1
valueAtRisk.confidence
0.95
valueAtRisk.method
historical
valueAtRisk.horizonPeriods
1
valueAtRisk.cornishFisher
false
valueAtRisk.quantileEstimator
hyndman-fan-7
method
historical
confidence
0.95
horizonPeriods
1
returns
reader or sample returns as supplied
annualization.periodsPerYear
252

Diagnostics & warnings

No warnings. Engine, method and convergence details:

dataNotice
Synthetic sample returns, not market history.

Use it in your project

valueAtRiskReport returns valueAtRisk and conditionalValueAtRisk as positive loss magnitudes (decimals of the position), with the applied confidence, method and horizon echoed and any warnings in diagnostics.

Sample inputs

249 returns from: Synthetic volatility shock (seed 99, not market data), daily simple returns. Preview: the first five values. Copy setup + call includes every value.

Preview
[-0.00114,0.002647,0.001502,-0.000318,-0.001682]
Complete setup · included when you copy
First call
const report = valueAtRiskReport(returns, { confidence: 0.95, method: 'historical', horizonPeriods: 1 });
const result = {
  valueAtRisk: report.valueAtRisk,
  expectedShortfall: report.conditionalValueAtRisk,
};
console.log(result);
Output of this example
{
  "valueAtRisk": 0.022892999999999993,
  "expectedShortfall": 0.03526776923076923
}
Reproduce this entire calculator
Full result object

Both examples use the inputs of the last successful calculation. Displayed metrics are rounded; copied programs keep exact values. Every copy on this page is type-checked and executed against the packed package in CI.

Ask your AI agent

With the TotalFinance MCP server connected, your agent runs this calculation with the totalfinance_risk_value_at_risk tool (on by default). The prompt below uses your current inputs.

Prompt

Use the TotalFinance MCP tool totalfinance_risk_value_at_risk with the historical method at 95% confidence on my daily returns, then totalfinance_performance_analyze with 252 periods per year for volatility and drawdown. Explain what the VaR and expected shortfall mean in plain words. [Paste your daily returns here, one decimal per line: 0.01 = 1%]

Connect Claude, Cursor, VS Code, Codex or ChatGPT

What this calculates

valueAtRiskReport estimates one-period value at risk and expected shortfall (conditional VaR) from a return series. Both are positive loss magnitudes, as decimals of the position: 0.021 means a 2.1% loss. The report echoes the confidence level, method and horizon, and its diagnostics explain any adjustment it could not apply.

Historical or parametric

  • Historical takes the empirical tail quantile of your returns. It keeps fat tails and skew, but it can only see losses that are in the sample.
  • Parametric fits a normal distribution's mean and volatility. It is smooth, but it assumes the tails are normal, which equity returns usually are not.

Reading the charts

The histogram shades the returns at or below −VaR; expected shortfall is their average. The drawdown chart compounds the returns in order and shows how far below its running peak the investment fell, a path risk that a one-period VaR does not capture.

Edit this page on GitHub ↗Every code block on this site is executed in CI against the library.