Module trading
Expand description
Trading containers, measures, lenses and scenarios.
Nothing in this layer carries a scalar type parameter. A Book is a
Book, not a Book<f64> and a Book<AReal>; a Measure names a quantity
without knowing how it will be differentiated; a Lens selects trades by
what they are, which is passive data.
That is a consequence rather than a rule. Contract terms are passive, so an instrument carries no mode; a container of instruments therefore carries none either, and the mode enters only where the container asks the market for a number. Valuation is a generic method on a non-generic type — which is what lets one book be valued, risked and shocked without ever being rebuilt.
The analytics layer holds no active-scalar references, and a test asserts the property that makes it so rather than a count.
Re-exports§
Modules§
- presets
- The risk measures a desk names, declared once.
Structs§
- Book
- A collection of trades valued together.
- Measure
Parse Error - A spelling that names no measure.
- Request
- A measure as a report is asked for it: the measure, and the default scale of the preset it was asked through, if it was.
- Row
- One report row.
- Scenario
- A named perturbation of the market, written in the units its quotes are made in.
- Scenario
Leg - One leg of a scenario: what it moves, and by how much.
- Selector
Parse Error - A spelling that names no selector.
- Trade
- A booked position: an instrument, how much of it, and what to call it.
Enums§
- Book
PnlError - A book’s P&L that could not be produced.
- Bumped
Kind - A sensitivity computed outside the one risk pass a report takes.
- Credit
Bump Error - Why a credit bump sensitivity could not be taken.
- FxMode
- What an FX spot move holds fixed on the FX-implied discount curves.
- FxTarget 🔒
- The FX spots an FX leg reaches.
- Lens
- A selection over a book. Passive data — it asks what a trade is, never what it is worth, so applying one needs no market and no mode.
- Measure
- A quantity a report asks for. Names a number; says nothing about how it is computed, which is what keeps it mode-free.
- Moved
From 🔒 - What a fetch in flight moved a book’s market away from: a market, or none
at all, where
demand_forattached an undated one. - Scenario
Error - Why a scenario cannot be applied to a market.
- Selector
- What one leg of a scenario moves.
- Sensitivity
- A bumped sensitivity a book computes outside its one risk pass.
- Shift
- How much a selected quote moves, and with what shape.
- Shift
Type - Whether a leg’s amount moves an input relatively,
x·(1 + s), or absolutely,x + s. - Smile
Component - The part of an FX smile a smile-shape leg moves.
- Strategy
Quote 🔒 - What one strategy quotes under: the formula and the market it shares. Two legs belong to one strategy when these are equal.
- Tranche
Input - Which of a credit index’s tranche model marks a
Selector::TrancheModelleg moves.
Constants§
- IMPLIED_
VOL_ 🔒ITERATION_ CAP - Brent halves the bracket at worst; a lognormal bracket of five vols to a 1e-12 step is under fifty halvings.
- PROBE_
LIMIT 🔒 - How many resolved views
Book::npvwill probe linearly before it builds an index instead.
Functions§
- axis_
of_ 🔒curve - The risk axis a curve identifier belongs to — the classifier
axis_ofapplies to a node, read from the curve alone. Total: every curve belongs to exactly one axis. - book_
value 🔒 - The book’s passive value against
market. - correlation_
sensitivities - The book’s sensitivity to each credit index’s base correlation: the
central-difference value change
(V(ρ + h) − V(ρ − h))/2for a parallel shifth = bumpof every point on that index’s skew, everything else held. One row per base-correlation curve the market holds, in store order. - demand_
covers 🔒 - Whether
givenasks for everythingcurrentdoes. - held_
curves 🔒 - Every curve
marketholds, under every identity it is held by. - moved_
quotes 🔒 - Each rung quote moved by
leg’s shape at the rung’s pillar —τAct/365F fromreferencefor a slope — absolutely unless the leg asks for a relative move. - npv_
under - The book’s value under
scenario, against a market nothing mutates. - quote_
delta - The P&L of a unit parallel move of
axis’s quote, from the risk vector a pass already produced. - quote_
held_ recovery_ sensitivities - The book’s sensitivity to each entity’s market recovery with its CDS
quotes held: the central difference
(V(R + h) − V(R − h))/2, the survival curve solved again to the same ladder at each bumped recovery — the counterpart ofrecovery_sensitivities’ curve-held one. A contract quoted on the ladder itself is then worth what it was; a product off the ladder moves by the recovery and by the hazards the quotes imply under it. - recovery_
sensitivities - The book’s sensitivity to each entity’s market recovery: the
central-difference value change
(V(R + h) − V(R − h))/2forh = bump, the survival curve held fixed — read straight off the protection leg,−N·P(t_v)∫P dQper unit of recovery. One row per entity the market holds a recovery for, in store order; a product carrying a contractual recovery does not move. - repin 🔒
marketwith the curveidnames replaced bycurve. Re-pinscurveunder the roleidnames.- report
- Evaluates
measuresoverbookagainstmarket, from one risk pass. - report_
records - A report’s rows as records: what was measured, which row of it, the
number and its unit, then the curve and pillar date the row was reached
under where it was reached under one — empty text and an absent date
otherwise. The two are appended after
scale, so a reading of the first four columns by position is what it always was. - shocked_
credit_ 🔒quotes marketwithentity’s survival curve solved again from its CDS quotes moved byleg: each rung’s quote moved by the leg’s shape at its pillar —τAct/365F from the curve’s reference for a slope — absolutely unless the leg asks for a relative move, the ladder solved in its own family against its own discount at the entity’s market recovery, and the result re-pinned with its new ladder and refit. A market that does not hold the entity is carried through.- shocked_
future_ 🔒prices - shocked_
fx 🔒 marketwith its quoted FX spots moved by1 + amount: every stored pair for the axis, or the onetargetnames — inverted where the market stores it the other way round, so the named direction moves by exactly1 + amount. Crosses move with the legs they are derived from.- shocked_
fx_ 🔒implied marketwith every FX-implied curve the FX leg reaches moved to its spot times1 + amount— divided, where the curve quotes the pair the other way round — with its outrights held. An axis leg reaches every implied curve; a pair leg the ones stating that pair.- shocked_
rate_ 🔒quotes marketwith the rate curveidbootstrapped again from its par quotes moved byleg(seemoved_quotes), in the form its ladder was solved in — over the curves its refit holds — and re-pinned, with its new ladder and refit, under every role that shares the refit: a self-discounting curve pinned as a discount and a projection moves in both. A curve calibrated over the moved one keeps its own curve. A market that does not holdidis carried through.- shocked_
rate_ 🔒smile marketwith the credit indexindex’s tranche model markinputmoved by a parallelleg— absolutely unless the leg asks for a relative move — and re-pinned as the parameter it is, so the layout is kept. A market without the mark is carried through, as a vol leg on a surface it does not hold.- shocked_
smile 🔒 marketwith the smile ofpair’s FX surface moved in vol points: the leg’s shape read at each smile’s expiry, and applied to each node by its side of ATM ascomponentsays. A market with no surface for the pair is returned as it is, as a vol-surface selector does.- shocked_
spread_ 🔒correlation marketwith its CMS spread correlation for the pair moved byleg— absolutely unless the leg asks for a relative move — and re-pinned as the parameters it is, so the layout is kept. A term structure moves pillar by pillar, the leg’s shape read at each pillar’s expiry (the vol rule); a flat mark has no expiry to read a shape at, so it takes a parallel move only. A market without a mark for the pair is carried through, as a vol leg on a surface it does not hold.- shocked_
tranche_ 🔒model - shocked_
vols 🔒 marketwith every vol surfacelegselects moved node by node: the leg’s shape read at each node’s expiry, applied relatively (the default) or in vol points, every surface re-pinned under its own key.- tent_
weight 🔒 - The tent’s weight at
x, its corners on the same axis: one atpeak, linear to zero at each present corner, flat on a side whose corner is absent. - with_
warm_ 🔒tape - Runs
fon this thread’s warm tape: created on the first call, kept at the largest capacity it ever reached, cleared on every recording.