Documentation
Swaps
Building and pricing fixed/floating, overnight-indexed and cross-currency swaps with NxSwapLeg and NxSwap - schedules, notional profiles, PV, par rates, annuities and cash-flow reports.
A swap in NitroX is a list of legs, each with a coefficient. A leg (NxSwapLeg) is a coupon schedule in one currency that pays a fixed rate, a floating index plus a margin, or both, on a notional that can change from period to period, with or without exchange of that notional. A swap (NxSwap) values as
PV(swap) = sum over legs i of coef_i * PV(leg_i)
Market data is never stored in an instrument. Every pricing call takes the market at call time, either as an IndexGlob (normally the NxIndexGlob built in Curves) or as raw curve pointers. The same swap object can therefore be priced against any number of curve sets.
Headers:
#include "NX_Date.h"
#include "NX_SwapLeg_NxSwapLeg.h" // NxSwapLeg, NxLegFlow
#include "NX_Swap_NxSwap.h" // NxSwap (includes the leg header)
#include "NX_SwapLegPricer_NxSwapLegPricer.h"
#include "NX_SwapPricer_NxSwapPricer.h" // cancellation tables
#include "NX_IndexGlob_NxIndexGlob.h"
#include "NX_NxWallet.h"
Everything is in namespace NitroX. Rates are decimals (0.031 is 3.10 %). Errors are thrown, mostly as std::string; see Getting started.
Legs: NxSwapLeg
Constructors
NxSwapLeg derives from Schedule. Its four constructors differ only in how the schedule is defined; each has a matching Init(...) with the same arguments. The trailing arguments are common to all four:
const std::string & ccy, // currency of the payments
double fixRate = 0.0, // fixed coupon, or the margin on a floating leg
std::string floatRate = "", // index name; "" makes a fixed leg
bool notionalExchange = false,
double notional = 1.0
| Form | Schedule arguments | Start date |
|---|---|---|
| Dates | (const Date & startDate, const Date & endDate, const std::string & rollHolidays, char rollRule, char frequency, const std::string & basis, ...) | startDate, adjusted with rollRule |
| Start + tenor | (const Date & startDate, const std::string & matCode, const std::string & rollHolidays, char rollRule, char frequency, const std::string & basis, ...) | startDate, adjusted following |
| Trade date + spot rule | (const Date & tradeDate, std::string bizzDaysRule, const std::string & matCode, const std::string & rollHolidays, char rollRule, char frequency, const std::string & basis, ...) | tradeDate adjusted, then moved by bizzDaysRule (e.g. "2USD": two USD business days) |
| Today + start tenor | (const Date & today, std::string bizzDaysRule, const std::string & startCode, const std::string & matCode, const std::string & rollHolidays, char rollRule, char frequency, const std::string & basis, ...) | "" = spot from today; otherwise today + startCode, then moved by bizzDaysRule |
rollHolidays is a string of three-letter calendar codes ("USD", "EURUSD"); an empty string is a calendar with no closed days at all, not even weekends. rollRule is 'f' following, 'm' modified following or 'p' preceding. frequency is 'M', 'Q', 'S', 'A' (also 'Y') or 'Z' (zero coupon: one period from start to end). basis is a day-count code ("MM" ACT/360, "A5" ACT/365F, "AA" ACT/ACT ISDA, "BB" 30/360 ISDA, "Z" zero coupon, …). The full lists are in Conventions.
In the fourth form, a non-empty startCode is applied first and bizzDaysRule is then applied on top of it, so a "1Y" forward start with "2USD" starts two business days after the 1Y date. Pass "" as bizzDaysRule if the forward start already includes the spot lag. The tenors "ON", "TN" and "SN" are recognised as matCode in this form.
Schedule rules
- Coupon dates are generated backwards from the unadjusted maturity, one period at a time, and each is then adjusted with
rollHolidaysandrollRule. A broken period is therefore a stub at the front. - With a maturity tenor (forms 2 to 4), a front stub shorter than one period minus five days is merged into the next period (a long first period). With explicit dates (form 1) a short front stub is kept.
FlowDate(i)is both the accrual end of period i and its payment date: there is no payment lag, and accrual uses adjusted dates.Coverage(i)is the year fraction of period i in the leg’s basis;FlowDate(0)is the start date andCoverage(0)is 0.- The floating rate of period i is the index rate over exactly
[FlowDate(i-1), FlowDate(i)], stubs included. It is fixed at the accrual start: there is no fixing lag, and overnight legs have no lookback, lockout or observation shift.
Fixed, floating and overnight legs
Coupon i of any leg is
interest_i = Coverage(i) * (couponRate + floatRate_i) * Notional(i-1)
- Fixed leg:
floatRate = "", sofloatRate_i = 0andcouponRateis the fixed rate. - Floating leg:
floatRatenames an index,fixRateis the margin, quoted in the leg’s own basis.floatRate_i = index.IndexRate(FlowDate(i-1), FlowDate(i), leg basis). - Overnight (OIS) leg: a floating leg whose index is an
NxOisIndex. The period rate is the compounded overnight rate over the period as the curve defines it (see Concepts for how forwards are built). For a period that started before the curve date, the past part compounds the published overnight fixings and the remaining part is projected; see Past fixings. - Zero-coupon leg: frequency
'Z'and basis"Z". The fixed rate is compounded annually, so the leg paysN * ((1 + r)^t - 1)at maturity withtthe 30/360 year fraction from start to end. This is how the fixed leg of a zero-coupon inflation swap is built; see Inflation.
An index rate is converted to the leg basis by rescaling, so that the interest amount is the same whichever day count it is expressed in: with no margin, a SOFR leg with basis "A5" pays the same coupons as one with "MM".
A floating leg finds its index in the market by name. If the exact name is not found, it tries the name followed by the fixing tenor of its frequency, in months: a semi-annual "EURIBOR" leg looks for "EURIBOR6", a quarterly one for "EURIBOR3". If neither exists the pricing call throws. ResolveIndexLoc(const IndexGlob &) performs this lookup and returns the index (null for a fixed leg).
Notional profiles
A leg holds one notional per flow date. Notional(i) is the notional of the period that starts at FlowDate(i); period i accrues on Notional(i-1). The last entry, Notional(NbFlowDates()-1), is the notional after maturity and is always 0.
- Bullet: the
notionalconstructor argument, for every period. - Accreting at a rate:
SetAccreting(const double & accretingRate)setsNotional(i) = Notional(i-1) * (1 + Coverage(i) * accretingRate)from the first notional, i.e. compounded once per period. It returns the new notional vector. - Any profile (amortising, stepped, accreting):
SetAccreting(const std::vector<Date> & dates, const std::vector<double> & notionals)maps a step schedule onto the leg. Each period takes the notional of the latest source date on or before its start date, and the source schedule is walked at most one step per period, so give one step per period or fewer (the fixed leg’s own flow dates are the natural choice). It throws ifdatesis empty or the two vectors differ in size.
On an NxSwap, SetAccreting(const double & accretingRate, const int & leg = 0) accretes one leg and maps the resulting schedule onto every other leg with the dated form above. For an amortising swap, call the dated form on each leg yourself.
NxSwap::GetNotional(const Date & dt, int leg = 0) returns the notional of the period running on dt: Notional(i-1) when dt falls inside the period FlowDate(i-1) → FlowDate(i). On a flow date it returns the notional of the period that starts there; before the first flow date, Notional(0); on or after the last flow date, 0.
Notional exchange
With notionalExchange = true, a leg also pays its principal flows, discounted like any other flow:
-Notional(0)onFlowDate(0)(the initial exchange, paid away), andNotional(i-1) - Notional(i)on eachFlowDate(i). On a bullet leg this is the redemption at maturity; on an amortising leg each repayment is received as it occurs; on an accreting leg each accretion step is a negative flow, and the accreted notional is redeemed at maturity.
Single-currency swaps are normally built without exchange; cross-currency swaps with it.
Reading a leg
Ccy(), Frequency(), Basis(), FixRate(), IndexName(), StartDate(), EndDate(), NotionalExchange(), NbFlowDates(), FlowDate(i), Coverage(i), Notional(i); FlowDates() and Coverage() return the whole vectors. SetFixRate(double) changes the fixed rate or margin in place. CouponFixRate() returns the simple rate each coupon multiplies by Coverage(i): equal to FixRate() except on a "Z" leg, where it is the 30/360 equivalent of the compounded quote.
Flows(const Date & cutOff, const IndexLoc * indexLoc, double couponRate) returns the flows still to be paid at cutOff as std::vector<NxLegFlow>. Every valuation in this chapter is a sum over these rows:
NxLegFlow field | Meaning |
|---|---|
date | payment date, FlowDate(period) |
period | 0 for the initial exchange row; i ≥ 1 for the period FlowDate(i-1) → FlowDate(i) |
notional | notional the interest accrues on, Notional(i-1); 0 on row 0 |
coverage | Coverage(period) |
floatRate | index rate of the period; 0 on row 0 or without an index |
interest | coverage * (couponRate + floatRate) * notional |
principal | the notional exchanged on the date (0 without notional exchange) |
Row 0 is present when cutOff <= FlowDate(0). Then come every period paying on or after cutOff, the running period first, with its full coupon. Pass CouponFixRate() as couponRate for the leg’s own coupons, or 0 for the floating side alone.
Swaps: NxSwap
Single-currency swaps
Each single-currency constructor builds a fixed leg (leg 0, coefficient +1) and a floating leg (leg 1, coefficient −1) on the same dates, calendar and notional. A positive notional therefore receives fixed; pass a negative notional for a payer swap.
NxSwap(const std::string & ccy, const Date & startDate, const Date & endDate,
const std::string & rollHolidays, char rollRule,
double fixRate, char fixFreq, const std::string & fixBasis,
const std::string & floatIndex, char floatFreq, const std::string & floatBasis,
bool notionalExchange = false, double notional = 1.0);
NxSwap(const std::string & ccy, const Date & startDate, const std::string & matCode,
const std::string & rollHolidays, char rollRule,
double fixRate, char fixFreq, const std::string & fixBasis,
const std::string & floatIndex, char floatFreq, const std::string & floatBasis,
bool notionalExchange = false, double notional = 1.0);
NxSwap(const std::string & ccy, const Date & today, std::string bizzDaysRule,
const std::string & startCode, const std::string & matCode,
const std::string & rollHolidays, char rollRule,
double fixRate, char fixFreq, const std::string & fixBasis,
const std::string & floatIndex, char floatFreq, const std::string & floatBasis,
bool notionalExchange = false, double notional = 1.0);
The schedule arguments behave as in the corresponding NxSwapLeg forms. The floating leg is built with a zero margin; set one with swap.Leg(1)->SetFixRate(margin).
Standard swaps: NxSwap::Swap
A standard swap has two legs in one currency and one notional. Each leg is fixed if its index is "", at its rate, or floating on its index with the rate as a margin, so the same function builds fixed/float, float/float basis (for example EURIBOR 3M + margin against €STR) and fixed/fixed swaps.
static NxSwap NxSwap::Swap(const std::string & ccy, const Date & startDate, const Date & endDate,
const std::string & rollHolidays, char rollRule,
double recRate, const std::string & recIndex, char recFreq, const std::string & recBasis,
double payRate, const std::string & payIndex, char payFreq, const std::string & payBasis,
bool notionalExchange = false, double notional = 1.0);
plus the matching (ccy, startDate, matCode, ...) and (ccy, today, bizzDaysRule, startCode, matCode, ...) forms. The receive leg is leg 0 with coefficient +1, the pay leg is leg 1 with −1: to pay fixed, put the fixed leg second. The notional must be positive and finite. A fixed/float Swap has exactly the legs of the single-currency constructor above. In Excel this is nxSwap.SwapInit; nxSwap.VanillaInit stays the shortcut for fixed against float with the conventions taken from the index.
Cross-currency swaps: NxSwap::CrossCcy
static NxSwap NxSwap::CrossCcy(const Date & startDate, const Date & endDate,
const std::string & rollHolidays, char rollRule,
const std::string & recCcy, double recRate, const std::string & recIndex, char recFreq, const std::string & recBasis,
const std::string & payCcy, double payRate, const std::string & payIndex, char payFreq, const std::string & payBasis,
bool notionalExchange = true, double recNotional = 1.0, double payNotional = 1.0);
plus the (startDate, matCode, ...) and (today, bizzDaysRule, startCode, matCode, ...) forms. The two currencies must differ (compared regardless of case); one currency is refused with a pointer to NxSwap::Swap. Legs are set up as for a standard swap: fixed/fixed, fixed/float and float/float all work. Each leg has its own notional, in its own currency: recNotional for the receive leg, payNotional for the pay leg (for example 10,000,000 EUR against 10,850,000 USD), each positive and finite. Notionals are exchanged by default. The notionals do not reset to the FX rate during the life of the swap. swap.SetAccreting(rate, leg) accretes leg and makes the other leg follow in proportion, so the ratio of the two notionals is the same in every period. In Excel this is nxSwap.CrossCcyInit, with RecNotional and PayNotional as its last two arguments (1 each when left out).
The two-currency constructors NxSwap(startDate, endDate, rollHolidays, rollRule, recCcy, ..., payCcy, ..., notionalExchange = false, recNotional = 1.0, payNotional = 1.0) remain as the general two-leg form, for code whose currencies come from parameters: a swaption’s or capfloor’s underlying, where a quanto has two currencies and a vanilla one. They take any currencies; new code should use Swap or CrossCcy.
Custom swaps
NxSwap() creates an empty swap; AddLeg(std::shared_ptr<NxSwapLeg> leg, double coef) appends a leg with any coefficient. Any number of legs, currencies and notional profiles can be combined this way.
NbLegs(), Leg(i) (a std::shared_ptr<NxSwapLeg>), Coef(i), and the per-leg shortcuts Frequency(leg), Basis(leg), IndexName(leg), StartDate(leg), EndDate(leg) read the swap back.
Legs are held by std::shared_ptr. Copying an NxSwap copies the pointers, so the copy shares its legs with the original: SetFixRate or SetAccreting through one changes both. Build a new swap if you need an independent one.
Pricing
Present value
| Call | Returns | Flows included | Discounting |
|---|---|---|---|
NxSwap::Pv(const IndexGlob &, const Date & pvDt) | NxWallet, one amount per currency | paying on or after pvDt | a floating leg on its index’s funding curve, a fixed leg on the currency’s discount curve |
NxSwap::CalcPv(const IndexGlob &, const Date & dt) | double, sum of the legs | paying on or after the discount curve’s start date | each leg on its currency’s discount curve |
NxSwapLeg::CalcPv(const IndexGlob &, const Date & dt) | double, one leg, coefficient not applied | as NxSwap::CalcPv | the leg currency’s discount curve |
NxSwapLeg::CalcPv(const DiscountLoc *, const IndexLoc *, const Date & dt) | double | as NxSwap::CalcPv | the curve given |
NxSwapLeg::Pv(const DiscountLoc *, const IndexLoc *, const Date & pvDt) | NxWallet | paying on or after pvDt | the curve given |
All of them value the leg as received: a leg’s PV is the value of receiving its flows. Each flow is discounted to the pricing date, with discount factor DF(flow date) / DF(pricing date) on the curve, so the result is a value as of that date. Pass the curve date to get today’s value.
Within one NxCcyIndexes every index shares the currency’s single funding curve, so the two discounting choices in the table give the same number. Likewise the two cut-offs agree whenever the pricing date is the curve date; see Seasoned swaps.
NxWallet holds parallel vectors of currencies and amounts: Ccy(), Amount(), size(), Amount(const std::string & ccy) (0 for a currency it does not hold), Add(...) and + - += -=. It never converts between currencies. Amount(ccy) is not a const member, so call it on a non-const wallet.
CalcPv adds the legs’ PVs as plain numbers. On a cross-currency swap that sum mixes currencies without any FX conversion; use Pv and convert the wallet yourself.
NxSwapLeg has no Pv(const IndexGlob &, ...) overload; for one leg against a curve set use CalcPv.
Par rate and par margin
double NxSwap::CalcFixRate(const IndexGlob &, const int & legIndex, const Date & pvDt, double targetPv = 0.0) const;
double NxSwapLeg::CalcFixRate(const IndexGlob &, double targetPv, const Date & pvDt) const;
double NxSwapLeg::CalcFixRate(const DiscountLoc *, const IndexLoc *, double targetPv, const Date & pvDt) const;
Note the different argument order between the swap and the leg.
NxSwap::CalcFixRate returns the fixed rate (or, on a floating leg, the margin) of leg legIndex that makes the swap’s PV equal targetPv, all other legs unchanged:
legTarget = (targetPv - sum over j != legIndex of coef_j * PV(leg_j)) / coef_legIndex
rate = (legTarget - PV(leg_legIndex at rate 0)) / annuity(leg_legIndex)
where the leg PV at rate 0 includes its floating coupons and principal flows, and the PVs and annuity are those of CalcPv and CalcSensi. For a "Z" leg the result is converted back to the annually compounded rate. With targetPv = 0 the result does not depend on pvDt. The other legs’ PVs are summed as plain numbers, so on a cross-currency swap solve on the leg instead, with NxSwapLeg::CalcFixRate and a target PV expressed in that leg’s currency (example below).
Annuity and PV01
double NxSwapLeg::CalcSensi(const IndexGlob &, const Date & dt) const;
double NxSwapLeg::CalcSensi(const DiscountLoc * discLoc, const Date & dt, const double inflaRate = -100.0) const;
CalcSensi returns the leg’s annuity: the change in the leg’s PV per unit change (1.0 = 100 %) of its own fixed rate, or of its margin on a floating leg,
annuity = sum over remaining periods i of DF(FlowDate(i)) / DF(dt) * Coverage(i) * Notional(i-1)
over the same periods CalcPv values: every period paying on or after the curve date, the running one with its full coverage. The coefficient is not applied and the result is positive for a positive notional. Divide by 10,000 for a PV01 per basis point, and multiply by swap.Coef(leg) for the swap’s sensitivity to that rate.
On a "Z" leg the annuity is per unit of the simple 30/360 rate. Pass the zero-coupon rate as inflaRate (with the DiscountLoc * overload) and the annuity is multiplied by d(simple)/d(ZC) at that rate, taken as a central difference with a 0.01 bp shift and scaled to 1 bp. Pass the leg’s FixRate() to get the sensitivity of the swap’s PV to its own quoted rate. Without inflaRate, no conversion is applied. See Inflation.
This is a sensitivity to the swap’s own rate, not to the curve. A curve DV01 is obtained by rebuilding the curves with bumped quotes and repricing; see Curves.
NxSwapPricer::CalcSensi is not implemented and returns 0; use the leg’s CalcSensi.
Cash-flow report
static NxSwapCancelRes NxSwapPricer::CalcCancellation(const NxSwap &, const IndexGlob &, const Date & cancelDt);
static NxSwapLegCancelRes NxSwapLegPricer::CalcCancellation(const NxSwapLeg &, const DiscountLoc *, const IndexLoc *, const Date & cancelDt);
The flow-by-flow table of what remains to be paid at cancelDt, valued at cancelDt. NxSwapCancelRes holds one NxSwapLegCancelRes per leg (legCancelRes), the swap’s currencies (resCcy) with the coefficient-weighted total in each (resCcyAmount), and cancelDate. Each leg table has one entry per flow in the vectors flowDates, notional, fixRate, floatRate, coverage, expInterest, expPrincipal, df and pv, with pv = (expInterest + expPrincipal) * df on every row, plus totPv (their sum), coef and pvDate.
The table uses the same flows and the same cut-off as Pv(..., cancelDt). fixRate shows the rate as quoted (for a "Z" leg, the compounded rate, not its simple equivalent), and is 0 on the initial-exchange row. A leading row with neither interest nor principal is omitted.
Pricers
Every leg and swap is created with a default pricer (NxSwapLegPricer, NxSwapPricer), which the methods above call. SetPricer accepts only a pricer of the matching type and throws on a null or foreign one. There is nothing to configure.
Seasoned swaps and the cut-off
A swap that started before the curve date is priced like any other:
- The coupon of the running period is paid in full at its end date. Its floating rate comes from the index’s history for the part before the curve date and from the curve for the rest (see below).
- Periods already paid are ignored. A flow paying exactly on the cut-off date is still included.
- The initial notional exchange is included only while the cut-off is on or before the start date.
The cut-off is where “already paid” ends:
CalcPv,CalcFixRateandCalcSensicut at the discount curve’s start date, whatever date they are given.PvandCalcCancellationcut at the date they are given.
The two agree whenever the pricing date is the curve date, which is how a swap is normally priced. If you pass a later date to both, they differ by exactly the flows paying between the curve date and that date: Pv treats them as paid, CalcPv still values them. Because the par rate and the annuity use the same flows as CalcPv, a seasoned swap struck at its CalcFixRate has a CalcPv of zero.
Past fixings
The fixings themselves are attached to the index data when the curves are built; see Curves.
- IBOR: a period starting before the curve date takes the published fixings dated on its start date. The rate is interpolated linearly in days between the two published tenors whose end dates bracket the period’s end date, and held flat below the shortest and beyond the longest tenor. Every tenor in the history must have a fixing on that date, otherwise pricing throws. A period starting exactly on the curve date uses the index’s current fixing from its data.
- OIS: for a period that started before the curve date, the published overnight fixings are compounded from the period’s start date to the curve date, each fixing accruing until the next fixing date in the index’s floating basis. The history must contain a fixing dated exactly on the period’s start date, otherwise pricing throws. If the last published fixing is earlier than the curve date, it accrues on up to the curve date. The rest of the period is projected from the curve and the two are compounded together.
- Inflation: the base CPI of a seasoned zero-coupon swap is read from the published CPI; see Inflation.
Examples
All examples assume market, a std::shared_ptr<NxIndexGlob> stripped on today, holding a "USD" currency with a "SOFR" OIS index as in Getting started, and, where used, a "EUR" currency with "ESTR" and a 6M EURIBOR index (see Curves).
Spot-starting OIS: par rate, PV, PV01
using namespace NitroX;
const Date today(30, 11, 2026);
// 5Y SOFR OIS from spot, receive 3.25% annual ACT/360 vs SOFR annual ACT/360, 10mm.
NxSwap ois("USD", today, "2USD", "", "5Y", "USD", 'm',
0.0325, 'A', "MM",
"SOFR", 'A', "MM",
false, 10e6);
const double par = ois.CalcFixRate(*market, 0, today); // fixed rate for PV = 0
NxWallet pv = ois.Pv(*market, today);
const double pvUsd = pv.Amount("USD");
const double annuity = ois.Leg(0)->CalcSensi(*market, today);
const double pv01 = ois.Coef(0) * annuity / 1e4; // PV change for +1 bp on the fixed rate
// Same number by bump and reprice: the PV is linear in the fixed rate.
std::shared_ptr<NxSwapLeg> fixedLeg = ois.Leg(0);
const double k = fixedLeg->FixRate();
fixedLeg->SetFixRate(k + 0.5e-6);
const double up = ois.Pv(*market, today).Amount("USD");
fixedLeg->SetFixRate(k - 0.5e-6);
const double down = ois.Pv(*market, today).Amount("USD");
fixedLeg->SetFixRate(k);
const double pv01Bumped = (up - down) * 100.0; // 0.01 bp shift, per 1 bp
pvUsd is approximately (0.0325 - par) * annuity.
Forward-starting and seasoned swaps
// 1Y into 5Y: start one year from today, then two business days.
NxSwap fwd("USD", today, "2USD", "1Y", "5Y", "USD", 'm',
0.0330, 'A', "MM", "SOFR", 'A', "MM", false, 10e6);
// Started 16 Jun 2025: needs the SOFR fixings from 16 Jun 2026 (the running
// period's start) up to today in the SOFR data.
NxSwap seasoned("USD", Date(16, 6, 2025), Date(16, 6, 2030), "USD", 'm',
0.0350, 'A', "MM", "SOFR", 'A', "MM", false, 25e6);
const double seasonedPar = seasoned.CalcFixRate(*market, 0, today);
NxWallet seasonedPv = seasoned.Pv(*market, today);
IBOR swap with an amortising notional
// 10Y EUR: annual 30/360 fixed vs EURIBOR 6M ACT/360, 50mm amortising linearly to zero.
NxSwap amort("EUR", today, "2EUR", "", "10Y", "EUR", 'm',
0.0250, 'A', "BB",
"EURIBOR", 'S', "MM", // resolves to "EURIBOR6"
false, 50e6);
std::vector<Date> steps = amort.Leg(0)->FlowDates(); // one step per fixed period
const int n = (int)steps.size();
std::vector<double> notionals(n);
for(int i = 0; i < n; ++i)
notionals[i] = 50e6 * double(n - 1 - i) / double(n - 1);
amort.Leg(0)->SetAccreting(steps, notionals);
amort.Leg(1)->SetAccreting(steps, notionals); // the float leg follows the same steps
const double amortPar = amort.CalcFixRate(*market, 0, today);
Floating leg with a margin
NxSwap withMargin("EUR", today, "2EUR", "", "5Y", "EUR", 'm',
0.0240, 'A', "BB", "EURIBOR", 'S', "MM", false, 10e6);
withMargin.Leg(1)->SetFixRate(0.0010); // pay EURIBOR 6M + 10 bp
const double parMargin = withMargin.CalcFixRate(*market, 1, today); // margin for PV = 0
Cross-currency swap with a margin
Different notionals per currency need hand-built legs:
const Date start(2, 12, 2026), end(2, 12, 2031);
auto eurLeg = std::make_shared<NxSwapLeg>(start, end, "EURUSD", 'm', 'Q', "MM", "EUR",
-0.0015, "ESTR", true, 10e6); // receive ESTR - 15 bp
auto usdLeg = std::make_shared<NxSwapLeg>(start, end, "EURUSD", 'm', 'Q', "MM", "USD",
0.0, "SOFR", true, 11.6e6); // pay SOFR flat
NxSwap xccy;
xccy.AddLeg(eurLeg, 1.0);
xccy.AddLeg(usdLeg, -1.0);
NxWallet w = xccy.Pv(*market, today);
const double eur = w.Amount("EUR"); // receive leg, EUR
const double usd = w.Amount("USD"); // pay leg, USD, coefficient -1 applied
// Par margin on the EUR leg: the EUR leg must be worth the USD leg in EUR.
const double eurPerUsd = 1.0 / 1.16; // your spot FX
const double usdLegPv = usdLeg->CalcPv(*market, today);
const double parXccyMargin = eurLeg->CalcFixRate(*market, usdLegPv * eurPerUsd, today);
Each leg is discounted on its own currency’s discount curve in the curve set. For a cross-currency swap that curve should be the currency’s cross-currency funding curve; see Curves.
Cash-flow report
NxSwapCancelRes report = NxSwapPricer::CalcCancellation(seasoned, *market, today);
for(size_t leg = 0; leg < report.legCancelRes.size(); ++leg)
{
const NxSwapLegCancelRes & t = report.legCancelRes[leg];
for(size_t k = 0; k < t.flowDates.size(); ++k)
{
// t.flowDates[k], t.notional[k], t.fixRate[k], t.floatRate[k], t.coverage[k],
// t.expInterest[k], t.expPrincipal[k], t.df[k], t.pv[k]
}
// t.totPv is the leg's PV; t.coef its coefficient in the swap
}
// report.resCcy[j], report.resCcyAmount[j]: the swap's PV per currency
Limits
- No payment lag, no fixing lag, and no lookback, lockout or observation shift on overnight legs.
- No FX conversion anywhere:
NxWalletkeeps currencies apart, andCalcPv/NxSwap::CalcFixRateon a cross-currency swap add amounts in different currencies as plain numbers. - No discounting adjustment beyond the curves in the curve set: a cross-currency leg is discounted on its currency’s discount curve as built.
- Sensitivities provided directly are to the swap’s own rate (
CalcSensi). Curve sensitivities come from rebuilding the curves with bumped quotes. - See Accuracy and known behaviours for how forwards differ from DF-ratio projection and other model choices.
From the library at v1.0.0 (ccaff0b). Edit this page on GitHub