Skip to main content

portfolio-risk-engine

Reusable portfolio analytics with explicit price, FX, identity, and configuration inputs. The wheel contains only portfolio_risk_engine; it never imports the Risk checkout. portfolio-math is a separate declared library dependency.

Install

pip install portfolio-risk-engine

For a source build, build portfolio_math/ and this directory with python -m build, then install both wheels (the other declared dependencies resolve from PyPI).

Public API

from portfolio_risk_engine import (
    build_portfolio_view,
    normalize_weights,
    calculate_portfolio_performance_metrics,
    PriceProvider,
    FXProvider,
    set_price_provider,
    get_price_provider,
    set_fx_provider,
    get_fx_provider,
)

The engine covers portfolio risk, performance, optimization, efficient frontiers, Monte Carlo, stress/scenario analysis, factors, income, and allocation drift. Applications provide the data needed by the analytics they invoke; a missing provider raises an explicit configuration error rather than importing a default application.

Quick start: deterministic portfolio risk

This complete example runs without credentials, network data, or the Risk checkout. The fixture supplies month-end prices; replace it with your own PriceProvider for market data. The five symbols and prices are illustrative inputs, not live quotes.

import numpy as np
import pandas as pd
from portfolio_risk_engine import build_portfolio_view, set_price_provider

weights = {"AAPL": 0.30, "MSFT": 0.25, "GOOGL": 0.20, "IEF": 0.15, "GLD": 0.10}
index = pd.date_range("2020-01-31", "2024-12-31", freq="ME")
prices = pd.DataFrame({
    ticker: 100 * np.cumprod(1 + 0.005 + 0.02 * np.sin(np.arange(len(index)) + offset))
    for offset, ticker in enumerate(weights)
}, index=index)

class FramePrices:
    def fetch_monthly_close(self, ticker, start_date=None, end_date=None, **kwargs):
        return prices[ticker].loc[start_date:end_date]

    def fetch_monthly_total_return_price(self, ticker, start_date=None, end_date=None, **kwargs):
        return prices[ticker].loc[start_date:end_date]

set_price_provider(FramePrices())
result = build_portfolio_view(
    weights=weights,
    start_date="2020-01-01",
    end_date="2024-12-31",
    currency_map={ticker: "USD" for ticker in weights},
    instrument_types={"AAPL": "equity", "MSFT": "equity", "GOOGL": "equity", "IEF": "etf", "GLD": "etf"},
)
print("observations:", result["return_observation_count"])
print("annual volatility:", round(result["volatility_annual"], 12))
print("risk contributions:", result["risk_contributions"].round(12).to_dict())

Provider and policy integration

portfolio_risk_engine.providers owns the price/FX/currency ports and the optional instrument-chain/metadata registry input. Configure providers with set_price_provider, set_fx_provider, set_currency_resolver, and set_provider_registry. Derivative history and latest-futures pricing are supplied by the configured price provider; option chains retain their observed/theoretical policy and explicit contract identity.

portfolio_risk_engine.config.configure binds application policy: CASH_MAP, CONFIG_PATH_RESOLVER, CONTRACT_SPEC_LOADER, POSITION_IDENTITY_RESOLVER, LISTED_INSTRUMENT_TYPE_RESOLVER, and optional RESULT_FACTORIES, alongside the analytics settings. Library position identities are canonical projected mappings; legacy/persisted-row decoding belongs to the application. Configure before importing calculation modules that consume scalar settings.

The single alias precedence algorithm is portfolio_risk_engine._ticker.resolve_ticker_alias: explicit alias, caller resolver/map, reviewed alias data, then the normalized symbol. Pass reviewed aliases as reviewed_aliases; the engine does not load application YAML. Explicit futures, derivative, or option kind excludes reviewed equity aliases and preserves an unaliased contract symbol. Explicit per-position/map aliases still apply. No kind is inferred from ticker spelling.

Risk application boundary

Risk's settings.py explicitly calls providers.engine.configure_engine to install its configuration and adapters. providers/engine_fmp.py is application code, not part of this wheel. core/ and services/ orchestrate application workflows; the engine owns reusable calculations, coverage, canonical metadata, cash mechanics, quality contracts, price requests, and risk-limit evaluation. Applications may supply result factories to build their own rich response types; standalone calls return library payload objects with to_api_response().

License

Proprietary. All rights reserved. See the LICENSE file at the repository root.

Metadata

Release files for portfolio-risk-engine 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for portfolio-risk-engine 0.3.0
File Size Uploaded Provenance
portfolio_risk_engine-0.3.0.tar.gz 189.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for portfolio-risk-engine 0.3.0
File Interpreter ABI Platform
portfolio_risk_engine-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 420.8 kB

Release files / portfolio_risk_engine-0.3.0.tar.gz

Download URL portfolio_risk_engine-0.3.0.tar.gz
Size 189.3 kB
Tags Source
SHA-256 checksum
How to use checksums
48bb7128a865176f15579b80ea3b35a20ece331599fc91f83a1800f03694c31c
BLAKE2b-256 checksum
How to use checksums
bbe8e8e4524dbc475d578dc9f857144c155bd64b63e3e532fb28c82a868b3cfa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Release files / portfolio_risk_engine-0.3.0-py3-none-any.whl

Download URL portfolio_risk_engine-0.3.0-py3-none-any.whl
Size 231.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d829ce4b24bd38f9f86202c280495851544d4db62386b128d470ad617ce7bf72
BLAKE2b-256 checksum
How to use checksums
505e51b4924aa8782a87eed4be9e654317ff0a1277ba5f06e1f069a90b99ce26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Security for portfolio-risk-engine 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page