Aleksej.Finance 1.0.0

dotnet add package Aleksej.Finance --version 1.0.0
                    
NuGet\Install-Package Aleksej.Finance -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Aleksej.Finance" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Aleksej.Finance" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Aleksej.Finance" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Aleksej.Finance --version 1.0.0
                    
#r "nuget: Aleksej.Finance, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Aleksej.Finance@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Aleksej.Finance&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Aleksej.Finance&version=1.0.0
                    
Install as a Cake Tool

Aleksej.Finance

NuGet NuGet downloads CI codecov License: MIT

A comprehensive C# quantitative finance library with 180+ pure-math static methods and zero external dependencies. Every method is public static and takes explicit inputs — no state, no configuration, no side effects.

Built to back the Excel Finance Add-In and usable standalone in any .NET project.

Install

dotnet add package Aleksej.Finance

Target framework: .NET 6.0+


Modules

Options

Class What it computes
BlackScholes European call/put, 5 first-order Greeks (Δ Γ V Θ ρ), 5 higher-order Greeks (Vanna Charm Volga Speed Zomma), implied volatility
GarmanKohlhagen FX option pricing, full Greeks + implied vol (extends BS with foreign risk-free rate)
BinomialTree CRR binomial tree — European and American option pricing, Delta, Gamma
MonteCarlo GBM path simulation; European pricing; American option pricing via Longstaff-Schwartz LSM
ExoticOptions Binary (cash-or-nothing, asset-or-nothing), European barrier (knock-in/out), geometric Asian (closed-form), arithmetic Asian (Monte Carlo), floating-strike lookback call/put
OptionsOnFutures Black (1976) model — call/put on futures, full Greeks, put-call parity, implied vol
using Aleksej.Finance.Options;

double call  = BlackScholes.Call(s: 100, k: 100, t: 1, r: 0.05, sigma: 0.20);  // ≈ 10.45
double delta = BlackScholes.Delta(100, 100, 1, 0.05, 0.20, isPut: false);        // ≈ 0.637
double iv    = BlackScholes.ImpliedVolatility(10.45, 100, 100, 1, 0.05, false);  // ≈ 0.200
double amPut = BinomialTree.Price(100, 100, 1, 0.05, 0.20, steps: 500, isPut: true, isAmerican: true);
double fxOpt = GarmanKohlhagen.Call(s: 1.10, k: 1.10, t: 0.5, r: 0.03, rf: 0.01, sigma: 0.10);
double barr  = ExoticOptions.BarrierCall(s: 100, k: 100, h: 120, t: 1, r: 0.05, sigma: 0.20, knockIn: false, isUp: true);
double futOpt = OptionsOnFutures.Call(f: 105, k: 100, t: 0.5, r: 0.05, sigma: 0.20);

Bonds

Class What it computes
BondMath Bond price from YTM, YTM from price (Newton-Raphson), Macaulay/modified duration, convexity, DV01, approximate price change
YieldCurve Discount factors, rate conversions (simple ↔ continuous), forward rate curve, par yield, zero curve bootstrapping from par rates or bond prices, linear interpolation
MortgageMath Payment formula, outstanding balance, full amortisation schedule, total interest paid, EAR/APR conversions
using Aleksej.Finance.Bonds;

double price   = BondMath.Price(face: 1000, couponRate: 0.05, ytm: 0.05, years: 10); // = 1000
double ytm     = BondMath.YieldToMaturity(950, 1000, 0.05, 10);
double mdur    = BondMath.ModifiedDuration(1000, 0.05, 0.05, 10);
double[] zeros = YieldCurve.Bootstrap(new[] { 0.5, 1.0, 1.5, 2.0 }, new[] { 0.04, 0.042, 0.044, 0.046 });
double payment = MortgageMath.Payment(principal: 500_000, annualRate: 0.065, years: 30); // monthly payment

Derivatives

Class What it computes
ForwardFutures Forward pricing (no income, continuous yield, known income, FX interest rate parity, commodity cost-of-carry), value of existing forward positions
ForwardRateAgreement Forward rate from zero curve (continuous and simple), FRA mark-to-market value, settlement cash flow, DV01
InterestRateSwap Fixed-for-floating IRS value, par swap rate, fixed/floating leg PV, DV01
BlackModel Caplets, floorlets, interest rate caps, floors, forward swap rate, swaptions (payer/receiver)
ShortRateModels Vasicek: bond price/yield/long-run yield/bond option. CIR: bond price/yield/long-run yield. Term structure generation
using Aleksej.Finance.Derivatives;

double fwd  = ForwardFutures.FxForwardPrice(s: 1.10, r: 0.03, rf: 0.01, t: 1);   // ≈ 1.122
double par  = InterestRateSwap.ParSwapRate(new[] { 0.5, 1.0, 1.5, 2.0 }, new[] { 0.028, 0.030, 0.031, 0.032 });
double cap  = BlackModel.CapPrice(1_000_000, strike: 0.04, sigma: 0.20, paymentTimes, zeroRates, forwardRates, accrualFracs);
double vBond = ShortRateModels.VasicekBondPrice(r: 0.03, tau: 5, kappa: 0.15, theta: 0.05, sigma: 0.01);

Credit

Class What it computes
CreditDerivatives Merton model (equity value, debt value, default probability, distance to default, credit spread). CDS: survival probability, hazard rate from spread, fair CDS spread, CDS mark-to-market
using Aleksej.Finance.Credit;

double pd    = CreditDerivatives.MertonDefaultProbability(v: 100, d: 80, t: 1, r: 0.05, sigmaV: 0.25);
double cdsS  = CreditDerivatives.CdsFairSpread(hazardRate: 0.02, r: 0.03, maturity: 5); // ≈ 120bps
double dd    = CreditDerivatives.DistanceToDefault(100, 80, 1, 0.05, 0.25);

Portfolio

Class What it computes
Markowitz Mean returns, covariance matrix, portfolio return/variance/volatility/Sharpe, minimum variance portfolio (analytical), efficient frontier (analytical Lagrange), unconstrained and long-only max Sharpe, risk parity (ERC), risk contributions
EquityMetrics Market cap, enterprise value, portfolio market value, P/E, P/B, P/S, EV/EBITDA, EV/EBIT, dividend yield, earnings yield, unrealised/realised P&L, Kelly criterion (continuous and discrete), half-Kelly
FeeCalculations Management fee accrual, performance fee with high-water mark + hurdle, carried interest (PE style), catch-up, expense ratio drag, cumulative fee impact, transaction cost, slippage
PerformanceAttribution Time-weighted return (TWR), Modified Dietz, IRR / money-weighted return (Newton-Raphson on NPV), NPV, Brinson-Hood-Beebower attribution (allocation, selection, interaction per sector and total)
using Aleksej.Finance.Portfolio;

double[] mu  = Markowitz.MeanReturns(returns);       // returns is double[T, n]
double[,] cov = Markowitz.CovarianceMatrix(returns);
double[] wMV  = Markowitz.MinVariancePortfolio(cov);
double[] wMS  = Markowitz.MaxSharpePortfolioConstrained(mu, cov, riskFreeRate: 0.05);
double[] wRP  = Markowitz.RiskParityPortfolio(cov);

double pe     = EquityMetrics.PriceToEarnings(price: 150, eps: 6.25);          // 24×
double ev     = EquityMetrics.EnterpriseValue(marketCap: 500e9, debt: 50e9, cash: 30e9);
double kelly  = EquityMetrics.KellyCriterion(mu: 0.12, sigma: 0.20);           // f* = 3.0

double fee    = FeeCalculations.PerformanceFee(currentNav: 115, highWaterMark: 100,
                    previousNav: 100, carryRate: 0.20, hurdleRate: 0.08);
double carry  = FeeCalculations.CarriedInterest(totalDistributions: 200e6,
                    investedCapital: 100e6, preferredReturn: 0.08, holdingYears: 5);

double twr    = PerformanceAttribution.TimeWeightedReturn(new[] { 0.05, -0.02, 0.08 }); // ≈ 11.1%
double irr    = PerformanceAttribution.InternalRateOfReturn(
                    cashFlows: new[] { -1000.0, 200, 300, 400, 400 },
                    times:     new[] { 0.0, 1, 2, 3, 4 });

var (alloc, select, interact, active) = PerformanceAttribution.BhbAttribution(
    portfolioWeights, benchmarkWeights, portfolioReturns, benchmarkReturns);

Risk

Class What it computes
RiskMetrics Sharpe, Sortino, Calmar, Treynor ratios; Beta; Jensen's Alpha; historical VaR; CVaR (Expected Shortfall); parametric VaR; annualised return and volatility; max drawdown; tracking error; information ratio
VolatilityModels EWMA volatility series (RiskMetrics, λ=0.94 default), latest EWMA estimate, GARCH(1,1) conditional variance series, long-run variance, N-day ahead GARCH forecast, rolling historical volatility, GARCH MLE parameter estimation
using Aleksej.Finance.Risk;

double sharpe  = RiskMetrics.SharpeRatio(daily, riskFreeRateAnnual: 0.05);
double var95   = RiskMetrics.HistoricalVaR(daily, confidence: 0.95);
double sortino = RiskMetrics.SortinoRatio(daily, riskFreeRateAnnual: 0.05);
double beta    = RiskMetrics.Beta(portfolioReturns, benchmarkReturns);
double ir      = RiskMetrics.InformationRatio(portfolioReturns, benchmarkReturns);
double[] ewma  = VolatilityModels.EwmaVolatility(daily, lambda: 0.94);
double gFcast  = VolatilityModels.GarchForecast(currentVariance: 0.0001, omega: 0.000002,
                     alpha: 0.05, beta: 0.90, nDays: 10);

Design Principles

  • Zero dependencies — no NuGet packages, no external libraries
  • Pure functions — every method is public static, takes all inputs explicitly, no global state
  • Numerically stable — Gaussian elimination with partial pivoting, Box-Muller transform, Abramowitz & Stegun CDF, Brent's method, Newton-Raphson
  • Modular — outputs of one method are valid inputs to another: YieldCurve.Bootstrap()InterestRateSwap.SwapValue()InterestRateSwap.DV01()

Build from Source

git clone https://github.com/aleksejcupic/aleksej-finance
cd aleksej-finance
dotnet build
dotnet pack --configuration Release

Author

Aleksej Cupic · aleksejcupic.com · LinkedIn

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 107 6/2/2026