monteplan 0.5.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.
- monteplan-0.5.0/.github/workflows/ci.yml +43 -0
- monteplan-0.5.0/.github/workflows/docs.yml +45 -0
- monteplan-0.5.0/.github/workflows/publish.yml +18 -0
- monteplan-0.5.0/.gitignore +25 -0
- monteplan-0.5.0/CLAUDE.md +90 -0
- monteplan-0.5.0/CONTRIBUTING.md +20 -0
- monteplan-0.5.0/LICENSE +190 -0
- monteplan-0.5.0/PKG-INFO +150 -0
- monteplan-0.5.0/README.md +108 -0
- monteplan-0.5.0/SECURITY.md +9 -0
- monteplan-0.5.0/SPEC.md +576 -0
- monteplan-0.5.0/app/Home.py +111 -0
- monteplan-0.5.0/app/__init__.py +0 -0
- monteplan-0.5.0/app/components/__init__.py +0 -0
- monteplan-0.5.0/app/components/charts.py +705 -0
- monteplan-0.5.0/app/components/forms.py +40 -0
- monteplan-0.5.0/app/components/theme.py +105 -0
- monteplan-0.5.0/app/pages/1_Plan_Setup.py +169 -0
- monteplan-0.5.0/app/pages/2_Portfolio.py +360 -0
- monteplan-0.5.0/app/pages/3_Run_Results.py +420 -0
- monteplan-0.5.0/app/pages/4_Policies.py +336 -0
- monteplan-0.5.0/app/pages/5_Compare_Scenarios.py +67 -0
- monteplan-0.5.0/app/pages/6_Sensitivity.py +229 -0
- monteplan-0.5.0/app/pages/__init__.py +0 -0
- monteplan-0.5.0/docs/api/analytics.md +49 -0
- monteplan-0.5.0/docs/api/config.md +71 -0
- monteplan-0.5.0/docs/api/engine.md +23 -0
- monteplan-0.5.0/docs/api/io.md +19 -0
- monteplan-0.5.0/docs/api/returns.md +37 -0
- monteplan-0.5.0/docs/api/spending.md +41 -0
- monteplan-0.5.0/docs/api/taxes.md +19 -0
- monteplan-0.5.0/docs/case-studies/coast-fire.md +75 -0
- monteplan-0.5.0/docs/case-studies/conservative-retiree.md +78 -0
- monteplan-0.5.0/docs/case-studies/fire.md +63 -0
- monteplan-0.5.0/docs/case-studies/guardrails-vs-constant.md +70 -0
- monteplan-0.5.0/docs/case-studies/index.md +25 -0
- monteplan-0.5.0/docs/changelog.md +81 -0
- monteplan-0.5.0/docs/contributing.md +93 -0
- monteplan-0.5.0/docs/getting-started/first-simulation.md +143 -0
- monteplan-0.5.0/docs/getting-started/installation.md +53 -0
- monteplan-0.5.0/docs/getting-started/quickstart.md +39 -0
- monteplan-0.5.0/docs/guide/app.md +90 -0
- monteplan-0.5.0/docs/guide/cli.md +101 -0
- monteplan-0.5.0/docs/guide/market-assumptions.md +129 -0
- monteplan-0.5.0/docs/guide/plan-config.md +119 -0
- monteplan-0.5.0/docs/guide/return-models.md +147 -0
- monteplan-0.5.0/docs/guide/sensitivity.md +86 -0
- monteplan-0.5.0/docs/guide/spending-policies.md +150 -0
- monteplan-0.5.0/docs/guide/stress-testing.md +121 -0
- monteplan-0.5.0/docs/guide/tax-models.md +73 -0
- monteplan-0.5.0/docs/images/fan_chart.png +0 -0
- monteplan-0.5.0/docs/images/ruin_curve.png +0 -0
- monteplan-0.5.0/docs/images/spending_comparison.png +0 -0
- monteplan-0.5.0/docs/index.md +58 -0
- monteplan-0.5.0/docs/math/inflation.md +82 -0
- monteplan-0.5.0/docs/math/limitations.md +62 -0
- monteplan-0.5.0/docs/math/return-models.md +107 -0
- monteplan-0.5.0/docs/math/taxes.md +99 -0
- monteplan-0.5.0/docs/notebooks/index.md +40 -0
- monteplan-0.5.0/mkdocs.yml +107 -0
- monteplan-0.5.0/notebooks/01_getting_started.ipynb +327 -0
- monteplan-0.5.0/notebooks/02_spending_policies.ipynb +317 -0
- monteplan-0.5.0/notebooks/03_advanced_analysis.ipynb +363 -0
- monteplan-0.5.0/notebooks/04_case_study_fire.ipynb +277 -0
- monteplan-0.5.0/notebooks/05_case_study_retiree.ipynb +282 -0
- monteplan-0.5.0/paper/Makefile +16 -0
- monteplan-0.5.0/paper/monteplan.bib +255 -0
- monteplan-0.5.0/paper/monteplan.pdf +0 -0
- monteplan-0.5.0/paper/monteplan.tex +1910 -0
- monteplan-0.5.0/pyproject.toml +86 -0
- monteplan-0.5.0/requirements.txt +3 -0
- monteplan-0.5.0/scripts/generate_readme_charts.py +218 -0
- monteplan-0.5.0/src/monteplan/__init__.py +23 -0
- monteplan-0.5.0/src/monteplan/analytics/__init__.py +0 -0
- monteplan-0.5.0/src/monteplan/analytics/metrics.py +169 -0
- monteplan-0.5.0/src/monteplan/analytics/sensitivity.py +486 -0
- monteplan-0.5.0/src/monteplan/analytics/swr.py +104 -0
- monteplan-0.5.0/src/monteplan/cli/__init__.py +0 -0
- monteplan-0.5.0/src/monteplan/cli/main.py +87 -0
- monteplan-0.5.0/src/monteplan/config/__init__.py +0 -0
- monteplan-0.5.0/src/monteplan/config/defaults.py +117 -0
- monteplan-0.5.0/src/monteplan/config/schema.py +497 -0
- monteplan-0.5.0/src/monteplan/core/__init__.py +0 -0
- monteplan-0.5.0/src/monteplan/core/engine.py +503 -0
- monteplan-0.5.0/src/monteplan/core/rng.py +13 -0
- monteplan-0.5.0/src/monteplan/core/state.py +107 -0
- monteplan-0.5.0/src/monteplan/core/timeline.py +71 -0
- monteplan-0.5.0/src/monteplan/io/__init__.py +0 -0
- monteplan-0.5.0/src/monteplan/io/serialize.py +135 -0
- monteplan-0.5.0/src/monteplan/io/yaml_loader.py +38 -0
- monteplan-0.5.0/src/monteplan/models/__init__.py +0 -0
- monteplan-0.5.0/src/monteplan/models/inflation.py +143 -0
- monteplan-0.5.0/src/monteplan/models/returns/__init__.py +0 -0
- monteplan-0.5.0/src/monteplan/models/returns/base.py +20 -0
- monteplan-0.5.0/src/monteplan/models/returns/bootstrap.py +55 -0
- monteplan-0.5.0/src/monteplan/models/returns/mvn.py +130 -0
- monteplan-0.5.0/src/monteplan/models/returns/regime_switching.py +121 -0
- monteplan-0.5.0/src/monteplan/models/stress.py +118 -0
- monteplan-0.5.0/src/monteplan/policies/__init__.py +0 -0
- monteplan-0.5.0/src/monteplan/policies/contributions.py +31 -0
- monteplan-0.5.0/src/monteplan/policies/rebalancing.py +68 -0
- monteplan-0.5.0/src/monteplan/policies/spending/__init__.py +0 -0
- monteplan-0.5.0/src/monteplan/policies/spending/base.py +21 -0
- monteplan-0.5.0/src/monteplan/policies/spending/constant_real.py +28 -0
- monteplan-0.5.0/src/monteplan/policies/spending/floor_ceiling.py +32 -0
- monteplan-0.5.0/src/monteplan/policies/spending/guardrails.py +82 -0
- monteplan-0.5.0/src/monteplan/policies/spending/percent_of_portfolio.py +28 -0
- monteplan-0.5.0/src/monteplan/policies/spending/vpw.py +38 -0
- monteplan-0.5.0/src/monteplan/policies/withdrawals.py +70 -0
- monteplan-0.5.0/src/monteplan/py.typed +0 -0
- monteplan-0.5.0/src/monteplan/taxes/__init__.py +0 -0
- monteplan-0.5.0/src/monteplan/taxes/base.py +60 -0
- monteplan-0.5.0/src/monteplan/taxes/rmd.py +53 -0
- monteplan-0.5.0/src/monteplan/taxes/simple.py +46 -0
- monteplan-0.5.0/src/monteplan/taxes/tables/__init__.py +0 -0
- monteplan-0.5.0/src/monteplan/taxes/tables/rmd_divisors.yaml +56 -0
- monteplan-0.5.0/src/monteplan/taxes/tables/us_federal_2024.yaml +37 -0
- monteplan-0.5.0/src/monteplan/taxes/us_federal.py +189 -0
- monteplan-0.5.0/src/monteplan/utils/__init__.py +0 -0
- monteplan-0.5.0/src/monteplan/utils/exceptions.py +15 -0
- monteplan-0.5.0/tests/__init__.py +0 -0
- monteplan-0.5.0/tests/conftest.py +12 -0
- monteplan-0.5.0/tests/golden/basic_retirement.json +37 -0
- monteplan-0.5.0/tests/test_antithetic.py +141 -0
- monteplan-0.5.0/tests/test_bootstrap.py +79 -0
- monteplan-0.5.0/tests/test_charts.py +247 -0
- monteplan-0.5.0/tests/test_cli.py +52 -0
- monteplan-0.5.0/tests/test_engine.py +310 -0
- monteplan-0.5.0/tests/test_events.py +137 -0
- monteplan-0.5.0/tests/test_exports.py +73 -0
- monteplan-0.5.0/tests/test_fees.py +87 -0
- monteplan-0.5.0/tests/test_floor_ceiling.py +73 -0
- monteplan-0.5.0/tests/test_glide_path.py +131 -0
- monteplan-0.5.0/tests/test_guaranteed_income.py +184 -0
- monteplan-0.5.0/tests/test_guardrails.py +105 -0
- monteplan-0.5.0/tests/test_inflation.py +43 -0
- monteplan-0.5.0/tests/test_metrics.py +120 -0
- monteplan-0.5.0/tests/test_mvn.py +121 -0
- monteplan-0.5.0/tests/test_niit.py +117 -0
- monteplan-0.5.0/tests/test_rebalancing.py +93 -0
- monteplan-0.5.0/tests/test_regime_switching.py +287 -0
- monteplan-0.5.0/tests/test_rmd.py +92 -0
- monteplan-0.5.0/tests/test_roth_conversion.py +254 -0
- monteplan-0.5.0/tests/test_sensitivity.py +136 -0
- monteplan-0.5.0/tests/test_serialize.py +63 -0
- monteplan-0.5.0/tests/test_spending.py +72 -0
- monteplan-0.5.0/tests/test_state.py +67 -0
- monteplan-0.5.0/tests/test_state_tax.py +86 -0
- monteplan-0.5.0/tests/test_stress.py +350 -0
- monteplan-0.5.0/tests/test_swr.py +106 -0
- monteplan-0.5.0/tests/test_tax_brackets.py +133 -0
- monteplan-0.5.0/tests/test_threshold_rebalancing.py +120 -0
- monteplan-0.5.0/tests/test_timeline.py +49 -0
- monteplan-0.5.0/tests/test_vpw.py +100 -0
- monteplan-0.5.0/tests/test_withdrawals.py +120 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
lint:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
- uses: actions/setup-python@v5
|
|
15
|
+
with:
|
|
16
|
+
python-version: "3.12"
|
|
17
|
+
- run: pip install -e ".[dev]"
|
|
18
|
+
- run: ruff check src/ tests/
|
|
19
|
+
- run: ruff format --check src/ tests/
|
|
20
|
+
|
|
21
|
+
typecheck:
|
|
22
|
+
runs-on: ubuntu-latest
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v4
|
|
25
|
+
- uses: actions/setup-python@v5
|
|
26
|
+
with:
|
|
27
|
+
python-version: "3.12"
|
|
28
|
+
- run: pip install -e ".[dev]"
|
|
29
|
+
- run: mypy --strict src/monteplan/
|
|
30
|
+
|
|
31
|
+
test:
|
|
32
|
+
runs-on: ubuntu-latest
|
|
33
|
+
strategy:
|
|
34
|
+
matrix:
|
|
35
|
+
python-version: ["3.11", "3.12", "3.13"]
|
|
36
|
+
steps:
|
|
37
|
+
- uses: actions/checkout@v4
|
|
38
|
+
- uses: actions/setup-python@v5
|
|
39
|
+
with:
|
|
40
|
+
python-version: ${{ matrix.python-version }}
|
|
41
|
+
- run: pip install -e ".[dev]"
|
|
42
|
+
- run: pytest -v --cov=monteplan --cov-report=term-missing
|
|
43
|
+
- run: pytest --benchmark-only --benchmark-min-rounds=1
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
name: Deploy Docs
|
|
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
|
+
concurrency:
|
|
14
|
+
group: pages
|
|
15
|
+
cancel-in-progress: false
|
|
16
|
+
|
|
17
|
+
jobs:
|
|
18
|
+
build:
|
|
19
|
+
runs-on: ubuntu-latest
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v4
|
|
22
|
+
|
|
23
|
+
- uses: actions/setup-python@v5
|
|
24
|
+
with:
|
|
25
|
+
python-version: "3.12"
|
|
26
|
+
|
|
27
|
+
- name: Install dependencies
|
|
28
|
+
run: pip install -e ".[docs]"
|
|
29
|
+
|
|
30
|
+
- name: Build docs
|
|
31
|
+
run: mkdocs build --strict
|
|
32
|
+
|
|
33
|
+
- uses: actions/upload-pages-artifact@v3
|
|
34
|
+
with:
|
|
35
|
+
path: site/
|
|
36
|
+
|
|
37
|
+
deploy:
|
|
38
|
+
needs: build
|
|
39
|
+
runs-on: ubuntu-latest
|
|
40
|
+
environment:
|
|
41
|
+
name: github-pages
|
|
42
|
+
url: ${{ steps.deployment.outputs.page_url }}
|
|
43
|
+
steps:
|
|
44
|
+
- id: deployment
|
|
45
|
+
uses: actions/deploy-pages@v4
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
tags: ["v*"]
|
|
5
|
+
jobs:
|
|
6
|
+
publish:
|
|
7
|
+
runs-on: ubuntu-latest
|
|
8
|
+
permissions:
|
|
9
|
+
id-token: write
|
|
10
|
+
environment: pypi
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v4
|
|
13
|
+
- uses: actions/setup-python@v5
|
|
14
|
+
with:
|
|
15
|
+
python-version: "3.12"
|
|
16
|
+
- run: pip install build
|
|
17
|
+
- run: python -m build
|
|
18
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.py[cod]
|
|
3
|
+
*$py.class
|
|
4
|
+
*.egg-info/
|
|
5
|
+
*.egg
|
|
6
|
+
dist/
|
|
7
|
+
build/
|
|
8
|
+
.eggs/
|
|
9
|
+
*.so
|
|
10
|
+
.mypy_cache/
|
|
11
|
+
.ruff_cache/
|
|
12
|
+
.pytest_cache/
|
|
13
|
+
.benchmarks/
|
|
14
|
+
.venv/
|
|
15
|
+
venv/
|
|
16
|
+
env/
|
|
17
|
+
.env
|
|
18
|
+
*.log
|
|
19
|
+
.DS_Store
|
|
20
|
+
.idea/
|
|
21
|
+
.vscode/
|
|
22
|
+
*.swp
|
|
23
|
+
*.swo
|
|
24
|
+
site/
|
|
25
|
+
.ipynb_checkpoints/
|
|
@@ -0,0 +1,90 @@
|
|
|
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
|
+
**monteplan** is a Monte Carlo financial planning simulator (Python package + Streamlit web app). It supports accumulation and decumulation modeling with realistic taxes, multiple spending policies, multi-asset correlated portfolios, and professional reporting. The engine is usable as a library, CLI, and web UI.
|
|
8
|
+
|
|
9
|
+
## Build & Development Commands
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# Install in editable mode with dev dependencies
|
|
13
|
+
pip install -e ".[dev]"
|
|
14
|
+
|
|
15
|
+
# Run all tests
|
|
16
|
+
pytest
|
|
17
|
+
|
|
18
|
+
# Run a single test file or test
|
|
19
|
+
pytest tests/test_engine.py
|
|
20
|
+
pytest tests/test_engine.py::test_basic_simulation -v
|
|
21
|
+
|
|
22
|
+
# Type checking
|
|
23
|
+
mypy src/monteplan/ # or pyright
|
|
24
|
+
|
|
25
|
+
# Linting and formatting
|
|
26
|
+
ruff check src/ tests/
|
|
27
|
+
ruff format src/ tests/
|
|
28
|
+
|
|
29
|
+
# Run benchmarks
|
|
30
|
+
pytest --benchmark-only
|
|
31
|
+
|
|
32
|
+
# Run the Streamlit app locally
|
|
33
|
+
streamlit run app/Home.py
|
|
34
|
+
|
|
35
|
+
# Build docs
|
|
36
|
+
mkdocs serve # local preview
|
|
37
|
+
mkdocs build # build static site
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Architecture
|
|
41
|
+
|
|
42
|
+
### Separation of Concerns
|
|
43
|
+
|
|
44
|
+
The project enforces strict separation between three layers:
|
|
45
|
+
- **Engine** (`src/monteplan/`): Pure computation, no UI dependencies. This is the installable Python package.
|
|
46
|
+
- **App** (`app/`): Streamlit web UI that imports the engine as a library. Never put simulation logic here.
|
|
47
|
+
- **Data adapters** (`src/monteplan/io/`): Serialization and optional market data adapters, isolated from both engine and UI.
|
|
48
|
+
|
|
49
|
+
### Engine Core (`src/monteplan/core/`)
|
|
50
|
+
|
|
51
|
+
- `engine.py` — Orchestrator: takes a plan config, market assumptions, policies, and simulation config, returns a `SimulationResult`. Entry point: `simulate(plan, market, policies, sim_cfg)`.
|
|
52
|
+
- `timeline.py` — Monthly time grid with date/age conversions. Default time step is monthly.
|
|
53
|
+
- `state.py` — Mutable simulation state passed through each time step (balances, income, tax status, age).
|
|
54
|
+
- `rng.py` — Deterministic RNG via `numpy.random.Generator(PCG64DXSM)`. Every run must be seedable and reproducible.
|
|
55
|
+
- `vectorize.py` — Vectorized numpy helpers for fast path evolution.
|
|
56
|
+
|
|
57
|
+
### Plugin-Style Interfaces
|
|
58
|
+
|
|
59
|
+
Models and policies are defined via protocols/ABCs so they can be swapped or extended:
|
|
60
|
+
|
|
61
|
+
- **Return models** (`models/returns/`): `ReturnModel.sample(n_paths, n_steps, rng) -> ndarray[paths, steps, assets]`. Implementations: multivariate normal/t (default), historical bootstrap, regime-switching.
|
|
62
|
+
- **Spending policies** (`policies/spending/`): `SpendingPolicy.compute(state) -> SpendingDecision`. Each policy is independently testable. Implementations: constant real, percent-of-portfolio, floor-and-ceiling, Guyton-Klinger guardrails, VPW.
|
|
63
|
+
- **Tax model** (`taxes/`): `TaxModel.compute_taxes(income_events, realized_gains, deductions, state)`. Jurisdiction is pluggable; US federal is the baseline. Tax bracket tables are config-driven YAML/CSV, not hardcoded.
|
|
64
|
+
|
|
65
|
+
### Config System (`config/`)
|
|
66
|
+
|
|
67
|
+
- Pydantic or dataclass-based typed configs: `PlanConfig`, `MarketAssumptions`, `SimulationConfig`, `PolicyBundle`.
|
|
68
|
+
- Default assumptions in `defaults.py`. All configs are exportable/importable as JSON for reproducibility.
|
|
69
|
+
- Config hashing is used for caching and result provenance.
|
|
70
|
+
|
|
71
|
+
### Account Types & Tax Awareness
|
|
72
|
+
|
|
73
|
+
The engine models taxable, traditional (401k/IRA), and Roth accounts with distinct tax treatment. Withdrawal ordering policy and RMD integration drive decumulation. Tax bracket tables are stored in `taxes/tables/` as data files.
|
|
74
|
+
|
|
75
|
+
### Streamlit App (`app/`)
|
|
76
|
+
|
|
77
|
+
Multi-page Streamlit app with pages numbered for nav ordering (1_Plan_Setup.py through 6_Sensitivity.py). Uses `st.cache_data`/`st.cache_resource` keyed by config hash for simulation results. No database — user data persists only via downloadable config JSON.
|
|
78
|
+
|
|
79
|
+
## Key Conventions
|
|
80
|
+
|
|
81
|
+
- **Reproducibility**: Every simulation result embeds `config_hash`, `seed`, and `engine_version`. Golden test snapshots verify deterministic outputs for fixed seeds.
|
|
82
|
+
- **Performance**: Vectorized numpy by default; optional numba acceleration (auto-detected). Memory modes: `summary_only=True` stores only percentiles incrementally; `store_paths=False` is the default for web.
|
|
83
|
+
- **Testing**: Property-based tests via Hypothesis for invariants (weights sum to 1, no unexpected negative balances). Table-driven tests for tax calculations. Benchmark suite via `pytest-benchmark` to prevent perf regressions.
|
|
84
|
+
- **Python version**: >=3.11. CI runs a test matrix across 3.11, 3.12, and 3.13.
|
|
85
|
+
- **Time step**: Monthly by default with annual support. All financial math must handle arithmetic/geometric return conversion consistently.
|
|
86
|
+
|
|
87
|
+
## Git
|
|
88
|
+
|
|
89
|
+
- **Remote:** https://github.com/engineerinvestor/monteplan
|
|
90
|
+
- **Commit attribution:** Name: Engineer Investor, Email: egr.investor@gmail.com
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Contributing to monteplan
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing! Please see our full
|
|
4
|
+
[Contributing Guide](https://engineerinvestor.github.io/monteplan/contributing/)
|
|
5
|
+
for details on:
|
|
6
|
+
|
|
7
|
+
- Setting up the development environment
|
|
8
|
+
- Running tests and type checks
|
|
9
|
+
- Code style and conventions
|
|
10
|
+
- Submitting pull requests
|
|
11
|
+
|
|
12
|
+
## Quick Start
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
git clone https://github.com/engineerinvestor/monteplan.git
|
|
16
|
+
cd monteplan
|
|
17
|
+
python -m venv .venv && source .venv/bin/activate
|
|
18
|
+
pip install -e ".[dev]"
|
|
19
|
+
pytest
|
|
20
|
+
```
|
monteplan-0.5.0/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2024 Engineer Investor
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
monteplan-0.5.0/PKG-INFO
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: monteplan
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: Monte Carlo financial planning simulator
|
|
5
|
+
Project-URL: Homepage, https://github.com/engineerinvestor/monteplan
|
|
6
|
+
Project-URL: Repository, https://github.com/engineerinvestor/monteplan
|
|
7
|
+
Project-URL: Documentation, https://engineerinvestor.github.io/monteplan/
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/engineerinvestor/monteplan/issues
|
|
9
|
+
Author-email: Engineer Investor <egr.investor@gmail.com>
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: financial-planning,monte-carlo,retirement,simulation
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
15
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
Requires-Dist: click>=8.0
|
|
22
|
+
Requires-Dist: numpy>=1.26
|
|
23
|
+
Requires-Dist: pydantic>=2.5
|
|
24
|
+
Requires-Dist: pyyaml>=6.0
|
|
25
|
+
Requires-Dist: scipy>=1.12
|
|
26
|
+
Provides-Extra: app
|
|
27
|
+
Requires-Dist: plotly>=5.18; extra == 'app'
|
|
28
|
+
Requires-Dist: streamlit>=1.30; extra == 'app'
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: hypothesis>=6.90; extra == 'dev'
|
|
31
|
+
Requires-Dist: mypy>=1.8; extra == 'dev'
|
|
32
|
+
Requires-Dist: pytest-benchmark>=4.0; extra == 'dev'
|
|
33
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
34
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
35
|
+
Requires-Dist: ruff>=0.2; extra == 'dev'
|
|
36
|
+
Requires-Dist: types-pyyaml>=6.0; extra == 'dev'
|
|
37
|
+
Provides-Extra: docs
|
|
38
|
+
Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
|
|
39
|
+
Requires-Dist: mkdocs>=1.6; extra == 'docs'
|
|
40
|
+
Requires-Dist: mkdocstrings[python]>=0.24; extra == 'docs'
|
|
41
|
+
Description-Content-Type: text/markdown
|
|
42
|
+
|
|
43
|
+
<p align="center">
|
|
44
|
+
<h1 align="center">monteplan</h1>
|
|
45
|
+
<p align="center">Monte Carlo financial planning simulator</p>
|
|
46
|
+
</p>
|
|
47
|
+
|
|
48
|
+
<p align="center">
|
|
49
|
+
<a href="https://github.com/engineerinvestor/monteplan/actions"><img src="https://github.com/engineerinvestor/monteplan/workflows/CI/badge.svg" alt="CI"></a>
|
|
50
|
+
<img src="https://img.shields.io/badge/python-3.11%2B-blue" alt="Python 3.11+">
|
|
51
|
+
<a href="https://github.com/engineerinvestor/monteplan/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-Apache--2.0-green" alt="License"></a>
|
|
52
|
+
<a href="https://engineerinvestor.github.io/monteplan/"><img src="https://img.shields.io/badge/docs-mkdocs-blue" alt="Docs"></a>
|
|
53
|
+
</p>
|
|
54
|
+
|
|
55
|
+
<p align="center">
|
|
56
|
+
<a href="https://engineerinvestor.github.io/monteplan/">Documentation</a> |
|
|
57
|
+
<a href="https://github.com/engineerinvestor/monteplan/blob/main/paper/monteplan.pdf">Technical Paper</a> |
|
|
58
|
+
<a href="https://engineerinvestor.github.io/monteplan/notebooks/">Notebooks</a> |
|
|
59
|
+
<a href="https://colab.research.google.com/github/engineerinvestor/monteplan/blob/main/notebooks/01_getting_started.ipynb">Try in Colab</a>
|
|
60
|
+
</p>
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
monteplan models accumulation and decumulation with realistic taxes, multiple spending policies, multi-asset correlated portfolios, and professional reporting. Use it as a **Python library**, **CLI tool**, or interactive **Streamlit web app**.
|
|
65
|
+
|
|
66
|
+
## Features
|
|
67
|
+
|
|
68
|
+
- **Monte Carlo Engine** -- Vectorized numpy simulation with monthly time steps and deterministic seeding
|
|
69
|
+
- **4 Return Models** -- Multivariate normal, Student-t (fat tails), historical block bootstrap, Markov regime switching
|
|
70
|
+
- **5 Spending Policies** -- Constant real, percent-of-portfolio, Guyton-Klinger guardrails, VPW, floor-and-ceiling
|
|
71
|
+
- **Tax-Aware Withdrawals** -- US federal progressive brackets, LTCG rates, RMD enforcement, configurable withdrawal ordering
|
|
72
|
+
- **Multi-Account Support** -- Taxable, traditional (401k/IRA), and Roth accounts with distinct tax treatment
|
|
73
|
+
- **Guaranteed Income** -- Social Security, pensions, and annuities with COLA adjustments
|
|
74
|
+
- **Stress Testing** -- Market crashes, lost decades, high inflation, and sequence-of-returns risk scenarios
|
|
75
|
+
- **Sensitivity Analysis** -- One-at-a-time tornado charts and 2D heatmaps with parallel execution
|
|
76
|
+
- **Antithetic Variates** -- Variance reduction for tighter confidence intervals
|
|
77
|
+
- **Glide Paths** -- Age-based target allocation shifts
|
|
78
|
+
- **Investment Fees** -- Expense ratios, AUM fees, and advisory fees as monthly drag
|
|
79
|
+
- **Streamlit App** -- Interactive web UI with Plotly charts, scenario comparison, and CSV export
|
|
80
|
+
|
|
81
|
+
## Example Output
|
|
82
|
+
|
|
83
|
+
<p align="center">
|
|
84
|
+
<img src="docs/images/fan_chart.png" alt="Monte Carlo Wealth Projection" width="100%">
|
|
85
|
+
</p>
|
|
86
|
+
|
|
87
|
+
<p align="center">
|
|
88
|
+
<img src="docs/images/spending_comparison.png" alt="Spending Policy Comparison" width="49%">
|
|
89
|
+
<img src="docs/images/ruin_curve.png" alt="Ruin Probability by Age" width="49%">
|
|
90
|
+
</p>
|
|
91
|
+
|
|
92
|
+
## Quick Start
|
|
93
|
+
|
|
94
|
+
### Python Library
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from monteplan import simulate, default_plan, default_market, default_policies, default_sim_config
|
|
98
|
+
|
|
99
|
+
result = simulate(default_plan(), default_market(), default_policies(), default_sim_config())
|
|
100
|
+
print(f"Success probability: {result.success_probability:.1%}")
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### CLI
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
monteplan run --paths 10000 --seed 42
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Streamlit App
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
pip install monteplan[app]
|
|
113
|
+
streamlit run app/Home.py
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Try It Now
|
|
117
|
+
|
|
118
|
+
[](https://colab.research.google.com/github/engineerinvestor/monteplan/blob/main/notebooks/01_getting_started.ipynb)
|
|
119
|
+
|
|
120
|
+
## Installation
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
pip install monteplan
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Or install from source:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
git clone https://github.com/engineerinvestor/monteplan.git
|
|
130
|
+
cd monteplan
|
|
131
|
+
pip install -e ".[dev]"
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Architecture
|
|
135
|
+
|
|
136
|
+
monteplan separates computation from presentation:
|
|
137
|
+
|
|
138
|
+
- **Engine** (`src/monteplan/`) -- Pure Python package with no UI dependencies
|
|
139
|
+
- **App** (`app/`) -- Streamlit web UI that imports the engine as a library
|
|
140
|
+
- **Plugin-style models** -- Return models, spending policies, and tax models are swappable via protocols
|
|
141
|
+
|
|
142
|
+
See the [documentation](https://engineerinvestor.github.io/monteplan/) for the full user guide, API reference, and mathematical details.
|
|
143
|
+
|
|
144
|
+
## Disclaimer
|
|
145
|
+
|
|
146
|
+
This is an educational tool for exploring financial planning concepts. It is **not financial advice**. Results are simulations based on simplified models and assumptions. Consult a qualified financial advisor for real planning decisions.
|
|
147
|
+
|
|
148
|
+
## License
|
|
149
|
+
|
|
150
|
+
Apache-2.0
|