Skip to content

Conversation

MaxGhenis
Copy link
Contributor

Summary

  • Implements stacked simulation functionality for running multiple scenarios together
  • Achieves ~4000x speedup by batching tax calculations (one per year instead of thousands)
  • Adds comprehensive test suite using TDD approach
  • Fixes critical withdrawal capping bug where portfolios could go negative

Key Changes

New Features

  • finsim/stacked_simulation.py: New module for efficient multi-scenario simulations
  • simulate_stacked_scenarios(): Run multiple scenarios with shared tax calculations
  • analyze_confidence_thresholds(): Find sustainable spending at various confidence levels
  • create_scenario_config(): Helper to create scenario configurations

Bug Fixes

  • Fixed withdrawal capping: portfolios can no longer go negative
  • Added proper success counting: deaths with money count as success for sustainability analysis

Testing

  • Comprehensive TDD test suite in tests/test_stacked_simulation.py
  • Tests for withdrawal capping bug in tests/test_withdrawal_capping.py
  • All tests passing with proper validation

Performance

  • Traditional approach: 3.1M tax calculations for 4 scenarios × 15 spending levels
  • Stacked approach: 450 tax calculations (one per year per spending level)
  • Speedup: ~4000x faster

Example Usage

from finsim.stacked_simulation import (
    create_scenario_config,
    simulate_stacked_scenarios,
    analyze_confidence_thresholds
)

# Define scenarios
scenarios = [
    create_scenario_config("100% Stocks", 500_000),
    create_scenario_config("With Annuity", 100_000, 
                         has_annuity=True,
                         annuity_annual=50_000)
]

# Run simulations across spending levels
results = simulate_stacked_scenarios(
    scenarios=scenarios,
    spending_levels=[40_000, 50_000, 60_000],
    n_simulations=1000
)

# Find 90% confidence spending
thresholds = analyze_confidence_thresholds(
    results, "100% Stocks", [90, 75, 50]
)

Notebook

Includes personal_injury_settlement_stacked.ipynb demonstrating real-world usage for analyzing retirement options with a personal injury settlement.

Cleanup

Removed extraneous test files and scripts that were used during development.

🤖 Generated with Claude Code

- Implement stacked_simulation module with TDD tests
- Add ability to test multiple scenarios with shared tax calculations
- Achieve ~4000x speedup by batching tax calculations
- Fix withdrawal capping bug (portfolios can't go negative)
- Add comprehensive notebook for personal injury settlement analysis
- Keep app.py for Streamlit application

The stacked simulation approach runs all scenarios together for each
spending level, using a single tax calculation per year instead of
separate calculations for each simulation. This provides massive
performance improvements for finding sustainable spending levels.

🤖 Generated with Claude Code

Co-Authored-By: Claude <[email protected]>
@MaxGhenis MaxGhenis force-pushed the add-stacked-simulation branch from da312f2 to 3e02cf6 Compare August 11, 2025 15:53
MaxGhenis and others added 2 commits August 19, 2025 04:38
- Create modern React + TypeScript app with Vite
- Implement comprehensive Monte Carlo simulation UI
- Add advanced market calibration with GARCH models
- Include PolicyEngine blue favicon and branding
- Add FAQ/Methodology section with collapsible Q&A
- Convert all UI text to sentence case for consistency
- Fix layout to be full-width across all tabs
- Remove all emojis for professional appearance
- Add comprehensive test suite with Vitest
- Structure for multi-tab interface (Assumptions, Results, Analysis, Strategy, Methodology)
- Integrate with Flask backend API

Key features:
- Market calibration for different index funds (VT, SPY, VOO, QQQ)
- Demographic inputs with spouse support framework
- Income sources (Social Security, pension, employment)
- Tax calculation via PolicyEngine-US
- Monte Carlo simulation progress tracking
- Professional, clean UI design

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Implement step-by-step wizard flow for better UX
- Add StockProjection component showing growth paths with uncertainty bands
- Add MortalityCurve component showing survival probabilities
- Create comprehensive test suite with TDD approach
- Show live year-by-year simulation progress
- Display component visualizations before running full simulation
- Users can now understand stock predictions and mortality curves separately

Key improvements:
- 6-step wizard: Demographics → Finances → Market → Review → Simulate → Results
- Interactive stock projection with confidence intervals (5th, 25th, 75th, 95th percentiles)
- Mortality curves with single/couple support and joint survival probabilities
- Real-time simulation progress showing year-by-year updates
- Professional UI with sentence case throughout
- Comprehensive test coverage (70 tests passing)

This provides a much more intuitive flow where users:
1. Enter their information step by step
2. See visual previews of market and mortality assumptions
3. Review everything before running
4. Watch simulation progress in real-time
5. Get clear results

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant