Skip to content

AlexFiliakov/Ergodic-Insurance-Limits

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Ergodic Insurance Limits

Rationalizing and optimizing insurance purchasing decisions.

Repo Banner

This research model applies Ole Peters’ ergodic economics framework to insurance optimization for a widget manufacturing company, demonstrating that traditional expected value approaches systematically mislead insurance decisions. By optimizing time-average growth rates (for a single company) rather than ensemble averages (across many companies), the model aims to demonstrate that insurance premiums can significantly exceed expected losses while still enhancing long-term growth, transforming insurance from a cost center to a growth enabler. The implementation features:

  • A comprehensive Monte Carlo simulation engine with stochastic processes (GBM, mean-reversion)
  • Multi-layer insurance programs with collateral management
  • Extensive configuration architecture
  • CPU-optimized parallel processing

Documentation Status

Introduction - Why Do Companies Buy Insurance?

Ergodic theory transforms insurance optimization fundamentally

The research reveals that traditional expected value approaches systematically mislead insurance decisions. Ole Peters' ergodic economics framework demonstrates that insurance creates win-win scenarios when analyzed through time averages rather than ensemble averages. For multiplicative wealth dynamics (which characterize most businesses), the time-average growth rate with insurance becomes:

$$g = \lim_{T\to\infty}{\frac{1}{T}\ln{\frac{x(T)}{x(0)}}}$$

This framework resolves the fundamental insurance puzzle: while insurance appears zero-sum in expected value terms, both parties benefit when optimizing time-average growth rates. For our widget manufacturing model with $10M starting assets, the hypothesis is that optimal insurance premiums can exceed expected losses by 200-500% while still enhancing long-term growth. This package is being built to validate this hypothesis.

Value Proposition

Ergodic Distinction Between Averages

The framework fundamentally reframes insurance from a cost center to growth enabler. By optimizing time-average growth rates rather than expected values, widget manufacturers can achieve 30-50% better long-term performance while maintaining acceptable ruin probabilities. The key insight: maximizing ergodic growth rates naturally balances profitability with survival, eliminating the need for arbitrary risk preferences or utility functions.

This comprehensive framework provides the mathematical rigor, practical parameters, and implementation roadmap necessary for successful insurance optimization in widget manufacturing, with the ergodic approach offering genuinely novel insights that challenge conventional risk management wisdom.

Key Features

flowchart LR
    %% Simplified Executive View
    INPUT[("πŸ“Š Market Data<br/>& Configuration")]
    BUSINESS[("🏭 Business<br/>Simulation")]
    ERGODIC[("πŸ“ˆ Ergodic<br/>Analysis")]
    OPTIMIZE[("🎯 Strategy<br/>Optimization")]
    OUTPUT[("πŸ“‘ Reports &<br/>Insights")]

    INPUT --> BUSINESS
    BUSINESS --> ERGODIC
    ERGODIC --> OPTIMIZE
    OPTIMIZE --> OUTPUT

    %% Styling
    classDef inputStyle fill:#e3f2fd,stroke:#0d47a1,stroke-width:3px,font-size:14px
    classDef processStyle fill:#f3e5f5,stroke:#4a148c,stroke-width:3px,font-size:14px
    classDef outputStyle fill:#e8f5e9,stroke:#1b5e20,stroke-width:3px,font-size:14px

    class INPUT inputStyle
    class BUSINESS,ERGODIC,OPTIMIZE processStyle
    class OUTPUT outputStyle
Loading

Financial Modeling

  • Widget manufacturer model with comprehensive balance sheet management
  • Stochastic processes including geometric Brownian motion, lognormal volatility, and mean-reversion
  • Insurance claim processing with multi-year payment schedules
  • Collateral management for letter of credit requirements

Configuration Management

  • 3-tier configuration architecture with profiles, modules, and presets
  • ConfigManager with profile inheritance and module composition
  • Runtime overrides for flexible parameter experimentation
  • Preset libraries for common market conditions and risk scenarios

Documentation & Testing

  • Sphinx documentation system for professional API reference
  • Comprehensive Google-style docstrings throughout the codebase
  • 90% test coverage with pytest framework
  • Type safety enforced with mypy static analysis

Analysis Tools

Sample Analytics: Optimal Insurance Configuration by Company Size

  • Performance metrics including ROE, risk of ruin, and time-average growth rates
  • Robust Visualizations and Annotations to help you see the stories behind the results
  • Jupyter notebooks with examples of interactive exploration and visualization
  • Demo scripts showing stochastic vs deterministic comparisons

Enhanced Parallel Processing (v2.0)

  • CPU-optimized parallel executor designed for budget hardware (4-8 cores)
  • Memory efficiency - handles 100K+ simulations in <4GB RAM
  • Smart dynamic chunking that adapts to workload complexity
  • Shared memory management for zero-copy data sharing across processes
  • Near-linear scaling with minimal serialization overhead (<5%)
  • Performance monitoring with detailed metrics and benchmarking tools

Published Results

Installation

Prerequisites

  • Python 3.12 or higher
  • Git

Setup

  1. Clone the repository:
git clone https://github.com/AlexFiliakov/Ergodic-Insurance-Limits.git
cd Ergodic-Insurance-Limits
  1. Install dependencies using uv (recommended) or pip:
# Using uv
uv sync

# Or using pip
pip install -e .
  1. Install pre-commit hooks for code quality:
pre-commit install

Verify Installation

# test_installation.py
from ergodic_insurance.manufacturer import WidgetManufacturer
from ergodic_insurance.claim_generator import ClaimGenerator
from ergodic_insurance.config_v2 import ManufacturerConfig

print("βœ… Framework imported successfully!")

# Create configuration
config = ManufacturerConfig(
    initial_assets=10_000_000,
    asset_turnover_ratio=1.0,
    base_operating_margin=0.08,
    tax_rate=0.25,
    retention_ratio=0.7
)

# Create a simple manufacturer
company = WidgetManufacturer(config)

print(f"βœ… Created company with ${company.assets:,.0f} in assets")
print("πŸŽ‰ Installation successful!")

Exploratory Notebooks

Documentation

See Getting Started for starter examples.

Project Structure

Ergodic-Insurance-Limits/
β”œβ”€β”€ ergodic_insurance/          # Main Python package
β”‚   β”œβ”€β”€ src/                   # Core modules (50+ files)
β”‚   β”‚   β”œβ”€β”€ config_*.py        # Configuration system v2.0 - 3-tier architecture with profiles, modules, and presets
β”‚   β”‚   β”œβ”€β”€ manufacturer.py    # Widget manufacturer financial model with balance sheet management
β”‚   β”‚   β”œβ”€β”€ insurance*.py      # Insurance optimization, pricing, and multi-layer program management
β”‚   β”‚   β”œβ”€β”€ claim_*.py         # Claim generation and multi-year payment development patterns
β”‚   β”‚   β”œβ”€β”€ loss_distributions.py # Statistical loss modeling (lognormal, pareto, etc.)
β”‚   β”‚   β”œβ”€β”€ monte_carlo.py     # Enhanced Monte Carlo simulation engine with parallel processing
β”‚   β”‚   β”œβ”€β”€ ergodic_analyzer.py # Ergodic theory implementation for time-average growth analysis
β”‚   β”‚   β”œβ”€β”€ simulation.py      # Main simulation orchestrator
β”‚   β”‚   β”œβ”€β”€ stochastic_processes.py # GBM, mean-reversion, and volatility models
β”‚   β”‚   β”œβ”€β”€ risk_metrics.py    # VaR, CVaR, tail risk, and ruin probability calculations
β”‚   β”‚   β”œβ”€β”€ optimization.py    # Core optimization algorithms and solvers
β”‚   β”‚   β”œβ”€β”€ business_optimizer.py # Business-specific optimization strategies
β”‚   β”‚   β”œβ”€β”€ decision_engine.py # Decision framework for insurance purchasing
β”‚   β”‚   β”œβ”€β”€ parallel_executor.py # CPU-optimized parallel processing for budget hardware
β”‚   β”‚   β”œβ”€β”€ convergence*.py    # Convergence analysis and advanced stopping criteria
β”‚   β”‚   β”œβ”€β”€ sensitivity*.py    # Sensitivity analysis and visualization tools
β”‚   β”‚   β”œβ”€β”€ bootstrap_analysis.py # Statistical bootstrap methods
β”‚   β”‚   β”œβ”€β”€ validation_metrics.py # Model validation and accuracy metrics
β”‚   β”‚   β”œβ”€β”€ walk_forward_validator.py # Walk-forward validation framework
β”‚   β”‚   β”œβ”€β”€ strategy_backtester.py # Insurance strategy backtesting
β”‚   β”‚   β”œβ”€β”€ result_aggregator.py # Results aggregation and summary statistics
β”‚   β”‚   β”œβ”€β”€ excel_reporter.py  # Excel report generation for business users
β”‚   β”‚   └── visualization*.py  # Comprehensive plotting and visualization utilities
β”‚   β”œβ”€β”€ tests/                 # Test suite with 80%+ coverage
β”‚   β”œβ”€β”€ notebooks/             # Jupyter notebooks for analysis and exploration
β”‚   β”œβ”€β”€ examples/              # Demo scripts showing framework usage
β”‚   β”œβ”€β”€ data/                  # Configuration and parameter files
β”‚   β”‚   └── config/           # 3-tier configuration system
β”‚   β”‚       β”œβ”€β”€ profiles/     # Complete configuration profiles (default, conservative, aggressive)
β”‚   β”‚       β”œβ”€β”€ modules/      # Reusable configuration components
β”‚   β”‚       └── presets/      # Quick-apply market condition templates
β”‚   └── docs/                  # Sphinx documentation with API reference
β”œβ”€β”€ simone/                    # AI project management engine
β”œβ”€β”€ assets/                    # Images, diagrams, and visual resources
β”œβ”€β”€ results/                   # Simulation outputs and analysis reports
β”œβ”€β”€ .github/workflows/         # CI/CD pipelines for docs and testing
β”œβ”€β”€ pyproject.toml            # Python project configuration and dependencies
β”œβ”€β”€ uv.lock                   # Locked dependency versions for reproducibility
β”œβ”€β”€ README.md                 # Project overview and documentation (this file)
β”œβ”€β”€ CLAUDE.md                 # AI assistant development instructions
└── LICENSE                   # MIT open source license

Contributing

See the list of Open Issues for improvement ideas.

Code Quality Tools

This project uses several tools to maintain code quality:

  • Black: Code formatting (line length: 100)
  • isort: Import sorting
  • mypy: Static type checking
  • pylint: Code linting
  • pytest-cov: Test coverage reporting (minimum: 80%)

Running Tests

# Run all tests with coverage
pytest

# Run specific test file
pytest ergodic_insurance/tests/test_manufacturer.py

# Run with coverage report
pytest --cov=ergodic_insurance --cov-report=html

Pre-commit Hooks

Pre-commit hooks run automatically on commit. To run manually:

# Run on all files
pre-commit run --all-files

# Run specific hook
pre-commit run black --all-files

Type Checking

# Run mypy
mypy ergodic_insurance

# Run with specific file
mypy ergodic_insurance/src/manufacturer.py

Code Formatting

# Format with black
black ergodic_insurance

# Sort imports with isort
isort ergodic_insurance

About

Exploring Ergodic Economics to Determine Excess Limit Selection

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •