#allocation #portfolio #distribution #quant #resources

bin+lib cutup

A flexible and efficient allocation library for Rust, capable of distributing assets, resources, and other divisible entities

5 releases

0.1.4 Apr 7, 2025
0.1.3 Apr 7, 2025
0.1.2 Apr 7, 2025
0.1.1 Feb 9, 2025
0.1.0 Feb 9, 2025

#438 in Math

Download history 194/week @ 2025-02-05 33/week @ 2025-02-12 27/week @ 2025-02-19 5/week @ 2025-02-26 3/week @ 2025-03-12 1/week @ 2025-03-26 294/week @ 2025-04-02 63/week @ 2025-04-09 11/week @ 2025-04-16

368 downloads per month

MIT license

21KB
264 lines

Cutup: A Rust Portfolio Allocation Library

Crates.io Build Status codecov Docs.rs License

Cutup is a Rust library for portfolio allocation strategies, providing implementations for various allocation methods.

It's designed to be efficient and easy to use.

Here are some of the allocation methods included in this library:

  • Mean-Variance Optimization (MVO)
  • Equal Weight Allocation (EW)
  • Hierarchical Risk Parity (HRP)

This library leverages nalgebra for efficient matrix operations and is designed for performance and extensibility.

Features

  • MVO Allocation: Computes portfolio weights using mean-variance optimization with covariance matrix regularization.
  • EW Allocation: Assigns equal weights to all assets.
  • HRP Allocation: Uses hierarchical clustering and recursive bisection for risk-based allocation.
  • Fully Unit-Tested: Includes test cases for correctness verification.

Installation

Add cutup to your Cargo.toml:

[dependencies]
cutup = "0.1.4"

Usage

use nalgebra::DMatrix;
use cutup::PortfolioAllocator;

fn main() {
    let prices = DMatrix::from_row_slice(
        4,
        4,
        &[
            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,
        ],
    );

    let allocator = PortfolioAllocator::new(prices);

    let mvo_weights = allocator.mvo_allocation();
    let ew_weights = allocator.ew_allocation();
    let hrp_weights = allocator.hrp_allocation();

    println!("MVO Weights: {:?}", mvo_weights);
    println!("EW Weights: {:?}", ew_weights);
    println!("HRP Weights: {:?}", hrp_weights);

    // or do it all in one go

    let weights = run_portfolio_allocation(prices);
    println!("Portfolio Weights: {:?}", weights);
}

License

This project is licensed under the MIT License.

Dependencies

~3MB
~64K SLoC