Skip to main content

Factor-structured mean-variance portfolio optimization

Project description

Ledge Python binding

Package name on install: ledge-portfolio (import name: ledge).

It exposes Ledge's factor mean-variance solver to NumPy (float64 only) and releases the GIL while solving. This is an alpha binding; the release workflow builds abi3 wheels for the supported platforms. Each distribution includes the Apache-2.0 project license and the generated Rust dependency notices in THIRD_PARTY_LICENSES.html.

Registry install after the 0.2.0 artifacts are published:

python -m pip install ledge-portfolio==0.2.0

From the repository root:

python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip maturin
python -m pip install -e python/
python python/examples/rebalance.py
python -m pytest python/tests

For binding development:

cd python
maturin develop
python examples/rebalance.py

Primary API:

from ledge import PortfolioProblem, solve_mean_variance_factor

PortfolioProblem.solve(warm_start=previous_weights) re-solves a single problem. For rolling multi-date rebalances, prefer PortfolioProblem.sequence(): the returned PortfolioSequence caches the equilibration and reduced factorizations across dates and chains full primal/dual warm starts automatically — each date is one sequence.solve_next(expected_returns=..., previous_weights=..., benchmark_weights=..., budget=..., equality_rhs=..., inequality_rhs=...) call (all arguments optional; only factorization-preserving updates are accepted). See examples/rolling.py and the full backtest in ../docs/examples/rolling_backtest.py. For many accounts sharing one model, ledge.solve_batch(problems, steps, chain_previous_weights=..., **solver_kwargs) runs one sequence per account in parallel over the account axis (the GIL is released for the whole batch); steps is one list of per-date dicts per account whose keys mirror the solve_next keyword arguments, and chain_previous_weights=True anchors each date's turnover at the previous solved date's weights, the usual backtest convention. SolveResult reports weights, status, objective, KKT residuals, iterations, solve time, and adaptive-penalty diagnostics. Infeasible problems stop early with status 'primal infeasible' (or 'dual infeasible' for unbounded objectives): by default a RuntimeError names the conflicting portfolio constraints; pass raise_on_failure=False to inspect SolveResult.certificate, an independently checkable Farkas combination (or descent direction).

Turnover control around previous_weights: turnover_penalty is a smooth L2 penalty; l1_turnover_costs (a scalar broadcast to all assets, or a per-asset array) is exact proportional transaction cost with a genuine no-trade region, handled by a dedicated proximal block. Both may be combined. benchmark_weights switches the risk term to active risk (w - b)' Sigma (w - b) against a tracking benchmark.

Migrating an existing cvxpy rebalance? See ../docs/cvxpy_migration.md — every mapping in it is executed against cvxpy + Clarabel by tests/test_migration_guide.py.

See the root README for scope, limitations, and smoke timings.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ledge_portfolio-0.2.0.tar.gz (164.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

ledge_portfolio-0.2.0-cp39-abi3-win_amd64.whl (482.0 kB view details)

Uploaded CPython 3.9+Windows x86-64

ledge_portfolio-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (606.0 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

ledge_portfolio-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (578.7 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

ledge_portfolio-0.2.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (1.1 MB view details)

Uploaded CPython 3.9+macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

File details

Details for the file ledge_portfolio-0.2.0.tar.gz.

File metadata

  • Download URL: ledge_portfolio-0.2.0.tar.gz
  • Upload date:
  • Size: 164.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for ledge_portfolio-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a317d721d6c658f3071a2841931fa6ff35dcb62c955d533dc4710f5ead6cad64
MD5 18c4d8f593c032f4715054afa366df60
BLAKE2b-256 a1458b3c75f2b9c57371aa0c95bfa9a2d02bdc57a5913d60bc3020ce97e99838

See more details on using hashes here.

Provenance

The following attestation bundles were made for ledge_portfolio-0.2.0.tar.gz:

Publisher: release.yml on Jiangki/ledge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ledge_portfolio-0.2.0-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for ledge_portfolio-0.2.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 cbf5a82eeffd95708ff6c2c9003af18bc1565992d145bb2d9152296dcaddf0eb
MD5 abb1c0a1558d42a0d8040ee161b5ea55
BLAKE2b-256 421dd9f697d4801ce383a3c3cc1cdf6f57e8ca8adba0e61f6cacb10eab4d033a

See more details on using hashes here.

Provenance

The following attestation bundles were made for ledge_portfolio-0.2.0-cp39-abi3-win_amd64.whl:

Publisher: release.yml on Jiangki/ledge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ledge_portfolio-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ledge_portfolio-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 244c7c6680e6f01433516369a54b850a415b805284f044f247b2b92536d42c4d
MD5 84af8a646d62243427ac2ba191d4e84d
BLAKE2b-256 9cbde3b1c585e237ef154a36ad5979745260366f14ee9707a21e5ae4e14c8c5b

See more details on using hashes here.

Provenance

The following attestation bundles were made for ledge_portfolio-0.2.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on Jiangki/ledge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ledge_portfolio-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for ledge_portfolio-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 566a2071c35358035805593a12fe6cd57d0053702df0c2279eb79ff125371900
MD5 4cbfd34cfbdf39ef06e4fe435e33a0f4
BLAKE2b-256 58595d103e7af72f9d87c20b65d7380bb6ca2510b95f643da267c7a70a8a1d9a

See more details on using hashes here.

Provenance

The following attestation bundles were made for ledge_portfolio-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on Jiangki/ledge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ledge_portfolio-0.2.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for ledge_portfolio-0.2.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 6795594b6bd0aa9ba3209a904ecd5d96f0d553a210a60854ba9f0839b6d33ce8
MD5 c857f368f0fe0ac706d61a67343caadb
BLAKE2b-256 ed138c14962a38b484c27a4ffe6b508cda31b8885823c0ba650501a7f9434b6d

See more details on using hashes here.

Provenance

The following attestation bundles were made for ledge_portfolio-0.2.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl:

Publisher: release.yml on Jiangki/ledge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page