{
  "schemaVersion": 1,
  "slug": "investment-calculator-ramsey",
  "category": "finance",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "318783b7af96230b96c21446856bc0299e62c2c7320133faab350289e4e9cc49",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/investment-calculator-ramsey.json",
    "src/engine.js"
  ],
  "runtimeSource": "/sources/engine.txt",
  "runtimeHash": "5c888d8898afbdee36267bb9977829e1e2ac568f6677c8ee87469c139864645c",
  "scope": "The compute function records implemented equations, constants, lookup tables and custom rules. Inputs record defaults and allowed values; outputs record precision and units. Defaults are examples, not recommendations. General background references are not evidence for this specific algorithm.",
  "publishedFormula": {
    "formula": "B_{k+1} = B_k × (1 + r_m) + M; r_m = (1 + r_a)^(1/12) − 1",
    "vars": [
      [
        "B_k",
        "Balance after k months"
      ],
      [
        "r_m",
        "Monthly rate"
      ],
      [
        "r_a",
        "Annual return (%)"
      ],
      [
        "M",
        "Monthly contribution ($)"
      ],
      [
        "n",
        "Number of months"
      ]
    ],
    "note": "Real value = projected balance ÷ (1 + user-entered inflation rate)^years. All return and withdrawal inputs are scenarios, not guarantees."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const r = annualReturn/100;\nconst rm = Math.pow(1 + r, 1/12) - 1;\nconst n = Math.max(0, Math.round(years*12));\nlet bal = initialAmount;\nfor (let i = 0; i < n; i++) bal = bal*(1 + rm) + monthlyInvestment;\nconst contributed = initialAmount + monthlyInvestment*n;\nconst num = 1000000*rm + monthlyInvestment;\nconst den = initialAmount*rm + monthlyInvestment;\nconst ttm = rm > 0 && num > 0 && den > 0 ? Math.log(num/den)/Math.log(1 + rm)/12 : 0;\nconst deflator = Math.pow(1 + inflationRate/100, years);\nreturn { futureValue: bal, totalContributions: contributed, totalGrowth: bal - contributed, monthlyIncome: bal*(withdrawalRate/100)/12, yearsToMillion: ttm, ruleOf72Years: annualReturn > 0 ? 72/annualReturn : null, valueInTodaysDollars: deflator > 0 ? bal/deflator : bal };",
    "inputs": [
      {
        "name": "initialAmount",
        "type": "number",
        "default": 1000,
        "min": 0,
        "max": 5000000,
        "step": 100
      },
      {
        "name": "monthlyInvestment",
        "type": "number",
        "default": 500,
        "min": 0,
        "max": 100000,
        "step": 10
      },
      {
        "name": "annualReturn",
        "type": "number",
        "default": 7,
        "min": -20,
        "max": 30,
        "step": 0.1,
        "slider": true
      },
      {
        "name": "years",
        "type": "number",
        "default": 30,
        "min": 1,
        "max": 60,
        "step": 1,
        "slider": true
      },
      {
        "name": "withdrawalRate",
        "type": "number",
        "default": 8,
        "min": 0,
        "max": 15,
        "step": 0.1,
        "slider": true
      },
      {
        "name": "inflationRate",
        "type": "number",
        "default": 2.5,
        "min": 0,
        "max": 20,
        "step": 0.1
      }
    ],
    "outputs": [
      {
        "name": "futureValue",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "totalContributions",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "totalGrowth",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "monthlyIncome",
        "precision": 2,
        "unit": "$"
      },
      {
        "name": "yearsToMillion",
        "precision": 1,
        "unit": "years"
      },
      {
        "name": "ruleOf72Years",
        "precision": 1,
        "unit": "years",
        "optional": true
      },
      {
        "name": "valueInTodaysDollars",
        "precision": 2,
        "unit": "$"
      }
    ],
    "interpret": null
  }
}
