Skip to main content

A Python financial planning toolkit with CEFR calculations, Monte Carlo simulations, and beautiful visualizations

Project description

Financial Health Calculator

A comprehensive Python financial planning toolkit with CEFR calculations, Monte Carlo simulations, and beautiful Plotly visualizations.

Open In Colab

Features

  • CEFR (Certainty-Equivalent Funded Ratio): A fundedness metric that accounts for taxes, liquidity, and concentration risk
  • Monte Carlo Simulations: Project retirement outcomes with configurable market assumptions
  • Withdrawal Strategy Lab: Compare strategies including fixed SWR, guardrails, VPW, and RMD-style
  • Beautiful Visualizations: Interactive Plotly charts with fan charts, waterfalls, and survival curves
  • REST API: FastAPI backend for programmatic access
  • Streamlit App: User-friendly web interface

Quick Start

Installation

pip install git+https://github.com/engineerinvestor/financial-health-calculator.git

For development with all extras:

pip install "git+https://github.com/engineerinvestor/financial-health-calculator.git#egg=fundedness[all]"

Basic Usage

from fundedness import Asset, BalanceSheet, Liability, compute_cefr
from fundedness.models.assets import AccountType, LiquidityClass, ConcentrationLevel

# Define your assets
assets = [
    Asset(
        name="401(k)",
        value=500_000,
        account_type=AccountType.TAX_DEFERRED,
        liquidity_class=LiquidityClass.RETIREMENT,
        concentration_level=ConcentrationLevel.DIVERSIFIED,
    ),
    Asset(
        name="Roth IRA",
        value=200_000,
        account_type=AccountType.TAX_EXEMPT,
        liquidity_class=LiquidityClass.RETIREMENT,
        concentration_level=ConcentrationLevel.DIVERSIFIED,
    ),
]

# Define your spending
liabilities = [
    Liability(name="Living Expenses", annual_amount=50_000, is_essential=True),
    Liability(name="Travel", annual_amount=20_000, is_essential=False),
]

# Calculate CEFR
result = compute_cefr(
    balance_sheet=BalanceSheet(assets=assets),
    liabilities=liabilities,
    planning_horizon=30,
)

print(f"CEFR: {result.cefr:.2f}")
print(f"Funded: {result.is_funded}")
print(result.get_interpretation())

Tutorials

Running the Apps

Streamlit Web App

streamlit run streamlit_app/app.py

FastAPI REST API

uvicorn api.main:app --reload

API documentation available at http://localhost:8000/docs

Key Concepts

CEFR (Certainty-Equivalent Funded Ratio)

CEFR measures how well-funded your retirement is after accounting for:

  • Tax Haircuts: What you'll owe when withdrawing from different account types
  • Liquidity Haircuts: How easily you can access your assets
  • Reliability Haircuts: Risk from concentrated positions

Formula:

CEFR = Σ(Asset × (1-τ) × λ × ρ) / PV(Liabilities)

Where τ = tax rate, λ = liquidity factor, ρ = reliability factor

Interpretation:

  • CEFR ≥ 2.0: Excellent - Very well-funded
  • CEFR 1.5-2.0: Strong - Well-funded with margin
  • CEFR 1.0-1.5: Adequate - Fully funded
  • CEFR < 1.0: Underfunded - Action needed

Withdrawal Strategies

Strategy Description Best For
Fixed SWR 4% of initial portfolio, adjusted for inflation Predictability
% of Portfolio Fixed % of current value Market adaptation
Guardrails Adjustable with floor/ceiling Balance
VPW Age-based variable percentage Maximizing spending
RMD-Style IRS distribution table based Tax efficiency

Development

Setup

git clone https://github.com/engineerinvestor/financial-health-calculator.git
cd financial-health-calculator
pip install -e ".[dev]"

Running Tests

pytest

Code Quality

ruff check .
mypy fundedness

Project Structure

financial-health-calculator/
├── fundedness/           # Core Python package
│   ├── models/           # Pydantic data models
│   ├── viz/              # Plotly visualizations
│   ├── withdrawals/      # Withdrawal strategies
│   ├── allocation/       # Asset allocation strategies
│   ├── cefr.py           # CEFR calculation
│   ├── simulate.py       # Monte Carlo engine
│   └── policies.py       # Spending/allocation policies
├── api/                  # FastAPI REST API
├── streamlit_app/        # Streamlit web application
├── examples/             # Jupyter notebooks
└── tests/                # pytest tests

Contact

License

MIT License

Disclaimer

This tool is for educational purposes only and does not constitute financial advice. Consult a qualified financial advisor for personalized recommendations.

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

fundedness-0.1.0.tar.gz (85.7 kB view details)

Uploaded Source

Built Distribution

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

fundedness-0.1.0-py3-none-any.whl (51.7 kB view details)

Uploaded Python 3

File details

Details for the file fundedness-0.1.0.tar.gz.

File metadata

  • Download URL: fundedness-0.1.0.tar.gz
  • Upload date:
  • Size: 85.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for fundedness-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dd15a2a262faf7730b4a43c3d174c715ba553ea9e9d490b9d33f29955484ab95
MD5 9a5c3f135771682c40351d67360d3e50
BLAKE2b-256 2637c7720076a54d74f6289b1153830dafa37b940d114892a04af7b87669ce5c

See more details on using hashes here.

File details

Details for the file fundedness-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: fundedness-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 51.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for fundedness-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 61fa04081c8b2cfdccabc9ef7e8e06fb96c3bbd76b3328c5a3cc079dfcdf50a4
MD5 51e4b850b9656631ef4f085e38d46699
BLAKE2b-256 e6aaef973d0a361bd349476ea4160bee221cfcacd6349b99d8adac2a50cda28f

See more details on using hashes here.

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