How the Decision tools car total cost of ownership calculator is verified

Inputs

InputFieldType
Purchase pricepurchasePricenumber
Depositdepositnumber
Trade-in valuetradeInnumber
Finance APR (%)aprPctnumber
Finance term (months)loanTermMonthsinteger
Years you keep ityearsinteger
Distance per year (km)annualDistancenumber
Fuel typefuelTypestring
Consumption per 100 km (L, or kWh for an EV)consumptionPer100number
Price per litre (or per kWh)unitPricenumber
Insurance per yearinsurancePerYearnumber
Servicing per yearservicingPerYearnumber
Repairs allowance per yearrepairsPerYearnumber
Cost of a set of tyrestyreSetCostnumber
Tyre life (km)tyreLifeKmnumber
Road tax per yearroadTaxPerYearnumber
Inspection per yearinspectionPerYearnumber
Parking per yearparkingPerYearnumber
Tolls per yeartollsPerYearnumber
Breakdown cover per yearbreakdownCoverPerYearnumber

The formula

Each derived value below is computed by the Valem engine from the expression shown, in this order. Nothing else runs — there is no hidden code path.

Derived valueFieldFormula (JSONata)
Financed AmountfinancedAmount$max([0, $round(purchasePrice - deposit - tradeIn, 2)])
Monthly RatemonthlyRateaprPct / 1200
Compound FactorcompoundFactor$power(1 + monthlyRate, loanTermMonths)
Monthly finance paymentmonthlyPayment(financedAmount <= 0 or loanTermMonths <= 0) ? 0 : (monthlyRate = 0 ? $round(financedAmount / loanTermMonths, 2) : $round(financedAmount * monthlyRate * compoundFactor / (compoundFactor - 1), 2))
Finance interesttotalInterest$max([0, $round(monthlyPayment * loanTermMonths - financedAmount, 2)])
Resale value at the endresidualValue$round(purchasePrice * $residualPct(years, $const.residualCurve, $const.tailDepreciation), 2)
DepreciationtotalDepreciation$round(purchasePrice - residualValue, 2)
Energy Cost Per YearenergyCostPerYear$round(annualDistance / 100 * consumptionPer100 * unitPrice, 2)
Tyre Cost Per YeartyreCostPerYear$round($ceil(annualDistance * years / tyreLifeKm) * tyreSetCost / years, 2)
Fixed Cost Per YearfixedCostPerYear$round(insurancePerYear + servicingPerYear + repairsPerYear + roadTaxPerYear + inspectionPerYear + parkingPerYear + tollsPerYear + breakdownCoverPerYear, 2)
What you pay each year, by cost categoryyearly$map([1..years], function($y) { ( $m1 := $min([($y - 1) * 12, loanTermMonths]); $m2 := $min([$y * 12, loanTermMonths]); $b1 := $balanceAt($m1, financedAmount, monthlyRate, compoundFactor, loanTermMonths); $b2 := $balanceAt($m2, financedAmount, monthlyRate, compoundFactor, loanTermMonths); $int := $max([0, $round(monthlyPayment * ($m2 - $m1) - ($b1 - $b2), 2)]); $v0 := $round(purchasePrice * $residualPct($y - 1, $const.residualCurve, $const.tailDepreciation), 2); $v1 := $round(purchasePrice * $residualPct($y, $const.residualCurve, $const.tailDepreciation), 2); $dep := $round($v0 - $v1, 2); $cumInt := $max([0, $round(monthlyPayment * $m2 - (financedAmount - $b2), 2)]); {"year": $y, "depreciation": $dep, "interest": $int, "energy": energyCostPerYear, "tyres": tyreCostPerYear, "fixed": fixedCostPerYear, "total": $round($dep + $int + energyCostPerYear + tyreCostPerYear + fixedCostPerYear, 2), "cumulative": $round(purchasePrice - $v1 + $cumInt + $y * (energyCostPerYear + tyreCostPerYear + fixedCostPerYear), 2)} ) })
Total cost of ownershiptotalCost$round($sum($map(yearly, function($r) { $r.total })), 2)
Cost per kmcostPerKmannualDistance <= 0 ? 0 : $round(totalCost / (annualDistance * years), 4)
Cost per monthcostPerMonth$round(totalCost / (years * 12), 2)
Depreciation sharedepreciationSharetotalCost <= 0 ? 0 : $round(totalDepreciation / totalCost * 100, 1)

Rates and thresholds

The expressions above read these as $const. They are the figures the annual refresh replaces, so they live as data rather than being written into the formulas — which is what makes a year-on-year change a one-line diff instead of an edit to arithmetic.

ConstantValue
residualCurve[0.8,0.7,0.62,0.55,0.49,0.44,0.39,0.35,0.31,0.28]
tailDepreciation0.1

Test vectors (3)

Every case is executed against this model on each build, by the Java engine and independently by a JavaScript one. A mismatch of a single cent fails the build, so the page cannot ship advertising a figure the model no longer produces.

Case 1 — 32,000 petrol car on 6.5% finance over 60 months, 15,000 km a year, kept five years

given purchasePrice32000
given deposit6000
given aprPct6.5
given loanTermMonths60
given years5
given annualDistance15000
expect financedAmount26000
expect monthlyPayment508.72
expect totalInterest4523.2
expect residualValue15680
expect totalDepreciation16320
expect energyCostPerYear1706.25
expect tyreCostPerYear192
expect fixedCostPerYear1960
expect yearly[0].depreciation6400
expect yearly[0].interest1556.08
expect yearly[0].total11814.33
expect yearly[4].cumulative40134.45
expect totalCost40134.45
expect costPerKm0.5351
expect costPerMonth668.91
expect depreciationShare40.7

Case 2 — the same car bought for cash — the total falls by exactly the finance interest

given deposit32000
expect financedAmount0
expect monthlyPayment0
expect totalInterest0
expect totalCost35611.25
expect costPerKm0.4748
expect costPerMonth593.52

Case 3 — the same car as an EV at 17 kWh/100 km and 0.28 per kWh — only the energy line changes

given fuelTypeev
given consumptionPer10017
given unitPrice0.28
expect energyCostPerYear714
expect totalInterest4523.2
expect totalDepreciation16320
expect totalCost35173.2
expect costPerKm0.469
expect depreciationShare46.4

Sources

Check it yourself — and reuse it

The whole model as JSON — inputs, outputs, formulas, vectors and sources in one re-runnable document.

This model is published under CC BY 4.0: use it, adapt it, build on it, with attribution. The licence covers the model — the expression of each rule and the arrangement of the catalog. The rates and thresholds are law, and nobody licenses those; the sources above are where they come from.

← Back to the Decision tools car total cost of ownership calculator

Built with Valem — a live, verifiable calculator you can fork and embed.