No.0256 min read
Cutup 1.0: Portfolio Allocation in Rust, All Grown Up
Cutup went from three allocation methods at v0.1.1 to 1.0: thirteen methods solved exactly by its own solvers, constraints and rebalancing, JSON and TypeScript, the same Rust in the browser, and tests that check every bit.

Back in February 2025 I announced Cutup, a Rust crate for portfolio allocation. It was at v0.1.1 and did three things: mean-variance optimization, hierarchical risk parity, and equal weight. I promised Black-Litterman, factor models, and the browser.
Then it sat. A few patches that April, then nothing for a year and a half.
This fall I picked it back up, and over six weeks it went through 26 releases. As of today it's at 1.0.2: thirteen allocation methods, solved exactly by solvers written for it, checked against the Python libraries people actually use, and running in the browser. Here's what changed.
The API, rebuilt
v0.1.1 had one function, run_portfolio_allocation, that took a nalgebra matrix and handed back a vector. 1.0 is built around a Returns value and methods you pass to it:
use cutup::{CutupError, Hrp, MinVariance, Returns, WeightBounds};
fn main() -> Result<(), CutupError> {
let prices = [
[125.0, 1500.0, 210.0, 600.0],
[123.0, 1520.0, 215.0, 620.0],
[130.0, 1510.0, 220.0, 610.0],
[128.0, 1530.0, 225.0, 630.0],
[131.0, 1525.0, 223.0, 640.0],
[129.5, 1550.0, 228.0, 635.0],
[133.0, 1545.0, 226.0, 650.0],
[135.5, 1560.0, 231.0, 645.0],
[134.0, 1580.0, 229.0, 660.0],
[137.0, 1575.0, 234.0, 668.0],
[136.0, 1600.0, 238.0, 662.0],
[139.5, 1595.0, 236.0, 675.0],
[141.0, 1615.0, 241.0, 680.0],
];
let data = Returns::from_prices(&prices)?.labeled(["AAA", "BBB", "CCC", "DDD"])?;
// The lowest-variance portfolio with no asset above 40%.
let capped = data.allocate(&MinVariance::default().bounds(WeightBounds::uniform(0.0, 0.4)))?;
// Hierarchical risk parity, which never inverts the covariance.
let hrp = data.allocate(&Hrp::default())?;
println!("{capped}");
println!("{hrp}");
Ok(())
}The capped minimum variance portfolio, then HRP's:
AAA 0.2494
BBB 0.4000
CCC 0.1297
DDD 0.2209
AAA 0.1498
BBB 0.4308
CCC 0.1564
DDD 0.2629A few things to notice:
- No matrix library needed. Prices or returns come in as arrays,
Vecs or slices. nalgebra is still under the hood, and an optional feature takes its matrices directly. - Methods are values. Each one is a struct with chained settings, and anything that implements the
Allocationtrait works, including your own. - Errors, not garbage. Bad input, such as NaNs, too few rows or bounds no portfolio can meet, returns a
CutupErrorinstead of meaningless weights. - Labels everywhere. Name your assets once, and every per-asset setting takes the labels.
Thirteen methods, and the constraints people actually use
The method list now covers the workhorses:
- Variance-based: minimum variance, mean-variance (by risk aversion, target return or target volatility, plus the efficient frontier), max Sharpe, and max diversification, long-only or long-short.
- Risk-based: inverse volatility, inverse variance, risk parity with risk budgets, HRP with four linkages, and HERC.
- Tail and drawdown risk: minimum CVaR, minimum mean absolute deviation (or the least shortfall below a threshold), and minimum CDaR, straight from the return scenarios.
- Equal weight, because sometimes simplicity still wins.
On top of those:
- Constraints: caps and floors on each asset, and on groups of assets.
- Rebalancing from your current weights: turnover caps, turnover penalties, and transaction costs netted against the expected return.
- Black-Litterman, with views as variances or as Idzorek confidences. That was the first item on v0.1.1's wish list.
- Estimators: Ledoit-Wolf shrinkage, exponentially weighted and semi covariances, and exponentially weighted, CAPM, James-Stein and Bayes-Stein means.
- Analytics: statistics for any weights (volatility, Sharpe ratio, risk contributions, CVaR, drawdowns), and any method over rolling windows.
Exact, with no solver to install
Most Python portfolio libraries hand their problems to cvxpy and a solver. Cutup solves its own: a hand-written active-set solver for the quadratic programs, a bounded revised simplex for the linear ones, and cutting planes for drawdown risk. They find the exact optimum, to floating-point rounding, rather than one within a solver's tolerance. The only dependency is nalgebra.
It's quick, too. On an Apple M5, HRP on 500 assets takes about 2.6 ms, and long-only minimum variance takes about 5 ms at 100 assets and 0.45 s at 500.
Tested like money depends on it
Because sometimes it does.
- Checked against references. Every method and estimator is checked against an independent implementation: PyPortfolioOpt, Riskfolio-Lib, SciPy's HiGHS, scikit-learn, pandas, or closed forms. The expected values are committed, and CI checks the Python still reproduces them.
- Lots of tests. 649 unit tests and 202 doctests, plus 59 property tests that run at 50,000 cases each before every release.
- Mutation testing. cargo-mutants makes thousands of small changes to the code, a
<for a<=here, a+for a-there, and checks that some test notices. 98.8% of them get caught. - Fuzzing. Four fuzz targets throw tens of millions of random inputs at it before each release: 46 million for 1.0.2, with no crashes.
- A golden corpus. 1,074 results recorded bit for bit, per platform, so a change to any of them fails CI.
- Semver checks on every PR, and a minimum supported Rust version of 1.85.
The golden corpus paid for itself right away. It turned up that f64::max(-0.0, 0.0) gives -0 in unoptimized builds on x86_64 and wasm with Rust 1.92, and +0 on arm64. The simplex solver broke ties between equal steps with total_cmp, which puts -0 before +0, so a problem with more than one optimal portfolio could return a different one on a different machine. Fixed in 1.0.1.
Floating point is fun.
In the browser, as promised
v0.1.1's next step was bringing Cutup to the browser with WebAssembly. Done: wasm32 is a tested target in CI, and with the serde and ts-rs features every method reads and writes JSON, with TypeScript types to match.
The sample app shows it off. It splits an ad budget across six ad platforms, treating each platform as an asset and what its spend bought each day as its return. The same Rust runs either on Vercel as native serverless functions, the way I ran Monte Carlo sims, or right in your browser as WebAssembly, and a switch picks which.
Which gets at something else: Cutup isn't just for stocks. An asset is any return series. An ad platform, a forecasting model, a data source.
What 1.0 means
1.0 is a promise: nothing in the public API breaks until 2.0. New features come in minor releases, and the patches since 1.0 have been about correctness. 1.0.1 added the golden corpus and the four fixes it and its review turned up, and 1.0.2 fixed three edge cases in the solvers that an earlier audit had left.
What's next
The road to 2.0 is in the roadmap, with a minor release per feature and a few patches after each:
- Reports and shadow prices (1.1.0): every solve with its certificate, and what each binding constraint is costing you.
- Infeasibility explained (1.2.0): when no portfolio meets your constraints, the smallest set that conflicts, by name.
- Limits and cancellation (1.3.0), for running it in services.
- The same bits on every platform (1.4.0).
- Factor models (1.5.0), to thousands of assets.
- Then constraints everywhere, more risk measures and estimators, cardinality, entropy pooling, and the rest of the list.
Outside the crate, a docs site, a Python package and an npm package are on the way.
Try it
cargo add cutupDocs are on docs.rs/cutup, and the code is on GitHub. If you allocate anything with it, stocks or ad spend or something I haven't thought of, I want to hear about it.
Hasta luego, kiddos.
Get new entries by email
Occasional notes on Rust, TypeScript, Python, finance, and building on the web.