This chapter defines how the library values a portfolio: what every product promises to the portfolio, how a cash flow says whether its amount is known, how a netting set's collateral terms change the discounting, how values are added up without ever adding different currencies, and how the valuation runs in parallel and still gives the same totals every time.
The portfolio framework knows no product. A product joins it by implementing one small contract and registering one handler in a catalog; nothing in the portfolio, the valuer or the totals changes when a product is added. Risk comes from the same contract: the value function of every product, differentiated by AAD on a market recorded once (Section 20.7), gives node risk that adds up over any group of positions and is turned into quote risk once per group (Section 20.8).
20.1 The product contract and the sign
| Symbol | Meaning |
|---|---|
| \(p\) | A position: one stored trade, with its book, counterparty, netting set, legal entity, strategy and tags |
| \(\ell = 0, 1, \dots, L_p - 1\) | The legs of position \(p\), as the product numbers them |
| \(c(p, \ell)\) | The currency of leg \(\ell\) |
| \(V_{p,\ell}\) | The present value of leg \(\ell\) on the valuation date, in \(c(p, \ell)\) |
| \(V_p(c)\) | The value of position \(p\) in currency \(c\) |
| \(\kappa\) | The collateral terms the position is valued under (Section 20.3) |
A resolved trade answers five questions, whatever the product:
- Its last payment date, so that a report can leave out trades that have fully settled.
- Its market dependencies under collateral terms \(\kappa\): the discount curves, projection curves, fixings, volatilities, survival curves and FX rates it reads (Section 20.6).
- Its value per leg, \(V_{p,\ell}\), each in its own currency.
- Its cash flows, each with a payment date, an amount, a currency, a kind (interest, principal, fee or settlement, Section 10.9) and a status (Section 20.2).
- Its settled cash flows over a window: the flows paid from a start date to the valuation date, with the amounts actually paid (Section 20.2.1).
Every value and every cash flow is signed for the holder of the trade: cash received or receivable is positive, cash paid or payable is negative. A negative swap notional pays fixed and receives floating; a negative bond face amount sells, shorts or issues. The value of a position in a currency is the sum of its legs in that currency:
In words: a single-currency swap has one value, the sum of its two legs; a cross-currency swap has one value in each currency and is never collapsed into one number unless a reader asks for a conversion (Section 20.4). A position with no leg in \(c\) has no value in \(c\), not a zero.
Legs. A product chooses its legs so that each has one currency and a name a reader recognises: the fixed and floating legs of a swap ("Fixed SAR", "SAR-SAIBOR-3M SAR"), the holding and the settlement of a bond trade, the two currency amounts of an FX forward. A product with a single price, such as an option, has one leg.
Stored trades. Every trade is stored as a document of kind Trade with
its own type. A handler reads a document of one type into a resolved trade,
looking up any referenced document (a bond trade looks up its security) and
validating the fields first. The catalog maps each type to its handler and
refuses two handlers for one type; a document whose type has no handler is
reported, not valued. The library ships handlers for OIS, IRS, FRA, FX
forward, cap/floor, cross-currency swap, swaption, CDS, CMS swap, CMS rate leg,
bond and loan trades.
Frozen terms. A trade booked on a convention stores a copy of the
convention's contractual terms in its group field Terms (index, calendars,
day counts, frequencies, lags), so that a later amendment of the convention
never changes a booked trade; the convention's name is kept for reference
only. Valuation defaults the convention also names, such as a loan's
discount collateral, are left out and read from the current convention; the
convention's schema version is frozen with the terms. A swaption freezes its
underlying swap's convention; a CMS swap freezes its swap index, the index's
underlying swap convention and a floating other leg's convention, and is read
against those frozen copies; indices and calendars are always read by name; a CDS freezes the standard contract and keeps
its reference obligation, so a credit curve that now names another entity
is refused; a cross-currency swap stores the FX rate agreed at trade. An
IRS, and a cross-currency swap whose spread leg is on a term rate, store
FixingTiming when the floating leg fixes in arrears (Chapter 22); a
document without it fixes in advance. A
document written before frozen terms existed is read through the current
convention of its name.
Position attributes. The book is a path such as Treasury/ALM/SAR, so a
hierarchy of books needs no separate table: a position is in book \(B\) when its
path is \(B\) or starts with \(B\) followed by /. The counterparty, netting set,
legal entity, strategy and tags are free identifiers used to select and to
group positions.
20.2 Cash-flow status
A treasury report lists past flows as well as future ones, so every cash flow says how much is known about its amount on the valuation date \(t_0\):
| Status | Meaning |
|---|---|
| Projected | The amount depends on a rate not yet fixed; it is read from a projection curve |
| Fixed | The amount is known (a fixed coupon, a published fixing, an FX forward amount) but not yet paid |
| Settled | The payment date is on or before \(t_0\); the amount has been paid |
The rules, product by product:
- Fixed legs, bonds and FX forwards. Every amount is fixed.
- Term-rate legs and FRAs (Chapter 10). A period is fixed once its fixing date is before \(t_0\), or is \(t_0\) and the fixing is published in the market; otherwise it is projected.
- Overnight legs (Chapter 6). A period compounds every daily fixing up to its end date, so it is fixed only when its end date is on or before \(t_0\); a running period is projected, even though part of it is already known.
- Resetting legs (Chapter 12). A cross-currency leg whose notional follows the FX rate knows only its first period's notional on the trade date. A later period's notional is known once its FX fixing is published, by the same rule as a term-rate fixing, so a coupon is fixed only when both its rate and its notional are known.
- Notional exchanges. Fixed, except on a resetting leg: an exchange on a period start or on the end date is fixed once the notional it pays is known; the initial exchange is fixed.
The unsettled list holds the projected and fixed flows; settled flows are a second list (Section 20.2.1). Options, caps and floors, swaptions and credit default swaps list no unsettled cash flows yet: their payoffs are not known amounts.
20.2.1 Settled cash flows
For a window start \(f\), a trade lists every flow with payment date \(p\) in \([f, t_0]\), with status settled. The two lists partition the trade's schedule: a period or an exchange paid on or before \(t_0\) is in the settled list, any other in the unsettled list, and none is in both or in neither. The valuation date is the window's end because a flow after it is not settled; a report on a closed past month filters the rows by payment date rather than building a market as of the month end.
A settled row has the amount actually paid (Section 10.9), signed for the holder and with its kind. Its present value is 0 and its discount factor is not defined, so adding settled rows to a sum of present values changes nothing. Amounts come from the market's fixings only: a term period reads its fixing, an overnight period compounds its daily fixings with its lookback and shift, a resetting leg reads its FX fixings, a CMS period its swap-rate fixing. A missing fixing throws, naming the index and the date; nothing is projected.
- Swaps of every leg type: one interest row per period and one principal row per notional exchange.
- Loans (Section 21.6): interest, drawdown and repayments, and each floorlet's payoff \(N_i \delta_i \max(F - B_i, 0)\) on its period's benchmark rate \(B_i\). Under a daily floor basis the published fixings are already floored inside \(B_i\) (Section 21.4), so the interest row carries the floor and the floorlet pays only where the compounded floored rate is still below \(F\).
- Bond trades (Section 19.4): the settlement amount once paid, and the coupons and redemptions the holder was entitled to after the trade's settlement. A trade that sells (negative face) lists them up to its own settlement only, so a buy and a later sell net to the coupons paid between the two settlements.
- FRAs: the settlement amount from the published fixing. FX forwards: the two deliveries. Caps and floors: the premium once paid and each caplet's payoff \(N_i \delta_i \max(\omega (R_i - K_i), 0)\); with a payment lag, a caplet fixed but paid after \(t_0\) stays in the unsettled list.
- Swaptions and CDS list none: an exercised swaption is booked as its swap, and a CDS's premiums and default settlement need trade events of their own. An expired swaption lists nothing and does not throw.
- A product added by a host (Section 20.1) that does not list its settled flows throws "not supported", so a report shows the position as such instead of dropping it.
Each trade also lists, per index, the earliest fixing its settled flows in the window read: the fixing of the first term period paid in the window, or the first daily observation, minus any lookback, of the first overnight period paid in it, even when that period starts before \(f\). The union over a portfolio is the fixing history the window needs (Section 20.6).
A portfolio. The settled flows of a portfolio are one result per
position, in the order of the positions: its rows, or the error that stopped
them. A missing fixing is an error on that position only; a host product
without settled flows is flagged as not supported. Neither is ever dropped
silently. A gap report compares, per index, the earliest fixing the window
needs with the earliest fixing the market holds, and lists the indices whose
history starts too late or is absent; a front end shows each with the
fixings --from --to run that fills it. Holes inside a stored history are
not in the gap report; they throw when the rows are listed.
20.3 Collateral terms and netting sets
| Symbol | Meaning |
|---|---|
| \(\kappa\) | Collateral terms: trade default, none, or a currency \(X\) |
| \(P(t)\) | A discount factor to time \(t\) on a curve collateralised in \(X\) |
| \(s\) | The CSA's discount spread (counterparty or netting set), a decimal rate, continuously compounded |
| \(P_s(t)\) | The discount factor with the spread applied |
| \(t\) | The curve time from the valuation date: Act/365 (Fixed), as in Chapter 7 |
Every trade can say which collateral it is discounted under: a SAR swap defaults to the FX CSA curve against USD collateral, an FX forward to USD collateral. A netting set groups the trades covered by one CSA and holds its terms. Collateral terms take one of three values:
- Trade default. The trade's own default applies. This is the value for a position with no netting set. A trade that names no collateral is discounted on its currency's own curve, except a SAR rates derivative (swap, FRA, cap or floor, swaption), which is discounted on the SAR curve against USD collateral, and a cross-currency trade, which is discounted under USD collateral.
- None. The trade is uncollateralised and is discounted on each currency's default discount curve: its own curve, except SAR, whose discounting is the curve against USD collateral, so an uncollateralised SAR trade is discounted on it too.
- Currency \(X\). Every cash flow in currency \(c\) is discounted on the curve of \(c\) collateralised in \(X\); when \(c = X\) that is the curve of \(c\) itself.
Two present values. Every position has two present values, each discounted under its own collateral terms:
- Standard CSA PV, \(\kappa_{\text{std}}\): the trade's own default, or
USD collateral (currency \(X = \text{USD}\)) when the trade is marked
IsCrossCurrencyTrade. A marked JPY floor is then discounted on the JPY curve against USD collateral instead of the JPY TONA curve; a USD flow stays on the USD curve, since the curve of USD against USD collateral is the USD curve itself. The mark is a position field, like the book or the netting set (IsCrossCurrencyTrade), not one of the frozen contractual terms, and is the same for every leg of the trade. - CSA PV, \(\kappa_{\text{csa}}\), with spread \(s\): the terms of the CSA
signed with the trade's counterparty. They are held by the counterparty
(stored kind
Counterparty) and can be amended at any time without touching a booked trade. A netting set, needed only for a counterparty with several agreements, overrides the counterparty's terms for the trades that name it, and its counterparty must be the trade's. A trade naming neither a counterparty nor a netting set takes its standard terms, and the portfolio reports it; a trade naming a counterparty that is not stored gets no CSA PV, only an error, while its Standard CSA PV is still valued.
In symbols, with \(V(\kappa, s)\) the value of a trade under terms \(\kappa\) and spread \(s\),
In words: the same trade, valued twice on the same market, once on standard terms that do not depend on who the counterparty is, and once on the CSA actually signed. Under a counterparty without collateral the CSA PV discounts each currency on its own default curve and ignores the cross-currency mark, so it can differ from the Standard CSA PV of a marked trade. Debt (bonds, Sukuk and loans) is discounted under its convention's discount collateral whatever the terms (Section 19.7), so its two present values are equal. When both present values discount under the same terms and no spread, the position is valued once. Risk is computed on one basis only, chosen in the valuation settings (CSA PV by default); the other basis gives values only.
Discount spread. A CSA may pay the collateral rate plus a spread. The netting set then holds a spread \(s\), and every discount curve collateralised in \(X\) (the curve of \(X\) itself and every curve of another currency against \(X\)) is replaced, for the trades of that netting set, by
In words: the spread is a zero spread added to the curve. Its zero rate rises by \(s\), every discount factor falls by the factor \(e^{-st}\), and a forward rate read from discount factors rises by about \(s\). Projection curves, fixings and FX rates are not touched: the spread changes what collateral earns, not the index rates. A spread without a collateral currency is refused, since there is no curve to add it to. The time \(t\) is the curve's own time, so the spread is exact on that curve's continuously compounded zero rates. A curve modified by a spread keeps the node dates of the curve it modifies, so a pricer that integrates between nodes, such as the protection leg of a credit default swap (Chapter 18), uses the same grid with and without a spread.
Swaptions. The terms of the basis, spread included (the trade's own terms for the Standard CSA PV, the counterparty's CSA or the netting set overriding it for the CSA PV), discount every flow of a swaption up to and on its settlement date. After settlement they apply only to a physically settled swaption, whose swap joins the netting set; a cash-settled swaption's amount is the swap's value on the curve of the swap's own collateral, without the spread (Section 13.6).
20.4 Aggregation
| Symbol | Meaning |
|---|---|
| \(\mathcal{P}\) | The positions of a portfolio, in their stored order |
| \(\mathcal{V} \subseteq \mathcal{P}\) | The positions that were valued (Section 20.5) |
| \(V(c)\) | The value of the portfolio in currency \(c\) |
| \(x_{c \to b}\) | The FX rate today: units of currency \(b\) per unit of \(c\) |
| \(V_b\) | The portfolio value converted into currency \(b\) |
The total of a portfolio is a set of amounts, one per currency:
Totals by book, counterparty, netting set or any other attribute are the same sum over the positions with that attribute. Different currencies are never added. A single number in a base currency \(b\) is a separate, explicit step:
using the FX rates of the market for the valuation date (Chapter 12). The same market also gives the FX position per currency, \(V(c)\) itself, which is what moves when an FX rate moves.
Because Equation (20.3) sums position values in position order, a total can be assembled from position results valued earlier on the same market, with the same settings, netting sets and counterparties: it is then the same number as a full revaluation. The desktop's deal entry page keeps each trade's result and reprices only the trades that changed.
20.5 Parallel valuation, determinism and errors
One market, shared. A portfolio is valued on one market for one date. The market is immutable, so every thread reads it at once without locks. A netting set with a discount spread gets its own view of the market, built once before the valuation starts; the view shares every curve and wraps only the curves collateralised in its currency (Equation (20.2)).
Chunks. Positions are cut into chunks of consecutive positions (32 by default) and the chunks are valued in parallel, on at most a chosen number of threads. Each result is written to the slot of its position, so the results come back in the stored order whatever the order the threads finish in.
Determinism. Floating-point addition is not associative: adding the same numbers in another order can change the last digits. Every total (Equation (20.3)) is therefore summed in position order after the parallel step, never as threads finish, so the same portfolio and market give the same totals to the last bit for any number of threads and any chunk size, on the same hardware and build. Across machines, the compiler's choices (for example fused multiply-add) can still move the last bit.
Errors. A position that cannot be valued (a missing curve, a missing fixing, a convention the market does not support) does not stop the others. Its result carries the error message and no values, it is listed among the failures, and it is left out of every total, so \(\mathcal{V}\) is smaller than \(\mathcal{P}\) and the reader is told which positions are missing. Only cancellation stops the whole valuation. A stored trade that cannot be read at all, or names a netting set that does not exist, is reported when the portfolio is loaded, before any valuation.
20.6 Market dependencies and fixing history
Each resolved trade lists what it reads from a market, by identifier only: the discount keys (currency and collateral) under its collateral terms, the projection curves, the earliest fixing date of each index, the caplet and swaption volatilities, the survival curves, and whether it needs FX rates. The portfolio's dependencies are the union over its positions, keeping the earliest fixing date per index.
The union serves two purposes. Before a valuation, it lists everything a
market lacks for the portfolio ("the SAR discount curve under USD collateral",
"the SAR-SAIBOR-3M projection curve"), so a missing item is named once rather than
on every failing trade. For treasury use, the earliest fixing date of each
index says how far back the stored fixing history must reach, and therefore
which fixings --from --to run fills a hole (item 4). For
settled flows over a window, each trade's settled dependencies give the same
earliest date per index (Section 20.2.1). The
portfolio never shapes the market: there stays one market per definition and
date, shared by every portfolio valued on it.
20.7 Risk: the market recorded once
| Symbol | Meaning |
|---|---|
| \(x\) | The recorded market inputs: every node value \(y\) and zero spread of the curve group, \(\alpha\), \(\rho\), \(\nu\) of every SABR node, every caplet volatility node, every hazard rate \(\lambda\) of a survival curve |
| \(m\) | The mark: the length of the tape when the market is recorded |
| \(G\) | The tape's generation, increased by each rewind or reset |
| \(G_m\) | The generation when the mark was set |
| \((i, g)\) | A recorded number: its place \(i\) on the tape and the generation \(g\) it was recorded in |
Sensitivities come from adjoint algorithmic differentiation (Section 5.3). Recording the whole market for every trade, as a single-trade risk call does, repeats the same work: the curve group, the volatility grids and the survival curves are the same for every position. The portfolio engine therefore records the market once per thread and reuses it for every position.
- Record. The inputs \(x\) are recorded as variables on the thread's tape, and the market context is built on them: curves, today's FX rates (Section 8.8), synthetic collateral curves when asked for (Section 14.9) and the survival curves. Only the volatility grids and survival curves that the portfolio's positions depend on (Section 20.6) are recorded; the curve group always is, because every quote risk goes through it. Everything is built at this point: nothing on the recorded market is computed later and kept, so the market part of the tape never changes.
- Mark. The tape's length \(m\) and generation \(G_m\) are kept.
- Price, sweep, rewind. For each position, the legs are valued on the recorded market and summed per currency, \(V_p(c)\) (Equation (20.1)). One adjoint sweep per currency gives \(\partial V_p(c) / \partial x\); then the tape is cut back to the mark and its generation increased. A position that fails, for example on a missing fixing, is rewound the same way, so the next position starts on the same tape.
The staleness rule. After a rewind, the places after the mark are reused by the next position, so a number kept from an earlier position would read another position's nodes. A recorded number \((i, g)\) is accepted only when
that is, when it was recorded since the last rewind, or it belongs to the market. Anything else is rejected with an error. A reset empties the tape and clears the mark.
Cost. Each position costs one valuation on the recorded market and one sweep per currency of its legs; a sweep runs back over the position's own nodes and the market's, a few hundred to a few thousand variables. Neither depends on the number of quotes: bumping each quote and revaluing would recalibrate the market and reprice the position once per quote, well over a hundred times on a market of several currencies.
Threads. A tape belongs to one thread (Section 5.4), so each worker records its own copy of the market at the start and keeps it for all the positions it values, and a recording, like its tape, is used by that thread only. The values are those of the market without a tape: the arithmetic is the same, and the tests check the equality to the last digit (it is checked, not guaranteed: a pricer that took a different path for recorded numbers would break it).
Held inputs. The FX spot rates the curves were calibrated against are held fixed, as in a single-trade risk call: FX risk is given by the FX positions per currency of each group (Section 8.9). A netting set's discount spread (Equation (20.2)) is a constant.
20.8 Node risk, aggregation and quote risk
| Symbol | Meaning |
|---|---|
| \(g_p(c)\) | The node risk of position \(p\) in currency \(c\): \(\partial V_p(c) / \partial x\), one entry per recorded input |
| \(A\) | A group of positions: the portfolio, a book, a counterparty, a netting set |
| \(J = \partial x / \partial q\) | The calibration Jacobian: how each recorded input moves with each market quote \(q\) |
The node risk of a position is a list of sensitivities, one per recorded input it depends on, kept per currency so that different currencies are never added. Each entry is identified by what it is in the market (the curve and node, the SABR node and parameter, the caplet node, the survival curve and node), never by its place on a tape, so node risk from different threads adds up. The node risk of a group is the sum over its valued positions, in position order:
The calibration gives each recorded input as a function of the market quotes, and the implicit function theorem gives its derivatives at the calibrated point: Equation (11.7) for the curve group, Equation (13.20) for SABR, Equation (13.22) for caplets, Equation (18.14) for survival curves. The quote risk of the group is
and since this is linear in \(g_A(c)\), applying \(J\) once to the sum gives the sum of the positions' quote risks. The Jacobians are therefore applied once per group and currency, not once per position; a position's own quote risk is computed only when someone asks for it.
Conventions, as for a single trade:
- Curve delta holds the SABR parameters, the caplet volatilities and the hazard rates (Section 13.7, Section 18.10). The parallel delta of a curve is the sensitivity to its zero spread (Section 7.9).
- Vega is through the implicit function theorem of the SABR calibration or of the caplet stripping, with the curves held.
- CS01 holds the discount curves. On the recorded market the survival curve is built from its hazard rates as variables, not bootstrapped again from the recorded curves, so a curve quote does not move the hazard rates: there is no hazard-to-discount cross term. Bumping a SOFR quote and rebuilding the whole market would re-bootstrap the survival curves as well, and so differs from this delta by that term; that is the market convention, the same as Section 18.10.
- The recovery delta stays a single-trade measure (Section 18.10): in a portfolio each trade values with its own recovery rate.
20.9 Worked example
A portfolio of two positions, valued on one market:
| Position | Leg | Currency | Value |
|---|---|---|---|
| SAR swap, receive fixed | Fixed SAR | SAR | \(+1{,}250{,}000\) |
| SAR-SAIBOR-3M SAR | SAR | \(-1{,}180{,}000\) | |
| USD bond trade, unsettled purchase | Holding | USD | \(+5{,}010{,}000\) |
| Settlement | USD | \(-4{,}980{,}000\) |
- Position values (Equation (20.1)): the swap is worth \(1{,}250{,}000 - 1{,}180{,}000 = 70{,}000\) SAR, the bond trade \(5{,}010{,}000 - 4{,}980{,}000 = 30{,}000\) USD.
- Portfolio total (Equation (20.3)): \(70{,}000\) SAR and \(30{,}000\) USD, two amounts, not one.
- In USD at \(x_{\text{SAR} \to \text{USD}} = 1/3.75\) (Equation (20.4)): \(70{,}000 / 3.75 + 30{,}000 = 18{,}666.67 + 30{,}000 = 48{,}666.67\) USD.
Discount spread. A cash flow of \(1{,}000{,}000\) USD in two years, on a curve under USD collateral with \(P(2) = 0.92\), is worth \(920{,}000\) USD. In a netting set with USD collateral and a spread of 10 basis points (\(s = 0.001\)), Equation (20.2) gives \(P_s(2) = 0.92 \times e^{-0.002} = 0.918162\), and the flow is worth \(918{,}161.84\) USD.
Node risk mapped once. A book holds two SAR swaps on a curve with two nodes \(y_1, y_2\) and two quotes \(q_1, q_2\), with the Jacobian
(row: node, column: quote). Their node risks in SAR are \(g_1 = (100, 200)\) and \(g_2 = (-50, 300)\). Mapped one by one (Equation (20.6)), the first swap's quote risk is \((100 \times 1.02,\; 100 \times (-0.01) + 200 \times 1.05) = (102, 209)\) and the second's \((-51, 315.5)\), which add up to \((51, 524.5)\). Mapped once, Equation (20.5) gives \(g = (50, 500)\) and \((50 \times 1.02,\; 50 \times (-0.01) + 500 \times 1.05) = (51, 524.5)\): the same numbers for one product with \(J\) instead of two. A USD bond in the same book keeps its own node risk in USD, mapped separately; its SOFR delta is never added to the SAR swaps' SOFR delta, which is in SAR.
20.10 Edge cases and limits
- Empty portfolio. Every total is empty; a total converted into a base currency is zero in that currency.
- No netting set. The trade's own default collateral applies.
- Unknown netting set. Reported when the portfolio is loaded; the position is not valued.
- Counterparty mismatch. A position whose counterparty differs from its netting set's is reported when the portfolio is loaded.
- Collateral the market lacks. A trade valued under collateral terms whose curve the market does not hold fails with the curve named, for example a SAR trade under none on a market that holds only the SAR curve under USD collateral.
- A grid or curve the recording lacks. Only what the positions name is recorded; a position that reads a grid the market does not hold fails as it would without a tape.
- Synthetic collateral curves. The portfolio valuer records none: a position whose terms need one fails with the curve named, as it does without risk on the built market. A recording made directly can compose them when asked.
- Risk to two markets. Node risk is to the inputs of one built market; adding the node risk of two markets is refused.
- Not yet covered. Trade documents for every product, settled cash flows, and the desktop and Excel views of a portfolio.