Python package for performing time step-based simulations of personal finances. Note that this package is still early in development and likely contains bugs. Use at your own risk!
The package provides comprehensive models of people, jobs, accounts, insurance, debt, and more within a time step-based simulation framework. Built on the Mesa agent-based modeling framework, it includes an interactive dashboard, an example Jupyter Notebook, deep reinforcement learning capabilities for AI-driven financial planning, and can be used programmatically for in-depth financial studies.
- Comprehensive Financial Modeling: Model families, individuals, jobs, various account types, insurance policies, debt, taxes, and more
- Interactive Dashboard: Web-based interface using Solara for real-time financial simulations and visualizations
- Deep Learning Integration: Train reinforcement-learning agents (DQN, REINFORCE, PPO) to optimize financial decisions, and build a simulation-grounded language-model adviser whose advice is scored by the simulator
- Flexible Configuration: YAML-based configuration system for different economic scenarios
While impossible to predict the future, the goal of this package is to provide a robust framework for modeling financial outcomes based on various inputs. The best way to use this model is to change one variable at a time and evaluate how it impacts the outcome.
Check out the example simulation notebook:
python -m pip install life-modellife-model runs a household spec from the shell (python -m life_model is the same program):
life-model examples --copy married_homeowners my-models/h.yaml # a synthetic example to edit
life-model validate my-models/h.yaml # findings, exit code 2 on errors
life-model run my-models/h.yaml --out my-models/out # yearly summary + out/result.json
life-model explain my-models/h.yaml --year 2035 # one year: income, bills, taxes
life-model compare my-models/h.yaml --set 'people[john].retirement_age=58'
life-model montecarlo my-models/h.yaml --scenario stochastic --n 1000Every command takes --json for machine-readable output. The same operations are Python one-liners
(life_model.run, validate, explain, compare), and pip install 'life-model[mcp]' adds an MCP
server (life-model mcp) for Claude Code and other MCP clients. See docs/cli.md and,
for the end-to-end workflow, docs/modeling-a-household.md. Coding
agents: start with AGENTS.md.
A household can be written as a YAML or JSON household spec (people, jobs, accounts, debts, home, insurance, Social Security records and dated events) instead of Python:
from life_model.spec import build_model, load, validate_spec
spec = load("my-models/household.yaml") # my-models/ is git-ignored: keep real data there
for finding in validate_spec(spec): # errors and warnings before anything runs
print(finding)
model = build_model(spec)
model.run()The engine steps one calendar month at a time (model.step(); model.step_year() runs to the next
year end); salaries, bills, growth and benefits flow monthly and taxes settle in December. See
docs/units-and-conventions.md.
Synthetic examples ship in life_model/spec/examples/ (life_model.spec.load_example("married_homeowners")),
every field is documented in docs/household-spec.md, and
python -m life_model.spec schema prints the JSON Schema.
For a web-based interface to run simulations:
pip install -e . -r dashboard/requirements-dash.txt
solara run dashboard/app.pyThen open your browser to http://localhost:8765
Train AI agents to make optimal financial decisions with DQN, REINFORCE, or PPO:
pip install -r deepqlearning/requirements-rl.txt
python -m deepqlearning.train --env financial:basic --algo dqn --episodes 1000
python -m deepqlearning.train --env financial:mid_career --algo ppo --total-env-steps 200000See deepqlearning/README.md for the environment registry, the algorithm interface, and the evaluation protocol.
slm/ turns the simulator into a data generator and verifier for a small language
model that gives household financial-decision advice: every candidate decision is scored by Monte
Carlo simulation, so rationales are certified by the simulator rather than asserted, and out-of-scope
questions are refused. It is educational decision support, not financial advice; see the
slm README for the pipeline, evaluation, and training configurations.
This package supports a comprehensive range of financial modeling components:
- Family & Person Models - Multi-person households with individual financial profiles
- Children - Dependents with education and care costs
- Jobs - Employment with salary progression and benefits
- Stock Compensation - RSU grants with multi-year vesting schedules
- Bank Accounts - Checking/savings with interest
- 401k Plans - Traditional and Roth with employer matching, one elective limit across jobs, 415(c) cap
- Traditional & Roth IRAs - Deductible Traditional IRAs with RMDs; Roth IRAs drawn basis-first; one shared limit
- HSA - Deductible, invested, family tier and catch-up; non-medical withdrawals taxed
- 529 Plans - Education savings accounts
- Brokerage Accounts - Taxable investment accounts
- Pensions - Defined benefit retirement plans with vesting, accrual formula, COLA and survivor elections
- Trust Accounts - Revocable and irrevocable trusts for estate planning
- Life Insurance - Term and whole life policies with loans
- General Insurance - Health, auto, home, umbrella insurance
- Long Term Care Insurance - Coverage for nursing home, assisted living, and in-home care
- Annuities - Fixed and variable annuities with various payout options
- Social Security - Comprehensive benefit calculations with timing strategies
- Student Loans - Education debt with various repayment options
- Car Loans - Auto financing
- Credit Cards - Revolving debt with interest calculations
- Mortgages - Home loans (integrated with housing model)
- Federal Taxes - Complete income tax calculations with brackets
- State Taxes - Per-state, per-year tax packs for 19 states (brackets by filing status or flat rate, exemptions and credits, retirement exclusions, SALT integration), residency timelines with part-year returns; an unknown state is an error
- FICA Taxes - Social Security and Medicare taxes
- Capital Gains - Short-term and long-term capital gains
- Required Minimum Distributions (RMDs) - From 401ks and Traditional IRAs
- Early-Withdrawal Penalties - 10% before 59½ on pre-tax and non-qualified Roth IRA draws; 20% on non-medical HSA draws before 65
- Deductions - Standard deduction with the §63(f) amount for 65+, OBBBA senior deduction, itemized (SALT cap schedule, mortgage interest, medical with long-term care premiums, charity at 60% cash / 30% appreciated property with carryovers; 2026 floor, non-itemizer deduction and §68 limit), QBI (§199A), student loan interest and IRA deduction phase-outs
- Credits - Child tax credit and credit for other dependents (Schedule 8812 with the additional child tax credit), earned income credit, child and dependent care credit with dependent-care FSAs, American opportunity / lifetime learning credits (529 coordination), saver's credit, prior-year minimum tax credit; each on its own Form 1040 / Schedule 3 line
- Alternative Minimum Tax - Form 6251 with capital-gain rates, incentive stock option exercises, and the minimum tax credit carryforward
- Self-Employment - Schedule C profit, self-employment tax sharing the wage base with W-2 wages, SEP and solo 401(k) contributions, QBI deduction
- Kiddie Tax - A child's interest and dividends on the parents' return (Form 8814)
- Charitable Distributions - Qualified charitable distributions from IRAs counting toward the RMD; gifts of appreciated shares at fair market value
- Withholding & Estimated Payments - Pub. 15-T paycheck withholding (supplemental rates for bonuses and RSU vests, per-employer FICA, state), quarterly estimates (fixed or safe harbor), the balance due or refund settled in April, the Form 2210 penalty; opt-in (the default is a December lump)
- ACA Premium Tax Credit - Form 8962 for marketplace coverage, with advance payments and repayment limits by year
- Filing Statuses - Single, joint, separate, head of household (a child or a qualifying relative such as a parent), qualifying surviving spouse
- Home Ownership - Purchase, mortgage, appreciation, and selling
- Rental Housing - Apartment leasing with rent increases
- Life Events - Marriage, retirement, career changes, and mortality (stochastic or fixed-age death)
- Medicare Coverage - Part B and Part D premiums with IRMAA income surcharges (two-year MAGI lookback); Part A is premium-free
- Long-Term Care Services - Seeded care-need hazard with care episodes and annual costs, offset by LTC insurance
- Medical Expense Modeling - Age-related healthcare cost increases with medical inflation above CPI
- Chronic Care Management - Ongoing medical conditions and treatment costs (modeled via the age-band cost curve)
- Prescription Drug Coverage - Medicare Part D premium and IRMAA surcharge (modeled via Part D; supplemental plans not itemized)
- Charitable Giving - Tax-deductible donations with itemized deduction support
- Donor Advised Funds - Charitable investment accounts with growth, fees, and distributions
- Estate Planning - Mortality-driven death, spousal/beneficiary estate transfer, per-account beneficiary designations, estate tax, revocable/irrevocable trusts, and the SECURE Act 10-year inherited-account rule (trust income is untaxed until distributed — no compressed trust brackets; the annuity two-life survivor factor is not modeled)
- End of Life Care - Long-term care facilities and a final-year medical expense spike charged to the estate
- Funeral and Final Expenses - Funeral cost charged against the estate before transfer and estate tax
- Economic Scenarios - Configurable market conditions (recession, inflation, etc.)
- Payment Services - Intelligent bill payment with account prioritization
- Tax Optimization - Strategic withdrawal and contribution planning
- Reinforcement Learning - DQN / REINFORCE / PPO agents (
deepqlearning/) that learn an in-episode financial policy, evaluated against planner heuristics with an outcome-based protocol - Simulation-Grounded Adviser - A language-model adviser (
slm/) that maps a household to a recommended retirement plan (savings rate, 401k routing, Social Security claiming age, drawdown) with a Monte-Carlo-certified rationale (educational decision support, not financial advice; seeslm/README.md)
The interactive dashboard simulates a two-person household (John and Jane) and charts income, bank and 401k balances, debt, spending, 401k contributions and match, and income vs. taxes, with a results table and CSV download. Its controls cover:
- Each person: include/exclude, age, retirement age, salary, bonus, spending, starting bank balance, 401k (balance, contribution, employer match) and number of children
- Household: start and end year, state of residence, annual salary and spending increase, bank interest rate, an optional home (price, mortgage rate and term) and optional healthcare costs
- Economy: a packaged economic scenario (there is no separate inflation control; pick
high_inflation,deflation,stochastic, ... to change inflation and returns)
The deep learning module includes:
- A registry of financial environments (
financial, plusbasic,high_earner,low_earner,mid_careerhouseholds) with domain randomization and a stochastic economy - 16 financial action types (contributions, withdrawals, spending, early retirement), flattened into 52 discrete actions with amount buckets
- Utility-based reward presets for different objectives
- DQN, REINFORCE and PPO, planner-grade heuristic baselines, a statistical evaluation protocol, and policy-analysis reports
- The simulation-grounded language-model adviser in
slm/, which uses the same environment as its data generator
YAML scenario files packaged with life-model (in src/life_model/config/data/scenarios/) overlay the
default financial configuration; use one with LifeModel(scenario="recession"), meta.scenario in a
household spec, or life-model run SPEC --scenario recession:
conservative- lower equity returns (5%)aggressive- higher equity returns (10%)boom- a multi-year run of elevated equity returns and cash yields (path economy)recession- a multi-year equity downturn, then recovery (path economy)high_inflation- 8% inflation, wages lagging, lower real returnsdeflation- falling prices with depressed returnsstochastic- random, correlated equity/bond/inflation draws each year (for Monte Carlo)high_tax,low_tax,tax_reform- alternative federal brackets, deductions, state and payroll rates
See docs/configuration.md for authoring your own.
This project is open source and welcomes contributions. See CONTRIBUTING.md for development setup, the tox targets used by CI, and the pre-commit install step. The test suite in src/life_model/tests/ shows examples of expected functionality.
This project is licensed under the MIT License. See the LICENSE file for details.
If you use this package in your research, please cite it as follows:
@software{life_model,
author = {Spencer Williams},
title = {life-model: Personal Finance Simulation Framework},
url = {https://github.com/sw23/life-model},
version = {0.0.0},
year = 2025
}
