{
  "schemaVersion": 1,
  "slug": "loan-calculator",
  "category": "finance",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "4d64549e87bfc539ac5e63df14f6ff9d3184f904e8aa66aa9a216dde464c90b6",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/loan-calculator.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": "M = P · r(1+r)^n / ((1+r)^n − 1)",
    "vars": [
      [
        "M",
        "Periodic (usually monthly) payment"
      ],
      [
        "P",
        "Principal — the original amount borrowed"
      ],
      [
        "r",
        "Periodic interest rate — annual rate divided by 12, expressed as a decimal"
      ],
      [
        "n",
        "Total number of payments — term in years multiplied by 12"
      ]
    ],
    "note": "The same payment is due every period. Total repaid is M·n; subtract P to get the total interest. If r is 0, the payment is simply P/n."
  },
  "externalEvidence": {
    "reviewedAt": "2026-09-24",
    "sources": [
      {
        "name": "CFPB — How mortgage lenders calculate monthly payments",
        "url": "https://www.consumerfinance.gov/ask-cfpb/how-do-mortgage-lenders-calculate-monthly-payments-en-1965/"
      }
    ]
  },
  "contract": {
    "compute": "if(!Number.isFinite(principal)||principal<1||principal>1e9||!Number.isFinite(annualRate)||annualRate<0||annualRate>100||!Number.isFinite(years)||years<1||years>50||!Number.isInteger(years))return{__error:'inputError'};const r = annualRate / 100 / 12; const n = years * 12; const monthly = r === 0 ? principal / n : (principal * r) / (1 - Math.pow(1 + r, -n)); const total = monthly * n; return { monthly: monthly, total: total, interest: total - principal };",
    "inputs": [
      {
        "name": "principal",
        "type": "number",
        "default": 250000,
        "min": 1,
        "step": 100,
        "max": 1000000000,
        "strictRange": true
      },
      {
        "name": "annualRate",
        "type": "number",
        "default": 6.5,
        "min": 0,
        "max": 100,
        "step": 0.01,
        "slider": true,
        "strictRange": true
      },
      {
        "name": "years",
        "type": "number",
        "default": 30,
        "min": 1,
        "max": 50,
        "step": 1,
        "slider": true,
        "strictRange": true
      }
    ],
    "outputs": [
      {
        "name": "monthly",
        "precision": 2
      },
      {
        "name": "total",
        "precision": 0
      },
      {
        "name": "interest",
        "precision": 0
      }
    ],
    "interpret": null
  }
}
