feat(kode): bring the ownership comparison in line with clarifications 62-69

eierskap.py: the residual value and the sale at the final year, the levies,
the private owners' cash flow and the settlement over the draws, the present
value with rho_D without the debt flows, the required return before tax, and
equal values in the ranking. Also the median of the petroleum cash flow in
2025 kroner, the state's cash flow next to M6, the shares shown next to each
verdict, and the sources' figures for M5 (i).

Made-up numbers only: 424 tests pass, 7 documented misses. The project's
code and the independent reader's code agree to within one krone on 1 500
made-up paths.

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

View file

@ -279,3 +279,11 @@ def test_del_I_ser_bare_paa_A_B_og_C() -> None:
def test_del_II_folger_M7() -> None:
assert dommer.del_II(Dom.BETINGELSER) is Dom.BETINGELSER
def test_hvor_mye_av_dommen_som_skyldes_baner_som_ikke_lar_seg_bygge() -> None:
"""Clarification 69: 2 of 8 draws cannot be built; 3 of the 6 others meet the condition."""
oppfylt = [True, None, False, True, None, False, True, False]
assert dommer.ved_siden_av_dommen(oppfylt) == pytest.approx((0.25, 0.5))
assert dommer.ved_siden_av_dommen([None, None]) == (1.0, None)
assert dommer.ved_siden_av_dommen([True, True]) == (0.0, 1.0)

View file

@ -153,7 +153,9 @@ def test_R_bedriftsstrom_haandregnet(oppdiktet: LagInndata) -> None:
pris = 700.0 - 10e-6 * (10e6 - 0.5 * E_D)
utkobling = 100.0 * _lcoc_v() / (8760.0 * 1.2) * 600.0
assert strom.inntekt[aar[2031]] == pytest.approx(1000.0 * _lcoc_v())
assert strom.avgifter[aar[2031]] == pytest.approx(70.0 * E_D + 0.3e6 * 1200.0)
# the state's levies: the electricity tax, minus what the private data centres that are
# displaced from half of the grid capacity would have paid; the tariff is not the state's
assert strom.avgifter[aar[2031]] == pytest.approx(70.0 * E_D - 0.5 * 70.0 * E_D)
assert strom.drift[aar[2031]] == pytest.approx(
2.5e9 + pris * E_D + 70.0 * E_D + 0.3e6 * 1200.0 + utkobling
)
@ -165,8 +167,9 @@ def test_R_bedriftsstrom_haandregnet(oppdiktet: LagInndata) -> None:
# 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.
# they start) and loses 2 % a year in constant kroner (clarification 47). At the final
# year the project is valued as sold, and what is left is written off (clarification 62):
# 4 of the building's 15 years on top of the year's own, and the whole vintage of 2040.
def realt(aar_siden: int) -> float:
return 1.02**-aar_siden
@ -177,14 +180,26 @@ def test_R_bedriftsstrom_haandregnet(oppdiktet: LagInndata) -> None:
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)
55e9 * 5.0 / 15.0 * (realt(12) + realt(11)) + 200e9 * 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)
assert strom.kapital[aar[2040]] == pytest.approx(0.0, abs=1.0)
assert strom.NK[aar[2034]] == pytest.approx(
strom.inntekt[aar[2034]] - strom.drift[aar[2034]] - 200e9
)
# The residual value: the facility runs 20 years from 2030, so 9 are left after 2040.
# The average of the last five years holds one vintage of 200 mrd. kr (paid in 2039).
assert res.anlegg[0].L_rest == 9
snitt = float(strom.inntekt[aar[2040]] - strom.drift[aar[2040]]) - 200e9 / 5.0
ventet = max(0.0, snitt / _crf(0.08, 9))
assert strom.restverdi[aar[2040]] == pytest.approx(ventet)
assert strom.restverdi_anlegg == pytest.approx((ventet,))
assert not strom.restverdi[: aar[2040]].any()
assert strom.NK[aar[2040]] == pytest.approx(
strom.inntekt[aar[2040]] - strom.drift[aar[2040]] + ventet
)
@pytest.mark.parametrize("losning", list(Losning))
@ -271,7 +286,8 @@ def test_kraftverk_paa_nettet_selger_uten_tilleggsregelen(oppdiktet: LagInndata)
+ float(anlegg.kraftdrift[ks.KJERNEKRAFT][j])
+ float(anlegg.ulykke[j])
+ res.kraftaar[j].pris * E_D
+ float(strom.avgifter[j])
+ 70.0 * E_D
+ 0.3e6 * 1200.0
)
assert strom.drift[j] == pytest.approx(uten_salg - float(anlegg.salg[ks.KJERNEKRAFT][j]))
# S30 is computed with the factor of S45 on the sales (chapter 1.4)
@ -297,7 +313,7 @@ def test_kapitalkostnad_per_eierform(oppdiktet: LagInndata) -> None:
def test_direkte_eierskap_gir_staten_hele_kontantstrommen(oppdiktet: LagInndata) -> None:
"""No company and no corporate tax: FKE = NK, and the state also receives tax and tariff."""
"""No company and no corporate tax: FKE = NK, and the state also receives the levies."""
inn = oppdiktet(T_slutt=2040)
strom = ei.bedriftsstrom(inn, _regn(inn, Losning.R))
ut = ei.eierresultat(inn, strom, inn.eierformer["direkte"])
@ -305,10 +321,23 @@ def test_direkte_eierskap_gir_staten_hele_kontantstrommen(oppdiktet: LagInndata)
assert not ut.saerskatt.any()
assert (ut.FKE == strom.NK).all()
assert not ut.gjeld.any()
assert ut.KS_stat == pytest.approx(strom.NK + strom.avgifter)
assert ut.KS_stat == pytest.approx(strom.NK + strom.elavgift)
NV = math.fsum(float(x) / 1.02**j for j, x in enumerate(strom.NK))
assert ei.naaverdi_etter_skatt(inn, strom, inn.eierformer["direkte"]) == pytest.approx(NV)
assert ut.NV_NK == pytest.approx(NV)
# the state's cash flow is valued with rho_D (clarification 65), with the electricity tax
# the displaced private data centres would have paid deducted (63): the whole surplus
assert strom.elavgift[4] == pytest.approx(70.0 * E_D)
assert strom.fortrengt[4] == pytest.approx(0.5 * 70.0 * E_D)
NV_stat = math.fsum(float(x) / 1.08**j for j, x in enumerate(strom.NK + strom.avgifter))
assert ut.NV_stat == pytest.approx(NV_stat)
assert ut.NV_samlet == pytest.approx(NV_stat)
assert not ut.KS_privat.any()
assert ut.NV_privat == 0.0
# with the state's borrowing rate, shown as a sensitivity
med_laanerente = ei.eierresultat(inn, strom, inn.eierformer["direkte"], rente=0.02)
assert med_laanerente.NV_stat == pytest.approx(
math.fsum(float(x) / 1.02**j for j, x in enumerate(strom.NK + strom.avgifter))
)
# 310 mrd. kr is paid before the first revenue
assert ut.storste_innskutte_kapital == pytest.approx(310e9)
@ -317,13 +346,15 @@ def test_heleid_selskap_skatt_gjeld_og_statens_kontantstrom(oppdiktet: LagInndat
"""One wholly owned company, half debt at 5 % nominal (1.05 / 1.02 - 1 real).
Tax is 20 % of revenue minus operation and depreciation; nothing is carried forward
because the first operating year already has a profit. The state owns everything, so
the tax cancels: what it gets is NK, tax and tariff, minus interest, plus new debt.
because the first operating year already has a profit. In the final year the residual
value is taxed as a sale. The state owns everything, so the tax cancels: what it gets
is NK and the levies, minus interest, plus new debt.
"""
inn = oppdiktet(T_slutt=2040)
strom = _lonnsom(inn)
assert strom.restverdi[-1] > 0
ut = ei.eierresultat(inn, strom, inn.eierformer["heleid_selskap"])
overskudd = strom.inntekt - strom.drift - strom.avskrivning
overskudd = strom.inntekt - strom.drift + strom.restverdi - strom.avskrivning
assert (overskudd[3:] > 0).all()
assert ut.selskapsskatt == pytest.approx(0.2 * overskudd)
assert not ut.saerskatt.any()
@ -334,19 +365,27 @@ def test_heleid_selskap_skatt_gjeld_og_statens_kontantstrom(oppdiktet: LagInndat
FKE = strom.NK - ut.selskapsskatt - rente * gjeld_inn + ut.gjeld - gjeld_inn
assert ut.FKE == pytest.approx(FKE)
assert ut.KS_stat == pytest.approx(
strom.NK + strom.avgifter - rente * gjeld_inn + ut.gjeld - gjeld_inn
strom.NK + strom.elavgift - rente * gjeld_inn + ut.gjeld - gjeld_inn
)
r_e = 1.07 / 1.02 - 1.0
NV_e = ei.naaverdi_etter_skatt(inn, strom, inn.eierformer["heleid_selskap"])
assert NV_e == pytest.approx(
math.fsum(float(x) / (1.0 + r_e) ** j for j, x in enumerate(strom.NK - ut.selskapsskatt))
)
# Valued with rho_D, and the debt flows with the borrowing rate, where they are worth
# nothing (clarification 65): the state's value is that of the whole surplus, exactly as
# with direct ownership
assert math.fsum(
float(x) / (1.0 + rente) ** j
for j, x in enumerate(ut.gjeld - gjeld_inn - rente * gjeld_inn)
) == pytest.approx(0.0, abs=1.0)
assert ut.NV_stat == pytest.approx(
math.fsum(float(x) / 1.02**j for j, x in enumerate(ut.KS_stat))
math.fsum(float(x) / 1.08**j for j, x in enumerate(strom.NK + strom.avgifter))
)
andel = ut.andel_av_overskudd
assert andel is not None
assert andel == pytest.approx(ut.NV_stat / ut.NV_NK)
direkte = ei.eierresultat(inn, strom, inn.eierformer["direkte"])
assert ut.NV_stat == pytest.approx(direkte.NV_stat)
assert ut.andel_av_overskudd == pytest.approx(1.0)
assert not ut.KS_privat.any()
# the owners put in half of what is built, and the interest in 2029 on what was borrowed
# in 2028; the other half is borrowed
assert ut.storste_innskutte_kapital == pytest.approx(155e9 + rente * 77.5e9)
@ -363,7 +402,7 @@ def test_privat_minoritet_og_direkte_andel(oppdiktet: LagInndata) -> None:
ut = ei.eierresultat(inn, strom, inn.eierformer["petroleumsmodell"])
assert ut.saerskatt.sum() > 0
skatt = ut.selskapsskatt + ut.saerskatt
ventet = 0.75 * skatt + strom.avgifter + 0.6 * 0.75 * ut.FKE + 0.25 * strom.NK
ventet = 0.75 * skatt + strom.elavgift + 0.6 * 0.75 * ut.FKE + 0.25 * strom.NK
assert ut.KS_stat == pytest.approx(ventet)
# 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
@ -376,6 +415,17 @@ def test_privat_minoritet_og_direkte_andel(oppdiktet: LagInndata) -> None:
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 private owners have 40 % of the company: all of it, or the 75 % outside the state's
# direct part. Their share is valued as the state's: with rho_D and without the debt flows
assert boers.KS_privat == pytest.approx(0.4 * boers.FKE)
assert ut.KS_privat == pytest.approx(0.4 * 0.75 * ut.FKE)
etter_skatt = strom.NK - boers.selskapsskatt
assert boers.NV_privat == pytest.approx(
math.fsum(float(x) / 1.08**j for j, x in enumerate(0.4 * etter_skatt))
)
# what the state and the private owners have together is the whole surplus
assert boers.NV_stat + boers.NV_privat == pytest.approx(boers.NV_samlet)
assert ut.NV_stat + ut.NV_privat == pytest.approx(ut.NV_samlet)
# the special tax lowers the project's value after tax (S28)
assert ei.naaverdi_etter_skatt(
inn, strom, inn.eierformer["majoritet_boers"]
@ -386,21 +436,24 @@ def test_privat_minoritet_og_direkte_andel(oppdiktet: LagInndata) -> None:
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.
"""Clarifications 48 and 64: nothing is counted twice or 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.
What the state, the private owners and the lenders receive adds up to the project's net
cash flow plus the electricity tax, every year: when the state covers overruns by its share only
(zeta = s), and when it covers all of them and the private owners are spared theirs.
"""
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)
inn = oppdiktet(u_xi=0.1)
strom = ei.bedriftsstrom(inn, _regn(inn, Losning.A, knapphet=Knapphet.VARER))
assert (strom.investering - strom.budsjett).sum() > 0
for zeta in (inn.eierformer[navn].s, 1.0):
e = dataclasses.replace(inn.eierformer[navn], zeta=zeta)
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))
assert ut.KS_stat + ut.KS_privat + laangivere == pytest.approx(
strom.NK + strom.elavgift, abs=1.0
)
def test_saerskatten_treffer_bare_avkastning_utover_r_e() -> None:
@ -450,19 +503,20 @@ def test_staten_dekker_overskridelser_ut_over_eierandelen(oppdiktet: LagInndata)
assert overskridelse.sum() > 0
ut = ei.eierresultat(inn, strom, inn.eierformer["majoritet_boers"])
skatt = ut.selskapsskatt + ut.saerskatt
uten = skatt + strom.avgifter + 0.6 * ut.FKE
uten = skatt + strom.elavgift + 0.6 * ut.FKE
assert ut.KS_stat == pytest.approx(uten - 0.4 * overskridelse)
def test_underskudd_i_oppstarten_gir_ingen_skatt(oppdiktet: LagInndata) -> None:
"""«Overkapasitet»: the price is 30 % under the competitor's cost, and nothing is taxable.
The last vintage, from 2040, is sold at cost and gives a small profit; the losses
carried forward cover it.
The losses carried forward cover what little profit there is. At the final year the
project is valued as sold (clarification 62), but the value is lower than what is
written off, so the sale gives no tax either.
"""
inn = oppdiktet(T_slutt=2040)
strom = ei.bedriftsstrom(inn, _regn(inn, Losning.R, knapphet=Knapphet.OVERKAPASITET))
assert (strom.inntekt - strom.drift - strom.avskrivning)[-1] > 0
assert 0 < strom.restverdi[-1] < strom.avskrivning[-1]
ut = ei.eierresultat(inn, strom, inn.eierformer["heleid_selskap"])
assert not ut.selskapsskatt.any()
assert ut.NV_stat < 0
@ -497,8 +551,10 @@ def test_storste_innskutte_kapital() -> None:
def _kriterier(navn: str, **endringer: float | None) -> ei.Eierkriterier:
verdier: dict[str, float | None] = {
"oppgjor": 0.0,
"verdi": 100.0,
"andel_av_overskudd": 0.9,
"andel_for_oppgjor": 0.9,
"r_e": 0.05,
"LCOC": 80.0,
"tapssannsynlighet": 0.1,
@ -515,8 +571,9 @@ def test_eierkriterier_fra_utfallene(oppdiktet: LagInndata) -> None:
strom = _lonnsom(inn)
ut = ei.eierresultat(inn, strom, inn.eierformer["heleid_selskap"])
k = ei.eierkriterier("heleid_selskap", [ut, ut], [80.0, 90.0])
assert k.oppgjor == 0.0
assert k.verdi == pytest.approx(ut.NV_stat)
assert k.andel_av_overskudd == pytest.approx(ut.NV_stat / ut.NV_NK)
assert k.andel_av_overskudd == pytest.approx(1.0)
assert k.r_e == pytest.approx(ut.r_e)
assert k.LCOC == pytest.approx(85.0)
assert k.tapssannsynlighet == 0.0
@ -557,3 +614,154 @@ def test_regelen_for_eierformer() -> None:
# better than c on everything, and d is out itself
uten_a = ei.ranger_eierformer(kriterier[1:], eos)
assert set(uten_a.ute) == {"d"}
def test_private_eiere_betaler_det_andelen_er_verdt(oppdiktet: LagInndata) -> None:
"""Clarification 64: the settlement is the average present value of the private owners' share.
Two draws, one with the scarcity markup and one with overcapacity. The private owners
gain in the first and lose in the second; the settlement is the average, paid at T_0,
the same amount in both draws. It moves the state's present value and every cumulative
sum of its cash flow by that amount. After it the state's expected value is that of the
whole surplus, as with a wholly owned company, and the public's share is 1; what the
form changes is how the outcome is spread over the draws.
"""
inn = oppdiktet(T_slutt=2040)
strommer = [
ei.bedriftsstrom(inn, _regn(inn, Losning.R, knapphet=k))
for k in (Knapphet.VARER, Knapphet.OVERKAPASITET)
]
e = inn.eierformer["majoritet_boers"]
utfall = [ei.eierresultat(inn, strom, e) for strom in strommer]
assert utfall[0].NV_privat > 0 > utfall[1].NV_privat
k = ei.eierkriterier("majoritet_boers", utfall, [80.0, 90.0])
oppgjor = (utfall[0].NV_privat + utfall[1].NV_privat) / 2.0
assert oppgjor > 0
assert k.oppgjor == pytest.approx(oppgjor)
samlet = (utfall[0].NV_samlet + utfall[1].NV_samlet) / 2.0
assert k.verdi == pytest.approx(samlet)
assert k.andel_av_overskudd == pytest.approx(1.0)
assert k.andel_for_oppgjor == pytest.approx(1.0 - oppgjor / samlet)
assert k.tapssannsynlighet == ei.sannsynlighet_for_tap([u.NV_stat + oppgjor for u in utfall])
assert k.kapital_ute == pytest.approx(
math.fsum(max(0.0, -(u.laveste_sum + oppgjor)) for u in utfall) / 2.0
)
heleid = [ei.eierresultat(inn, s, inn.eierformer["heleid_selskap"]) for s in strommer]
h = ei.eierkriterier("heleid_selskap", heleid, [80.0, 90.0])
assert h.oppgjor == 0.0
assert h.verdi == pytest.approx(k.verdi)
# the private owners carry part of the loss in the bad draw, so the state's worst is better
assert k.daarligste > h.daarligste
# the sensitivity: the settlement priced with the private owners' own required return on
# equity (12 % nominal), on their cash flow with the debt
krav = ei.eierkriterier("majoritet_boers", utfall, [80.0, 90.0], egenkapitalkrav=True)
assert krav.oppgjor == pytest.approx(
math.fsum(float(x) / (1.12 / 1.02) ** j for u in utfall for j, x in enumerate(u.KS_privat))
/ 2.0
)
assert krav.verdi == pytest.approx(k.verdi - k.oppgjor + krav.oppgjor)
# with the state's borrowing rate as a sensitivity the price is still the market's
lav = [ei.eierresultat(inn, s, e, rente=0.02) for s in strommer]
assert [u.NV_privat for u in lav] == pytest.approx([u.NV_privat for u in utfall])
assert lav[0].NV_stat > utfall[0].NV_stat
@pytest.mark.parametrize("losning", list(Losning))
def test_anleggenes_kontantstrom_summerer_seg_til_programmets(
oppdiktet: LagInndata, losning: Losning
) -> None:
"""Clarification 62: the facilities' parts add up to the business cash flow of the programme.
In B the programme's nuclear units are shared among the facilities operated that year,
so only the years with a facility in operation are compared.
"""
inn = oppdiktet(u_eksport=None)
res = _regn(inn, losning, N_anlegg=2)
for tilleggsregel in (False, True):
strom = ei.bedriftsstrom(inn, res, tilleggsregel=tilleggsregel)
sum_anlegg = np.sum(ei.netto_per_anlegg(inn, res, tilleggsregel=tilleggsregel), axis=0)
programmet = strom.inntekt - strom.drift - strom.investering
med = np.array(
[losning is not Losning.B or res.plan.antall_i_drift(t) > 0 for t in res.aar]
)
assert med.sum() > 20
assert sum_anlegg[med] == pytest.approx(programmet[med], abs=1.0)
def test_restverdien_trekker_fra_avvikling_etter_sluttaaret(oppdiktet: LagInndata) -> None:
"""Clarification 62 in A: the value of the years left, minus the decommissioning after them.
The decommissioning is discounted with the rate of the plant in A over the years left.
The value is the same whatever the ownership form, and the booked capital ends at zero.
"""
inn = oppdiktet(T_slutt=2045)
res = _regn(inn, Losning.A, knapphet=Knapphet.VARER)
anlegg = res.anlegg[0]
assert anlegg.L_rest > 0
strom = ei.bedriftsstrom(inn, res)
netto = ei.netto_per_anlegg(inn, res)[0]
avvikling = math.fsum(anlegg.avvikling_etter.values())
assert avvikling > 0
verdi = max(0.0, float(np.mean(netto[-5:])) / _crf(0.08, anlegg.L_rest))
assert verdi > 0
ventet = verdi - avvikling * (1.0 + res.dim.rho_A) ** -anlegg.L_rest
assert strom.restverdi[-1] == pytest.approx(ventet)
assert lg.s28_restverdi(
NK_snitt=-1.0, L_rest=10, rho_D=0.08, rho_avvikling=0.06, avvikling=100.0
) == pytest.approx(-100.0 / 1.06**10)
assert (
lg.s28_restverdi(NK_snitt=5.0, L_rest=0, rho_D=0.08, rho_avvikling=0.06, avvikling=9.0)
== 0.0
)
assert strom.kapital[-1] == pytest.approx(0.0, abs=1.0)
def test_kravet_for_skatt(oppdiktet: LagInndata) -> None:
"""Clarification 66: r_e / (1 - tau_s) for a form that pays corporate tax."""
inn = oppdiktet()
assert lg.s29_krav_for_skatt(r_e=0.06, tau_s=0.25) == pytest.approx(0.08)
assert ei.krav_for_skatt(inn, inn.eierformer["direkte"]) == 0.02
assert ei.krav_for_skatt(inn, inn.eierformer["heleid_selskap"]) == pytest.approx(
(1.07 / 1.02 - 1.0) / 0.8
)
def test_private_eieres_kontantstrom() -> None:
"""Clarification 64: 40 % of 75 % of the free cash flow, and the overruns they are spared."""
assert lg.s30_private_eiere(
FKE=100.0, overskridelse=20.0, s=0.6, theta=0.25, zeta=1.0
) == pytest.approx(0.4 * 0.75 * 100.0 + 0.4 * 0.75 * 20.0)
assert lg.s30_private_eiere(FKE=100.0, overskridelse=20.0, s=1.0, theta=0.0, zeta=1.0) == 0.0
def test_like_verdier_staar_likt_i_rangeringen() -> None:
"""Clarification 67: a difference below the tolerance is no difference."""
kriterier = [
_kriterier("a", verdi=100.0),
_kriterier(
"b",
verdi=100.0 * (1.0 - 1e-12),
andel_av_overskudd=0.9 * (1.0 - 1e-12),
r_e=0.06,
LCOC=85.0,
tapssannsynlighet=0.2,
daarligste=-60.0,
kapital_ute=310.0,
),
_kriterier("c", verdi=90.0),
]
eos = dict.fromkeys("abc", "består")
rangering = ei.ranger_eierformer(kriterier, eos)
# b is not strictly worse than a on value, so it is not taken out
assert rangering.ute == {}
assert rangering.rangert == ("a", "b", "c")
assert rangering.like == (("a", "b"),)
# within a group of equal values the order given decides, not the rounding residue
omvendt = ei.ranger_eierformer([kriterier[1], kriterier[0], kriterier[2]], eos)
assert omvendt.rangert == ("b", "a", "c")
assert ei.klart_lavere(1.0, 1.1)
assert not ei.klart_lavere(1.0, 1.0 + 1e-12)
# amounts in kroner near zero: rounding residue is no difference
assert ei.klart_lavere(-2e-4, 1e-4)
assert not ei.klart_lavere(-2e-4, 1e-4, kroner=True)
assert ei.klart_lavere(0.0, 2.0, kroner=True)

View file

@ -6,6 +6,7 @@ here says anything about the hypothesis.
from __future__ import annotations
from pathlib import Path
from typing import TYPE_CHECKING
import pytest
@ -150,3 +151,18 @@ def test_m5_samlet() -> None:
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
def test_tabellen_for_m5_er_den_i_spesifikasjonen() -> None:
"""Clarification 68: the fixed figures in the code are the table of the specification.
Only the numbers are compared. M5 is not decided here.
"""
tekst = (Path(__file__).parents[1] / "modell" / "spesifikasjon.md").read_text("utf-8")
assert len(miljo.KILDEVERDIER_M5) == 3
for k in miljo.KILDEVERDIER_M5:
(rad,) = [linje for linje in tekst.splitlines() if linje.startswith(f" | {k.kilde} (")]
celler = [celle.strip() for celle in rad.strip().strip("|").split("|")]
tall = [float(celle.replace(",", ".")) for celle in celler[1:5]]
assert tall == [k.kjernekraft, k.vind, k.vann, k.vind_hoyeste]
assert celler[5].split(", ") == list(k.poster)

View file

@ -5,6 +5,7 @@ from __future__ import annotations
import copy
import json
import re
import statistics
from collections import Counter
from pathlib import Path
from typing import Any
@ -248,6 +249,14 @@ def test_lister_og_tabeller(sett: pm.Parametersett) -> None:
petroleum = sett.petroleumsinntekt()
assert petroleum[2022] == pytest.approx(1285.223e9)
assert sum(petroleum.values()) / 10 == pytest.approx(482.4e9, rel=1e-3)
# in 2025 kroner the average is the denominator of M6, and the median lies between 2019
# and 2021 (clarification 53); in current prices it is 272.2 mrd. kr
faste = sett.petroleumsinntekt(faste_kroner=True)
assert faste[2025] == petroleum[2025]
assert faste[2016] == pytest.approx(124.779e9 * 137.7 / 103.6)
assert sum(faste.values()) / 10 == pytest.approx(sett.fast("SNKS_snitt"), rel=1e-4)
assert statistics.median(faste.values()) == pytest.approx(330.1e9, rel=1e-3)
assert statistics.median(petroleum.values()) == pytest.approx(272.2e9, rel=1e-3)
with pytest.raises(pm.ParameterError, match="not a table"):
sett.tabell("c_N_ref")

View file

@ -263,3 +263,15 @@ def test_programmets_enheter_i_B_teller_ogsaa_etter_at_anleggene_er_gaatt_ut(
ut = skala.overskudd_utover_avkastning(inn, res)
assert ut[2058 - 2027] < 0
assert np.count_nonzero(ut[2056 - 2027 :]) == 5
def test_statens_kontantstrom_ved_siden_av_M6(oppdiktet: LagInndata) -> None:
"""Clarification 53: S30 in the first year of stable operation over the petroleum cash flow."""
inn = oppdiktet(T_slutt=2040)
dim = ks.dimensjoner(inn, Losning.R)
res = ks.regn_program(
inn, Losning.R, ks.lag_plan(inn, Losning.R, dim, N_anlegg=1), Knapphet.VARER, dim=dim
)
KS_stat = np.arange(len(res.aar), dtype=np.float64) * 1e9
assert skala.forste_aar_med_stabil_drift(res) == 2030
assert skala.statens_kontantstrom_mot_petroleum(inn, res, KS_stat) == pytest.approx(3e9 / 500e9)