Documentation

Getting started

Build the library and its tests with CMake, then strip a SOFR OIS curve and price a swap off it.

Requirements

  • A C++20 compiler. Continuous integration builds and tests every change, with warnings treated as errors, on:
    • clang and gcc on Ubuntu (the current ubuntu-latest GitHub runner),
    • MSVC on Windows (the current windows-latest runner), x64. MSVC compilers from cl 19.29 (Visual Studio 2019) to cl 19.51 have been checked.
  • CMake 3.20 or later. CI uses the Ninja generator; any generator works, including the Visual Studio ones.
  • Nothing else. There are no external dependencies: the one third-party component (a small part of ALGLIB, used for matrix inversion) is vendored in the source tree.

Building

From the repository root:

cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake --build build
ctest --test-dir build --output-on-failure

RelWithDebInfo is the default when no build type is given with a single-configuration generator. The library target is nitrox_core, a static library. Its two include directories, CommonSources/Api and CommonSources/Implementation, are exported as PUBLIC, so linking against the target is enough to compile against the headers.

CMake options:

OptionDefaultEffect
NITROX_BUILD_TESTINGONBuild the test programs and register them with CTest.
NITROX_WARNINGS_AS_ERRORSOFFPromote the warning set to errors (-Werror / /WX), as CI does.
NITROX_SANITIZEemptyComma-separated sanitizers, for example address,undefined (clang, gcc). On MSVC any non-empty value gives AddressSanitizer.

To use the library from your own CMake project, add the source tree and link the target:

set(NITROX_BUILD_TESTING OFF CACHE BOOL "" FORCE)
add_subdirectory(path/to/nitrox)
target_link_libraries(my_app PRIVATE nitrox_core)

Building the Excel add-in

NitroX.xll builds on Windows with MSVC, 64-bit, for 64-bit Excel. It needs Microsoft’s Excel XLL SDK (XLCALL.H, XLCALL.CPP, x64/XLCALL32.LIB), which Microsoft does not allow to be redistributed: download it from Microsoft and point CMake at the folder that holds it.

cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DNITROX_BUILD_XLL=ON -DNITROX_XLCALL_DIR=<Excel XLL SDK dir>
cmake --build build --target nitrox_xll        # -> build/NitroX.xll
powershell -File scripts/check-xll-loads.ps1   # loads it into Excel and checks it answers

Open build\NitroX.xll in Excel (File > Open, or the add-in manager), then the demo workbook in examples/excel/rfr_demo/.

A first curve and a first swap

The example below builds a USD SOFR curve and prices a five-year SOFR OIS off it. It follows the same steps as the library’s own OIS bootstrap test; every class lives in namespace NitroX.

The chain is always the same, whatever the curve:

  1. Conventions: an NxIndexParam for the index.
  2. Quotes: a data object (NxOisData here) holding the market quotes for that index.
  3. Bootstrap: a shape (NxOisShape) stripped from the data.
  4. Funding: a discount curve (NxDiscountLoc) built on the shape.
  5. Projection: an index (NxOisIndex) built on the shape, discounted on the funding curve.
  6. Market: an NxCcyIndexes for the currency, inside an NxIndexGlob.
  7. Instrument: an NxSwap, priced against the NxIndexGlob.
#include <cstdio>
#include <exception>
#include <memory>
#include <string>
#include <vector>

#include "NX_Date.h"
#include "NX_Params_NxIndexParam.h"
#include "NX_Datas_NxOisData.h"
#include "NX_DiscountLoc_NxOisShape.h"
#include "NX_DiscountLoc_NxDiscountLoc.h"
#include "NX_IndexLoc_NxOisIndex.h"
#include "NX_CcyIndexes_NxCcyIndexes.h"
#include "NX_IndexGlob_NxIndexGlob.h"
#include "NX_Swap_NxSwap.h"
#include "NX_NxWallet.h"

using namespace NitroX;

int main()
{
    try
    {
        const Date today(15, 1, 2026);

        // 1. Conventions: USD calendar, spot = 2 USD business days, modified
        //    following; ACT/360 floating basis; annual ACT/360 on both legs
        //    below and above the 370-day short/long limit.
        auto sofr = std::make_shared<NxIndexParam>(
            "USD", "SOFR", "USD", "2USD", 'm',
            "MM",               // floating-leg basis
            370,                // short/long limit, in days
            "MM", 'A', 'A',     // short end: fixed basis, fixed freq, float freq
            "MM", 'A', 'A');    // long end:  fixed basis, fixed freq, float freq

        // 2. Quotes: the overnight fixing, then par OIS rates by tenor.
        const std::vector<std::string> tenors = {
            "1W", "1M", "3M", "6M", "9M", "1Y", "18M", "2Y", "3Y",
            "4Y", "5Y", "7Y", "10Y", "15Y", "20Y", "30Y" };
        const std::vector<double> quotes = {
            0.0363, 0.0361, 0.0352, 0.0340, 0.0330, 0.0322, 0.0310, 0.0303, 0.0298,
            0.0300, 0.0305, 0.0315, 0.0328, 0.0340, 0.0343, 0.0335 };

        const std::vector<std::string> noFraTenors;
        const std::vector<double>      noFraQuotes;
        const std::vector<Date>        noDates;
        const std::vector<double>      noRates;

        // A year-end turn: one night at +25 bp, dated 31 Dec 2026.
        const std::vector<Date>   turnDates = { Date(31, 12, 2026) };
        const std::vector<double> turnRates = { 0.0025 };

        auto data = std::make_shared<NxOisData>(
            sofr, 0.0363,                   // param, overnight rate
            tenors, quotes,                 // OIS swaps
            noFraTenors, noFraQuotes,       // OIS FRAs / futures codes
            noDates, noDates, noRates,      // custom periods: start, end, quote
            turnDates, turnRates, "MM",     // turn jumps (the basis is not used)
            noDates,                        // central-bank step dates
            noDates, noRates,               // past overnight fixings
            false);                         // rejectZeroRates

        // 3. Bootstrap, with Hagan-West monotone-convex interpolation.
        auto shape = std::make_shared<NxOisShape>(today, data, 'm');

        // 4. Funding curve: the shape itself, no funding margins.
        auto discount = std::make_shared<NxDiscountLoc>(
            shape, std::vector<std::string>{}, std::vector<double>{}, 'A', "AA");

        // 5. The SOFR projection index, discounted on that funding curve.
        auto index = std::make_shared<NxOisIndex>(discount, shape, data);

        // 6. The market: one currency, one funding curve, one index.
        auto usd = std::make_shared<NxCcyIndexes>();
        usd->SetDiscountLoc(discount);
        usd->AddIndexLoc(index);

        auto market = std::make_shared<NxIndexGlob>();
        market->AddCcyIndexes(usd);

        // 7. A 5Y spot-starting SOFR OIS on 10mm, receiving 3.10% fixed.
        //    Leg 0 is the fixed leg (coefficient +1), leg 1 the SOFR leg (-1).
        NxSwap swap("USD", today, "2USD", "", "5Y", "USD", 'm',
                    0.0310, 'A', "MM",          // fixed rate, frequency, basis
                    "SOFR", 'A', "MM",          // index, frequency, basis
                    false, 10e6);               // no notional exchange, notional

        const double parRate = swap.CalcFixRate(*market, 0, swap.StartDate(0));
        const double pv      = swap.CalcPv(*market, today);
        NxWallet wallet      = swap.Pv(*market, today);
        const double annuity = swap.Leg(0)->CalcSensi(*market, today);

        std::printf("5Y par rate     %.6f %%\n", 100.0 * parRate);
        std::printf("PV (USD)        %.2f\n", pv);
        std::printf("PV wallet USD   %.2f\n", wallet.Amount("USD"));
        std::printf("fixed-leg PV01  %.2f per bp\n", annuity / 1e4);
        std::printf("DF(5Y)          %.8f\n",
                    discount->DiscountFactor(Date::GetFwdDate(today, "5Y", "USD")));
    }
    catch(const std::string & e)    // the library reports errors as std::string
    {
        std::fprintf(stderr, "%s\n", e.c_str());
        return 1;
    }
    catch(const char * e)
    {
        std::fprintf(stderr, "%s\n", e);
        return 1;
    }
    catch(const std::exception & e)
    {
        std::fprintf(stderr, "%s\n", e.what());
        return 1;
    }
    return 0;
}

What to expect:

  • The par rate is the 5Y quote, 3.05 %. The index is calibrated so that every quoted OIS reprices, and the swap was built with the same conventions (spot start, annual ACT/360 both legs) as the 5Y calibration instrument. If the par rate of a quoted tenor comes back different, the swap’s conventions differ from the index’s.
  • The PV is positive. The swap receives 3.10 % against a 3.05 % par rate, so its value is about 5 bp times the annuity: PV ≈ (0.0310 − parRate) × annuity.
  • CalcPv returns one number, the sum of the legs; Pv returns an NxWallet with one amount per currency. For a single-currency swap they agree.
  • CalcSensi on a leg returns its annuity, the sum of discount factor × accrual × notional over the remaining periods. Divide by 10,000 for the PV01 per basis point.

Things that are easy to get wrong:

  • Default interpolation. The char interp argument of NxIborShape and NxOisShape defaults to 'l' (linear in zero rate). Pass 'm' for Hagan-West. The interpolation codes are listed in Curves.
  • rejectZeroRates defaults to true in the NxIborData and NxOisData constructors: a quote of exactly zero is then dropped as if blank. Pass false whenever a genuine 0.00 % quote is possible. See Accuracy and known behaviours.
  • Index names. An NxOisIndex is registered under the index name of its param ("SOFR"). An NxIborIndex is registered under the name plus its fixing tenor in months ("EURIBOR6" for a 6M index). A swap leg naming "EURIBOR" finds "EURIBOR6" through its frequency: a semi-annual leg looks for the 6M index.
  • One funding curve per currency. NxCcyIndexes::AddIndexLoc refuses an index that was built on a different NxDiscountLoc from the one already in the container.
  • Sign. The single-currency NxSwap constructors put the fixed leg first with coefficient +1 and the floating leg second with −1: a positive notional is a receiver swap. See Swaps.
  • Errors. Invalid input and calibration failures are reported by throwing, mostly std::string and in a few places const char*, not std::exception. Catch all three.

Where to go next

  • Concepts for the object model and the shape + spread construction.
  • Curves for IBOR curves, FRAs and futures, funding margins, cross-currency curves, turns and central-bank steps.
  • Swaps for leg-level control, amortising and cross-currency swaps, and cancellation tables.
  • Inflation for CPI curves and zero-coupon inflation swaps.
  • Accuracy and known behaviours before using any of it in production.

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