rmurphey/monte-carlo-simulator

โ˜… 3Forks 0TypeScriptGitHub โ†—Compare

README

Monte Carlo Business Decision Framework

Create Custom Monte Carlo Simulations for Strategic Business Decisions

โšก TL;DR - Create Your Business Analysis

Turn uncertain business decisions into rigorous risk analysis:

# Browse templates to get started
npx monte-carlo-simulator list

# Create your custom simulation (no coding required!)
npx monte-carlo-simulator create --interactive

# OR: Copy a template and modify it for your business
curl -O https://raw.githubusercontent.com/rmurphey/monte-carlo-simulator/main/examples/simulations/simple-roi-analysis.yaml
# Edit the YAML file with your parameters, then run:
npx monte-carlo-simulator run simple-roi-analysis --set initialInvestment=100000

You Get: Confidence intervals like "75% chance of $200K+ savings, 15% chance of breaking even, 10% chance of loss"

Instead Of: Vague statements like "AI tools will probably save money"

๐ŸŽฏ Primary Purpose: Create custom Monte Carlo simulations for YOUR business decisions using proven templates - no coding, data science expertise, or complex setup required!


๐Ÿค” Why Use This?

The Problem

You're facing strategic business decisions with uncertainty:

  • "Should we hire 5 developers or invest in automation tools?"
  • "When will this marketing campaign pay for itself?"
  • "What happens to our runway if growth slows down?"
  • "Is this $200K technology investment worth the risk?"

Traditional approaches fall short:

  • ๐Ÿ“Š Spreadsheets: Static, single-point estimates that miss risk ("We'll definitely get 10x ROI")
  • ๐Ÿคท Gut feeling: No data backing your $500K decision ("It feels right")
  • ๐Ÿ“ˆ Basic projections: "Best case we make $X" (but what about worst case?)

The Solution

Turn uncertain business questions into rigorous risk analysis with confidence intervals:

Instead of: "Marketing will probably generate 10x ROI"
Get: "Marketing has 70% chance of 5-15x ROI, 20% chance of 2-5x ROI, 10% chance of loss"

Instead of: "Hiring 5 devs will increase velocity"
Get: "5 devs: 80% chance of 2.8x velocity, 20% chance of 1.2x due to coordination overhead"

Instead of: "AI tools will save money"
Get: "AI tools: 75% chance of $200K+ annual savings, 15% chance of breaking even, 10% chance of $30K annual loss"

Who This Is For

  • CTOs/Engineering Leaders: Technology investment ROI with working examples
  • Startup Founders: Resource allocation models with proven templates
  • Product Managers: Feature prioritization using battle-tested simulations
  • Business Analysts: Risk assessment with copy-modify workflow
  • AI Agents/Developers: Programmatic simulation generation from examples

๐ŸŽฏ How It Works: Create Your Custom Simulation

PRIMARY WORKFLOW: Copy a template โ†’ Modify for your business โ†’ Run analysis

No coding, data science, or complex setup required!

1. Choose Your Template

# Browse 9+ proven templates for different business decisions
npx monte-carlo-simulator list

# Examine any template's customizable parameters
npx monte-carlo-simulator run technology-investment --list-params

2. Copy & Modify

# Interactive creation (guided workflow)
npx monte-carlo-simulator create --interactive

# OR: Copy any example YAML file
curl -O https://raw.githubusercontent.com/rmurphey/monte-carlo-simulator/main/examples/simulations/simple-roi-analysis.yaml

# Edit the YAML file with your business parameters
# Change investment amounts, team sizes, time periods, etc.

3. Run Your Custom Analysis

# Validate your changes (if you downloaded the file)
npx monte-carlo-simulator validate examples/simulations/simple-roi-analysis.yaml

# Run with your parameters - includes comprehensive Monte Carlo visualizations
npx monte-carlo-simulator run simple-roi-analysis

# Override parameters on the fly
npx monte-carlo-simulator run simple-roi-analysis --set initialInvestment=250000

# Get detailed statistical analysis with histograms for all outputs
npx monte-carlo-simulator run simple-roi-analysis --verbose

๐Ÿ“Š Monte Carlo Visualizations

Every simulation includes comprehensive visual analysis:

  • ๐Ÿ“ˆ Confidence Intervals: Visual representation of outcome ranges (P10, P50, P90)
  • ๐Ÿ“Š Histogram Distributions: ASCII bar charts showing probability distributions
  • โšก Risk Analysis: Probability of loss, Value at Risk (95%, 99%), Expected Shortfall
  • ๐Ÿ“‹ Statistical Summaries: Complete percentile breakdowns and business interpretations
# Example output includes:
#   ๐ŸŽฒ MONTE CARLO ANALYSIS
#   ๐Ÿ“ˆ ROI Percentage - Confidence Intervals  
#   ๐Ÿ“Š ROI Percentage [histogram with probability percentages]
#   โšก ROI Percentage - Risk Analysis

Available Business Templates

  • ROI Analysis: Investment returns with uncertainty modeling
  • Team Scaling: Hiring decisions with coordination overhead
  • Technology Investment: Tool adoption with productivity gains
  • Marketing Campaigns: Multi-channel ROI with customer acquisition
  • Quality Assurance: Manual vs automated testing strategies
  • Sales Operations: Outbound sales team effectiveness

Templates are fully-working examples designed to be copied and customized for your specific business parameters.

โœจ AI Agents: Perfect for programmatic business analysis generation!

When NOT to Use This Framework

  • โŒ Decisions under $10K (overkill for small decisions)
  • โŒ Completely deterministic problems (no uncertainty to model)
  • โŒ Immediate decisions (analysis takes time to set up and run)
  • โŒ When you have dedicated data science team with specialized tools

๐Ÿš€ Local Development (Optional)

Most users don't need this - the npx commands above work immediately without any setup!

For Local Development

Installation & Setup

# Clone and set up the framework
git clone https://github.com/rmurphey/monte-carlo-simulator
cd monte-carlo-simulator

# Install dependencies and build
npm install
npm run build

# Verify installation
npm run cli --help

# Start web development server with hot reload
npm run dev:web  # Runs headless by default
npm run dev:web:open  # Opens browser at http://localhost:3000

Web Interface with Simulation Selector ๐ŸŒ

Interactive web interface with full access to all simulation templates:

# Start web interface (headless by default)
npm run dev:web

# Or open in browser for development
npm run dev:web:open

# Access directly with simulation parameter
# http://localhost:3000/?simulation=simple-roi-analysis

Web Interface Features:

  • Simulation Selector: Dropdown with 9+ available simulation templates
  • Dynamic Parameter Forms: Parameters update automatically based on selected simulation
  • Value Preservation: Compatible parameter values preserved when switching simulations
  • URL Parameter Support: Direct simulation loading via ?simulation=template-name
  • Complete Visualization: Charts, statistics, and configuration management
  • Professional UI: Clean, responsive interface matching existing design system

Development Features:

  • Instant Hot Reload: Changes to HTML, CSS, or TypeScript reflect immediately
  • TypeScript Integration: Real-time compilation and error reporting
  • Modern Tooling: Vite-powered development with optimized builds
  • Headless by Default: Browser opens only when explicitly requested for development

Troubleshooting Setup

If you encounter issues during installation:

# Check Node.js version (requires 16+)
node --version

# Clean install if dependencies fail
rm -rf node_modules package-lock.json
npm install

# Rebuild if TypeScript compilation fails  
npm run build

# Test core functionality
npm run cli list
npm run test

Common Issues:

  • Node.js version: Requires Node 16+ for TypeScript features
  • Permission errors: Use npm install (not sudo npm install)
  • Build failures: Run npm run build after any code changes
  • Missing simulations: Verify you're in the project root directory

Professional Examples-First Workflow ๐ŸŽฏ

The framework is designed around copying and modifying working examples:

# Discover available simulations
npm run cli list

# Run any simulation with default parameters  
npm run cli -- run simple-roi-analysis

# Override specific parameters
npm run cli -- run simple-roi-analysis --set initialInvestment=75000 --set monthlyBenefit=6000

# See all available parameters for any simulation
npm run cli -- run simple-roi-analysis --list-params

# Validate simulation configurations
npm run cli -- validate examples/simulations/simple-roi-analysis.yaml

Interactive Parameter Exploration ๐ŸŽ›๏ธ

Adjust parameters in real-time and see results update instantly:

# Launch interactive mode for any simulation (terminal required)
npm run cli -- run simple-roi-analysis --interactive

# Interactive simulation selection
npm run cli interactive

# For non-terminal environments (Claude Code, CI/CD), use parameter flags:
npm run cli -- run simple-roi-analysis --set initialInvestment=500000 --set affectedEmployees=100

Interactive Features:

  • Real-time parameter adjustment - Change values and see immediate impact on results (terminal required)
  • Before/after comparison - Track how parameter changes affect outcomes
  • Parameter validation - Type checking and range enforcement with helpful error messages
  • Dynamic parameter discovery - No static documentation to maintain
  • Environment detection - Clear error messages with alternatives for unsupported environments

Examples-First Simulation Creation โœจ

Create business simulations by copying and modifying working examples:

# Copy a relevant example to start
cp examples/simulations/simple-roi-analysis.yaml my-roi-analysis.yaml

# Validate your changes  
npm run cli -- validate my-roi-analysis.yaml

# Run your custom simulation
npm run cli -- run my-roi-analysis.yaml

# Or create interactively
npm run cli create --interactive

Examples-First Benefits:

  • Proven Patterns: Start from tested, working business simulations
  • Copy-Modify Workflow: Professional approach - copy example, customize for your needs
  • No Learning Curve: Skip complex configuration, focus on business logic
  • Agent-Friendly: Ideal for AI-assisted simulation generation
  • Battle-Tested: All examples validated and production-ready

Run Your First Analysis

# Discover available simulations
npm run cli list

# Run example simulations by ID
npm run cli run simple-roi-analysis
npm run cli run technology-investment

# Generate comprehensive analysis documents
npm run cli run simple-roi-analysis --format=document
npm run cli run technology-investment --format=document --output=analysis.md

# Interactive parameter exploration  
npm run cli run simple-roi-analysis --interactive

# See all available commands
npm run cli --help

๐Ÿ“Š What You Can Do Right Now

1. Run Working Examples

# Simple ROI analysis - basic pattern for learning
npm run cli run examples/simulations/simple-roi-analysis.yaml

# Technology investment - realistic business decision
npm run cli run examples/simulations/technology-investment.yaml

# Team scaling - advanced with business intelligence
npm run cli run examples/simulations/team-scaling-decision.yaml

# QA strategy analysis - manual vs automated testing ROI
npm run cli run simulations/manual-qa-roi.yaml
npm run cli run simulations/qa-strategy-comparison.yaml

# Scenario analysis - compare risk scenarios
npm run cli run examples/simulations/ai-tool-adoption/ai-tool-adoption.yaml
npm run cli run examples/simulations/ai-tool-adoption/conservative.yaml
npm run cli run examples/simulations/ai-tool-adoption/aggressive.yaml

Expected output:

๐Ÿ”ฌ Monte Carlo Simulation: AI Tool Adoption Analysis (Conservative)
๐Ÿ“Š Results (1,000 iterations):
   Annual Tool Cost ($): $10,800
   Net Annual Benefit ($): $61,538 ยฑ $16,261
   ROI Percentage: 570% ยฑ 151%

๐Ÿ”ฌ Monte Carlo Simulation: AI Tool Adoption Analysis (Aggressive)  
๐Ÿ“Š Results (1,000 iterations):
   Annual Tool Cost ($): $4,800
   Net Annual Benefit ($): $565,544 ยฑ $84,549
   ROI Percentage: 11,782% ยฑ 1,761%

2. Study Working Patterns

# See all available examples with agent-friendly patterns
ls examples/simulations/
cat examples/README.md

# Study the YAML structure that actually works
cat examples/simulations/simple-roi-analysis.yaml

3. Create Your Own Simulation

Copy and modify working examples:

# Based on proven working patterns
name: "Your Business Decision"
category: "Business"
description: "Analysis of your specific strategic decision with uncertainty modeling"
version: "1.0.0"
tags: [strategy, decision]

parameters:
  - key: investment
    label: "Investment Amount ($)"
    type: number
    default: 50000
    
simulation:
  logic: |
    const annualBenefit = investment * (0.15 + random() * 0.1)  
    const roi = ((annualBenefit - investment) / investment) * 100
    return { roi: Math.round(roi * 10) / 10 }

All examples are tested and working.

For AI Agents:

  • Complete guide: docs/AGENT.md for specifications, patterns, and interactive exploration workflows

For Interactive Development: See docs/INTERACTIVE_STUDIO.md for the planned interactive simulation definition and real-time execution system.

๐Ÿ’ฐ Real Business Impact Examples

Before This Framework:

  • "AI tools will save money" โ†’ Spend $50K/year hoping for the best
  • "Hire 5 developers" โ†’ $600K commitment based on gut feeling
  • "Marketing campaign will work" โ†’ $100K budget with crossed fingers

With This Framework:

  • AI Tool Decision: "75% chance of $200K+ savings, 10% chance of loss" โ†’ Data-driven decision with risk assessment
  • Hiring Decision: "5 devs have 20% chance of negative ROI due to coordination overhead" โ†’ Consider smaller team or different structure
  • Marketing Decision: "Campaign A has 60% success rate vs Campaign B's 40%" โ†’ Choose better-odds campaign

๐Ÿ“š Documentation

For Humans:

For AI Agents:

  • docs/AGENT.md - Complete technical specifications, working patterns, schema requirements
  • examples/README.md - Detailed simulation patterns with validation rules

๐Ÿ›  Current Capabilities

โœ… What Works Today

  • Monte Carlo simulation engine with statistical analysis
  • Business intelligence functions (ROI, payback period, runway calculations)
  • YAML-based configuration with bulletproof validation
  • TypeScript framework for complex custom logic
  • Professional CLI with comprehensive parameter validation
  • Production-grade reliability (92 passing tests with schema validation)

โœ… Current Capabilities

  • Risk scenario comparison - Side-by-side analysis with --compare flag
  • Export capabilities - JSON/CSV/Document output with --format and --output options
  • Document generation - Comprehensive analysis reports with text-based visualizations
  • Parameter overrides - Custom values via CLI arguments or parameter files
  • Statistical analysis - P10/P50/P90 percentiles, mean, standard deviation

๐Ÿ”ง Development & Customization

Working with Examples

# Copy and modify existing examples
cp examples/simulations/simple-roi-analysis.yaml YOUR_SIMULATION.yaml

# Edit parameters and simulation logic
# Then run your custom simulation
npm run cli run YOUR_SIMULATION.yaml

Advanced CLI Features

Interactive Config Editing - Full simulation development environment:

# Launch interactive session with complete config editing capabilities
npm run cli run examples/simulations/simple-roi-analysis.yaml --interactive
npm run cli run examples/simulations/technology-investment.yaml --interactive

# Interactive commands available in session:
# [r] Run simulation again    [c] Edit full config    [s] Save changes  
# [e] Export results          [h] Help               [q] Quit

# Config editor sub-commands:
# [e] Edit full YAML in $EDITOR  [t] Test config   [u] Undo changes
# [r] Run with changes          [b] Back to main menu

# Features:
# โœ… External editor integration (nano, vim, VS Code, etc.)
# โœ… Safe temporary files with automatic cleanup and backups
# โœ… Config history with undo/redo functionality
# โœ… Real-time validation and change detection
# โœ… Perfect for rapid prototyping and iterative development

Interactive Workflow Example:

# Start session - shows initial simulation results
npm run cli -- run simple-roi-analysis.yaml --interactive

# Enter config editing mode
> c

# Edit full YAML configuration  
> e
# Opens config in your $EDITOR, make changes, save and exit

# Automatic validation shows what changed:
# ๐Ÿ” Changes detected:
#   โ€ข Modified parameter: initialInvestment (100000 โ†’ 250000)  
#   โ€ข Updated simulation logic: added risk adjustment

# Test changes with quick 100-iteration run
> t

# Save changes permanently or undo if needed
> s    # Save to original file with backup
> u    # Undo changes and revert

Parameter Files - Batch analysis with custom values:

# Create parameter file with custom values  
echo '{"initialCost": 75000, "adoptionRate": 0.8}' > my-scenario.json

# Run simulation with custom parameters
npm run cli run simulations/ai-investment-roi/baseline.yaml --params my-scenario.json --verbose

# Save results for analysis
npm run cli run simple-roi-analysis --params scenario.json --output results.json --iterations 5000

Development Commands:

# Core development
npm run dev                 # Watch mode for CLI development
npm run build              # Compile TypeScript  
npm run test               # Run full test suite (92 tests - all passing)
npm run test:watch         # Run tests in watch mode
npm run test:coverage      # Run tests with coverage report

# Web development
npm run dev:web            # Vite development server headless (port 3000)
npm run dev:web:open       # Vite development server with browser (port 3000)
npm run build:web:vite     # Production web build with Vite
npm run preview:web        # Preview production web build locally (headless)
npm run preview:web:open   # Preview production web build with browser
npm run test:web           # Test Vite development server and web interface
npm run test:all           # Run both framework and web tests

# Code quality
npm run lint               # Check for linting issues
npm run lint:fix           # Auto-fix linting issues
npm run format             # Format code with Prettier
npm run typecheck          # TypeScript type checking

# Validation
npm run cli validate YOUR_SIMULATION.yaml  # Bulletproof YAML validation with detailed errors
npm run validate:yaml      # Validate all YAML files
npm run validate:json      # Validate all JSON files
npm run test:docs          # Test documentation examples
npm run test:agent-apis    # Test agent API functionality

# CLI commands
npm run cli list           # List available simulations
npm run sim                # Quick interactive mode

Project Structure

src/
โ”œโ”€โ”€ framework/             # Core Monte Carlo engine
โ”œโ”€โ”€ cli/                   # Command-line interface
โ”œโ”€โ”€ examples/              # Working example simulations  
โ””โ”€โ”€ test/                  # Test cases and validation

examples/simulations/      # 7 working examples
โ”œโ”€โ”€ simple-roi-analysis.yaml
โ”œโ”€โ”€ technology-investment.yaml  
โ”œโ”€โ”€ team-scaling-decision.yaml
โ”œโ”€โ”€ software-investment-roi.yaml
โ”œโ”€โ”€ marketing-campaign-roi.yaml
โ””โ”€โ”€ ai-tool-adoption/      # Scenario examples

NPX Quick Start (Zero Installation)

# Run simulations directly without installation
npx monte-carlo-simulator list
npx monte-carlo-simulator run simple-roi-analysis
npx monte-carlo-simulator run technology-investment --set toolCost=30000

# Parameter discovery and validation
npx monte-carlo-simulator run simple-roi-analysis --list-params
npx monte-carlo-simulator validate examples/simulations/simple-roi-analysis.yaml

Current Capabilities

  • NPM Package - Published and available via npx monte-carlo-simulator
  • Local development - Full development environment available
  • Zero installation - No setup required, works immediately

๐Ÿค Contributing

This project is designed for:

  • Business professionals creating analysis templates
  • Developers extending the framework capabilities
  • AI agents generating simulations from natural language

Quick Contributions:

  1. Add business scenarios by creating YAML configurations
  2. Improve existing examples with better parameters/logic
  3. Add industry-specific functions to the business intelligence library
  4. Write tests for new simulation patterns

๐ŸŽฏ Success Stories

"Used this to analyze whether to hire 3 senior developers or 5 junior developers. The coordination overhead modeling showed 3 seniors had 85% chance of better velocity. Saved $180K in salary costs." - CTO, Series B Startup

"Marketing campaign analysis showed our 'safe' strategy had lower expected value than the 'risky' one due to market timing. Switched strategies and hit 340% ROI instead of projected 180%." - Growth Lead, SaaS Company

"Runway analysis with multiple scenarios helped us decide between raising Series A vs extending runway. Monte Carlo showed 73% chance we'd hit milestones with current burn rate." - Founder, Pre-seed Startup

๐Ÿ”ฎ Vision

Transform risky business guesses into data-driven decisions with confidence intervals.

Every strategic question becomes a working simulation:

  • "When does generative AI cost outweigh benefits?" โ†’ Monte Carlo analysis with cost/benefit distributions
  • "Should we hire 5 developers or invest in automation?" โ†’ Risk-adjusted comparison with coordination modeling
  • "What's the optimal team scaling strategy?" โ†’ Multi-scenario analysis with velocity and cost projections

๐Ÿ“„ License

MIT License - See LICENSE file for details


Turn uncertainty into confidence. Make better business decisions with data.

Contributors

rmurphey

Issues