fundedness 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of fundedness might be problematic. Click here for more details.

Files changed (85) hide show
  1. fundedness-0.1.0/.github/workflows/docs.yml +36 -0
  2. fundedness-0.1.0/.github/workflows/publish.yml +28 -0
  3. fundedness-0.1.0/.gitignore +106 -0
  4. fundedness-0.1.0/CLAUDE.md +98 -0
  5. fundedness-0.1.0/PKG-INFO +233 -0
  6. fundedness-0.1.0/README.md +179 -0
  7. fundedness-0.1.0/api/__init__.py +1 -0
  8. fundedness-0.1.0/api/main.py +54 -0
  9. fundedness-0.1.0/api/routes/__init__.py +1 -0
  10. fundedness-0.1.0/api/routes/cefr.py +201 -0
  11. fundedness-0.1.0/api/routes/compare.py +154 -0
  12. fundedness-0.1.0/api/routes/simulate.py +145 -0
  13. fundedness-0.1.0/background_information.md +927 -0
  14. fundedness-0.1.0/docs/api/core.md +15 -0
  15. fundedness-0.1.0/docs/api/models.md +31 -0
  16. fundedness-0.1.0/docs/api/viz.md +29 -0
  17. fundedness-0.1.0/docs/api/withdrawals.md +27 -0
  18. fundedness-0.1.0/docs/examples/tutorials.md +112 -0
  19. fundedness-0.1.0/docs/getting-started/installation.md +81 -0
  20. fundedness-0.1.0/docs/getting-started/quickstart.md +94 -0
  21. fundedness-0.1.0/docs/guide/cefr.md +102 -0
  22. fundedness-0.1.0/docs/guide/simulations.md +120 -0
  23. fundedness-0.1.0/docs/guide/visualizations.md +144 -0
  24. fundedness-0.1.0/docs/guide/withdrawals.md +149 -0
  25. fundedness-0.1.0/docs/index.md +73 -0
  26. fundedness-0.1.0/examples/01_cefr_basics.ipynb +298 -0
  27. fundedness-0.1.0/examples/02_time_distribution.ipynb +341 -0
  28. fundedness-0.1.0/examples/03_withdrawal_comparison.ipynb +353 -0
  29. fundedness-0.1.0/fundedness/__init__.py +38 -0
  30. fundedness-0.1.0/fundedness/allocation/__init__.py +12 -0
  31. fundedness-0.1.0/fundedness/allocation/base.py +32 -0
  32. fundedness-0.1.0/fundedness/allocation/constant.py +25 -0
  33. fundedness-0.1.0/fundedness/allocation/glidepath.py +111 -0
  34. fundedness-0.1.0/fundedness/cefr.py +241 -0
  35. fundedness-0.1.0/fundedness/liabilities.py +221 -0
  36. fundedness-0.1.0/fundedness/liquidity.py +49 -0
  37. fundedness-0.1.0/fundedness/models/__init__.py +35 -0
  38. fundedness-0.1.0/fundedness/models/assets.py +148 -0
  39. fundedness-0.1.0/fundedness/models/household.py +153 -0
  40. fundedness-0.1.0/fundedness/models/liabilities.py +99 -0
  41. fundedness-0.1.0/fundedness/models/market.py +188 -0
  42. fundedness-0.1.0/fundedness/models/simulation.py +80 -0
  43. fundedness-0.1.0/fundedness/models/tax.py +125 -0
  44. fundedness-0.1.0/fundedness/models/utility.py +154 -0
  45. fundedness-0.1.0/fundedness/policies.py +204 -0
  46. fundedness-0.1.0/fundedness/risk.py +72 -0
  47. fundedness-0.1.0/fundedness/simulate.py +401 -0
  48. fundedness-0.1.0/fundedness/viz/__init__.py +19 -0
  49. fundedness-0.1.0/fundedness/viz/colors.py +110 -0
  50. fundedness-0.1.0/fundedness/viz/comparison.py +294 -0
  51. fundedness-0.1.0/fundedness/viz/fan_chart.py +193 -0
  52. fundedness-0.1.0/fundedness/viz/histogram.py +225 -0
  53. fundedness-0.1.0/fundedness/viz/survival.py +230 -0
  54. fundedness-0.1.0/fundedness/viz/tornado.py +236 -0
  55. fundedness-0.1.0/fundedness/viz/waterfall.py +203 -0
  56. fundedness-0.1.0/fundedness/withdrawals/__init__.py +19 -0
  57. fundedness-0.1.0/fundedness/withdrawals/base.py +116 -0
  58. fundedness-0.1.0/fundedness/withdrawals/comparison.py +230 -0
  59. fundedness-0.1.0/fundedness/withdrawals/fixed_swr.py +113 -0
  60. fundedness-0.1.0/fundedness/withdrawals/guardrails.py +136 -0
  61. fundedness-0.1.0/fundedness/withdrawals/rmd_style.py +203 -0
  62. fundedness-0.1.0/fundedness/withdrawals/vpw.py +136 -0
  63. fundedness-0.1.0/mkdocs.yml +49 -0
  64. fundedness-0.1.0/pyproject.toml +96 -0
  65. fundedness-0.1.0/requirements.txt +7 -0
  66. fundedness-0.1.0/streamlit_app/__init__.py +1 -0
  67. fundedness-0.1.0/streamlit_app/app.py +104 -0
  68. fundedness-0.1.0/streamlit_app/components/__init__.py +1 -0
  69. fundedness-0.1.0/streamlit_app/components/asset_editor.py +124 -0
  70. fundedness-0.1.0/streamlit_app/components/liability_editor.py +117 -0
  71. fundedness-0.1.0/streamlit_app/components/metrics_display.py +144 -0
  72. fundedness-0.1.0/streamlit_app/pages/0_Inputs.py +242 -0
  73. fundedness-0.1.0/streamlit_app/pages/1_CEFR_Dashboard.py +112 -0
  74. fundedness-0.1.0/streamlit_app/pages/2_Time_Runway.py +219 -0
  75. fundedness-0.1.0/streamlit_app/pages/3_Withdrawal_Lab.py +225 -0
  76. fundedness-0.1.0/streamlit_app/pages/4_Sensitivity.py +305 -0
  77. fundedness-0.1.0/streamlit_app/utils/__init__.py +21 -0
  78. fundedness-0.1.0/streamlit_app/utils/session_state.py +160 -0
  79. fundedness-0.1.0/tests/__init__.py +1 -0
  80. fundedness-0.1.0/tests/conftest.py +119 -0
  81. fundedness-0.1.0/tests/test_api.py +179 -0
  82. fundedness-0.1.0/tests/test_cefr.py +294 -0
  83. fundedness-0.1.0/tests/test_liabilities.py +239 -0
  84. fundedness-0.1.0/tests/test_simulate.py +242 -0
  85. fundedness-0.1.0/tests/test_withdrawals.py +275 -0
@@ -0,0 +1,36 @@
1
+ name: Deploy Documentation
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ workflow_dispatch:
7
+
8
+ permissions:
9
+ contents: read
10
+ pages: write
11
+ id-token: write
12
+
13
+ jobs:
14
+ build:
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+ - uses: actions/setup-python@v5
19
+ with:
20
+ python-version: '3.11'
21
+ - run: pip install mkdocs mkdocs-material mkdocstrings[python]
22
+ - run: pip install -e .
23
+ - run: mkdocs build
24
+ - uses: actions/upload-pages-artifact@v3
25
+ with:
26
+ path: site
27
+
28
+ deploy:
29
+ needs: build
30
+ runs-on: ubuntu-latest
31
+ environment:
32
+ name: github-pages
33
+ url: ${{ steps.deployment.outputs.page_url }}
34
+ steps:
35
+ - uses: actions/deploy-pages@v4
36
+ id: deployment
@@ -0,0 +1,28 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+ workflow_dispatch: # Allow manual trigger
7
+
8
+ jobs:
9
+ publish:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+
14
+ - uses: actions/setup-python@v5
15
+ with:
16
+ python-version: '3.11'
17
+
18
+ - name: Install build tools
19
+ run: pip install build twine
20
+
21
+ - name: Build package
22
+ run: python -m build
23
+
24
+ - name: Publish to PyPI
25
+ env:
26
+ TWINE_USERNAME: __token__
27
+ TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
28
+ run: twine upload dist/*
@@ -0,0 +1,106 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ *.manifest
31
+ *.spec
32
+
33
+ # Installer logs
34
+ pip-log.txt
35
+ pip-delete-this-directory.txt
36
+
37
+ # Unit test / coverage reports
38
+ htmlcov/
39
+ .tox/
40
+ .nox/
41
+ .coverage
42
+ .coverage.*
43
+ .cache
44
+ nosetests.xml
45
+ coverage.xml
46
+ *.cover
47
+ *.py,cover
48
+ .hypothesis/
49
+ .pytest_cache/
50
+
51
+ # Translations
52
+ *.mo
53
+ *.pot
54
+
55
+ # Jupyter Notebook
56
+ .ipynb_checkpoints
57
+
58
+ # IPython
59
+ profile_default/
60
+ ipython_config.py
61
+
62
+ # pyenv
63
+ .python-version
64
+
65
+ # Environments
66
+ .env
67
+ .venv
68
+ env/
69
+ venv/
70
+ ENV/
71
+ env.bak/
72
+ venv.bak/
73
+
74
+ # Spyder project settings
75
+ .spyderproject
76
+ .spyproject
77
+
78
+ # Rope project settings
79
+ .ropeproject
80
+
81
+ # mkdocs documentation
82
+ /site
83
+
84
+ # mypy
85
+ .mypy_cache/
86
+ .dmypy.json
87
+ dmypy.json
88
+
89
+ # Pyre type checker
90
+ .pyre/
91
+
92
+ # IDE
93
+ .idea/
94
+ .vscode/
95
+ *.swp
96
+ *.swo
97
+ *~
98
+
99
+ # OS
100
+ .DS_Store
101
+ Thumbs.db
102
+
103
+ # Project specific
104
+ *.log
105
+ secrets.yaml
106
+ config.local.yaml
@@ -0,0 +1,98 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Project Overview
6
+
7
+ This is a Python financial planning toolkit that implements:
8
+ - **CEFR (Certainty-Equivalent Funded Ratio)**: A fundedness metric that applies after-tax, liquidity, and risk haircuts to assets
9
+ - **Victor-style lifetime utility optimization**: Spending and asset allocation policies that maximize expected lifetime utility
10
+ - **Withdrawal Strategy Lab**: Comparison framework for withdrawal strategies (fixed SWR, guardrails, VPW, RMD-style)
11
+
12
+ The project includes both a Python package (`fundedness/`) and a Streamlit web application (`streamlit_app/`).
13
+
14
+ ## Development Status
15
+
16
+ This project is in the **specification/planning phase**. The `background_information.md` file contains the complete design spec. No implementation code exists yet.
17
+
18
+ ## Planned Commands
19
+
20
+ Once implemented, the project will use:
21
+ - **Package manager**: pip
22
+ - **Testing**: pytest (with property tests for monotonicity)
23
+ - **Docs**: MkDocs
24
+ - **CLI**: `fundedness cefr config.yaml`, `fundedness simulate config.yaml`, `fundedness policy-search config.yaml`
25
+ - **Streamlit**: `streamlit run streamlit_app/app.py`
26
+
27
+ ## Architecture
28
+
29
+ ### Core Package Structure (`fundedness/`)
30
+
31
+ ```
32
+ fundedness/
33
+ ├── cefr.py # CEFR ratio calculation with haircut breakdowns
34
+ ├── liabilities.py # Liability PV calculations with schedules
35
+ ├── taxes.py # Tax modeling by account type
36
+ ├── liquidity.py # Liquidity factor adjustments
37
+ ├── risk.py # Reliability/concentration haircuts
38
+ ├── markets.py # Return/covariance/inflation assumptions
39
+ ├── simulate.py # Monte Carlo engine (time-to-floor, time-to-ruin)
40
+ ├── utility.py # CRRA utility with subsistence floor
41
+ ├── policies.py # Spending/allocation policy interface
42
+ ├── optimize.py # Parametric policy search (v0.4+)
43
+ ├── withdrawals/ # Withdrawal strategy implementations
44
+ ├── allocation/ # Glidepath strategies (constant, rising equity, bucket)
45
+ └── tax/strategy.py # Tax-aware withdrawal sequencing
46
+ ```
47
+
48
+ ### Data Models (Pydantic)
49
+
50
+ Key models: `Household`, `BalanceSheet`, `Asset`, `Liability`, `MarketModel`, `TaxModel`, `UtilityModel`, `SimulationConfig`
51
+
52
+ ### Core Formulas
53
+
54
+ **CEFR Calculation:**
55
+ ```
56
+ CEFR = Σ(Asset × (1-tax_rate) × liquidity_factor × reliability_factor) / PV(Liabilities)
57
+ ```
58
+
59
+ **CRRA Utility with Floor:**
60
+ ```
61
+ u(C) = (C - F)^(1-γ) / (1-γ) where C > F (subsistence floor)
62
+ ```
63
+
64
+ ## Development Tiers
65
+
66
+ 1. **MVP (v0.1-0.3)**: CEFR + Monte Carlo runway with P10/P50/P90 bands
67
+ 2. **v0.4-0.7**: Victor-style parametric policy search
68
+ 3. **v1.0+**: Tax-aware account flows, Roth conversions
69
+
70
+ ## Key Concepts
71
+
72
+ - **Haircuts**: Three adjustments to assets—after-tax (τ), liquidity (λ), reliability (ρ)
73
+ - **Floor/Flex spending**: Essential spending floor vs adjustable discretionary
74
+ - **Time metrics**: Time-to-floor-breach, time-to-ruin, max spending drawdown
75
+ - **Confidence intervals**: Scenario percentiles (P10/P50/P90), not statistical CIs
76
+
77
+ ## Default Haircut Assumptions
78
+
79
+ Liquidity: cash=1.0, taxable_index=0.95, retirement=0.85, home_equity=0.5, private_business=0.3
80
+ Reliability: diversified_bonds=0.95, diversified_equity=0.85, single_stock=0.60, startup=0.30
81
+
82
+ ## Deployment Preferences
83
+
84
+ - **Web App**: Deploy on Streamlit Cloud (free tier)
85
+ - **API**: Expose core functionality via a REST API (FastAPI recommended) for programmatic access
86
+ - **Tutorials**: Create Jupyter notebooks in `examples/` that run in Google Colab. Include working "Open in Colab" badge links in the README using the format:
87
+ ```
88
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/engineerinvestor/financial-health-calculator/blob/main/examples/NOTEBOOK.ipynb)
89
+ ```
90
+
91
+ ## Visualization Standards
92
+
93
+ Use **Plotly** as the primary visualization library for beautiful, interactive charts:
94
+ - Clean, professional appearance with `template="plotly_white"`
95
+ - Interactive features: hover tooltips, zoom, pan
96
+ - Consistent color palette: blues (#3498db, #2980b9) for wealth, greens (#27ae60, #2ecc71) for spending/survival
97
+ - Fan charts with gradient opacity for percentile bands (P10-P90)
98
+ - Export capability to HTML/PNG for reports
@@ -0,0 +1,233 @@
1
+ Metadata-Version: 2.4
2
+ Name: fundedness
3
+ Version: 0.1.0
4
+ Summary: A Python financial planning toolkit with CEFR calculations, Monte Carlo simulations, and beautiful visualizations
5
+ Project-URL: Homepage, https://github.com/engineerinvestor/financial-health-calculator
6
+ Project-URL: Documentation, https://engineerinvestor.github.io/financial-health-calculator/
7
+ Project-URL: Repository, https://github.com/engineerinvestor/financial-health-calculator
8
+ Author-email: Engineer Investor <egr.investor@gmail.com>
9
+ License-Expression: MIT
10
+ Keywords: CEFR,Monte Carlo,finance,planning,retirement,withdrawal
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: End Users/Desktop
13
+ Classifier: Intended Audience :: Financial and Insurance Industry
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Office/Business :: Financial :: Investment
20
+ Requires-Python: >=3.10
21
+ Requires-Dist: numpy>=1.24.0
22
+ Requires-Dist: pandas>=2.0.0
23
+ Requires-Dist: plotly>=5.18.0
24
+ Requires-Dist: pydantic>=2.0.0
25
+ Requires-Dist: scipy>=1.11.0
26
+ Provides-Extra: all
27
+ Requires-Dist: fastapi>=0.108.0; extra == 'all'
28
+ Requires-Dist: hypothesis>=6.92.0; extra == 'all'
29
+ Requires-Dist: mkdocs-material>=9.5.0; extra == 'all'
30
+ Requires-Dist: mkdocs>=1.5.0; extra == 'all'
31
+ Requires-Dist: mkdocstrings[python]>=0.24.0; extra == 'all'
32
+ Requires-Dist: mypy>=1.8.0; extra == 'all'
33
+ Requires-Dist: pytest-cov>=4.1.0; extra == 'all'
34
+ Requires-Dist: pytest>=7.4.0; extra == 'all'
35
+ Requires-Dist: ruff>=0.1.9; extra == 'all'
36
+ Requires-Dist: streamlit>=1.29.0; extra == 'all'
37
+ Requires-Dist: uvicorn[standard]>=0.25.0; extra == 'all'
38
+ Provides-Extra: api
39
+ Requires-Dist: fastapi>=0.108.0; extra == 'api'
40
+ Requires-Dist: uvicorn[standard]>=0.25.0; extra == 'api'
41
+ Provides-Extra: dev
42
+ Requires-Dist: hypothesis>=6.92.0; extra == 'dev'
43
+ Requires-Dist: mypy>=1.8.0; extra == 'dev'
44
+ Requires-Dist: pytest-cov>=4.1.0; extra == 'dev'
45
+ Requires-Dist: pytest>=7.4.0; extra == 'dev'
46
+ Requires-Dist: ruff>=0.1.9; extra == 'dev'
47
+ Provides-Extra: docs
48
+ Requires-Dist: mkdocs-material>=9.5.0; extra == 'docs'
49
+ Requires-Dist: mkdocs>=1.5.0; extra == 'docs'
50
+ Requires-Dist: mkdocstrings[python]>=0.24.0; extra == 'docs'
51
+ Provides-Extra: streamlit
52
+ Requires-Dist: streamlit>=1.29.0; extra == 'streamlit'
53
+ Description-Content-Type: text/markdown
54
+
55
+ # Financial Health Calculator
56
+
57
+ A comprehensive Python financial planning toolkit with CEFR calculations, Monte Carlo simulations, and beautiful Plotly visualizations.
58
+
59
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/engineerinvestor/financial-health-calculator/blob/main/examples/01_cefr_basics.ipynb)
60
+
61
+ ## Features
62
+
63
+ - **CEFR (Certainty-Equivalent Funded Ratio)**: A fundedness metric that accounts for taxes, liquidity, and concentration risk
64
+ - **Monte Carlo Simulations**: Project retirement outcomes with configurable market assumptions
65
+ - **Withdrawal Strategy Lab**: Compare strategies including fixed SWR, guardrails, VPW, and RMD-style
66
+ - **Beautiful Visualizations**: Interactive Plotly charts with fan charts, waterfalls, and survival curves
67
+ - **REST API**: FastAPI backend for programmatic access
68
+ - **Streamlit App**: User-friendly web interface
69
+
70
+ ## Quick Start
71
+
72
+ ### Installation
73
+
74
+ ```bash
75
+ pip install git+https://github.com/engineerinvestor/financial-health-calculator.git
76
+ ```
77
+
78
+ For development with all extras:
79
+ ```bash
80
+ pip install "git+https://github.com/engineerinvestor/financial-health-calculator.git#egg=fundedness[all]"
81
+ ```
82
+
83
+ ### Basic Usage
84
+
85
+ ```python
86
+ from fundedness import Asset, BalanceSheet, Liability, compute_cefr
87
+ from fundedness.models.assets import AccountType, LiquidityClass, ConcentrationLevel
88
+
89
+ # Define your assets
90
+ assets = [
91
+ Asset(
92
+ name="401(k)",
93
+ value=500_000,
94
+ account_type=AccountType.TAX_DEFERRED,
95
+ liquidity_class=LiquidityClass.RETIREMENT,
96
+ concentration_level=ConcentrationLevel.DIVERSIFIED,
97
+ ),
98
+ Asset(
99
+ name="Roth IRA",
100
+ value=200_000,
101
+ account_type=AccountType.TAX_EXEMPT,
102
+ liquidity_class=LiquidityClass.RETIREMENT,
103
+ concentration_level=ConcentrationLevel.DIVERSIFIED,
104
+ ),
105
+ ]
106
+
107
+ # Define your spending
108
+ liabilities = [
109
+ Liability(name="Living Expenses", annual_amount=50_000, is_essential=True),
110
+ Liability(name="Travel", annual_amount=20_000, is_essential=False),
111
+ ]
112
+
113
+ # Calculate CEFR
114
+ result = compute_cefr(
115
+ balance_sheet=BalanceSheet(assets=assets),
116
+ liabilities=liabilities,
117
+ planning_horizon=30,
118
+ )
119
+
120
+ print(f"CEFR: {result.cefr:.2f}")
121
+ print(f"Funded: {result.is_funded}")
122
+ print(result.get_interpretation())
123
+ ```
124
+
125
+ ## Tutorials
126
+
127
+ - [CEFR Basics](https://colab.research.google.com/github/engineerinvestor/financial-health-calculator/blob/main/examples/01_cefr_basics.ipynb) - Introduction to the CEFR metric
128
+ - [Time Distribution Analysis](https://colab.research.google.com/github/engineerinvestor/financial-health-calculator/blob/main/examples/02_time_distribution.ipynb) - Monte Carlo simulations
129
+ - [Withdrawal Strategy Comparison](https://colab.research.google.com/github/engineerinvestor/financial-health-calculator/blob/main/examples/03_withdrawal_comparison.ipynb) - Compare different approaches
130
+
131
+ ## Running the Apps
132
+
133
+ ### Streamlit Web App
134
+
135
+ ```bash
136
+ streamlit run streamlit_app/app.py
137
+ ```
138
+
139
+ ### FastAPI REST API
140
+
141
+ ```bash
142
+ uvicorn api.main:app --reload
143
+ ```
144
+
145
+ API documentation available at `http://localhost:8000/docs`
146
+
147
+ ## Key Concepts
148
+
149
+ ### CEFR (Certainty-Equivalent Funded Ratio)
150
+
151
+ CEFR measures how well-funded your retirement is after accounting for:
152
+
153
+ - **Tax Haircuts**: What you'll owe when withdrawing from different account types
154
+ - **Liquidity Haircuts**: How easily you can access your assets
155
+ - **Reliability Haircuts**: Risk from concentrated positions
156
+
157
+ **Formula:**
158
+ ```
159
+ CEFR = Σ(Asset × (1-τ) × λ × ρ) / PV(Liabilities)
160
+ ```
161
+
162
+ Where τ = tax rate, λ = liquidity factor, ρ = reliability factor
163
+
164
+ **Interpretation:**
165
+ - CEFR ≥ 2.0: Excellent - Very well-funded
166
+ - CEFR 1.5-2.0: Strong - Well-funded with margin
167
+ - CEFR 1.0-1.5: Adequate - Fully funded
168
+ - CEFR < 1.0: Underfunded - Action needed
169
+
170
+ ### Withdrawal Strategies
171
+
172
+ | Strategy | Description | Best For |
173
+ |----------|-------------|----------|
174
+ | Fixed SWR | 4% of initial portfolio, adjusted for inflation | Predictability |
175
+ | % of Portfolio | Fixed % of current value | Market adaptation |
176
+ | Guardrails | Adjustable with floor/ceiling | Balance |
177
+ | VPW | Age-based variable percentage | Maximizing spending |
178
+ | RMD-Style | IRS distribution table based | Tax efficiency |
179
+
180
+ ## Development
181
+
182
+ ### Setup
183
+
184
+ ```bash
185
+ git clone https://github.com/engineerinvestor/financial-health-calculator.git
186
+ cd financial-health-calculator
187
+ pip install -e ".[dev]"
188
+ ```
189
+
190
+ ### Running Tests
191
+
192
+ ```bash
193
+ pytest
194
+ ```
195
+
196
+ ### Code Quality
197
+
198
+ ```bash
199
+ ruff check .
200
+ mypy fundedness
201
+ ```
202
+
203
+ ## Project Structure
204
+
205
+ ```
206
+ financial-health-calculator/
207
+ ├── fundedness/ # Core Python package
208
+ │ ├── models/ # Pydantic data models
209
+ │ ├── viz/ # Plotly visualizations
210
+ │ ├── withdrawals/ # Withdrawal strategies
211
+ │ ├── allocation/ # Asset allocation strategies
212
+ │ ├── cefr.py # CEFR calculation
213
+ │ ├── simulate.py # Monte Carlo engine
214
+ │ └── policies.py # Spending/allocation policies
215
+ ├── api/ # FastAPI REST API
216
+ ├── streamlit_app/ # Streamlit web application
217
+ ├── examples/ # Jupyter notebooks
218
+ └── tests/ # pytest tests
219
+ ```
220
+
221
+ ## Contact
222
+
223
+ - Twitter: [@egr_investor](https://x.com/egr_investor)
224
+ - GitHub: [engineerinvestor](https://github.com/engineerinvestor)
225
+ - Email: egr.investor@gmail.com
226
+
227
+ ## License
228
+
229
+ MIT License
230
+
231
+ ## Disclaimer
232
+
233
+ This tool is for educational purposes only and does not constitute financial advice. Consult a qualified financial advisor for personalized recommendations.
@@ -0,0 +1,179 @@
1
+ # Financial Health Calculator
2
+
3
+ A comprehensive Python financial planning toolkit with CEFR calculations, Monte Carlo simulations, and beautiful Plotly visualizations.
4
+
5
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/engineerinvestor/financial-health-calculator/blob/main/examples/01_cefr_basics.ipynb)
6
+
7
+ ## Features
8
+
9
+ - **CEFR (Certainty-Equivalent Funded Ratio)**: A fundedness metric that accounts for taxes, liquidity, and concentration risk
10
+ - **Monte Carlo Simulations**: Project retirement outcomes with configurable market assumptions
11
+ - **Withdrawal Strategy Lab**: Compare strategies including fixed SWR, guardrails, VPW, and RMD-style
12
+ - **Beautiful Visualizations**: Interactive Plotly charts with fan charts, waterfalls, and survival curves
13
+ - **REST API**: FastAPI backend for programmatic access
14
+ - **Streamlit App**: User-friendly web interface
15
+
16
+ ## Quick Start
17
+
18
+ ### Installation
19
+
20
+ ```bash
21
+ pip install git+https://github.com/engineerinvestor/financial-health-calculator.git
22
+ ```
23
+
24
+ For development with all extras:
25
+ ```bash
26
+ pip install "git+https://github.com/engineerinvestor/financial-health-calculator.git#egg=fundedness[all]"
27
+ ```
28
+
29
+ ### Basic Usage
30
+
31
+ ```python
32
+ from fundedness import Asset, BalanceSheet, Liability, compute_cefr
33
+ from fundedness.models.assets import AccountType, LiquidityClass, ConcentrationLevel
34
+
35
+ # Define your assets
36
+ assets = [
37
+ Asset(
38
+ name="401(k)",
39
+ value=500_000,
40
+ account_type=AccountType.TAX_DEFERRED,
41
+ liquidity_class=LiquidityClass.RETIREMENT,
42
+ concentration_level=ConcentrationLevel.DIVERSIFIED,
43
+ ),
44
+ Asset(
45
+ name="Roth IRA",
46
+ value=200_000,
47
+ account_type=AccountType.TAX_EXEMPT,
48
+ liquidity_class=LiquidityClass.RETIREMENT,
49
+ concentration_level=ConcentrationLevel.DIVERSIFIED,
50
+ ),
51
+ ]
52
+
53
+ # Define your spending
54
+ liabilities = [
55
+ Liability(name="Living Expenses", annual_amount=50_000, is_essential=True),
56
+ Liability(name="Travel", annual_amount=20_000, is_essential=False),
57
+ ]
58
+
59
+ # Calculate CEFR
60
+ result = compute_cefr(
61
+ balance_sheet=BalanceSheet(assets=assets),
62
+ liabilities=liabilities,
63
+ planning_horizon=30,
64
+ )
65
+
66
+ print(f"CEFR: {result.cefr:.2f}")
67
+ print(f"Funded: {result.is_funded}")
68
+ print(result.get_interpretation())
69
+ ```
70
+
71
+ ## Tutorials
72
+
73
+ - [CEFR Basics](https://colab.research.google.com/github/engineerinvestor/financial-health-calculator/blob/main/examples/01_cefr_basics.ipynb) - Introduction to the CEFR metric
74
+ - [Time Distribution Analysis](https://colab.research.google.com/github/engineerinvestor/financial-health-calculator/blob/main/examples/02_time_distribution.ipynb) - Monte Carlo simulations
75
+ - [Withdrawal Strategy Comparison](https://colab.research.google.com/github/engineerinvestor/financial-health-calculator/blob/main/examples/03_withdrawal_comparison.ipynb) - Compare different approaches
76
+
77
+ ## Running the Apps
78
+
79
+ ### Streamlit Web App
80
+
81
+ ```bash
82
+ streamlit run streamlit_app/app.py
83
+ ```
84
+
85
+ ### FastAPI REST API
86
+
87
+ ```bash
88
+ uvicorn api.main:app --reload
89
+ ```
90
+
91
+ API documentation available at `http://localhost:8000/docs`
92
+
93
+ ## Key Concepts
94
+
95
+ ### CEFR (Certainty-Equivalent Funded Ratio)
96
+
97
+ CEFR measures how well-funded your retirement is after accounting for:
98
+
99
+ - **Tax Haircuts**: What you'll owe when withdrawing from different account types
100
+ - **Liquidity Haircuts**: How easily you can access your assets
101
+ - **Reliability Haircuts**: Risk from concentrated positions
102
+
103
+ **Formula:**
104
+ ```
105
+ CEFR = Σ(Asset × (1-τ) × λ × ρ) / PV(Liabilities)
106
+ ```
107
+
108
+ Where τ = tax rate, λ = liquidity factor, ρ = reliability factor
109
+
110
+ **Interpretation:**
111
+ - CEFR ≥ 2.0: Excellent - Very well-funded
112
+ - CEFR 1.5-2.0: Strong - Well-funded with margin
113
+ - CEFR 1.0-1.5: Adequate - Fully funded
114
+ - CEFR < 1.0: Underfunded - Action needed
115
+
116
+ ### Withdrawal Strategies
117
+
118
+ | Strategy | Description | Best For |
119
+ |----------|-------------|----------|
120
+ | Fixed SWR | 4% of initial portfolio, adjusted for inflation | Predictability |
121
+ | % of Portfolio | Fixed % of current value | Market adaptation |
122
+ | Guardrails | Adjustable with floor/ceiling | Balance |
123
+ | VPW | Age-based variable percentage | Maximizing spending |
124
+ | RMD-Style | IRS distribution table based | Tax efficiency |
125
+
126
+ ## Development
127
+
128
+ ### Setup
129
+
130
+ ```bash
131
+ git clone https://github.com/engineerinvestor/financial-health-calculator.git
132
+ cd financial-health-calculator
133
+ pip install -e ".[dev]"
134
+ ```
135
+
136
+ ### Running Tests
137
+
138
+ ```bash
139
+ pytest
140
+ ```
141
+
142
+ ### Code Quality
143
+
144
+ ```bash
145
+ ruff check .
146
+ mypy fundedness
147
+ ```
148
+
149
+ ## Project Structure
150
+
151
+ ```
152
+ financial-health-calculator/
153
+ ├── fundedness/ # Core Python package
154
+ │ ├── models/ # Pydantic data models
155
+ │ ├── viz/ # Plotly visualizations
156
+ │ ├── withdrawals/ # Withdrawal strategies
157
+ │ ├── allocation/ # Asset allocation strategies
158
+ │ ├── cefr.py # CEFR calculation
159
+ │ ├── simulate.py # Monte Carlo engine
160
+ │ └── policies.py # Spending/allocation policies
161
+ ├── api/ # FastAPI REST API
162
+ ├── streamlit_app/ # Streamlit web application
163
+ ├── examples/ # Jupyter notebooks
164
+ └── tests/ # pytest tests
165
+ ```
166
+
167
+ ## Contact
168
+
169
+ - Twitter: [@egr_investor](https://x.com/egr_investor)
170
+ - GitHub: [engineerinvestor](https://github.com/engineerinvestor)
171
+ - Email: egr.investor@gmail.com
172
+
173
+ ## License
174
+
175
+ MIT License
176
+
177
+ ## Disclaimer
178
+
179
+ This tool is for educational purposes only and does not constitute financial advice. Consult a qualified financial advisor for personalized recommendations.
@@ -0,0 +1 @@
1
+ """FastAPI REST API for the fundedness package."""