Skip to main content

Module trading

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§

pub use presets::How;
pub use presets::Preset;

Modules§

presets
The risk measures a desk names, declared once.

Structs§

Book
A collection of trades valued together.
MeasureParseError
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.
ScenarioLeg
One leg of a scenario: what it moves, and by how much.
SelectorParseError
A spelling that names no selector.
Trade
A booked position: an instrument, how much of it, and what to call it.

Enums§

BookPnlError
A book’s P&L that could not be produced.
BumpedKind
A sensitivity computed outside the one risk pass a report takes.
CreditBumpError
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.
MovedFrom 🔒
What a fetch in flight moved a book’s market away from: a market, or none at all, where demand_for attached an undated one.
ScenarioError
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.
ShiftType
Whether a leg’s amount moves an input relatively, x·(1 + s), or absolutely, x + s.
SmileComponent
The part of an FX smile a smile-shape leg moves.
StrategyQuote 🔒
What one strategy quotes under: the formula and the market it shares. Two legs belong to one strategy when these are equal.
TrancheInput
Which of a credit index’s tranche model marks a Selector::TrancheModel leg 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::npv will probe linearly before it builds an index instead.

Functions§

axis_of_curve 🔒
The risk axis a curve identifier belongs to — the classifier axis_of applies 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))/2 for a parallel shift h = bump of 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 given asks for everything current does.
held_curves 🔒
Every curve market holds, under every identity it is held by.
moved_quotes 🔒
Each rung quote moved by leg’s shape at the rung’s pillar — τ Act/365F from reference for 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 of recovery_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))/2 for h = bump, the survival curve held fixed — read straight off the protection leg, −N·P(t_v)∫P dQ per 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 🔒
market with the curve id names replaced by curve. Re-pins curve under the role id names.
report
Evaluates measures over book against market, 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 🔒
market with entity’s survival curve solved again from its CDS quotes moved by leg: 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 🔒
market with its quoted FX spots moved by 1 + amount: every stored pair for the axis, or the one target names — inverted where the market stores it the other way round, so the named direction moves by exactly 1 + amount. Crosses move with the legs they are derived from.
shocked_fx_implied 🔒
market with every FX-implied curve the FX leg reaches moved to its spot times 1 + 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 🔒
market with the rate curve id bootstrapped again from its par quotes moved by leg (see moved_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 hold id is carried through.
shocked_rate_smile 🔒
market with the credit index index’s tranche model mark input moved by a parallel leg — 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 🔒
market with the smile of pair’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 as component says. A market with no surface for the pair is returned as it is, as a vol-surface selector does.
shocked_spread_correlation 🔒
market with its CMS spread correlation for the pair moved by leg — 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 🔒
market with every vol surface leg selects 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 at peak, linear to zero at each present corner, flat on a side whose corner is absent.
with_warm_tape 🔒
Runs f on this thread’s warm tape: created on the first call, kept at the largest capacity it ever reached, cleared on every recording.