Quantitative finance
Positions valued as of a date, and their risk, with QuantLib: a curve bootstrapped from the model’s rates, bonds priced from their quotes or the curve, a day’s value at risk by Monte Carlo, and what drives it in words. The market is frozen with each run.
The market
Example Brewery’s treasury holds five bonds. The model has the NOK curve’s deposits and swaps on 13 October 2026, and the holdings with their quotes:
// the curve's instruments on 13 October 2026
EVALUATE SELECTCOLUMNS ( Rates, "Kind", Rates[Kind], "Tenor", Rates[Tenor], "Rate", Rates[Rate] )
| Kind | Tenor | Rate |
|---|---|---|
| deposit | 1M | 0.0405 |
| deposit | 3M | 0.041 |
| deposit | 6M | 0.0415 |
| swap | 2Y | 0.039 |
| swap | 3Y | 0.038 |
The first 5 of its 8 rows.
EVALUATE
SELECTCOLUMNS (
Holdings,
"Bond", Holdings[Bond],
"Maturity", Holdings[Maturity],
"Coupon", Holdings[Coupon],
"Nominal", Holdings[Nominal],
"Price", Holdings[Price]
)
| Bond | Maturity | Coupon | Nominal | Price |
|---|---|---|---|---|
| Government 2028 | 2028-03-02 | 0.03 | 250,000,000 | 97.84 |
| Government 2033 | 2033-03-15 | 0.0225 | 300,000,000 | 92.15 |
| Municipal 2031 | 2031-09-01 | 0.035 | 150,000,000 | |
| Covered 2029 | 2029-06-20 | 0.04 | 120,000,000 | |
| Corporate 2030 | 2030-11-25 | 0.0475 | 80,000,000 | 101.30 |
Value the positions
Curve.Bootstrap builds the curve with Norway’s calendar; Market.AsOf holds it with any quotes and FX rates; Valuation.Bonds values each position from its quote, or from the curve when it has none:
var asOf = new DateTime(2026, 10, 13);
var market = Market.AsOf(asOf).Add(Curve.Bootstrap("NOK zero", asOf, rates, calendar: "Norway"));
var valued = Valuation.Bonds(holdings, market, "NOK zero");
valued
5 positions as of 2026-10-13: market value 884,941,498, DV01 -318,623. 2 bonds have no quote today: priced from the curve NOK zero (Municipal 2031, Covered 2029)
The Run tab shows the totals, the risk and each position’s value; Market data the curve’s pillars and zero rates. A curve answers for any date:
var curve = market.Curve("NOK zero");
$"zero rate to 2031-10-13: {curve.Zero(new DateTime(2031, 10, 13)):P3}; discount factor: {curve.Discount(new DateTime(2031, 10, 13)):F6}"
zero rate to 2031-10-13: 3.674 %; discount factor: 0.832095
Risk
MonteCarlo.Simulate writes a simulation: what moves and what is uncertain, how they correlate, the time steps. Here, a day’s move in rates, normal with 5 basis points, gives the P&L of each of 20,000 paths, and its value at risk and expected shortfall join the valuation:
// a day's move in rates: normal, 5 basis points; the P&L of each path, then its VaR and expected shortfall
var pnl = MonteCarlo.Simulate(20_000, seed: 1).Normal("Rates, bp", 0, 5).Run().Value(p => valued.DV01 * p["Rates, bp"], "P&L");
valued.WithRisk("VaR 99 %, 1 day", pnl.ValueAtRisk(0.99, fromZero: true)).WithRisk("ES 97.5 %, 1 day", pnl.ExpectedShortfall(0.975, fromZero: true));
pnl
The risk in words
// what drives the risk, in words
string.Join(Environment.NewLine, valued.Explain())
Market value 884.94 M; DV01 -318,623: a rise in rates of one basis point costs 318,623.
What drives it: Government 2033 51 % (5.7 years' duration on 280.37 M); Municipal 2031 21 % (4.4 years' duration on 148.93 M); Government 2028 10 % (1.3 years' duration on 249.22 M).
Rates +100 bp: -30.98 M (-3.5 % of the value); the DV01 alone says -31.86 M, convexity softens it by 884,689.
The largest position, Government 2033, is 32 % of the value.
2 positions priced from the curve, without a quote today: Municipal 2031, Covered 2029 (31 % of the value).
VaR 99 %, 1 day: 3.79 M, 0.43 % of the market value.
ES 97.5 %, 1 day: 3.79 M, 0.43 % of the market value.
One instrument at a time
Quant prices single instruments: bonds from a yield or a curve, yields from prices, options (European and American), implied volatility, FX forwards, swaptions and CDS:
// one instrument at a time: a European call, Black-Scholes-Merton
var o = Quant.Option("call", spot: 100, strike: 105, date: new DateTime(2026, 10, 13), expiry: new DateTime(2027, 4, 13),
volatility: 0.25, rate: 0.04);
$"price {o.Price:F4}, delta {o.Delta:F4}, gamma {o.Gamma:F4}, vega {o.Vega:F4}, theta {o.Theta:F4}, rho {o.Rho:F4}"
price 5.7680, delta 0.4701, gamma 0.0225, vega 28.0914, theta -8.6917, rho 20.5623
More
CreditCurve and CreditRisk for default and portfolio loss, Xva and ExposureSimulation for counterparty exposure and valuation adjustments, Margin for initial margin, Risk for historical value at risk. In OAX, QUANT.* functions price row by row in measures. Every member is in the Quantitative finance reference.
Keep it
Results.Save("Bond portfolio", valued) keeps the valuation as a draft version, with the market it used. Approved and in use, its positions are a table of the model, and a what-if page prices them again under a rate shock (see Quantitative).