Documentation

Accuracy and known behaviours

How the library's correctness is checked, how to run the tests, and the behaviours you need to know before relying on a number.

The test suite

The tests are plain C++ programs under tests/, one per file test_*.cpp, with a small assertion header and no external framework. Each program groups its checks into sections, prints a line per failure and a summary, and exits non-zero if any check failed or any section threw. CMake builds every test_*.cpp it finds and registers it with CTest under the file name.

Run them after building (see Getting started):

ctest --test-dir build --output-on-failure          # everything
ctest --test-dir build -R bootstrap --verbose       # the bootstrap programs, with their output

Every change is built and tested in continuous integration with clang and gcc on Linux and MSVC on Windows, with warnings treated as errors, plus a Linux build under AddressSanitizer and UndefinedBehaviorSanitizer in which any sanitizer report fails the run. To reproduce the sanitizer build locally:

cmake -S . -B build-asan -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DNITROX_SANITIZE=address,undefined
cmake --build build-asan && ctest --test-dir build-asan --output-on-failure

What the tests cover

AreaTest programsWhat is checked
Curve bootstrap, IBORtest_bootstrapEvery input swap reprices off the finished curve, for EUR and USD conventions, on an ordinary, a negative-to-positive and a steep curve, with linear and Hagan-West interpolation. Duplicate pillars and an empty quote set are refused. A cash or swap quote overlapping a FRA is dropped as documented below.
Curve bootstrap, OIStest_bootstrap_oisEvery input OIS reprices on a SOFR-like curve with a year-end turn, with and without eight central-bank step dates, linear and Hagan-West. With steps, the overnight forward stays flat between two meeting dates. A one-swap curve. Duplicate tenors are refused.
Overlapping quotestest_pillar_rulesThe four rules for quotes landing on the same or nearby dates, in IBOR shapes, OIS shapes, OIS indexes and inflation indexes.
Hagan-Westtest_haganwestFlat curves at +3 %, +1 bp and negative levels are reproduced exactly (to 1e-12), zero and forward; pillars are honoured whatever their sign; the collar bounds node forwards as the paper requires; the no-collar mode used for deviation curves.
Past fixings and edge casestest_edge_inputs, test_fracodes, test_sr3_futureOIS long end extended from an IBOR curve when the OIS set ends inside the IBOR fixing period; every IBOR past fixing kept; OIS accrual between the last fixing and today; FRA and futures codes parsed or refused; SR3 futures dates (IMM to IMM) and forward.
Dates and calendarstest_holidays, test_daycounts, test_schedule, test_date_weekdayHoliday rules per calendar, Act/Act ISDA and 30/360 day counts, schedules rolled from the unadjusted maturity, end-of-month rule, first-period handling, weekday after date arithmetic.
Swap legstest_swapleg, test_pvpaths, test_swap_accreting_pricerPrincipal exchanges are discounted; the different PV entry points agree on fixed, floating, seasoned, amortising and forward-starting legs, including at negative rates; the annuity covers the running period of a seasoned leg; cancellation tables add up row by row; accreting and amortising notionals keep the final redemption.
Swaps and curves end to endtest_xll_swaps, test_xll_curves, test_xll_ois, test_xll_zcisThe same objects driven through the portable spreadsheet-function layer (no spreadsheet needed): the par rate of a swap on a curve stripped from flat 3 % swaps is 3 % to 1e-12; annuity and PV01 agree up to scale; OIS data with futures, turns and steps; zero-coupon inflation swaps (below).

Other programs in tests/ cover components that are not part of this release.

Every input instrument reprices

The central check is that a curve, once built, gives back the quotes it was built from.

How the bootstrap solves. Instruments are sorted by end date and solved one pillar at a time: a secant iteration on the pillar value until the instrument’s par rate is within 1e-9 of its quote (0.00001 bp), at most 30 iterations per pillar (100 for the OIS deviation curve). A pillar whose solve does not converge throws a NitroX::Error naming the curve, the pillar date and the quote (“Error : NxIborShape could not calibrate. [EUR-EURIBOR pillar 2031-03-17, quote 2.4500%]”, and so on). With Hagan-West interpolation, adding a pillar moves the curve between earlier pillars, so after the first pass the bootstrap sweeps the instruments again, re-solving any that are off their quote by more than 1e-9, until a sweep has nothing left to do. Two or three sweeps are typical. The sweeps stop after 50 without an error, returning the curve as it stands. With the local interpolations (linear, flat forward, step) the first pass is already exact and the sweep changes nothing.

What the tests measure. The IBOR and OIS bootstrap tests rebuild each calibration instrument and ask the finished curve for its par rate. The tolerance is 0.001 bp for both interpolations; the measured residuals are at the solver’s accuracy, about 1e-5 bp. Projection indexes and the inflation index solve their spreads or CPI levels to the same 1e-9, one pillar per instrument: a swap at a quoted tenor, built with the index’s own conventions, prices at its quote. The inflation tests check that zero-coupon swaps from 1Y to 30Y price at their quotes to 1e-10 and are worth zero at that rate.

Checking your own curve. Price each quoted instrument off the finished market and compare. For the SOFR curve of the Getting started example:

for(size_t i = 0; i < tenors.size(); ++i)
{
    NxSwap s("USD", today, "2USD", "", tenors[i], "USD", 'm',
             0.0, 'A', "MM", "SOFR", 'A', "MM");
    const double residualBp = 1e4 * (s.CalcFixRate(*market, 0, s.StartDate(0)) - quotes[i]);
    std::printf("%-4s %+.6f bp\n", tenors[i].c_str(), residualBp);
}

The swap must use the conventions the index was calibrated with (here: spot start, annual ACT/360 both legs). A residual well away from zero on one tenor usually means that quote was dropped by one of the rules below, or was zero with rejectZeroRates on.

Known behaviours

These are how the library behaves today. Each is either a modelling choice or a limitation you should design around.

Quotes and instruments

  • Zero quotes are dropped when rejectZeroRates is true, and true is the default. The NxIborData and NxOisData constructors take bool rejectZeroRates = true. With it on, a quote equal to exactly 0 is treated as a blank and skipped, for IBOR FRA and swap quotes and for OIS swap, FRA and custom-period quotes. In any market where a rate can print at 0.00 %, pass false. Entries with an empty tenor string are always skipped.

  • Futures are taken without convexity adjustment. A futures code (month letter and year, such as "H26") can be given in the FRA list of an IBOR or OIS data object. It is treated as a FRA starting on the third Wednesday of the contract month, over the index’s fixing tenor in an IBOR curve and over three months in an OIS curve, and its quote is used directly as that period’s forward rate, in decimal. Nothing converts a price or removes convexity. Pass convexity-adjusted forward rates. For SOFR futures, NxSr3Future turns a price and a convexity adjustment that you supply (in bp) into the forward over the IMM quarter; give its StartDate(), EndDate() and Forward() to NxOisData as a custom period, and skip contracts where IsPriced() is false.

  • FRA codes have no spot lag. A FRA "AxB" starts A months after the curve’s start date (the trade date, not spot) and runs for B − A months.

  • Cash deposit order matters when FRAs or futures are present. Deposits are read in the order given, and reading stops after the first deposit whose maturity reaches the start of the first FRA or future; later deposits in the list are ignored. List deposits in increasing maturity. A "1D" deposit starts today, the others at spot. If no "1D" is given, one is added at the rate of the shortest deposit or FRA, if there is one.

  • One pillar per date. Every bootstrap places one value per pillar date, and overlapping quotes are resolved by fixed rules:

    1. Two quotes of the same kind on the same pillar date (two 5Y swaps, "1Y" and "12M", two futures, two inflation tenors maturing in the same CPI month) are refused with an error naming both quotes.
    2. A FRA or future within 14 calendar days of a cash or swap pillar wins: the cash or swap quote is dropped. In an OIS curve, custom-dated periods count as futures.
    3. Cash and a swap on the same date: the swap wins.
    4. OIS curves only: a cash or swap quote maturing inside the futures strip (from the first future’s start to 14 days after the last one’s end, gaps included) is dropped. Quotes maturing before the strip or after it are kept.

    The anchor of a curve (the overnight rate, an IBOR shape’s "1D" deposit, the IBOR fixing) is never dropped. Dropped quotes are dropped silently: a quote that does not reprice is the sign.

  • A single distant pillar may not calibrate. An IBOR curve with nothing but its fixing and one swap at 5Y or beyond can fail with “could not calibrate”. Give at least one instrument at the short end.

Turns and central-bank steps

  • Turn jumps (the Dirac dates and rates of the data objects) multiply every discount factor from the given date onward by exp(−rate / 365.25): one night at the given rate, continuously compounded on ACT/365.25. The jump applies to the night before the date given. The basis argument passed with the jumps does not change the curve. Jumps dated before the curve’s start date still apply.
  • Central-bank steps on an OIS curve are split out after the instruments are fitted, by a fixed 30-pass iteration, after which the instruments are swept again so that they still reprice. Between two step dates the overnight forward is exactly flat with linear interpolation; with Hagan-West it keeps a small slope (measured at 0.016 bp, tested below 0.05 bp). Where the curve’s other pillars are not step dates, the slope inside a step period can be larger: on a SOFR curve with an overnight rate, a 1W swap and quarterly SR3 futures, the forward drifts by up to about 0.3 bp across a meeting period in the futures window (measured −0.28 bp, +0.34 bp and +0.17 bp in three periods, under 0.05 bp in the others). It comes from the Hagan-West pillar curve between the 1W end and the futures’ IMM dates, which do not coincide with meeting dates. Every input still reprices exactly.

Forwards, discounting and interpolation

  • Forwards. An OIS index forward is the ratio of the index’s discount factors (shape plus calibrated spread) over the period, as a simple rate in the index basis; with no funding margin it equals the shape’s forward day by day. An IBOR index forward is the shape’s continuously compounded zero forward plus the calibrated forward spread, read as a simple rate in the index basis: exact at the calibration instruments, and different from discount-factor-ratio projection between them. See Concepts.
  • Zero rates are continuously compounded on ACT/365.25 from the curve’s start date.
  • Hagan-West follows Hagan and West (2006) with a sign-aware collar, so negative rates are supported. The optional “amelioration” step of the paper is not implemented. Beyond the last pillar the curve extrapolates at a flat instantaneous forward. Beyond the last pillar NxMonotoneConvex::Forward(t) is flat at the last node’s forward, and a one-pillar curve is flat.

Calendars

  • Supported calendar codes are USD, EUR (TARGET2), GBP, JPY, MXN, AED and SAR; several can be combined by concatenation ("USDEUR"). An unrecognised code is an error, as is a string whose length is not a multiple of three (a separator, a stray letter). The empty string means weekends only: Saturday and Sunday closed, no holidays. Holidays::ValidUntil returns −1 for an unknown code.
  • AED and SAR Islamic holidays come from published dates up to the year returned by ValidUntil; beyond it they are computed from the tabular Islamic calendar, which can fall up to two days late.
  • GBP does not include one-off holidays (royal events, moved bank holidays).
  • In AED, only the two Eids come from published dates; the Islamic New Year and the Prophet’s Birthday always use the tabular calendar, so they can be up to two days late in any year.
  • The rule-based calendars (USD, EUR, GBP, JPY, MXN) follow the holiday rules as legislated when they were written (December 2026). A holiday added or moved by later legislation is not included until the rules are updated.

Portfolio risk

  • CalcShapeRisk measures one currency: only the PV in the shape’s currency counts, and no FX risk is computed. See Portfolio and risk.
  • NxRiskResult::gamma comes from 0.01 bp bumps, below the solver’s noise; do not rely on it.

Details are in Conventions.

Swaps

  • No payment lag. Each flow is paid on its accrual end date.
  • CalcPv adds currencies together. NxSwap::CalcPv returns the sum of the legs as one number with no FX conversion; for a cross-currency swap use NxSwap::Pv, which returns an NxWallet with one amount per currency. Nothing in the library converts between currencies.
  • Two-currency constructors use one notional for both legs. To give each currency its own notional, build the two NxSwapLeg objects yourself and add them with NxSwap::AddLeg(leg, coef).
  • Cut-off date. CalcPv, CalcFixRate and CalcSensi value the flows paying on or after the discount curve’s start date and discount them to the date you pass; Pv and the cancellation tables value the flows paying on or after the date you pass. Both agree when you price on the curve date. A period that has started is included at its full coverage, its rate taken from past fixings.
  • Discount curve. NxSwap::Pv discounts a floating leg on its index’s funding curve and a fixed leg on the currency’s discount curve; the other methods use the currency’s discount curve for both. With one funding curve per currency these are the same curve.
  • Zero-coupon legs (basis "Z"): the fixed rate is compounded annually on 30/360, the leg paying N × ((1 + r)^t − 1). Par rates come back in the same convention. Cancellation tables show the rate as quoted, with cash flows computed from its simple equivalent.

Inflation

  • CPI. The index value for a date is read from the deseasonalised CPI curve on the first day of the month lag months before the date, plus the seasonal coefficient of that calendar month. Seasonality is additive, in index points. The deseasonalised curve is linear between its points and extrapolates linearly.
  • Published CPI values are placed on the dates you give. Since the curve is read on the first day of each month, a value dated on any other day is interpolated rather than taken as that month’s print. At least one published value is required.
  • Interpolated mode (indexInterp = true) interpolates linearly by day of month between the months lag + 1 and lag before the date: CPI(d) = CPI(m − L − 1) + (day − 1) / (daysInMonth − 1) × (CPI(m − L) − CPI(m − L − 1)). This is not the usual market reference-CPI formula, CPI(m − L) + (day − 1) / daysInMonth × (CPI(m − L + 1) − CPI(m − L)): for the same lag the two use different months and different day weights. Check the lag you pass against the months your contract references.
  • Calibration. One CPI pillar per zero-coupon swap, on the first day of the month lag months before its maturity. Each quote is converted from the zero-coupon convention to a simple 30/360 rate over the swap’s business-day-adjusted maturity, so every quote reprices exactly. A calibration failure is reported as “NxIborIndex could not calibrate” even for an inflation index.
  • Seasonality coefficients passed to NxInflationIndex must be twelve values, January first. The C++ constructor does not check the count.
  • Seasonality estimation (NxInflationIndex::CalcSeasonalityCoefs) expects one CPI observation per month without gaps and returns twelve zeros with fewer than 28 observations. It takes a 2×12 centred moving average as the trend, smooths the detrended series with a (1, 2, 3, 2, 1)/9 moving average, averages the result by calendar month and removes the mean. The (1, 2, 3, 2, 1)/9 filter runs across adjacent months, not across the same month in successive years as in X-11-style seasonal adjustment, so a seasonal effect concentrated in one month comes out damped and spread over its neighbours. The estimator is not covered by the tests; review its output, or supply your own coefficients.

General

  • Errors are reported by throwing NitroX::Error (NX_Error.h), a std::runtime_error: catch (const NitroX::Error& e) or catch (const std::exception& e) both work. what() is the message, followed by [context] when the library knows which curve, pillar or quote failed; Message() and Context() give the two parts.
  • Threads. The library keeps no global mutable state. Using one curve set from several threads at once is not covered by the tests.

From the library at v1.0.0 (ccaff0b). Edit this page on GitHub