Skip to main content

Proteus Optimisation Package (POP): Domain-agnostic stochastic optimization engine for PAL variables

Project description

POP Logo

Proteus Optimisation Package (POP)

Domain-agnostic stochastic optimization engine for PAL (Proteus Actuarial Library) variables.

Features

  • 🎯 Metric-Centric Design: Unified framework for objectives and constraints
  • 📊 Multiple Metric Types: Mean, Std, SpreadVaR, plus composite metrics (Ratio, Product, Sum, Difference)
  • 🔗 Composite Metrics: Build complex metrics like Sharpe ratios, risk-adjusted returns
  • 🎲 Dual Data Support: StochasticScalar (aggregated) and FreqSevSims (frequency-severity)
  • ⚖️ Flexible Constraints: Portfolio-level and occurrence-level constraints
  • 📈 Efficient Frontiers: Parallel constraint variation for risk-return tradeoff analysis
  • ✅ Type-Safe API: Pydantic models with comprehensive validation

Installation

From PyPI

pip install proteusllp-optimisation-package

From Local Source (Development)

pip install -e /proteus-optimisation-package

Quick Start

from pop import (
    ObjectiveSpec, OptimizationInput, SimpleConstraint,
    MeanMetric, StdMetric, optimize
)
from pal.variables import ProteusVariable
from pal import StochasticScalar

# Create PAL variable with return simulations
returns = ProteusVariable("item", {
    "stock_a": StochasticScalar([0.10, 0.12, 0.08]),
    "stock_b": StochasticScalar([0.15, 0.18, 0.12])
})

# Define objective: maximize expected return
objective = ObjectiveSpec(
    objective_value=returns,
    metric=MeanMetric(),
    direction="maximize"
)

# Add risk constraint: limit portfolio std dev
risk_constraint = SimpleConstraint(
    constraint_value=returns,
    metric=StdMetric(),
    threshold=0.15,
    direction="cap",
    name="max_risk"
)

# Create optimization problem
opt_input = OptimizationInput(
    item_ids=["stock_a", "stock_b"],
    current_shares={"stock_a": 100.0, "stock_b": 100.0},
    objective=objective,
    simple_constraints=[risk_constraint]
)

# Run optimization
result = optimize(opt_input.preprocess())
print(f"Optimal shares: {result.optimal_shares}")
print(f"Expected return: {result.objective_value:.4f}")

Documentation

Full documentation is available at proteusllp-optimisation-package.readthedocs.io.

Requirements

  • Python 3.13+
  • PAL (Proteus Analytics Library) >=0.2.8
  • NumPy >=2.2
  • SciPy >=1.15
  • Pydantic >=2.0
  • cvxopt

Development

Setup

# Clone the repository
git clone https://github.com/ProteusLLP/proteusllp-optimisation-package.git
cd proteusllp-optimisation-package

# Open in VS Code - will prompt to reopen in devcontainer
code .  # Runs 'pdm install' automatically

# Or install locally with PDM
pdm install

Running Checks

# Run tests
pytest tests/ -v

# Run static analysis (lint, format, security, deadcode)
make static-analysis

# Run typecheck separately (has known issues with PAL's dynamic types)
make typecheck

Note on Type Checking: Pyright type checking is temporarily excluded from CI due to PAL's dynamic typing patterns. PAL adds attributes like .occurrence, .sim_index, and .n_sims at runtime, which pyright cannot fully infer. All tests pass, confirming functional correctness.

License

MIT License - see LICENSE file for details.

Contributing

Contributions welcome! Please see CONTRIBUTING.md for guidelines.

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

proteusllp_optimisation_package-0.1.1.tar.gz (59.7 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file proteusllp_optimisation_package-0.1.1.tar.gz.

File metadata

File hashes

Hashes for proteusllp_optimisation_package-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f761069f88fd0b7634056b4c915214754253b1de53313240f97e41ee7ffc7406
MD5 843dc186b65db8dc88a07be3477423d0
BLAKE2b-256 2ae1c874881defd994376ae2ece0c9fff38e44a0b1ae076e2cd19563117d949e

See more details on using hashes here.

Provenance

The following attestation bundles were made for proteusllp_optimisation_package-0.1.1.tar.gz:

Publisher: ci.yaml on ProteusLLP/proteusllp-optimisation-package

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

File details

Details for the file proteusllp_optimisation_package-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for proteusllp_optimisation_package-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 66e47a61558a3be9582cd1f0c27732acb881e88af52f5a0f59777c3380ff290b
MD5 ffc86f1d2f56e8db52b8ded492b09797
BLAKE2b-256 71401d2cf02d4e66b9d1fb6d64a3ee75f1016377763e7ca058f21b12bfa6a780

See more details on using hashes here.

Provenance

The following attestation bundles were made for proteusllp_optimisation_package-0.1.1-py3-none-any.whl:

Publisher: ci.yaml on ProteusLLP/proteusllp-optimisation-package

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