Skip to main content

RiskLabs

Decision-Risk & Robustness Simulator by Allostan Labs

RiskLabs is a Python library designed to help quantitative researchers and portfolio managers evaluate the robustness of their strategies. It goes beyond simple backtesting by subjecting strategies to various "flight path" scenarios, such as historical crashes, volatility spikes, and correlation breakdowns.

Features

  • Scenario Analysis: Simulate strategies under stress conditions (e.g., 2008 Crash, COVID-19 Volatility).
  • Robustness Metrics: Calculate specialized scores based on performance stability across regimes.
  • Regime Detection: Analyze strategy behavior in Bull vs. Bear markets.
  • HTML Reporting: Generate beautiful, standalone HTML dashboards with interactive charts.
  • Privacy-First: Runs entirely locally. No data leaves your machine.

Installation

pip install risklabs

Quick Start

from risklabs.client import create_strategy, analyze

# 1. Define a Strategy
strategy = create_strategy(
    name="My 60/40 Portfolio",
    allocations=[
        {"ticker": "SPY", "weight": 0.6},
        {"ticker": "AGG", "weight": 0.4}
    ]
)

# 2. Run Robustness Analysis
print("Running simulations...")
report = analyze(strategy)

# 3. Generate Report
report.to_file("my_portfolio_report.html")
print("Report generated: my_portfolio_report.html")

Running the Demo

We include a demo simulation script to showcase the library's capabilities:

# Ensure you are in the risklabs directory
python demo_generic.py

This will generate a sample robustness report showing stress tests and regime analysis.

How It Works

  1. Define Strategy: You specify target allocations (static weights for MVP).
  2. Fetch Data: The library automatically downloads historical data for the tickers using yfinance.
  3. Simulate Scenarios: The engine runs multiple simulations:
    • Historical Baseline: Standard backtest.
    • Crash Replay: Applies historical shock factors.
    • Regime Stress: Modifies volatility and correlation matrices.
  4. Score & Report: Aggregates results into a "Robustness Score" and renders an HTML dashboard.

Architecture & Methodology

RiskLabs is designed as a modular pipeline to ensure rigorous stress testing:

  1. Client Layer (risklabs.client):
    • The entry point for users. Accepts a concise human-readable Strategy definition and orchestrates the analysis.
  2. Simulation Engine (risklabs.engine):
    • The core "brain" of the system. It doesn't just run a single backtest; it executes a battery of tests including Historical Replays (e.g., 2008 Crisis), Monte Carlo Perturbations (Fragility), and Parameter Sweeps (Sensitivity).
  3. Analyzers:
    • RegimeDetectionEngine: Classifies market history into 4 regimes (Bull/Bear x High/Low Vol).
    • FragilityAnalyzer: Tests "what if my weights were slightly different?" to catch overfitting.
    • DecisionEngine: Aggregates all metrics into a final Confidence Rating and Recommendation (APPROVE/REJECT).
  4. Reporting (risklabs.reporting):
    • Compiles the rich data into an interactive, standalone HTML dashboard with no external dependencies.

License

MIT

Metadata

Release files for risklabs 0.2.4

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

Source distribution (sdist)

Source distribution for risklabs 0.2.4
File Size Uploaded
risklabs-0.2.4.tar.gz 49.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for risklabs 0.2.4
File Interpreter ABI Platform
risklabs-0.2.4-py3-none-any.whl Python 3 none any Details

Total release size: 72.5 kB

Release files / risklabs-0.2.4.tar.gz

Download URL risklabs-0.2.4.tar.gz
Size 49.4 kB
Tags Source
SHA-256 checksum
How to use checksums
63a04ff54106974d0dad4b090f5b23ec13f252ff9ae0d4308134344d57d796e2
BLAKE2b-256 checksum
How to use checksums
04a0406bf8544d07dc972705bd8f0873107d84eeddda8afc503e7c7a6b8d50c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.2

Release files / risklabs-0.2.4-py3-none-any.whl

Download URL risklabs-0.2.4-py3-none-any.whl
Size 23.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
569186b113d6190597e1c6fec8b6d304490f811e542181c85b88530adf017838
BLAKE2b-256 checksum
How to use checksums
5aecacfd867b3868cc5097a830eaae19b54f45f32df260798dcdb29e5faac04b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.2

Release history Release notifications | RSS feed

This release

0.2.4 This release

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

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