Module calibration
Expand description
Curve calibration: recovering pillars from quoted instruments.
§Why this layer sits above instruments
A calibration prices instruments to recover curve parameters, so it depends on
everything a valuation depends on. Filed inside curves, it would make
curves reach up into instruments, cashflows and analytics. Hoisting it
here is what makes the layer graph acyclic.
§The mode is the whole point
A sequential calibration solves one unknown against one residual, over and over. That is the exact shape forward mode is for: seed the pillar being solved, price once, and the derivative comes back beside the value.
Reverse mode would record the entire swap-pricing forward pass onto a tape at each Newton step, sweep the whole tape backwards, and read one scalar off the result — a full reverse pass to recover a single one-input, one-output derivative, on a tape that grows with every pillar.
Here nothing is recorded at all. The tests assert that as a statement count, not as a claim.
§A helper is a rung
A calibration instrument is here a Rung: a real instrument,
priced by the pricer a trade uses, with its quote declared and verified at
the solve. The template-dated builders — deposit_rung, fra_rung,
future_rung, par_rungs, tenor_basis_rung, cross_currency_rungs,
bond_rung in crate::products — are the helper family, and
calibrate_curve_helpers is the one verb that takes a list of them: it
groups the rungs by the curve each solves, read off the instrument’s declared
risk factors, solves each group as a ladder or jointly where groups read each
other, refuses two rungs on one pillar by name, and pins every curve with its
provenance. calibrate_recipe is that verb on a recipe’s templates
filled from a quote sheet — a swaps-only sheet is the one-template case.
Modules§
- sabr
- SABR calibration from a grid rate smile: one slice per smiled (expiry, tenor) node, and the record each fit keeps so its parameter risk can be read back onto the quotes that built it.
Structs§
- Calibrated
- A calibrated curve, and how it was reached.
- Calibrated
Base Correlation - A base-correlation curve solved from a tranche capital structure: one correlation per detachment and one solve record per tranche.
- Calibrated
Density - A survival curve solved in default density: one density per pillar, the node at the reference date reading the first pillar’s, one solve record per pillar, and the ladder the curve reprices.
- Calibrated
Inflation - A calibrated inflation curve, and what each pillar’s solve cost.
- Calibrated
Survival - A survival curve solved from a ladder of credit default swaps: the ISDA piecewise-flat-hazard curve and one solve record per pillar.
- Calibration
Options - How a par curve is solved: the rung notional, the interpolation scheme and
the tolerance — every knob of
calibrate, gathered so the one-step verb and a caller who wants the defaults name none of them. - CapQuote
- A term cap quote: the cap from the strip’s effective date to
termination, quoted as one flat volatility. - Collateral
Curves 🔒 - The fixed curves of a collateral ladder: the pay leg’s discount and both legs’ projections.
- Credit
Ladder 🔒 - What a credit ladder was solved against — the part of its inputs its read back needs, whichever family it solved.
- Curve
Provenance - The ladder a curve was calibrated from: what it reprices, and how its pillars move when those quotes do.
- Curve
Refit - The inputs a rate curve was calibrated from, less the published data a
market carries: enough to solve the same ladder again — at the same quotes,
or at quotes a scenario moved. The rate twin of
SurvivalRefit. - Helper
Group 🔒 - The helpers that solve one curve.
- Helper
Solve - One curve the helper verb solved: the roles it was pinned under and, where
it was solved as a ladder of its own, the solve — its curve, records and
par-quote provenance. A curve solved jointly with another carries no ladder
of its own, and
ladderisNone. - Joint
Calibration - Curves solved together, each under its role, and what the solve cost.
- Joint
Curve - One curve of a joint solve: the roles it is pinned under — a discount key, a projection index, or both, as a self-discounting overnight curve is — and the rungs whose pillars are its nodes.
- Lifted
Form 🔒 - A
Form’s fixed curves, lifted. - Pillar
Solve - The result of one pillar’s solve, for a caller that wants to see the work.
- Provenance
Entry - One rung of the ladder that calibrated a curve, kept so the curve can say what it reprices.
- Provenance
Shape - A ladder whose
∂z/∂qdoes not have one row and one column per rung. - Quote
Sheet - A quote sheet as a desk reads it: entries in sheet order, each a template, a locator and a value. The sheet is the grid — a recipe says which templates build the curve, and the sheet says where.
- Rung
- One rung of a calibration ladder: an instrument, the pillar it determines, and the kind of quote it was built at.
- Sheet
Entry - One quote on a sheet: the template it is quoted on, where it sits, and the number — a rate for a deposit or a swap, a price for a future, an outright for an FX swap, a spread for a basis swap.
- Smoothed
Calibration - A discount curve fitted globally, trading repricing error for smoothness of the pillar log discount factors — and saying so: it carries no provenance, because it reprices no rung exactly.
- Solved
Pillar 🔒 - One pillar’s Newton solve:
x, the steps it took, and the residual it left. - Stores 🔒
- The lifted stores a pass prices against, borrowed by every valuation.
- Survival
Refit - The inputs a survival curve was calibrated from, less the recovery and the published data a market carries: enough to solve the same ladder again.
- Tolerance
- How hard the solver tries.
Enums§
- Bond
Rung Error - Why a bond could not be made a rung.
- Calibration
Error - A calibration that did not produce a curve.
- Form 🔒
- Which curve a ladder solves, and where the rest of the view comes from.
- Helper
Form 🔒 - How a group of helpers solves: where the curve under solve sits, and what it reads.
- Jacobian
Engine - Which engine built a ladder’s
∂q/∂z. - Provenance
- What a converged solve knows about the ladder behind its curve.
- Quote
Kind - The two are not interchangeable and the difference is not cosmetic: a par rung’s instrument is worth nothing at its quote, while a priced rung’s is worth its quote. The solver’s target, the Jacobian’s read, and the check that a rung reprices at what it declared all follow from this one choice, so they cannot disagree.
- Recipe
Quote Error - Why a quote sheet could not be bound to a recipe.
- Refit
Form - The form a rate ladder was solved in, with the curves it held fixed — the owned twin of the solve’s own form, so a refit can name it again.
- Route 🔒
- The engine a quote block runs in.
- Strip
Scheme - How term cap quotes are turned into caplet vols.
- Survival
Family - The parameterisation a credit ladder solves: one segment hazard per rung (ISDA), or one default density per rung, the first segment flat.
Constants§
- ADJOINT_
BUDGET_ 🔒BYTES - How much adjoint memory the reverse engine’s read-back may hold at once.
- BISECTION_
CAP 🔒 - Bisection steps allowed per tranche — a bracket of width one halves to the step tolerance in fifty, and the cap is there for a residual that will not settle, not as a budget.
- LANES 🔒
∂q/∂z: rungi’s par quote against pillarj, on the solved curve.- REVERSE_
FROM 🔒 - The largest ladder the eight-lane engine still builds the Jacobian for.
- RHO_MAX 🔒
- The top of the correlation bracket: the store refuses
1.0itself. - SEED_
HAZARD 🔒 - The hazard a ladder starts from when its first rung is upfront-quoted, whose quote is not a spread to triangulate from.
- SEED_
LEVEL 🔒 - The index level a pillar starts its Newton solve from, before the previous pillar’s answer is available to re-seed it. Arbitrary but strictly positive, which is all a level has to be for the curve to build.
- SEED_
RECOVERY 🔒 - The recovery a seed assumes when neither the contract nor the ladder states one. It shapes where Newton starts and nothing about where it stops: the solve itself prices under the contract’s or the ladder’s recovery, and a contract that needs one and finds none fails by name.
- STRIP_
ITERATION_ 🔒CAP - Brent halves the bracket at worst; five vols to a 1e-12 step is under fifty halvings.
Functions§
- adjoint_
budget 🔒 - The budget the reverse engine reads back under.
- bond_
rung - A priced rung from a quote-less bond static and a tagged market quote.
- calibrate
- Calibrates a discount curve so that every rung prices to zero.
- calibrate_
base_ correlation - Calibrates a base-correlation curve to a contiguous capital structure of CDO tranches on one index — the market-standard bootstrap.
- calibrate_
cross_ currency - Calibrates the discount curve of a cross-currency swap’s receive leg under its collateral — EUR under a USD CSA, from EUR/USD basis swaps — against a pay-leg discount curve and both legs’ projection curves already known.
- calibrate_
curve_ helpers - Calibrates the curves a list of helpers solves and pins them into a copy
of
market. - calibrate_
inflation - Calibrates an inflation curve to a ladder of index-quoted instruments, discounted on a curve already known.
- calibrate_
jointly - Solves several rate curves at once — each a
JointCurve, its rungs’ pillars its nodes — by damped Newton on the stacked log discount factors. - calibrate_
jointly_ on calibrate_jointlyon a market that already holds curves the ladders read but do not solve — a tenor basis ladder’s base index, a term ladder’s discount pinned yesterday. The trial curves are pinned overbaseat each iteration;baseitself is untouched and supplies the fixings and FX.- calibrate_
projection_ under - Calibrates an index’s projection curve from non-deliverable swaps, against
the held settlement-currency
discountand the heldforeigncurve — the local currency’s discount under the settlement collateral, which every conversion reads.calibrate_with’s solve with the foreign slot filled. - calibrate_
recipe - The market with the curves its recipe for
keydescribes solved fromsheetand pinned, beside the solves —recipe_rungs_atthrough the helper verb. - calibrate_
smoothed - Fits a discount curve to a ladder globally under
scheme, minimising the rung quote residuals together withsmoothnesstimes the squared second divided difference of the log discount factor at each interior pillar. - calibrate_
survival - Calibrates an ISDA survival curve to a ladder of credit default swaps, discounted on a curve already known.
- calibrate_
survival_ density - Calibrates a default-density survival curve to a ladder of credit default swaps, discounted on a curve already known, the density linear between pillars.
- calibrate_
with - Calibrates a projection curve against a caller-supplied discount curve.
- cap_
maturity_ 🔒years - When a cap’s last caplet pays, in years from the valuation date — the maturity its quote is the vol of, rolled as the schedule rolls it.
- capital_
structure 🔒 - The shape a tranche bootstrap solves: non-empty, attaching at zero,
contiguous, detachments strictly increasing to at most one, and every
tranche’s recovery stated by its contract or by
recovery. - caplet_
nodes 🔒 - One node per caplet still to fix, at its interval’s vol: the expiries and the vols, a caplet already fixed or sharing an expiry with the node before it dropped.
- caplet_
value 🔒 - One caplet’s discounted value at
vol, by the convention’s kernel. - check_
credit_ 🔒ladder - A credit ladder’s shape, checked before any pillar is solved: at least one rung, pillars strictly increasing from the reference date, and a market recovery where a contract needs one.
- check_
joint 🔒 - The shape a joint solve needs: at least one curve, each under discount or projection roles, with rungs whose pillars strictly increase and whose values are read today.
- check_
pillars_ ascend - Every rung’s pillar strictly after the previous one’s, and the first after the reference date.
- check_
quotes 🔒 - The two things a quote block must satisfy before it becomes a ladder: every rung moves under its own pillar, and every rung reads back the quote it was declared at.
- collateral_
ladder_ 🔒indices - The pay and receive projection indices a collateral ladder’s rungs declare, read off any rung that names one, and the check that every rung solves the same collateral key.
- curve_
from 🔒 - A piecewise curve over
dateswith the given log discount factors, read underscheme. - discount_
quotes_ 🔒in - The discount form’s pass in mode
R: the stores lifted once, thenrunhanded the closure that values every rung on the curveseededdescribes. - fx_
swap_ 🔒sheet_ rung - A sheet entry on an FX-swap template: the outright at a tenor, in the template’s pair, against the pair’s spot in the market’s FX store.
- held_
curve 🔒 - The held curve under
id, or the market’s own missing-curve refusal. - helper_
group_ 🔒of - Which curve
rungsolves, and how, read off the roles its instrument declares and the family of the index it projects. - helper_
groups 🔒 - The rungs grouped by the curve they solve, each group’s rungs in pillar order and checked for overlaps.
- inflation_
from 🔒 - The inflation curve
levelsdescribes, in the shape the solve substitutes parameters into. - inflation_
quote_ 🔒block - Every rung’s quote read back on the inflation curve
levelsdescribes, and its derivative with respect to every node level — the inflation form of the quote block, over the same lane loop. - inflation_
quotes_ 🔒in - The inflation form’s pass in mode
R— seediscount_quotes_in. - is_
year_ 🔒end - Whether
dateis a 31 December — the start of the year-end turn. - joint_
curves 🔒 - Each curve read off its slice of the stacked log discount factors.
- joint_
market 🔒 basepinning each trial curve under every role it was given — on top of whateverbasealready holds, so a ladder may read a held curve the solve does not move.- joint_
seed 🔒 - The stacked log discount factors a joint solve starts from: each curve solved sequentially in the order given — a discount curve self-discounting, a projection curve against the first discount curve — where that succeeds, and flat at its first rung’s quote (as a continuously compounded rate) where it does not.
- ladder_
provenance 🔒 ∂q/∂zinverted into the ladder a curve carries:∂z/∂qrow-major with one entry per rung.- names 🔒
- Whether
recipenamestemplateanywhere: as a discount segment, an own-strip projection, or a window it fixes. - newton_
on_ 🔒pillar - The damped Newton solve itself, over whatever one pillar substitutes into a view.
- newton_
pillar 🔒 - Newton on pillar
jof the curve overdateswith parametersparams, starting fromparams[j], every other pillar held. - par_
quote_ 🔒jacobian - pin_
roles 🔒 marketwithcurvepinned under every one ofroles.- policy_
rung 🔒 - A sheet entry on the meeting template: a window opening on a year end is the turn, quoted as the simple forward over it; any other window is a policy window; a decision date is the window that decision opens, truncated at spot; anything else is refused by shape.
- policy_
spot 🔒 - The spot date a policy window is truncated to: the par-swap template’s spot where the recipe has one, two business days on the meeting template’s calendar otherwise.
- quote_
block 🔒 - quotes_
in_ 🔒reverse - The reverse engine: every rung’s quote recorded once on the thread’s
calibration tape, the parameters registered as inputs and the quotes as
outputs, and
dqread back by vector sweeps over that one recording —widthdirections per sweep, as many sweeps asbudgetmakes necessary. Returns(read_back, dq, Reverse { sweeps }). - quotes_
over_ 🔒lanes - The block loop every quote block shares: eight forward lanes at a time,
each seeding one parameter,
quotes_forreading every rung’s quote in whatever view the seeded parameters build. Returns(read_back, dq): each rung’s quote at the parameters, anddq[i][j] = ∂qᵢ/∂paramⱼ. - reads_
a_ 🔒solved_ curve - Whether
groupreads a curve another group ingroupssolves. - reads_
one 🔒 - Whether
readerreads a curvesolvedpins. - recipe_
rungs_ at - The helpers
sheetbinds to undermarket’s effective recipe forkey, each onnotional—rungs_foron the recipe the market resolves. - requoted_
rungs 🔒 - Every rung at its quote in
quotes, in order. - route 🔒
- Which engine builds the Jacobian of an
n-pillar ladder on this thread. - rung_
quotes 🔒 - Every rung’s quote in
view: the quantity its sensitivity is with respect to, which must be the one the solve drove. - rungs_
for - The rungs a sheet binds to a recipe: one per entry, dispatched on the template’s family and the locator’s shape; a template the recipe does not name is refused by name, a shape the template cannot take by shape, and a window the recipe fixes must be on the sheet. The market supplies the as-of date, the FX spots a cross segment reads, and the bank schedules that name a policy window’s decision.
- seed_
hazard 🔒 - Where the first pillar’s Newton starts: the credit triangle for a spread quote, under the recovery the rung will price with; a flat guess for an upfront quote, whose number is not a spread.
- shape_
refusal 🔒 - A refusal for a locator shape
templatecannot take. - sheet_
rung 🔒 - One sheet entry’s rung, dispatched on the template’s family and the locator’s shape.
- slot 🔒
- A registered handle’s tape slot, as an index.
- solve_
helper_ 🔒group - One group solved against the curves
marketholds: the curve to pin and, where it was a ladder of its own, the solve. - solve_
ladder 🔒 - The one ladder loop behind both forms.
- strip_
caplet_ smile - Caplet vols from a quoted cap matrix: one smiled surface in which each strike column is the caplet ladder stripped at that strike.
- strip_
caplet_ vols - Caplet vols from term cap quotes: the surface under which every quoted cap reprices, exactly, at its own strike.
- strip_
interval 🔒 - The vol of one new interval: the earlier caplets valued at their stripped
vols (
settled), the interval’s at the unknown, the sum reachingtarget. - strip_
ladder 🔒 - One strike’s caplet ladder: the expiry nodes still to fix and the vol at each, under the named scheme.
- strip_
overnight_ caplet_ vols - Caplet vols from term cap quotes on an overnight index at
frequency: the ladderstrip_caplet_volsstrips, over caps whose coupons compound the index’s daily prints. - strip_
per_ 🔒caplet - The caplet-by-caplet strip: one caplet at a time, the cap ending at each caplet’s maturity priced at the term vol interpolated there, the earlier caplets at their stripped vols.
- strip_
refusal 🔒 - surface_
or_ 🔒refusal - A built surface, or the market-data refusal it reports.
- survival_
from 🔒 - The survival curve
hazardsdescribes, in the shape the solve substitutes parameters into. - survival_
quote_ 🔒block - Every rung’s quote read back on the survival curve
hazardsdescribes, and its derivative with respect to every segment hazard — the credit form of the quote block, over the same lane loop. - survival_
quotes_ 🔒in - The survival form’s pass in mode
R— seediscount_quotes_in. - sweeps_
exhausted 🔒 - A fit still moving when its sweeps ran out, named by the rung left worst
off (or
fallback, for a ladder with no solves to name). - term_
vol_ 🔒at - The term vol curve read at
t: linear between quoted maturities, the end segments extended — a term vol surface in time. One quote is a flat curve. - term_
vol_ 🔒nodes - The term vol curve’s nodes: each quote at the time its cap actually matures — the last caplet’s payment, rolled as the schedule rolls it — so the cap ending there reads its own quote exactly.
- view_
over 🔒 - The view a rung is valued in, with
under_solvein the role the ladder’s form gives it: the discount curve for a self-discounting solve, the projection curve over a fixed discount otherwise. - window_
dates 🔒 - The dates a window locator’s ends stand for.
- with_
calibration_ 🔒tape - Runs
fon this thread’s calibration tape and adjoint buffer: created on the first call, kept at the largest capacity either ever reached, the tape cleared on every recording. Its own rather than the trading layer’s — that one is the tape a risk pass is recording on, and a calibration inside a risk pass has already been routed away from here. - xccy_
recipe_ 🔒rungs
Type Aliases§
- Quote
Block 🔒 - Every rung’s quote read back on the curve
paramsdescribes, and its derivative with respect to every log discount factor:(read_back, dq),dq[i][j] = ∂qᵢ/∂zⱼ, from eight-lane forward-mode passes. - Quotes
For 🔒 - The pass a quote block hands its engine: every rung’s quote on whatever view the seeded parameters build, in the engine’s mode.