Documentation
API reference
The public classes of the first release, grouped by layer, with their headers, constructors and key methods.
This reference covers the classes of the first release: curve stripping, swaps and inflation. It lists what you need to build curves and price swaps, with signatures copied from the headers; it is not a listing of every member. Everything is in namespace NitroX. Errors are reported by throwing NitroX::Error (NX_Error.h), a std::runtime_error whose what() is the message and, when known, [context] naming the curve, pillar or quote; see Errors.
Headers live in CommonSources/Api and, for a few utility classes, CommonSources/Implementation; linking the nitrox_core CMake target puts both on the include path.
Several classes also carry methods used to make scenario copies of a curve set and swap one shape for another (MakeCopy, MakeDuplicate, ChangeShape, RiskRecalibrate, RiskChangeShape, ChangeDiscountLoc). They are not covered here.
For the meaning of calendar, business-day, day-count and frequency codes see Conventions. The short version:
| Argument | Form | Examples |
|---|---|---|
calendar (holidayCurrencies, rollHolidays) | concatenated three-letter codes | "USD", "USDEUR" |
spot rule (bizzDayRule, bizzDaysRule) | business days and calendars | "2USD", "0D" |
roll rule (rollRule) | one character | 'f' following, 'm' modified following, 'p' preceding |
| basis | string | "MM" ACT/360, "A5" ACT/365F, "AA" ACT/ACT ISDA, "BB" 30/360, "Z" zero-coupon |
| frequency | one character | 'M', 'Q', 'S', 'A', 'Z' (one period) |
tenor (matCode, tenors) | string | "1W", "3M", "5Y", "ON", "TN", "SN" |
| rates and quotes | decimal | 0.0305 for 3.05 % |
Dates and schedules
Date
Header NX_Date.h. A calendar date, stored as day, month, year and Julian day number.
Date(); // 30 Dec 1899 (Excel serial 0)
Date(const int &dd, const int &mm, const int &yyyy);
| Method | Meaning |
|---|---|
int Day() const, int Month() const, int Year() const | Components. |
int WeekDay() const | 1 = Monday … 7 = Sunday. |
void AddDay(const int &nbDays=1), AddWeek, AddMonth, AddYear | Calendar arithmetic. Adding months clamps the day to the month end. |
void Set(const int &dd, const int &mm, const int &yyyy) | Reset the date. |
bool IsOpen(const std::string &ccyList) const | True if the date is a business day on every calendar in the list. |
void Modify(const std::string & rollHolidays, char rollRule) | Business-day adjustment in place. |
void ValueDate(std::string bizzDaysRule, int way=1) | Move forward (way = 1) by a spot rule such as "2USD". |
static Date Today() | System date. |
static double Coverage(const Date & startdt, const Date & enddt, const std::string & basis) | Year fraction in a day-count basis. |
static Date GetFwdDate(Date today, std::string fwdCode, const std::string & holidayCcy="", const std::string & bizzDaysRule="") | The date a tenor code after today. |
static Date GetFutureDate(std::string futCode) | Third Wednesday of the month of a futures code such as "H26". |
long operator-(const Date& that) const | Difference in calendar days. Comparison operators are defined. |
void SetFromExcel(const long &excelJulian), long ExcelJulian() const | Conversion from and to a spreadsheet serial date. |
Holidays
Header NX_Holidays.h (included by NX_Date.h). Rule-based holiday calendars.
| Method | Meaning |
|---|---|
bool IsHoliday(const std::string &ccyCode, const NitroX::Date &date) const | Holiday on one calendar. |
bool IsOpen(const std::string &ccyCode, const int& dd, const int& mm, const int& yyyy) const | Business day on one calendar. |
int ValidUntil(const std::string &ccyCode) const | Last year the calendar rests on published dates; 0 for a purely rule-based calendar, −1 for an unknown code. |
Unknown calendar codes are refused with an error, and the empty string means weekends only; see Accuracy and known behaviours.
Schedule
Header NX_Schedule.h. A coupon schedule: flow dates and the accrual fraction of each period. Base class of NxSwapLeg.
void Init(const Date & startDate, const Date & endDate, const std::string & rollHolidays, char rollRule,
char frequency, const std::string & basis, const bool firstLongPeriod = false, const bool eom = false);
void Init(const Date & startDate, const std::string & matCode, const std::string & rollHolidays, char rollRule,
char frequency, const std::string & basis);
void Init(const Date & tradeDate, std::string bizzDaysRule, const std::string & matCode,
const std::string & rollHolidays, char rollRule, char frequency, const std::string & basis);
void Init(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);
startDate,endDate: accrual start and maturity. Anniversaries roll back from the unadjusted maturity;eomapplies the end-of-month rule when the maturity is a month end.matCode: maturity as a tenor from the start.tradeDate,bizzDaysRule: the start is the trade date moved by the spot rule.today,startCode: the start istodaymoved by the tenorstartCodeand then by the spot rule; an emptystartCodegives a spot start.matCodemay also be"ON","TN"or"SN".
| Method | Meaning |
|---|---|
const std::vector<Date> & FlowDates() const | Flow dates; element 0 is the start date. |
const std::vector<double> & Coverage() const | Accrual fraction of each period; element i is the period ending on FlowDates()[i]. |
const Date & StartDate() const, const Date & EndDate() const | First and last flow date. |
const std::string & Basis() const | Day-count basis. |
Conventions
NxIndexParam
Header NX_Params_NxIndexParam.h. The static conventions of one index.
NxIndexParam(const std::string & ccy, const std::string & indexName, const std::string & holidayCurrencies,
const std::string & bizzDayRule, const char rollRule,
const std::string & floatBasis, long shortLimit,
const std::string & shortFixBasis, const char shortFixFreq, const char shortFloatFreq,
const std::string & longFixBasis, const char longFixFreq, const char longFloatFreq,
long floatFreqShortLimit=0);
ccy: currency code, the key under which curves for this index are filed.indexName: index name ("SOFR","EURIBOR").holidayCurrencies: calendar for rolling dates.bizzDayRule: spot rule ("2USD").rollRule: business-day convention.floatBasis: day count of the floating rate.shortLimit: maturity in days at or below which the short-end conventions apply.shortFixBasis,shortFixFreq,shortFloatFreq: fixed-leg basis and frequency and floating-leg frequency of quoted swaps up toshortLimit.longFixBasis,longFixFreq,longFloatFreq: the same beyondshortLimit.floatFreqShortLimit: if non-zero, a separate limit for the floating frequency.
| Method | Meaning |
|---|---|
const std::string & FixBasis(long matDays) const | Fixed basis for a swap of matDays days. |
char FixFreq(long matDays) const, char FloatFreq(long matDays) const | Fixed and floating frequency for that maturity. |
Ccy(), Name(), HolidayCurrencies(), BizzDayRule(), RollRule(), FloatBasis(), ShortLimit() | Accessors. |
Market data
All data classes derive from NxIndexData (header NX_Datas_NxIndexData.h), which holds the NxIndexParam and forwards its accessors (Ccy(), Name(), FixBasis(matDays), …).
NxIborData
Header NX_Datas_NxIborData.h. Quotes for one IBOR index.
NxIborData(std::shared_ptr<NitroX::NxIndexParam> param,
int fixingMat, char swapsFixFreq, double lastFixing,
const std::vector<std::string> & fraTenors, const std::vector<double> & fraQuotes,
const std::vector<std::string> & swapTenors, const std::vector<double> & swapQuotes,
std::shared_ptr<NitroX::NxIborPastFixings> pastFixings,
bool rejectZeroRates=true);
NxIborData(std::shared_ptr<NitroX::NxIndexParam> param,
int fixingMat, char swapsFixFreq, double lastFixing,
const std::vector<std::string> & fraTenors, const std::vector<double> & fraQuotes,
const std::vector<std::string> & swapTenors, const std::vector<double> & swapQuotes,
const std::vector<std::string> & spreadTenors, const std::vector<double> & spreadQuotes,
std::shared_ptr<NitroX::NxIborData> spreadIndex,
std::shared_ptr<NitroX::NxIborPastFixings> pastFixings,
bool rejectZeroRates=true);
fixingMat: fixing tenor in months (6 for a 6M index). The index is filed underName()= param name +fixingMat, for example"EURIBOR6".swapsFixFreq: fixed-leg frequency of the quoted swaps, used when the projection index calibrates.lastFixing: the latest fixing. The projection index uses it as its first calibration instrument and as the rate of a period starting on the curve date.fraTenors,fraQuotes: FRA codes ("3x9") or futures codes ("H26"), with their rates.swapTenors,swapQuotes: par swap rates.spreadTenors,spreadQuotes,spreadIndex: basis spreads of this index over another IBOR index (spreadIndex). For each swap tenor ofspreadIndexthat this data does not quote itself, a swap is added atspreadIndex’s quote plus the interpolated spread.pastFixings: fixing history, may be null.rejectZeroRates: drop quotes equal to 0 (see Accuracy).
Past fixings are built from NxIborXmPastFixings (one fixing tenor) and NxIborPastFixings (all tenors of an index):
void NxIborXmPastFixings::Set(double fixingMat, std::vector<NitroX::Date> & fixingDates,
const std::vector<double> & fixingRates);
void NxIborPastFixings::Set(std::string indexName, std::string holidayCurrencies, char rollRule,
std::vector<NxIborXmPastFixings> iborXmPastFixings);
fixingMat is in months (1 for 1M, 6 for 6M; 0.25 for 1W, 0.01 for overnight). fixingDates is taken by non-const reference.
NxOisData
Header NX_Datas_NxOisData.h. Quotes for one overnight index.
NxOisData(std::shared_ptr<NitroX::NxIndexParam> param, const double & overnightRate,
const std::vector<std::string> & tenors, const std::vector<double> & quotes,
const std::vector<std::string> & fraTenors, const std::vector<double> & fraQuotes,
const std::vector<Date> & customStartDates, const std::vector<Date> & customEndDates,
const std::vector<double> & customQuotes,
const std::vector<Date> & diracDates, const std::vector<double> & diracRates,
const std::string & diracBasis,
const std::vector<Date> & stepDates,
const std::vector<Date> & fixingDates, const std::vector<double> & fixingRates,
bool rejectZeroRates=true);
A second constructor takes const NxOisPastFixings & pastFixings in place of fixingDates and fixingRates.
overnightRate: today’s overnight rate, the curve’s first instrument.tenors,quotes: par OIS rates.fraTenors,fraQuotes: OIS FRA codes or futures codes, with their rates.customStartDates,customEndDates,customQuotes: periods with explicit dates, typically futures (seeNxSr3Future).diracDates,diracRates: one-night jumps (turn of year, month, quarter);diracBasisdoes not change the curve.stepDates: central-bank meeting effective dates; the overnight forward is piecewise flat between them.fixingDates,fixingRates: past overnight fixings, for periods that have already started.rejectZeroRates: drop quotes equal to 0.
NxSr3Future
Header NX_Datas_NxSr3Future.h. One 3M SOFR future.
NxSr3Future(const std::string & code, double price, double convexityBp);
code: month letter and year ("Z26").price: futures price, 100 − rate in percent; zero or less means not priced.convexityBp: futures rate minus forward rate, in bp, computed by you.
| Method | Meaning |
|---|---|
const Date & StartDate() const, const Date & EndDate() const | IMM date of the contract month and three months later. |
bool IsPriced() const | Price is positive. |
double FuturesRate() const | (100 − price) / 100. |
double Forward() const | Futures rate less convexity: the quote to give the curve. |
NxInflationData
Header NX_Datas_NxInflationData.h. Quotes and published values for one CPI index.
NxInflationData(std::shared_ptr<NitroX::NxIndexParam> param,
const std::vector<std::string> &swapTenors, const std::vector<double> &swapQuotes,
const std::vector<Date> &pubDates, const std::vector<double> &pubValues,
char periodicity, int lag, bool indexInterp);
swapTenors,swapQuotes: zero-coupon inflation swap rates.pubDates,pubValues: published CPI values. At least one is required.periodicity: coupon frequency of the calibration swaps,'Z'for zero-coupon.lag: observation lag in months.indexInterp: interpolate the CPI by day of month (see Accuracy).
Curve interfaces
These abstract classes are what pricers and containers take.
| Class | Header | Key members |
|---|---|---|
ZcCurve | NX_DiscountLoc_ZcCurve.h | const Date& StartDate() const; virtual double DiscountFactor(const Date & date) const; virtual double DiscountFactor(const Date & toDate, const Date & fromDate) const, the value at toDate of 1 paid at fromDate, that is DF(fromDate) / DF(toDate). |
NxShape : ZcCurve | NX_DiscountLoc_NxShape.h | ZcRate(const Date & date), ZcRate(const Date & startDate, const Date & endDate) (continuous, ACT/365.25); Ccy(), HolidayCurrencies(), BizzDayRule(), RollRule(), DataName(). |
DiscountLoc : ZcCurve | NX_DiscountLoc_Abstract.h | const std::string & Ccy() const; std::shared_ptr<NxShape> GetShape(). |
IndexLoc : DiscountLoc | NX_IndexLoc_Abstract.h | const std::string & IndexName() const; double IndexRate(const Date & fromDate, const Date & toDate, const std::string & basis) const, the index’s rate over a period as a simple rate in basis; double GetPastFixing(const Date & fixingDate) const; const std::shared_ptr<DiscountLoc> GetFundingPtr() const. DiscountFactor on an index discounts on its funding curve. |
Shapes
NxIborShape
Header NX_DiscountLoc_NxIborShape.h. Single-curve bootstrap of an IBOR index.
NxIborShape(const Date & startDate,
const std::shared_ptr<NitroX::NxIborData> nxIborData,
const std::vector<std::string> & cashTenors, const std::vector<double> & cashQuotes,
const std::vector<Date> & diracDates, const std::vector<double> & diracRates,
const std::string & diracBasis,
char interp = 'l');
startDate: curve date (today).nxIborData: FRAs, futures and swaps.cashTenors,cashQuotes: deposits;"1D"starts today, others at spot. List them in increasing maturity.diracDates,diracRates,diracBasis: turn jumps.interp:'l'linear in zero rate (the default),'t'linear in rate × time (flat forward),'s'√t-weighted,'f'step,'m'Hagan-West monotone convex.
Implements NxShape. Also const Date& LastTenorMat() const, the last pillar date.
NxOisShape
Header NX_DiscountLoc_NxOisShape.h. Single-curve bootstrap of an overnight index.
NxOisShape(const Date & startDate, const std::shared_ptr<NitroX::NxOisData> nxOisData, char interp = 'l');
NxOisShape(const Date & startDate, const std::shared_ptr<NitroX::NxOisData> nxOisData,
const std::shared_ptr<NitroX::NxIborData> nxIborData, char interp = 'l');
nxIborData: optional IBOR data used to extend the curve beyond the last OIS quote, keeping the IBOR−OIS forward spread measured at the end of the OIS quotes.interp: as forNxIborShape.
Implements NxShape. Also const Date& LastTenorMat() const.
Funding curves
NxDiscountLoc
Header NX_DiscountLoc_NxDiscountLoc.h. A discount curve: a shape plus a calibrated zero spread, DF(t) = exp(−(shapeZc(t) + spread(t)) · t).
Flat to the shape, or with funding margins:
NxDiscountLoc(std::shared_ptr<NitroX::NxShape> shape,
const std::vector<std::string> & fundTenors, const std::vector<double> & fundQuotes,
char fundFreq, const std::string & fundBasis);
fundTenors,fundQuotes: margins over the shape. For each tenor, the coupon of a par bond from spot (from today for"1D") is the shape’s par coupon plus the margin; one spread pillar per tenor. Empty vectors give a curve equal to the shape.fundFreq,fundBasis: coupon frequency and basis of those bonds.
Cross-currency, calibrated to basis swaps against another currency:
NxDiscountLoc(std::shared_ptr<NitroX::NxShape> discShape,
std::shared_ptr<NitroX::NxShape> xCcyIndexShape,
const std::vector<std::string> & xCcyTenors, const std::vector<double> & xCcyQuotes,
char xCcyFreq, const std::string xCcyBasis,
std::shared_ptr<NitroX::IndexLoc> fundRefXccyIndex,
const std::vector<std::string> & fundRefXccyTenors, const std::vector<double> & fundRefXccyQuotes,
char fundRefXccyFreq, const std::string & fundRefXccyBasis,
const std::string & bizzDaysRule, char rollRule, const std::string & rollHolidays);
discShape: the shape of this currency the spread is added to.xCcyIndexShape: the shape of the index paid on this currency’s leg.xCcyTenors,xCcyQuotes: cross-currency basis spreads on this currency’s leg.xCcyFreq,xCcyBasis: coupon frequency and basis of both legs of the basis swaps.fundRefXccyIndex: the floating index of the other (reference) currency, carrying its own funding curve.fundRefXccyTenors,fundRefXccyQuotes: margins on the reference-currency leg, interpolated to each basis-swap maturity;fundRefXccyFreqandfundRefXccyBasisare used to place them.bizzDaysRule,rollRule,rollHolidays: spot rule and date rolling of the basis swaps.
For each tenor the spread is solved so that this currency’s leg, with notional exchange, is worth the reference-currency leg (index plus margin, with notional exchange) per unit of notional. See Curves.
| Method | Meaning |
|---|---|
const std::string & Ccy() const | The shape’s currency. |
double DiscountFactor(const Date & date) const and the two-date form | Discount factors. |
std::shared_ptr<NxShape> GetShape() | The underlying shape. |
A one-argument constructor NxDiscountLoc(std::shared_ptr<NxShape> shape) also exists; it is not exercised by the tests, so use the margins constructor with empty vectors instead.
Projection indexes
NxIborIndex
Header NX_IndexLoc_NxIborIndex.h.
NxIborIndex(std::shared_ptr<NitroX::DiscountLoc> funding,
std::shared_ptr<NitroX::NxShape> shape,
std::shared_ptr<NitroX::NxIborData> data);
funding: discount curve for the calibration swaps.shape: the shape forwards are built on, usually theNxIborShapeof the same data.data: the quotes to calibrate to: the last fixing, FRAs and futures, swaps (and basis spreads).
Calibrates a forward spread over the shape, one pillar at each instrument’s last fixing date. IndexName() is the data’s Name() ("EURIBOR6"). IndexRate(from, to, basis) reads the fixing history for a period starting before the curve date, returns lastFixing for a period starting on the curve date, and otherwise the shape forward plus spread; the rate is rescaled from the index basis to basis. GetPastFixing(fixingDate) reads the fixing history.
NxOisIndex
Header NX_IndexLoc_NxOisIndex.h.
NxOisIndex(std::shared_ptr<NitroX::DiscountLoc> funding,
std::shared_ptr<NitroX::NxShape> shape,
std::shared_ptr<NitroX::NxOisData> data);
Calibrates a zero spread over the shape, one pillar per instrument maturity (overnight, OIS, OIS FRAs, custom periods). IndexName() is the param’s index name ("SOFR"). IndexRate(from, to, basis) compounds past overnight fixings for the part of a period before the curve date.
NxInflationIndex
Header NX_IndexLoc_NxInflationIndex.h.
NxInflationIndex(std::shared_ptr<NitroX::DiscountLoc> funding,
std::shared_ptr<NitroX::NxInflationData> data,
const std::vector<double> &seasonCoefs);
static std::vector<double> CalcSeasonalityCoefs(std::vector<Date> &cpiDates, std::vector<double> &cpiValues);
funding: discount curve for the calibration swaps.data: zero-coupon swap quotes and published CPI.seasonCoefs: twelve additive monthly coefficients in index points, January first. Not checked for size.CalcSeasonalityCoefs: estimates the twelve coefficients from a monthly CPI history (at least 28 observations, otherwise all zero). See Accuracy for the method.
IndexRate(from, to, basis) returns the inflation rate implied by the CPI ratio over the period, in basis ("Z" is read as 30/360). GetShape() throws: an inflation index has no shape. See Inflation.
Containers
NxCcyIndexes
Header NX_CcyIndexes_NxCcyIndexes.h. One currency: one funding curve and its indexes.
NxCcyIndexes();
void SetDiscountLoc(std::shared_ptr<DiscountLoc>);
void AddIndexLoc(std::shared_ptr<IndexLoc>);
AddIndexLoc throws if the index was calibrated on a different funding curve from the one already set (if none is set, the index’s funding curve is taken). An index with the same IndexName() as one already present replaces it.
| Method | Meaning |
|---|---|
std::shared_ptr<DiscountLoc> GetDiscountLoc() const | The funding curve. |
std::shared_ptr<IndexLoc> GetIndexLoc(const std::string & indexName) const | An index by name. |
double IndexRate(const Date & fromDate, const Date & toDate, const std::string & indexName, const std::string & basis) const | An index rate by name. |
int NbIndexLoc() const, std::string IndexName(int i) const | Enumerate the indexes. |
const std::string & Ccy() const, DiscountFactor(...) | Currency and discount factors of the funding curve. |
NxIndexGlob
Header NX_IndexGlob_NxIndexGlob.h. All currencies; the object pricers receive (as const IndexGlob &).
NxIndexGlob();
void AddCcyIndexes(std::shared_ptr<CcyIndexes>);
A second NxCcyIndexes for a currency already present replaces the first.
| Method | Meaning |
|---|---|
std::shared_ptr<NitroX::CcyIndexes> GetCcyIndexes(const std::string & ccy) const | One currency. |
std::shared_ptr<DiscountLoc> GetDiscountLoc(const std::string & ccy) const | Its funding curve. |
std::shared_ptr<IndexLoc> GetIndexLoc(const std::string & ccy, const std::string & indexName) const | An index. |
double DiscountFactor(const Date & date, const std::string & ccy) const | Discount factor from the curve date. |
double DiscountFactor(const Date & toDate, const Date & fromDate, const std::string & ccy) const | Discount factor between two dates. |
double IndexRate(const Date & fromDate, const Date & toDate, const std::string & ccy, const std::string & indexName, const std::string & basis) const | An index rate. |
double GetPastFixing(const Date & fixingDate, const std::string & ccy, const std::string & indexName) const | A past fixing. |
Lookups throw if the currency or index is not present.
NxDiscountGlob (header NX_DiscountGlob_NxDiscountGlob.h) is a lighter container of funding curves only, with AddDiscountLoc, GetDiscountLoc and DiscountFactor by currency.
Interpolation
NxMonotoneConvex
Header NX_ZcCurve_NxHaganWest.h (header-only). Hagan-West monotone-convex interpolation on continuously compounded zero rates.
enum CollarMode { SignAwareCollar = 0, NoCollar = 1 };
bool FiEstimates(const std::vector<double> &termsArg, const std::vector<double> &valuesArg,
bool inputsAreForwards = false, CollarMode collarMode = SignAwareCollar);
double Interpolant(double term) const;
double Forward(double term) const;
FiEstimates: fit to terms in years and zero rates (or discrete forwards ifinputsAreForwards).SignAwareCollarbounds node forwards as in the paper while allowing negative rates;NoCollarleaves them unbounded, for spread curves that cross zero.Interpolant(term): the zero rate atterm; beyond the last term, flat instantaneous forward.Forward(term): the instantaneous forward. Only meaningful up to the last term.
Give at least two terms.
NxZcCurve
Header NX_DiscountLoc_NxZcCurve.h. A zero curve on dates, used inside the shapes; usable on its own.
void Init(const Date& startDate, char lowInterp, char midInterp, char highInterp);
void InitHaganWest(const Date& startDate,
NxMonotoneConvex::CollarMode collarMode = NxMonotoneConvex::SignAwareCollar);
void SetZeroRates(const Date& startDate, const std::vector<Date> & zcDates, const std::vector<double> & zcRates);
void SetZeroRate(const Date& zcDate, double zcRate);
double ZcRate(const Date & date) const;
double DiscountFactor(const Date & date) const;
Init selects the interpolation before the first pillar, between pillars and after the last, each one of 'l', 't', 's', 'f' as listed for the shapes; InitHaganWest selects Hagan-West. Rates are continuous, ACT/365.25.
Swaps
NxSwapLeg
Header NX_SwapLeg_NxSwapLeg.h. One leg: a Schedule with a currency, a fixed rate or spread, an optional index and a notional per period.
NxSwapLeg(const Date & startDate, const Date & endDate, const std::string & rollHolidays, char rollRule,
char frequency, const std::string & basis, const std::string & ccy,
double fixRate=0.0, std::string floatRate="", bool notionalExchange=false, double notional=1.0);
NxSwapLeg(const Date & startDate, const std::string & matCode, /* same arguments from rollHolidays on */);
NxSwapLeg(const Date & tradeDate, std::string bizzDaysRule, const std::string & matCode, /* … */);
NxSwapLeg(const Date & today, std::string bizzDaysRule, const std::string & startCode,
const std::string & matCode, /* … */);
Each constructor has a matching Init with the same arguments. The first arguments build the schedule as in Schedule::Init. Then:
ccy: payment currency.fixRate: the fixed rate of a fixed leg, or the spread over the index of a floating leg.floatRate: the index name; empty for a fixed leg.notionalExchange: exchange notional at start and maturity (and amortisation flows).notional: notional of every period.
| Method | Meaning |
|---|---|
double CalcPv(const IndexGlob &, const Date & dt) const | PV discounted to dt, of the flows paying on or after the curve date. |
double CalcFixRate(const IndexGlob &, double targetPv, const Date & pvDt) const | The fixed rate or spread giving the leg a PV of targetPv. |
double CalcSensi(const IndexGlob &, const Date & dt) const | Annuity: Σ DF × coverage × notional over the remaining periods, discounted to dt. Divide by 10,000 for PV01 per bp. |
double CalcSensi(const DiscountLoc * discLoc, const Date & dt, const double inflaRate = -100.0) const | The same on a given curve. For a "Z" leg, passing the leg’s zero-coupon rate as inflaRate gives the annuity per unit of the zero-coupon rate. |
NxWallet Pv(const DiscountLoc * discLoc, const IndexLoc * indexLoc, const Date & pvDt) const | PV of the flows paying on or after pvDt, as a wallet. |
std::vector<NxLegFlow> Flows(const Date & cutOff, const IndexLoc * indexLoc, double couponRate) const | The flows still to be paid at cutOff: date, period, notional, coverage, float rate, interest, principal. |
std::shared_ptr<IndexLoc> ResolveIndexLoc(const IndexGlob & indexGlob) const | The leg’s index: by name, else by name + fixing tenor of the leg’s frequency. Null for a fixed leg. |
const std::vector<double> & SetAccreting(const double & accretingRate) | Notional grows by (1 + coverage × rate) each period. |
void SetAccreting(const std::vector<Date> & sourceFlowDates, const std::vector<double> & sourceNotionals) | Step notionals from a schedule (amortising or accreting). |
void SetFixRate(double fixRate) | Change the fixed rate or spread. |
int NbFlowDates(), FlowDate(i), Coverage(i), Notional(i) | Schedule access. Period i runs from FlowDate(i−1) to FlowDate(i) and accrues on Notional(i−1). |
Ccy(), Frequency(), Basis(), FixRate(), IndexName(), StartDate(), EndDate(), NotionalExchange() | Accessors. |
NxSwap
Header NX_Swap_NxSwap.h. A list of legs with coefficients; PV = Σ coefficient × leg PV.
Single currency (fixed leg 0 with coefficient +1, floating leg 1 with −1, so a positive notional receives fixed):
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);
Two other single-currency forms take (ccy, startDate, endDate, …) and (ccy, startDate, matCode, …) in place of (ccy, today, bizzDaysRule, startCode, matCode, …).
Two currencies (receive leg 0 with +1, pay leg 1 with −1):
NxSwap(const Date & today, std::string bizzDaysRule, const std::string & startCode, const std::string & matCode,
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=false, double notional=1.0);
with (startDate, endDate, …) and (startDate, matCode, …) forms as well. Both legs take the same notional. Each constructor has a matching Init. For any other structure, default-construct and add legs:
NxSwap();
void AddLeg(std::shared_ptr<NxSwapLeg> leg, double coef);
| Method | Meaning |
|---|---|
double CalcPv(const IndexGlob &, const Date & dt) const | Σ coefficient × leg CalcPv, as one number (currencies are added without conversion). |
NxWallet Pv(const IndexGlob &, const Date & pvDt) const | PV per currency. |
double CalcFixRate(const IndexGlob &, const int & legIndex, const Date & pvDt, double targetPv =0.0) const | The rate or spread on leg legIndex that sets the swap’s PV to targetPv: the par rate of the fixed leg, or the par spread of a floating leg. |
void SetAccreting(const double & accretingRate, const int & leg=0) | Accrete one leg and map its notionals onto the others. |
double GetNotional(const Date & dt, int leg=0) const | Notional of the period running on dt (see Swaps). |
int NbLegs() const, const std::shared_ptr<NxSwapLeg> Leg(const int & i) const, const double & Coef(const int & i) const | Leg access. |
Frequency(leg), Basis(leg), IndexName(leg), StartDate(leg), EndDate(leg) | Per-leg accessors. |
Pricers
NxSwapLeg and NxSwap are created with their default pricers, NxSwapLegPricer and NxSwapPricer; you normally call the instrument methods above. SetPricer(std::shared_ptr<InstrumentPricer>) refuses a pricer of another type.
The pricers also produce flow-by-flow cancellation tables:
static NxSwapCancelRes NxSwapPricer::CalcCancellation(const NxSwap &, const IndexGlob &, const Date & cancelDt);
static NxSwapLegCancelRes NxSwapLegPricer::CalcCancellation(const NxSwapLeg & swapLeg, const DiscountLoc * discLoc,
const IndexLoc * indexLoc, const Date & cancelDt);
NxSwapLegCancelRes holds, per remaining flow, flowDates, notional, fixRate, floatRate, coverage, expInterest, expPrincipal, df and pv, plus totPv, coef and pvDate. NxSwapCancelRes holds one NxSwapLegCancelRes per leg in legCancelRes, the total by currency in resCcy and resCcyAmount, and cancelDate.
NxWallet
Header NX_NxWallet.h. Amounts by currency.
| Method | Meaning |
|---|---|
int size() const | Number of currencies. |
const std::vector<std::string> & Ccy() const, const std::vector<double> & Amount() const | Currencies and amounts, in parallel. |
double Amount(const std::string & ccy) | Amount in one currency, 0 if absent. |
void Add(std::string ccy, double amount, double coef = 1.0) | Add coef × amount. |
operator+, operator-, +=, -= | Combine wallets currency by currency. |
No method converts between currencies.
Errors
NX_Error.h. Every failure in the library throws NitroX::Error, derived from std::runtime_error.
| Member | What it does |
|---|---|
explicit Error(const std::string & message) | A failure with no context; what() is message. |
Error(const std::string & message, const std::string & context) | A failure about context; what() is message [context]. |
const std::string & Message() const | The message without the context. |
const std::string & Context() const | What the failure was about, empty if not known. |
Error WithContext(const std::string & context) const | The same error with context appended, for a caller that knows more than the thrower. |
A solver that does not converge names the curve, the pillar date and the quote, for example Error : NxOisIndex could not calibrate. [USD-SOFR pillar 2031-03-17, quote 3.4500%].
A custom IndexGlob must throw NitroX::Error from GetIndexLoc when it does not hold the index: a swap leg retries with the tenor-suffixed name (EURIBOR → EURIBOR6) only on that type.
From the library at v1.0.0 (ccaff0b). Edit this page on GitHub