PortOpt 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package PortOpt --version 1.0.0
                    
NuGet\Install-Package PortOpt -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="PortOpt" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PortOpt" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="PortOpt" />
                    
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 PortOpt --version 1.0.0
                    
#r "nuget: PortOpt, 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 PortOpt@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=PortOpt&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=PortOpt&version=1.0.0
                    
Install as a Cake Tool

PortOpt

Portfolio optimization for .NET on a native C++23 engine: minimum variance, maximum return under a volatility cap, maximum Sharpe, utility, importance, Kelly, tracking error, maximum diversification and risk parity, with scalar or per-weight bounds, a gross exposure limit (leverage) and an optional risk-free asset. The package carries the native library for linux-x64, linux-arm64, linux-musl-x64, linux-musl-arm64, osx-arm64, osx-x64 and win-x64, and is trimming- and Native AOT-compatible.

using PortOpt;

double[] mu = [0.08, 0.12, 0.10];
double[,] covariance =
{
    { 0.040, 0.006, 0.010 },
    { 0.006, 0.090, 0.012 },
    { 0.010, 0.012, 0.060 },
};
using var data = new MarketData(new MarketInputs { Mu = mu, Covariance = covariance, RiskFree = 0.02 });
var result = Optimizer.Solve(new Spec { Objective = Objective.MaxSharpe, Bounds = new Bounds(0, 1) }, data);
Console.WriteLine($"{result.Status}: {string.Join(", ", result.Weights)}");
Console.WriteLine($"Sharpe {data.SharpeRatio(result.Weights)}");
  • Spec is an immutable record: the objective and the settings it takes (TargetReturn, RiskAversion, Importance, MaxVolatility, Leverage, TargetVolatility, RiskBudget, Bounds or WeightBounds).
  • MarketData holds a native handle: dispose it (using). With a risk-free rate the cash weight comes last.
  • Result is plain values: status, weights, iterations, the multipliers and the residual.
  • A native failure is a PortOptException with its Status and the library's message; an infeasible problem is a result with SolveStatus.Infeasible, not an exception.
  • PORTOPT_LIB loads a local build of the native library instead of the packaged one.

The C header portopt.h is the reference for every objective, setter and multiplier: https://github.com/GabrielMarquezMatte/PortfolioOptimization

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.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.1.0 41 11/26/2026
1.0.0 58 11/25/2026
1.0.0-rc.1 67 11/21/2026