feat(kode): bring business economics, ownership, scale and verdicts in line with clarifications 41-61

The accident cost stays in S11 and S31 when the additionality rule binds;
the peak year of M6 is taken among operating years; tax depreciation and
carried losses lose real value with price growth; the special tax deducts
the corporate tax, has a return allowance and carries a negative basis with
interest, so it only meets return above r_e; ownership forms are compared
only with forms that pass the EEA assessment; the overall verdict needs a
negative median to fell a solution and takes whether conditions can be
named; M5 does not hold when both (i) and (ii) are broken; a non-positive
price without the programme is an error in M3. Made-up numbers only.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Kjell Tore Guttormsen 2026-11-12 14:33:49 +01:00
commit d4aebad0f9
Signed by: ktg
SSH key fingerprint: SHA256:JakMjO6FTBBzN0Bhfj9saOoEjaFxlSdYuZQQpM/lF9Q
14 changed files with 335 additions and 95 deletions

View file

@ -258,6 +258,12 @@ def test_del_I_holder_ikke_naar_hver_losning_er_felt() -> None:
assert dommer.del_I(per_losning, median, valg) is Dom.HOLDER_IKKE
per_losning[Losning.C] = _dommer(M6=Dom.HOLDER_IKKE)
assert dommer.del_I(per_losning, median, valg) is Dom.BETINGELSER
# without conditions that can be named within the range of the sources it does not hold
assert dommer.del_I(per_losning, median, valg, betingelser_kan_navngis=False) is Dom.HOLDER_IKKE
# the pre-registration says a negative median; a median of exactly zero does not fell
median[Losning.B] = 0.0
per_losning[Losning.C] = _dommer(M4=Dom.HOLDER_IKKE)
assert dommer.del_I(per_losning, median, valg) is Dom.BETINGELSER
assert dommer.del_I(per_losning, median, Trinnvalg(None, Grunnlag.INGEN)) is Dom.HOLDER_IKKE

View file

@ -6,6 +6,7 @@ parameter file's. Nothing here says anything about the hypothesis.
from __future__ import annotations
import dataclasses
import math
from typing import TYPE_CHECKING
@ -79,6 +80,19 @@ def test_underskudd_fores_fram_uten_rente() -> None:
assert lg.s28_etter_framforing([10.0, -5.0, -5.0, 30.0]) == (10.0, 0.0, 0.0, 20.0)
def test_s28_framfort_underskudd_taper_realverdi() -> None:
"""Without interest means nominal: a loss of 100 is worth 100 / 1.1 the year after.
With 10 % price growth: the loss of 100 is 90.91 in year 2, where 60 is used (30.91 left);
28.10 in year 3, where it is used up and 80 - 28.10 is taxed.
"""
grunnlag = lg.s28_etter_framforing([-100.0, 60.0, 80.0], faktor=1.0 / 1.1)
assert grunnlag[:2] == (0.0, 0.0)
assert grunnlag[2] == pytest.approx(80.0 - (100.0 / 1.1 - 60.0) / 1.1)
assert lg.s28_realverdi(belop=121.0, iota=0.1, aar=2) == pytest.approx(100.0)
assert lg.s28_realverdi(belop=121.0, iota=0.0, aar=7) == 121.0
def test_s28_naaverdi() -> None:
assert lg.s28_naaverdi(netto=[-100.0, 0.0, 121.0], rente=0.1) == pytest.approx(0.0)
@ -93,8 +107,10 @@ def test_s29_kapitalkostnad() -> None:
def test_s30_skatt_med_egen_framforing_for_saerskatten() -> None:
"""Corporate tax 20 % on profit after the loss; special tax 50 % above 5 % of capital 200.
Profit above the return: -100, 50, 70, 40. The loss of 100 takes the 50 and half of the
70, so the special tax base is 0, 0, 20, 40.
Corporate tax: 0, 0, 8, 10. The basis of the special tax is the profit minus the corporate
tax and minus 5 % of 200: -100, 50, 62, 30. The negative basis is carried with 5 %
interest: 105 meets the 50 (55 left), 57.75 meets the 62 (4.25 taxed), then 30. The rate
on that basis is 0.5 / 0.8, so one more krone of profit pays 20 % + 50 %.
"""
selskap, saer = lg.s30_skatt(
overskudd=[-100.0, 60.0, 80.0, 50.0],
@ -104,7 +120,7 @@ def test_s30_skatt_med_egen_framforing_for_saerskatten() -> None:
r_e=0.05,
)
assert selskap == pytest.approx((0.0, 0.0, 8.0, 10.0))
assert saer == pytest.approx((0.0, 0.0, 10.0, 20.0))
assert saer == pytest.approx((0.0, 0.0, 0.625 * 4.25, 0.625 * 30.0))
def test_s30_statens_kontantstrom() -> None:
@ -146,8 +162,23 @@ def test_R_bedriftsstrom_haandregnet(oppdiktet: LagInndata) -> None:
for t in res.aar:
assert strom.investering[aar[t]] == pytest.approx(investert.get(t, 0.0))
assert (strom.budsjett == strom.investering).all()
# the building over 15 years and one vintage at a time over 5
assert strom.avskrivning[aar[2030] :] == pytest.approx(110e9 / 15.0 + 40e9)
# The building over 15 years and one vintage at a time over 5. The deduction is fixed in
# the kroner of the year each half was paid (2028 and 2029; later vintages the year before
# they start) and loses 2 % a year in constant kroner (clarification 47). Nothing is
# written off at the final year: the building and the last vintage are still in operation.
def realt(aar_siden: int) -> float:
return 1.02**-aar_siden
assert strom.avskrivning[aar[2030]] == pytest.approx(
(55e9 / 15.0 + 20e9) * (realt(2) + realt(1))
)
assert strom.avskrivning[aar[2036]] == pytest.approx(
55e9 / 15.0 * (realt(8) + realt(7)) + 40e9 * realt(2)
)
assert strom.avskrivning[aar[2040]] == pytest.approx(
55e9 / 15.0 * (realt(12) + realt(11)) + 40e9 * realt(1)
)
assert not strom.avskrivning[: aar[2030]].any()
assert strom.kapital[aar[2029]] == pytest.approx(310e9)
assert strom.kapital[aar[2030]] == pytest.approx(310e9 - 110e9 / 15.0 - 40e9)
@ -194,13 +225,21 @@ def test_eiendelene_gir_de_samme_investeringene_som_kontantstrommen(
def test_avskrivningene_summerer_seg_til_det_som_er_betalt(oppdiktet: LagInndata) -> None:
"""Every asset is out of operation by 2060, so the booked capital ends at zero."""
inn = oppdiktet()
res = _regn(inn, Losning.A)
strom = ei.bedriftsstrom(inn, res)
assert float(strom.avskrivning.sum()) == pytest.approx(float(strom.investering.sum()))
assert strom.kapital[-1] == pytest.approx(0.0, abs=1.0)
assert (strom.kapital > -1.0).all()
"""Every asset is out of operation by 2060, so the booked capital ends at zero.
Without price growth the tax depreciation sums to what is paid; with it, to less.
"""
for iota in (0.0, 0.02):
inn = oppdiktet(iota=iota)
res = _regn(inn, Losning.A)
strom = ei.bedriftsstrom(inn, res)
assert strom.kapital[-1] == pytest.approx(0.0, abs=1.0)
assert (strom.kapital > -1.0).all()
betalt = float(strom.investering.sum())
if iota == 0.0:
assert float(strom.avskrivning.sum()) == pytest.approx(betalt)
else:
assert 0.5 * betalt < float(strom.avskrivning.sum()) < 0.99 * betalt
def test_A_betaler_elavgift_men_ikke_nettariff(oppdiktet: LagInndata) -> None:
@ -326,12 +365,15 @@ def test_privat_minoritet_og_direkte_andel(oppdiktet: LagInndata) -> None:
skatt = ut.selskapsskatt + ut.saerskatt
ventet = 0.75 * skatt + strom.avgifter + 0.6 * 0.75 * ut.FKE + 0.25 * strom.NK
assert ut.KS_stat == pytest.approx(ventet)
# the special tax is 50 % of the profit above r_e on the capital booked at the start of the
# year; the return on what was booked during construction is carried forward and used in 2030
# the basis of the special tax is the profit with straight-line depreciation in constant
# kroner, minus the corporate tax and minus r_e on the capital booked at the start of the
# year; the rate on it is 0.5 / 0.8. The return on what was booked during construction is
# carried forward with interest and used in 2030
r_e = 1.08 / 1.02 - 1.0
overskudd = strom.inntekt - strom.drift - strom.avskrivning
overskudd = strom.inntekt - strom.drift - strom.avskrivning_fast
j = 2031 - 2027
assert ut.saerskatt[j] == pytest.approx(0.5 * (overskudd[j] - r_e * strom.kapital[j - 1]))
grunnlag = overskudd[j] - ut.selskapsskatt[j] - r_e * strom.kapital[j - 1]
assert ut.saerskatt[j] == pytest.approx(0.5 / 0.8 * grunnlag)
boers = ei.eierresultat(inn, strom, inn.eierformer["majoritet_boers"])
assert boers.NV_stat < ut.NV_stat
# the special tax lowers the project's value after tax (S28)
@ -340,6 +382,64 @@ def test_privat_minoritet_og_direkte_andel(oppdiktet: LagInndata) -> None:
) > ei.naaverdi_etter_skatt(inn, strom, inn.eierformer["petroleumsmodell"])
@pytest.mark.parametrize("navn", ["heleid_selskap", "majoritet_boers", "petroleumsmodell"])
def test_statens_eiernes_og_laangivernes_strommer_summerer_seg(
oppdiktet: LagInndata, navn: str
) -> None:
"""Clarification 48: nothing is counted twice and nothing is lost between the parties.
When the state covers overruns by its share only (zeta = s), what the state, the private
owners and the lenders receive adds up to the project's net cash flow plus the
electricity tax and grid tariff, every year.
"""
inn = oppdiktet(T_slutt=2040)
strom = _lonnsom(inn)
e = dataclasses.replace(inn.eierformer[navn], zeta=inn.eierformer[navn].s)
ut = ei.eierresultat(inn, strom, e)
gjeld_inn = np.concatenate(([0.0], ut.gjeld[:-1]))
rente = (1.0 + e.r_d) / 1.02 - 1.0
laangivere = (1.0 - e.theta) * (rente * gjeld_inn - (ut.gjeld - gjeld_inn))
private = (1.0 - e.s) * (1.0 - e.theta) * ut.FKE
assert ut.KS_stat + private + laangivere == pytest.approx(strom.NK + strom.avgifter)
def test_saerskatten_treffer_bare_avkastning_utover_r_e() -> None:
"""Clarification 48: the special tax is neutral.
100 paid in year 0 for an asset written off over 4 years, r_e 6 % after a corporate tax
of 20 %. The corporate tax has its own basis (20, 30, 10, 40: nominal deductions), so the
tax is 4, 6, 2, 8. A project whose profit after that tax is exactly 6 % of the booked
capital at the start of each year has no special tax, however the corporate tax is
computed. With 10 more in profit a year, corporate tax takes 2 and the special tax 5:
50 % of the 10. Negative bases are carried with interest.
"""
kapital_inn = [0.0, 100.0, 75.0, 50.0, 25.0]
selskapsgrunnlag = [0.0, 20.0, 30.0, 10.0, 40.0]
normal = [0.2 * g + 0.06 * k for g, k in zip(selskapsgrunnlag, kapital_inn, strict=True)]
for ekstra in (0.0, 10.0):
selskap, saer = lg.s30_skatt(
overskudd=[0.0] + [g + ekstra for g in selskapsgrunnlag[1:]],
overskudd_fast=[0.0] + [x + ekstra for x in normal[1:]],
kapital_inn=kapital_inn,
tau_s=0.2,
tau_g=0.5,
r_e=0.06,
iota=0.02,
)
assert saer == pytest.approx((0.0, *([0.5 * ekstra] * 4)))
assert selskap[1] == pytest.approx(0.2 * (20.0 + ekstra))
# a negative basis of 50 in year 1 is worth 53 in year 2
_, saer = lg.s30_skatt(
overskudd=[0.0] * 3,
overskudd_fast=[0.0, -50.0, 60.0],
kapital_inn=[0.0] * 3,
tau_s=0.0,
tau_g=0.5,
r_e=0.06,
)
assert saer == pytest.approx((0.0, 0.0, 0.5 * (60.0 - 53.0))) # tau_s = 0: the rate is tau_g
def test_staten_dekker_overskridelser_ut_over_eierandelen(oppdiktet: LagInndata) -> None:
"""Overrun 50 % on nuclear power; the state owns 60 % but carries all of it (zeta = 1)."""
inn = oppdiktet(u_xi=0.1)
@ -453,3 +553,7 @@ def test_regelen_for_eierformer() -> None:
strengere = ei.ranger_eierformer(kriterier, eos, risikogrense=0.05)
assert strengere.rangert == ()
assert strengere.over_risikogrensen == ("b", "a", "e")
# a form that fails the EEA assessment cannot take another form out: without a, only d is
# better than c on everything, and d is out itself
uten_a = ei.ranger_eierformer(kriterier[1:], eos)
assert set(uten_a.ute) == {"d"}

View file

@ -148,3 +148,10 @@ def test_relativ_prisvirkning_per_omraade(oppdiktet: LagInndata) -> None:
# the price level of the dry year cancels; the factor on the effect does not
tort = kraftsystem.relativ_prisvirkning(inn, Delta_Q=3e6, tort=True)
assert tort["NO1"] == pytest.approx(1.2 * 30.0 / 600.0)
def test_relativ_prisvirkning_krever_positiv_pris_uten_satsingen(oppdiktet: LagInndata) -> None:
"""A price of zero or less without the programme would turn the sign of the ratio."""
inn = oppdiktet(S0=80e6)
with pytest.raises(ValueError, match="not positive"):
kraftsystem.relativ_prisvirkning(inn, Delta_Q=3e6, tort=False)

View file

@ -376,6 +376,16 @@ def test_s11_kraftverk_som_akkurat_dekker_kostnaden_endrer_ingenting() -> None:
assert med == pytest.approx(600)
def test_s11_bindende_regel_lar_ulykkeskostnaden_staa() -> None:
"""Nuclear power with S45 binding: only the accident cost of 4 kr/MWh is left."""
kjerne = lg.Portefoljeledd(x=1.0, LCOE=500.0, psi=1.0, regelen_binder=True, q_N=4.0)
assert kjerne.nettoledd(600) == 4.0
verdi = lg.s11_kraftkostnad_nett(
p_z=600, n_tap=0.1, portefolje=[kjerne], E_G=8e6, E_D=4e6, H_a=0.0, F_a=0.0
)
assert verdi == pytest.approx(660 + 4.0 * 2)
def test_s11_portefolje_med_to_teknologier() -> None:
"""Hydro earns more than it costs, so S45 binds and its term is zero; wind stands as it is."""
vann = lg.Portefoljeledd(x=0.25, LCOE=500.0, psi=1.26, regelen_binder=True)

View file

@ -145,6 +145,8 @@ def test_m5_areal_mot_vind_paa_land() -> None:
def test_m5_samlet() -> None:
assert miljo.m5(Dom.HOLDER, Dom.HOLDER) is Dom.HOLDER
assert miljo.m5(Dom.BETINGELSER, Dom.HOLDER) is Dom.BETINGELSER
assert miljo.m5(Dom.BETINGELSER, Dom.BETINGELSER) is Dom.BETINGELSER
assert miljo.m5(Dom.HOLDER, Dom.BETINGELSER) is Dom.BETINGELSER
# "one of (i) and (ii) broken": with both broken it does not hold
assert miljo.m5(Dom.BETINGELSER, Dom.BETINGELSER) is Dom.HOLDER_IKKE
assert miljo.m5(Dom.HOLDER, Dom.HOLDER_IKKE) is Dom.HOLDER_IKKE
assert miljo.m5(Dom.HOLDER, Dom.HOLDER, kostnadsfort=False) is Dom.HOLDER_IKKE

View file

@ -256,15 +256,26 @@ def test_B_kraftkostnaden_bruker_programmets_enheter(oppdiktet: LagInndata) -> N
assert kost.c_a[:, j] == pytest.approx(c_a)
def test_bindende_tilleggsregel_gir_nettoledd_null(oppdiktet: LagInndata) -> None:
"""A cheap reactor that pays its way on the grid neither adds nor takes (clarification 11)."""
def test_bindende_tilleggsregel_lar_bare_ulykkeskostnaden_staa(oppdiktet: LagInndata) -> None:
"""A cheap reactor that pays its way on the grid neither adds nor takes (clarification 11).
The accident cost is outside NV_i of S45 and stays (clarification 41): 1e-5 a year per
unit times the cost of an accident beyond the 8 mrd. kr insured. In B three units of
1 000 MW (1 000 mrd. kr) shared by two facilities; in B' each facility's own units of
50 MW (50 mrd. kr).
"""
inn = oppdiktet(c_N_ref=10e6, f_N=0.3e6, s_brikker=0.12)
for losning in (Losning.B, Losning.B_MERKET):
res = _regn(inn, losning, N_anlegg=2)
assert res.varsigma[ks.KJERNEKRAFT] < 1.0
j = 2040 - 2027
H_a = 5e6 * (600.0 + res.dim.P_G_N) * _crf(0.06, 40)
c_a = 1.05 * res.kraftaar[j].pris + (H_a + float(res.F_a[j]) / 2.0) / E_D
if losning is Losning.B:
assert sum(len(f.gruppe.numre) for f in res.felles) == 3
ulykke = 3 * 1e-5 * (1e12 - 8e9) / 2.0
else:
ulykke = res.dim.N_u * 1e-5 * (50e9 - 8e9)
c_a = 1.05 * res.kraftaar[j].pris + (H_a + float(res.F_a[j]) / 2.0 + ulykke) / E_D
assert nv.kraftkostnad(inn, res).c_a[:, j] == pytest.approx(c_a)
# a business is credited the plant's surplus: S45 does not apply in M2
bedrift = nv.kraftkostnad(inn, res, bedrift=True)

View file

@ -92,9 +92,11 @@ def test_R_bidraget_aar_for_aar_og_M6(oppdiktet: LagInndata) -> None:
assert ut.M6_snitt == pytest.approx((i_drift - 1e9 / 5.0) / 500e9)
assert ut.M6_median == pytest.approx((i_drift - 1e9) / 250e9)
assert ut.M6_2050 is None
# at the made-up cost-based price the contribution is negative, so no year beats 2027
# at the made-up cost-based price the contribution is negative in every year; the peak
# is taken among the operating years, so the years before start-up (zero) do not count
assert i_drift < 0
assert (ut.M6_topp, ut.toppaar) == (0.0, 2027)
assert ut.M6_topp == pytest.approx(i_drift / 500e9)
assert ut.toppaar >= 2031
# with 40 % owned outside Norway only 60 % of the surplus above normal return counts
utenlandsk = skala.skala(inn, res, u_e=0.4)
assert utenlandsk.B_6[4] == pytest.approx(
@ -175,8 +177,14 @@ def test_A_uten_brikker_betaler_ikke_variable_kostnader(oppdiktet: LagInndata) -
assert ut[2039 - 2027] == pytest.approx(med_last)
def test_kraftverk_som_tilleggsregelen_binder_for_teller_null(oppdiktet: LagInndata) -> None:
"""Two facilities in B with a cheap reactor: the units neither add nor take in S31."""
def test_kraftverk_som_tilleggsregelen_binder_for_teller_bare_ulykkeskostnaden(
oppdiktet: LagInndata,
) -> None:
"""Two facilities in B with a cheap reactor: the units neither add nor take in S31.
Only the accident cost is left (clarification 41): three units of 1 000 MW, each
1e-5 a year times the 1 000 mrd. kr of an accident beyond the 8 mrd. kr insured.
"""
inn = oppdiktet(c_N_ref=10e6, f_N=0.3e6, s_brikker=0.12)
res = _regn(inn, Losning.B, N_anlegg=2)
assert res.varsigma[ks.KJERNEKRAFT] < 1.0
@ -186,7 +194,10 @@ def test_kraftverk_som_tilleggsregelen_binder_for_teller_null(oppdiktet: LagInnd
1000.0 * _lcoc_v() - 2.5e9 - 1.05 * res.kraftaar[j].pris * E_D - BYGG - MASKINVARE - nett
)
ut = skala.overskudd_utover_avkastning(inn, res)
assert ut[j] == pytest.approx(2.0 * per_anlegg - float(res.F_a[j]))
enheter = sum(len(f.gruppe.numre) for f in res.felles if f.gruppe.start <= 2040)
assert enheter == 3
ulykke = 3 * 1e-5 * (1e12 - 8e9)
assert ut[j] == pytest.approx(2.0 * per_anlegg - float(res.F_a[j]) - ulykke)
# without the rule the surplus of the units is credited
dim = ks.dimensjoner(inn, Losning.B)
uten = ks.regn_program(