{
  "schemaVersion": 1,
  "slug": "payback-period-calculator",
  "category": "finance",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "20d2089555270d5f406b5066ecada512963d65f456cac2aad54566605b03709b",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/payback-period-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": "PB = I ÷ C; PV_t = C ÷ (1 + r)^t; t = min{j ∈ ℕ : Σ_{k=1}^{j} PV_k ≥ I}; DPB = t − 1 + (I − Σ_{k=1}^{t−1} PV_k) ÷ PV_t",
    "vars": [
      [
        "I",
        "Initial investment"
      ],
      [
        "C",
        "Annual net cash flow"
      ],
      [
        "r",
        "Discount rate"
      ],
      [
        "t",
        "First year cumulative PV reaches I"
      ],
      [
        "PV_t",
        "Present value of year-t cash flow"
      ]
    ],
    "note": "Simple payback = initial investment / annual cash flow, assuming constant year-end inflows. Discounted payback accumulates each annual cash flow discounted at the entered rate and interpolates within the recovery year; if recovery does not occur within the modeled horizon, discounted payback is undefined."
  },
  "externalEvidence": null,
  "contract": {
    "compute": "const r=discountRate/100;\nconst simple = annualCashFlow>0 ? initialInvestment/annualCashFlow : 0;\nlet cum=0, cumD=0, discPay=0, found=false;\nfor(let t=1;t<=years;t++){\n  const p=annualCashFlow/Math.pow(1+r,t);\n  cumD+=p; cum+=annualCashFlow;\n  if(!found && cumD>=initialInvestment){ found=true; discPay = t-1 + (p>0 ? (initialInvestment-(cumD-p))/p : 0); }\n}\nif(!found)discPay=null;\nreturn { paybackYears: simple, discountedPaybackYears: discPay, cumulativeInflows: cum, pvInflows: cumD, surplus: cum-initialInvestment };",
    "inputs": [
      {
        "name": "initialInvestment",
        "type": "number",
        "default": 20000,
        "min": 1,
        "max": 10000000,
        "step": 500
      },
      {
        "name": "annualCashFlow",
        "type": "number",
        "default": 6000,
        "min": 1,
        "max": 10000000,
        "step": 100
      },
      {
        "name": "discountRate",
        "type": "number",
        "default": 8,
        "min": 0,
        "max": 40,
        "step": 0.1,
        "slider": true
      },
      {
        "name": "years",
        "type": "number",
        "default": 10,
        "min": 1,
        "max": 40,
        "step": 1,
        "slider": true
      }
    ],
    "outputs": [
      {
        "name": "paybackYears",
        "precision": 2,
        "unit": "years"
      },
      {
        "name": "discountedPaybackYears",
        "precision": 2,
        "unit": "years",
        "optional": true
      },
      {
        "name": "cumulativeInflows",
        "precision": 0,
        "unit": "USD"
      },
      {
        "name": "pvInflows",
        "precision": 0,
        "unit": "USD"
      },
      {
        "name": "surplus",
        "precision": 0,
        "unit": "USD"
      }
    ],
    "interpret": null
  }
}
