# Formula: does a home battery pay off for a Dutch household after salderen (1 Jan 2027)

Code: `calc.mjs`. Test cases: `test-cases.json`, computed by `scripts/expected.py` (a separate implementation, Python, reads only `products.json` and `prices.json`). Source of each constant: /methode/ and `products.json` `math`.

## Inputs
`U` yearly use (kWh). `P` yearly solar yield (kWh, 0 without panels). `price` energy price incl. tax (euro per kWh). `gross` feed-in compensation, `cost` feed-in costs (euro per kWh); net feed-in `fi = gross - cost`. `contract` fixed, variable or dynamic. `b` budget in euro (0 = none), `m` maximum usable capacity in kWh (0 = none). A battery has usable capacity `kwh` and price `cost`.

## Constants
direct use share `s = 0.30`; round-trip efficiency `eff = 0.80`; weather factor `0.70` (own assumption, no source: monthly averages overstate sunny days); ageing `2%` per year; life `15` years; dynamic extra per usable kWh per year: `37/5 = 7.4` with panels, `60/5 = 12` without (one study of a 5 kWh battery, not checked by us), counted only over the capacity the house uses on its best day. Monthly shares: solar from PVGIS (De Bilt, `data/pv-monthly.json`), use an own assumption with more use in winter.

## Steps
1. For each month `m` with `days` days: daily solar `p = P * pv[m] / days`, daily use `u = U * use[m] / days`, direct `d = min(s * p, u)`, daily surplus `e = p - d`, daily need `n = u - d`.
2. Battery gives back per day `x = 0.7 * min(kwh, n, e * eff)`. `deliver` = sum over all days. `D` = sum of `d` over all days, `E = P - D`, `I = U - D`.
3. Cost without battery after salderen: `c27 = I * price - E * fi`. During salderen: `c26 = max(I - E, 0) * price - max(E - I, 0) * fi`. What the end costs per year: `c27 - c26`.
4. Saving: `su = deliver * price - (deliver / eff) * fi`.
5. Dynamic contract only: `dyn = 7.4 * min(kwh, best daily x)` with panels, `12 * min(kwh, largest daily need)` without. Year-1 saving `S1 = su + dyn`.
6. Year `y` saves `S1 * 0.98^(y-1)`. Lifetime total = sum over 15 years. `net = total - cost`.
7. Payback = first moment the running total reaches `cost` (linear inside the year). None when it does not within 15 years.
8. Self-use share: before `D / P`, after `(D + deliver / eff) / P`.
9. Ranking: only models inside budget and size limit, cheapest in-stock offer, highest `net` first. Verdict "pays" when the best `net > 0`, otherwise "Nog niet kopen" with no buy buttons.
