r/csharp • u/gangning • 6d ago
Tutorial nanoql: stateless quant finance in C#: immutable values, static pricers, .NET 10
nanoql is an open-source pricing library for .NET 10: curves, swaps, swaptions, SABR, equity options, Heston, CDS. Instruments, curves and models are immutable values, and pricers are static functions of them; the evaluation date is an argument, not a global setting.
var today = new Date(15, Month.October, 2026);
var context = new EvaluationContext { EvaluationDate = today };
var curve = new FlatForward(today, 0.036, new Actual365Fixed());
var swap = new MakeOIS(new Period(5, TimeUnit.Years), new Sofr(curve))
.WithFixedRate(0.036).WithNominal(10e6)
.ToOvernightIndexedSwap(context);
var result = DiscountingSwapEngine.Calculate(swap, context, curve);
Console.WriteLine($"NPV {result.NPV:N2}, fair rate {result.FairRate:P4}");
// NPV 7,041.24, fair rate 3.6154%
Some .NET details that may interest you:
- It uses static abstract interface members, so it needs .NET 10 and has no .NET Framework build.
- Python, C and C++ reach it through Native AOT: one C interface over the compiled library, so
pip install nanoqlneeds no .NET runtime. - The Excel add-in is generated from the same surface with Excel-DNA.
- It's derived from QuantLib 1.44 and checked against it: 3.35 million reference outputs, 99.86% within a relative 1e-10, and QuantLib's own tests ported at their tolerances.
dotnet add package NanoQL · getting started ·
GitHub · Apache-2.0
20
Upvotes
3
u/Inevitable_Buy_4957 6d ago
That's the kind of minimalist beauty I can get behind.
1
u/MrLyttleG 5d ago
If your lib has public exports in your AOT, then I can use it in my scripting engine https://lyttleg.github.io/ScriptLangCore/
1
u/smartcave 4d ago
This sounds worth checking it out. What do/have you use(d) it for so far?