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

@ -103,6 +103,20 @@ def median(utfall: Utfall) -> float:
return statistics.median(-math.inf if x is None else x for x in utfall)
def ved_siden_av_dommen(oppfylt: Sequence[bool | None]) -> tuple[float, float | None]:
"""Clarification 69: how much of a verdict comes from paths that cannot be built.
``oppfylt`` says per draw whether the condition for «holder» is met, with
None for a draw in which the path cannot be built. Returns the share of
all the draws that cannot be built, and the share that meets the condition
among those that can; the second is None when no draw can be built. The
figures change no verdict (clarification 56).
"""
byggbare = [x for x in oppfylt if x is not None]
ikke_byggbar = lg.s37_andel([x is None for x in oppfylt])
return ikke_byggbar, lg.s37_andel(byggbare) if byggbare else None
def dom_av_andeler(andel_holder: float, andel_holder_ikke: float) -> Dom:
"""M3, M4 and M6: the verdict from the shares of the two conditions (clarification 2)."""
if andel_holder >= ANDEL_HOLDER:

View file

@ -16,11 +16,22 @@ How the text is read (chapter 16 of the specification, clarifications 45 to
straight-line depreciation in constant kroner; the depreciation the tax is
computed on, and losses carried forward, are nominal and lose real value with
the price growth; the special tax is computed in constant kroner with a return
allowance, so it only meets the return above r_e; an asset still in operation
at the final year is not written off there; the debt is the share h_e of the
booked capital, with the real borrowing rate, and is repaid at the final year;
tax is computed as if the project had no debt, on the company's part of the
project.
allowance, so it only meets the return above r_e; the debt is the share h_e of
the booked capital, with the real borrowing rate, and is repaid at the final
year; tax is computed as if the project had no debt, on the company's part of
the project.
Clarifications 62 to 67 correct the comparison of ownership forms. The value
of the operating time left at the final year enters the net cash flow there,
by the rule of S40 on the business cash flow, as a taxable sale with every
asset written off (62). The state's levy is the electricity tax, and in the
present value what private data centres would have paid is deducted; the grid
tariff is not the state's (63). Private owners pay what their share is worth
in expectation, valued the way the state's share is: the settlement is found
over the draws in ``eierkriterier`` (64). The state's cash flow is valued with
rho_D, the debt flows with the borrowing rate, where they are worth nothing
(65). The cost of compute in the criterion uses the required return before
tax (66). Equal values rank equally (67).
Nothing here reads the parameter file or draws random numbers.
"""
@ -48,6 +59,12 @@ if TYPE_CHECKING:
Tabell = npt.NDArray[np.float64]
LIK_VERDI: Final = 1e-9
"""Two figures closer than this, relatively, count as equal in the rule (clarification 67)."""
LIK_KRONE: Final = 1.0
"""Two amounts in kroner closer than this count as equal in the rule (clarification 67)."""
ANDEL_DAARLIGSTE: Final = 0.05
"""The share of the draws the average of the worst outcomes is taken over (chapter 8)."""
@ -67,8 +84,11 @@ class Bedriftsstrom:
drift: K^drift: operation, power bought, electricity tax, grid tariff, the power
plants' operation and accident cost, the disconnection arm of S47 and the
decommissioning when it is paid, minus the power plants' sales.
avgifter: the electricity tax and grid tariff that are part of ``drift``; the state's
income in S30.
elavgift: the electricity tax, part of ``drift``; the state's income from levies in
S30. The grid tariff is paid, but not to the state (clarification 63).
fortrengt: V, the electricity tax private data centres would have paid for the grid
capacity the programme takes. Not a payment: it is deducted in the present value
of S30, not in the cash the state has out.
investering: I, every investment but the grid connection (the tariff covers it).
budsjett: I^bud, the same with the overrun factor xi_N = 1.
avskrivning: the depreciation the tax is computed on: straight-line over each
@ -77,22 +97,36 @@ class Bedriftsstrom:
avskrivning_fast: straight-line depreciation in constant kroner; the special tax
and the booked capital use it.
kapital: the booked capital at the end of each year: what is paid minus
straight-line depreciation in constant kroner.
straight-line depreciation in constant kroner. Zero at the end of the final year.
restverdi: RV^bed, the value of the operating time left, in the final year and zero
in the others (clarification 62).
restverdi_anlegg: its part per facility, kr at the final year.
restverdi_felles: the decommissioning after the final year of the programme's units
(B), as a negative amount at the final year.
"""
inntekt: Tabell
drift: Tabell
avgifter: Tabell
elavgift: Tabell
fortrengt: Tabell
investering: Tabell
budsjett: Tabell
avskrivning: Tabell
avskrivning_fast: Tabell
kapital: Tabell
restverdi: Tabell
restverdi_anlegg: tuple[float, ...]
restverdi_felles: float
@property
def NK(self) -> Tabell:
"""The project's net cash flow before tax and financing."""
return self.inntekt - self.drift - self.investering
"""The project's net cash flow before tax and financing, the residual value included."""
return self.inntekt - self.drift - self.investering + self.restverdi
@property
def avgifter(self) -> Tabell:
"""The levies in the present value of S30: the electricity tax minus what is displaced."""
return self.elavgift - self.fortrengt
@dataclass(frozen=True)
@ -106,11 +140,23 @@ class Eierresultat:
saerskatt: special tax per year for the whole project, kr.
gjeld: the company's debt at the end of each year, for the whole project, kr.
FKE: the free cash flow to the owners after tax and debt service, whole project, kr.
KS_stat: the state's net cash flow per year (S30), kr.
NV_stat: its present value with the state's borrowing rate, kr.
NV_NK: the present value of the project's net cash flow with the same rate, kr.
KS_stat: the state's net cash flow per year as it is paid (S30), kr, before the
settlement with the private owners.
KS_privat: the private owners' cash flow per year as it is paid (clarification 64), kr.
NV_stat: the present value of S30 with rho_D, the debt flows valued with the
borrowing rate and what is displaced deducted (clarifications 63 and 65), kr,
before the settlement.
NV_samlet: the present value with the same rate of the project's net cash flow plus
the levies: the whole surplus (clarification 63), kr.
NV_privat: the present value of the private owners' cash flow with rho_D, the debt
flows valued with the borrowing rate, kr. Its average over the draws is the
settlement (clarification 64).
NV_privat_krav: the present value of ``KS_privat``, debt flows included, with the
owners' own real required return on equity, kr. The settlement of the
sensitivity in clarification 64.
laveste_sum: the lowest cumulative, undiscounted sum of ``KS_stat`` over time, kr.
storste_innskutte_kapital: the largest cumulative, undiscounted net payment from the
state over time, kr.
state over time, kr, before the settlement.
"""
eierform: Eierform
@ -120,14 +166,18 @@ class Eierresultat:
gjeld: Tabell
FKE: Tabell
KS_stat: Tabell
KS_privat: Tabell
NV_stat: float
NV_NK: float
NV_samlet: float
NV_privat: float
NV_privat_krav: float
laveste_sum: float
storste_innskutte_kapital: float
@property
def andel_av_overskudd(self) -> float | None:
"""The state's share of the surplus: NV_stat / NV_NK when the latter is positive."""
return self.NV_stat / self.NV_NK if self.NV_NK > 0 else None
"""The state's share of the surplus before the settlement, when the surplus is positive."""
return self.NV_stat / self.NV_samlet if self.NV_samlet > 0 else None
# ------------------------------------------------------------ the business cash flow
@ -140,6 +190,17 @@ def _eiendeler(res: Programresultat) -> list[Eiendel]:
return [e for e in alle if e.slag != ks.NETT]
def _betalt(eiendeler: Sequence[Eiendel], res: Programresultat) -> Tabell:
"""What is paid for the assets per year, as it is paid (clarifications 21, 33 and 34)."""
betalt = np.zeros(len(res.aar), dtype=np.float64)
for e in eiendeler:
if e.slag == ks.NETT:
continue
for j, andel in enumerate(lg.byggeaar_andeler(tau=e.byggetid)):
betalt[e.start - 1 - j - res.plan.T_0] += e.kostnad * andel
return betalt
def _investering_og_avskrivning(
res: Programresultat, iota: float
) -> tuple[Tabell, Tabell, Tabell, Tabell]:
@ -147,23 +208,26 @@ def _investering_og_avskrivning(
The tax depreciation of a payment is fixed in the kroner of the year it was
paid, so in constant kroner it shrinks with the price growth ``iota``. The
booked depreciation is the same straight line in constant kroner.
booked depreciation is the same straight line in constant kroner. An asset
in operation at the final year is written off in full there: the project
is valued as sold that year (clarification 62).
"""
T_0, T_s = res.plan.T_0, res.plan.T_s
investering, budsjett, skattemessig, bokfort = (
np.zeros(len(res.aar), dtype=np.float64) for _ in range(4)
)
for e in _eiendeler(res):
slutt = min(e.slutt, T_s)
for j, andel in enumerate(lg.byggeaar_andeler(tau=e.byggetid)):
betalt = e.start - 1 - j
investering[betalt - T_0] += e.kostnad * andel
budsjett[betalt - T_0] += e.budsjett * andel
for t in range(e.start, min(e.slutt, T_s) + 1):
for t in range(e.start, slutt + 1):
rett_linje = lg.s28_avskrivning(
kostnad=e.kostnad * andel,
levetid=e.levetid,
start=e.start,
slutt=e.slutt,
slutt=slutt,
t=t,
)
bokfort[t - T_0] += rett_linje
@ -191,8 +255,8 @@ def bedriftsstrom(
i_drift = np.array([plan.antall_i_drift(t) for t in res.aar], dtype=np.float64)
pris = np.array([rad.pris for rad in res.kraftaar], dtype=np.float64)
brukt = med_last * res.dim.E_D
avgifter = inn["t_el"] * brukt
drift = sum((a.drift + a.ulykke for a in res.anlegg), null.copy()) + avgifter
elavgift = inn["t_el"] * brukt
drift = sum((a.drift + a.ulykke for a in res.anlegg), null.copy()) + elavgift
for a in res.anlegg:
for i in a.salg:
faktor = res.varsigma[i] if tilleggsregel else 1.0
@ -202,24 +266,109 @@ def bedriftsstrom(
drift += f.drift + f.ulykke + f.avvikling - faktor * f.salg
if res.losning.paa_nett:
tariff = i_drift * lg.s27_nettariff(t_nett=inn["t_nett"], PUE=inn["PUE"], P_IT=inn["P_IT"])
avgifter = avgifter + tariff
drift += pris * brukt + tariff + nivaaisert.effektkostnad_bedrift(inn, res)
else:
P_buf = lg.s36_buffer(delta_L=inn["delta_L"], PUE=inn["PUE"], P_IT=inn["P_IT"])
drift += i_drift * inn["f_buf"] * P_buf
investering, budsjett, avskrivning, bokfort = _investering_og_avskrivning(res, inn["iota"])
RV_anlegg, RV_felles = restverdi_bedrift(inn, res, tilleggsregel=tilleggsregel)
restverdi = null.copy()
restverdi[-1] = math.fsum(RV_anlegg) + RV_felles
return Bedriftsstrom(
inntekt=sum((a.inntekt for a in res.anlegg), null.copy()),
drift=drift,
avgifter=avgifter,
elavgift=elavgift,
fortrengt=res.V,
investering=investering,
budsjett=budsjett,
avskrivning=avskrivning,
avskrivning_fast=bokfort,
kapital=np.cumsum(investering - bokfort),
restverdi=restverdi,
restverdi_anlegg=RV_anlegg,
restverdi_felles=RV_felles,
)
def netto_per_anlegg(
inn: Inndata, res: Programresultat, *, tilleggsregel: bool = False
) -> tuple[Tabell, ...]:
"""Clarification 62: each facility's part of the business net cash flow before tax, kr.
The facility's own revenue, costs and investments as a business pays
them. The disconnection arm of S47 is shared as F_a is: equally among the
facilities that use power that year. In B the year's cash flow of the
programme's nuclear units is shared equally among the facilities operated
that year; in a year without any, it is not shared.
"""
plan = res.plan
pris = np.array([rad.pris for rad in res.kraftaar], dtype=np.float64)
med_last = np.array([max(1, plan.antall_med_last(t)) for t in res.aar], dtype=np.float64)
i_drift = np.array([max(1, plan.antall_i_drift(t)) for t in res.aar], dtype=np.float64)
utkobling = nivaaisert.effektkostnad_bedrift(inn, res)
tariff = lg.s27_nettariff(t_nett=inn["t_nett"], PUE=inn["PUE"], P_IT=inn["P_IT"])
buffer = inn["f_buf"] * lg.s36_buffer(delta_L=inn["delta_L"], PUE=inn["PUE"], P_IT=inn["P_IT"])
def faktor(teknologi: str) -> float:
return res.varsigma[teknologi] if tilleggsregel else 1.0
felles = np.zeros(len(res.aar), dtype=np.float64)
for f in res.felles:
felles += faktor(ks.KJERNEKRAFT) * f.salg - f.drift - f.ulykke - f.avvikling
felles -= _betalt(f.eiendeler, res)
netto = []
for k, a in enumerate(res.anlegg):
last = np.array([1.0 if plan.har_last(k, t) else 0.0 for t in res.aar], dtype=np.float64)
drives = np.array([1.0 if plan.i_drift(k, t) else 0.0 for t in res.aar], dtype=np.float64)
brukt = last * res.dim.E_D
strom = a.inntekt - a.drift - a.ulykke - inn["t_el"] * brukt - _betalt(a.eiendeler, res)
for i in a.salg:
strom += faktor(i) * a.salg[i] - a.kraftdrift[i] - a.avvikling[i]
if res.losning.paa_nett:
strom -= pris * brukt + drives * tariff + utkobling * last / med_last
else:
strom -= drives * buffer
netto.append(strom + felles * drives / i_drift)
return tuple(netto)
def restverdi_bedrift(
inn: Inndata, res: Programresultat, *, tilleggsregel: bool = False
) -> tuple[tuple[float, ...], float]:
"""Clarification 62: RV^bed per facility, and the decommissioning of the programme's units.
The rule of S40 on the business cash flow, in kr at the final year. A
facility that loses money gets no value, but the decommissioning that
falls after the final year is always deducted, discounted with rho_N
(rho_A in A).
"""
vindu = min(res.plan.L_H, len(res.aar))
rho_avvikling = inn["rho_N"] if res.losning.paa_nett else res.dim.rho_A
anlegg = tuple(
lg.s28_restverdi(
NK_snitt=float(np.mean(netto[-vindu:])),
L_rest=a.L_rest,
rho_D=inn["rho_D"],
rho_avvikling=rho_avvikling,
avvikling=math.fsum(a.avvikling_etter.values()),
)
for a, netto in zip(
res.anlegg, netto_per_anlegg(inn, res, tilleggsregel=tilleggsregel), strict=True
)
)
felles = math.fsum(
lg.s28_restverdi(
NK_snitt=0.0,
L_rest=f.L_rest,
rho_D=inn["rho_D"],
rho_avvikling=inn["rho_N"],
avvikling=f.avvikling_etter,
)
for f in res.felles
)
return anlegg, felles
# ------------------------------------------------------------- one ownership form
@ -232,11 +381,23 @@ def kapitalkostnad(inn: Inndata, eierform: Eierform) -> float:
)
def krav_for_skatt(inn: Inndata, eierform: Eierform) -> float:
"""Clarification 66: the required return before tax the cost of compute is computed with.
r_e / (1 - tau_s) for a form that pays corporate tax, r_e (the state's
borrowing rate) with direct ownership.
"""
r_e = kapitalkostnad(inn, eierform)
return lg.s29_krav_for_skatt(r_e=r_e, tau_s=inn["tau_s"]) if eierform.skatt else r_e
def lcoc_med_kapitalkostnad(inn: Inndata, res: Programresultat, r_e: float) -> float:
"""Chapter 8: what the cost of capital does to the cost of compute, kr per MW IT and year.
LCOC^bed with r_e as the required return for both compute and power,
averaged over the vintages of the path with the weights of S42.
LCOC^bed with ``r_e`` as the required return for both compute and power,
averaged over the vintages of the path with the weights of S42. The
criterion of the pre-registration uses the requirement before tax,
``krav_for_skatt`` (clarification 66).
"""
kost = nivaaisert.kraftkostnad(
inn, res, bedrift=True, renter=Renter(rho_D=r_e, rho_N=r_e, rho_A=r_e)
@ -252,11 +413,15 @@ def lcoc_med_kapitalkostnad(inn: Inndata, res: Programresultat, r_e: float) -> f
def _skatt(
inn: Inndata, strom: Bedriftsstrom, eierform: Eierform, r_e: float
) -> tuple[Tabell, Tabell]:
"""Corporate tax and special tax per year for the whole project, as if it had no debt."""
"""Corporate tax and special tax per year for the whole project, as if it had no debt.
The residual value is taxable income in the final year (clarification 62).
"""
kapital_inn = np.concatenate(([0.0], strom.kapital[:-1]))
resultat = strom.inntekt - strom.drift + strom.restverdi
selskap, saer = lg.s30_skatt(
overskudd=[float(x) for x in strom.inntekt - strom.drift - strom.avskrivning],
overskudd_fast=[float(x) for x in strom.inntekt - strom.drift - strom.avskrivning_fast],
overskudd=[float(x) for x in resultat - strom.avskrivning],
overskudd_fast=[float(x) for x in resultat - strom.avskrivning_fast],
kapital_inn=[float(x) for x in kapital_inn],
tau_s=inn["tau_s"] if eierform.skatt else 0.0,
tau_g=eierform.tau_g,
@ -270,8 +435,8 @@ def naaverdi_etter_skatt(inn: Inndata, strom: Bedriftsstrom, eierform: Eierform)
"""S28: NV_e, the project's present value after tax with the cost of capital r_e, kr.
``strom`` is the business cash flow without the additionality rule. The
whole project is taxed as one company; nothing is counted after the final
year.
whole project is taxed as one company. What comes after the final year is
the residual value in the cash flow of that year (clarification 62).
"""
r_e = kapitalkostnad(inn, eierform)
selskapsskatt, saerskatt = _skatt(inn, strom, eierform, r_e)
@ -279,40 +444,65 @@ def naaverdi_etter_skatt(inn: Inndata, strom: Bedriftsstrom, eierform: Eierform)
return lg.s28_naaverdi(netto=[float(x) for x in netto], rente=r_e)
def eierresultat(inn: Inndata, strom: Bedriftsstrom, eierform: Eierform) -> Eierresultat:
def eierresultat(
inn: Inndata, strom: Bedriftsstrom, eierform: Eierform, *, rente: float | None = None
) -> Eierresultat:
"""S29 and S30 for one ownership form.
``strom`` is the business cash flow with the factor of the additionality
rule on the power plants' sales. Tax is computed for the project as one
taxpayer, as if it had no debt. The state receives the tax of the
company's part, 1 - theta_e, and the electricity tax and grid tariff of
the whole project. The debt is h_e of the booked capital, carries the real
company's part, 1 - theta_e, and the levies of the whole project
(clarification 63). The debt is h_e of the booked capital, carries the real
borrowing rate and is repaid at the final year. With direct ownership the
free cash flow to the owner is the project's net cash flow.
The present value of the state's cash flow is taken with ``rente``, rho_D
when it is not given, and with the debt flows left out: valued with the
borrowing rate they are worth nothing, because the debt is repaid
(clarification 65). The private owners' cash flow is valued the same way,
always with rho_D: the market sets the price of their share. The
settlement (clarification 64) is found over the draws and is not part of
this result.
"""
e = eierform
r_e = kapitalkostnad(inn, e)
rente_stat = inn["rho_D"] if rente is None else rente
NK = strom.NK
selskapsskatt, saerskatt = _skatt(inn, strom, e, r_e)
skatt = selskapsskatt + saerskatt
FKE_uten_gjeld = NK - skatt
if e.r_q is None:
gjeld = np.zeros_like(NK)
FKE = NK.copy()
FKE = FKE_uten_gjeld.copy()
else:
gjeld = e.h * strom.kapital
gjeld[-1] = 0.0
gjeld_inn = np.concatenate(([0.0], gjeld[:-1]))
rente = lg.realrente(nominell=e.r_d, iota=inn["iota"])
FKE = NK - skatt - rente * gjeld_inn + gjeld - gjeld_inn
KS_stat = lg.s30_statens_kontantstrom(
skatt=(1.0 - e.theta) * skatt + strom.avgifter,
FKE=FKE,
NK=NK,
overskridelse=np.maximum(0.0, strom.investering - strom.budsjett),
s=e.s,
theta=e.theta,
zeta=e.zeta,
)
laanerente = lg.realrente(nominell=e.r_d, iota=inn["iota"])
FKE = FKE_uten_gjeld - laanerente * gjeld_inn + gjeld - gjeld_inn
overskridelse = np.maximum(0.0, strom.investering - strom.budsjett)
def statens(FKE_: Tabell) -> Tabell:
return lg.s30_statens_kontantstrom(
skatt=(1.0 - e.theta) * skatt + strom.elavgift,
FKE=FKE_,
NK=NK,
overskridelse=overskridelse,
s=e.s,
theta=e.theta,
zeta=e.zeta,
)
def private(FKE_: Tabell) -> Tabell:
return lg.s30_private_eiere(
FKE=FKE_, overskridelse=overskridelse, s=e.s, theta=e.theta, zeta=e.zeta
)
KS_stat = statens(FKE)
KS_privat = private(FKE)
krav = inn["rho_D"] if e.r_q is None else lg.realrente(nominell=e.r_q, iota=inn["iota"])
laveste_sum = float(np.min(np.cumsum(KS_stat)))
return Eierresultat(
eierform=e,
r_e=r_e,
@ -321,9 +511,17 @@ def eierresultat(inn: Inndata, strom: Bedriftsstrom, eierform: Eierform) -> Eier
gjeld=gjeld,
FKE=FKE,
KS_stat=KS_stat,
NV_stat=lg.s28_naaverdi(netto=[float(x) for x in KS_stat], rente=inn["r_stat"]),
NV_NK=lg.s28_naaverdi(netto=[float(x) for x in NK], rente=inn["r_stat"]),
storste_innskutte_kapital=storste_innskutte_kapital(KS_stat),
KS_privat=KS_privat,
NV_stat=lg.s28_naaverdi(
netto=[float(x) for x in statens(FKE_uten_gjeld) - strom.fortrengt], rente=rente_stat
),
NV_samlet=lg.s28_naaverdi(netto=[float(x) for x in NK + strom.avgifter], rente=rente_stat),
NV_privat=lg.s28_naaverdi(
netto=[float(x) for x in private(FKE_uten_gjeld)], rente=inn["rho_D"]
),
NV_privat_krav=lg.s28_naaverdi(netto=[float(x) for x in KS_privat], rente=krav),
laveste_sum=laveste_sum,
storste_innskutte_kapital=max(0.0, -laveste_sum),
)
@ -352,19 +550,28 @@ class Eierkriterier:
Attributes:
navn: the ownership form.
verdi: the expected present value of the state's net cash flow, kr.
andel_av_overskudd: the expected present value of S30 over that of the project's net
cash flow, when the latter is positive; otherwise None.
oppgjor: O_e, what the private owners pay the state for their share: what it is
worth in expectation, kr at T_0; negative when the state has to pay them
(clarification 64).
verdi: the expected present value of the state's net cash flow, the settlement
included, kr.
andel_av_overskudd: the expected present value of S30 over that of the whole surplus,
when the latter is positive; otherwise None.
andel_for_oppgjor: the same before the settlement: the share the state receives as
cash flow. Shown next to the criterion.
r_e: the cost of capital (the average over the draws).
LCOC: the cost of compute with that cost of capital (the average over the draws).
LCOC: the cost of compute with the required return before tax (the average over the
draws).
tapssannsynlighet: the probability of a negative present value of S30.
daarligste: the average of the worst 5 % of the outcomes, kr.
kapital_ute: the largest capital the state has out (the average over the draws), kr.
"""
navn: str
oppgjor: float
verdi: float
andel_av_overskudd: float | None
andel_for_oppgjor: float | None
r_e: float
LCOC: float
tapssannsynlighet: float
@ -373,35 +580,64 @@ class Eierkriterier:
def eierkriterier(
navn: str, utfall: Sequence[Eierresultat], LCOC: Sequence[float]
navn: str,
utfall: Sequence[Eierresultat],
LCOC: Sequence[float],
*,
egenkapitalkrav: bool = False,
) -> Eierkriterier:
"""The criteria for one ownership form from its outcome in every draw that can be built."""
NV_stat = [u.NV_stat for u in utfall]
NV_NK = math.fsum(u.NV_NK for u in utfall)
"""The criteria for one ownership form from its outcome in every draw that can be built.
The settlement with the private owners is the average over these draws of
the present value of their cash flow, valued as the state's is. It is paid
at T_0 and is the same in every draw, so it moves every present value of
the state's cash flow, and every cumulative sum, by the same amount.
``egenkapitalkrav=True`` is the sensitivity of clarification 64: the
settlement priced with the owners' own required return on equity, on
their cash flow with the debt.
"""
privat = [u.NV_privat_krav if egenkapitalkrav else u.NV_privat for u in utfall]
oppgjor = math.fsum(privat) / len(privat)
NV_stat = [u.NV_stat + oppgjor for u in utfall]
NV_samlet = math.fsum(u.NV_samlet for u in utfall)
kapital_ute = [max(0.0, -(u.laveste_sum + oppgjor)) for u in utfall]
return Eierkriterier(
navn=navn,
oppgjor=oppgjor,
verdi=math.fsum(NV_stat) / len(NV_stat),
andel_av_overskudd=math.fsum(NV_stat) / NV_NK if NV_NK > 0 else None,
andel_av_overskudd=math.fsum(NV_stat) / NV_samlet if NV_samlet > 0 else None,
andel_for_oppgjor=(
math.fsum(u.NV_stat for u in utfall) / NV_samlet if NV_samlet > 0 else None
),
r_e=math.fsum(u.r_e for u in utfall) / len(utfall),
LCOC=math.fsum(LCOC) / len(LCOC),
tapssannsynlighet=sannsynlighet_for_tap(NV_stat),
daarligste=snitt_av_de_daarligste(NV_stat),
kapital_ute=math.fsum(u.storste_innskutte_kapital for u in utfall) / len(utfall),
kapital_ute=math.fsum(kapital_ute) / len(kapital_ute),
)
def klart_lavere(a: float, b: float, *, kroner: bool = False) -> bool:
"""True when ``a`` is lower than ``b`` by more than the tolerance (clarification 67).
Two figures are equal when they differ by less than 1e-9 of the larger in
absolute value, or, for amounts in kroner, by less than one krone.
"""
return a < b - max(LIK_VERDI * max(abs(a), abs(b)), LIK_KRONE if kroner else 0.0)
def _daarligere_paa_alt(a: Eierkriterier, b: Eierkriterier) -> bool:
"""True when ``a`` is worse than ``b`` on every measure of value, capital cost and risk."""
verdi = a.verdi < b.verdi and (
verdi = klart_lavere(a.verdi, b.verdi, kroner=True) and (
a.andel_av_overskudd is None
or b.andel_av_overskudd is None
or a.andel_av_overskudd < b.andel_av_overskudd
or klart_lavere(a.andel_av_overskudd, b.andel_av_overskudd)
)
kapitalkostnad_ = a.r_e > b.r_e and a.LCOC > b.LCOC
kapitalkostnad_ = klart_lavere(b.r_e, a.r_e) and klart_lavere(b.LCOC, a.LCOC, kroner=True)
risiko = (
a.tapssannsynlighet > b.tapssannsynlighet
and a.daarligste < b.daarligste
and a.kapital_ute > b.kapital_ute
klart_lavere(b.tapssannsynlighet, a.tapssannsynlighet)
and klart_lavere(a.daarligste, b.daarligste, kroner=True)
and klart_lavere(b.kapital_ute, a.kapital_ute, kroner=True)
)
return verdi and kapitalkostnad_ and risiko
@ -415,11 +651,14 @@ class Rangering:
the limit for the state's risk.
over_risikogrensen: forms that pass the first two tests but break the risk limit.
ute: forms that go out, with the reason.
like: groups of ranked forms with the same value, which share their place
(clarification 67).
"""
rangert: tuple[str, ...]
over_risikogrensen: tuple[str, ...]
ute: Mapping[str, str]
like: tuple[tuple[str, ...], ...] = ()
def ranger_eierformer(
@ -449,8 +688,20 @@ def ranger_eierformer(
if bedre:
ute[a.navn] = f"dårligere enn {bedre[0]} på alle de tre første kriteriene"
igjen = sorted((a for a in kriterier if a.navn not in ute), key=lambda a: -a.verdi)
grupper: list[list[Eierkriterier]] = []
for a in igjen:
if a.tapssannsynlighet >= risikogrense:
continue
if grupper and not klart_lavere(a.verdi, grupper[-1][0].verdi, kroner=True):
grupper[-1].append(a)
else:
grupper.append([a])
# within a group of equal values the forms keep the order they were given in
plass = {a.navn: i for i, a in enumerate(kriterier)}
grupper = [sorted(g, key=lambda a: plass[a.navn]) for g in grupper]
return Rangering(
rangert=tuple(a.navn for a in igjen if a.tapssannsynlighet < risikogrense),
rangert=tuple(a.navn for g in grupper for a in g),
over_risikogrensen=tuple(a.navn for a in igjen if a.tapssannsynlighet >= risikogrense),
ute=ute,
like=tuple(tuple(a.navn for a in g) for g in grupper if len(g) > 1),
)

View file

@ -102,7 +102,7 @@ class Inndata:
eierformer: the ownership forms by id (S29, S30).
areal: km2 per MWh per year for nuclear power and wind, and km2 per MW IT for the plot.
petroleum_median: the median of the state's net cash flow from petroleum over the ten
years, kr in current prices (shown next to M6).
years, kr in the kroner of the price year (shown next to M6; clarification 53).
"""
v: Mapping[str, float]
@ -220,5 +220,5 @@ def fra_trekning(
u_eksport=tuple(float(u) for u in u_eksport),
eierformer=tolk_eierformer(sett.tabell("eierformer")),
areal=tolk_areal(sett.tabell("alpha")),
petroleum_median=statistics.median(sett.petroleumsinntekt().values()),
petroleum_median=statistics.median(sett.petroleumsinntekt(faste_kroner=True).values()),
)

View file

@ -1165,11 +1165,32 @@ def s28_naaverdi(*, netto: Sequence[float], rente: float) -> float:
"""S28: the present value at T_0 of yearly amounts with index t - T_0, kr.
With ``netto`` = Y - K_drift - I - Skatt_e and ``rente`` = r_e this is NV_e.
The same sum gives the present value of S30 with the state's borrowing rate.
The same sum gives the present value of S30 with rho_D (clarification 65).
"""
return math.fsum(x * (1.0 + rente) ** -j for j, x in enumerate(netto))
def s28_restverdi(
*, NK_snitt: float, L_rest: int, rho_D: float, rho_avvikling: float, avvikling: float
) -> float:
"""Clarification 62: what one facility is worth at the final year, kr at T_s.
The rule of S40 on the business cash flow, without the factor that takes
S40 back to T_0: the value enters the net cash flow of the final year and
is discounted with it. ``NK_snitt`` is the facility's average business net
cash flow before tax over the last L_H years.
"""
return s40_restverdi(
NK_snitt=NK_snitt,
L_rest=L_rest,
rho_D=rho_D,
rho_avvikling=rho_avvikling,
avvikling=avvikling,
T_s=0,
T_0=0,
)
# --------------------------------------------------------- ownership: S29 and S30
@ -1190,6 +1211,16 @@ def s29_kapitalkostnad(*, h: float, r_d: float, r_q: float, tau_s: float, iota:
return realrente(nominell=nominell, iota=iota)
def s29_krav_for_skatt(*, r_e: float, tau_s: float) -> float:
"""Clarification 66: the real required return before tax, r_e / (1 - tau_s).
S29 is a requirement after tax, and the cost of compute is a cost before
tax. The quotient is exact for an asset without depreciation allowances;
with the tax rules of the model the exact figure depends on the lifetime.
"""
return r_e / (1.0 - tau_s)
def s30_skatt(
*,
overskudd: Sequence[float],
@ -1239,8 +1270,9 @@ def s30_statens_kontantstrom(
) -> Belop:
"""S30: the state's net cash flow in a year with ownership form e, kr.
``skatt`` is what the state receives in tax, electricity tax and grid
tariff, ``FKE`` the company's free cash flow to its owners, ``NK`` the
``skatt`` is what the state receives in tax and levies (clarification 63:
the electricity tax minus what private data centres would have paid; not
the grid tariff), ``FKE`` the company's free cash flow to its owners, ``NK`` the
project's net cash flow before tax and financing, and ``overskridelse``
max(0, I - I^bud). ``s`` is the state's share of the company, ``theta`` its
direct share outside the company and ``zeta`` its share of overruns.
@ -1248,6 +1280,19 @@ def s30_statens_kontantstrom(
return skatt + s * (1.0 - theta) * FKE + theta * NK - (zeta - s) * (1.0 - theta) * overskridelse
def s30_private_eiere(
*, FKE: Belop, overskridelse: Belop, s: float, theta: float, zeta: float
) -> Belop:
"""Clarification 64: the private owners' cash flow in a year, kr.
Their share of the company's free cash flow, plus the part of the
overruns the state covers on their behalf in S30. With the state's cash
flow and the lenders' it sums to the project's net cash flow plus the
levies.
"""
return (1.0 - s) * (1.0 - theta) * FKE + (zeta - s) * (1.0 - theta) * overskridelse
# ----------------------------------------------------- scale and environment

View file

@ -10,7 +10,7 @@ from __future__ import annotations
import math
from dataclasses import dataclass
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Final
import numpy as np
@ -109,6 +109,7 @@ class Kildeverdier:
vind: its central value for onshore wind.
vann: its central value for hydropower.
vind_hoyeste: the highest value the source gives for onshore wind.
poster: the entries of the source bank the numbers come from.
"""
kilde: str
@ -116,6 +117,22 @@ class Kildeverdier:
vind: float
vann: float
vind_hoyeste: float
poster: tuple[str, ...] = ()
KILDEVERDIER_M5: Final = (
Kildeverdier("IPCC", 12.0, 11.0, 24.0, 56.0, ("K04-046", "K11-045")),
Kildeverdier("UNECE", 5.1, 12.0, 11.0, 16.0, ("K21-001", "K21-002", "K21-003")),
Kildeverdier("NREL", 13.0, 13.0, 21.0, 13.0, ("K04-047",)),
)
"""The sources' own figures for M5 (i), g CO2 equivalents per kWh.
The table of clarification 68 in chapter 16 of the specification: IPCC's
medians (AR5), UNECE's table for Europe in 2020 with the representative
hydropower plant and the top of the range over the regions for onshore wind,
and NREL's medians, where the one figure for wind is also the highest. They
are fixed numbers from the source bank, not parameters that are drawn.
"""
def m5_utslipp(losning: Losning, kilder: Sequence[Kildeverdier]) -> Dom:

View file

@ -337,11 +337,21 @@ class Parametersett:
baner[bane][int(aar)] = verdi
return baner
def petroleumsinntekt(self) -> dict[int, float]:
"""The state's net cash flow from petroleum per year, kr in current prices (SNKS)."""
def petroleumsinntekt(self, *, faste_kroner: bool = False) -> dict[int, float]:
"""The state's net cash flow from petroleum per year (SNKS), kr.
In current prices, or with ``faste_kroner`` in the kroner of the price
year: each year's amount adjusted with the consumer price index of the
file, the way the ten-year average of M6 is made (clarification 53).
"""
s = self.parameter("SNKS").storrelser[0]
tabell = _ordbok(s.fordeling.tabell, "SNKS")
return {int(aar): _tall(v, f"SNKS[{aar}]") * s.faktor for aar, v in tabell.items()}
lopende = {int(aar): _tall(v, f"SNKS[{aar}]") * s.faktor for aar, v in tabell.items()}
if not faste_kroner:
return lopende
kpi = _ordbok(self.omregning["kpi_norge_2015_100"], "omregning.kpi_norge_2015_100")
naa = _tall(kpi[str(self.prisaar)], "kpi")
return {aar: v * naa / _tall(kpi[str(aar)], "kpi") for aar, v in lopende.items()}
# ------------------------------------------------------------------ JSON helpers

View file

@ -48,7 +48,8 @@ class Skala:
figure the verdict is set on. None without a year of stable operation.
M6_snitt: the same for the average over L_H years from that year (to the final year
at most).
M6_median: M6 against the median of the ten years instead of the average.
M6_median: M6 against the median of the ten years instead of the average, both in
2025 kroner (clarification 53).
M6_2050: the share in 2050; None when the analysis ends before that.
M6_topp: the share in the year the contribution is highest, among the years in
which at least one facility is operated.
@ -195,6 +196,21 @@ def forste_aar_med_stabil_drift(res: Programresultat) -> int | None:
return None
def statens_kontantstrom_mot_petroleum(
inn: Inndata, res: Programresultat, KS_stat: Tabell
) -> float | None:
"""Clarification 53: the state's net cash flow after investments, next to M6.
``KS_stat`` is S30 per year for one wholly state-owned company. The figure
is its value in the first year of stable operation as a share of the
state's net cash flow from petroleum; None without such a year.
"""
stabilt = forste_aar_med_stabil_drift(res)
if stabilt is None:
return None
return float(KS_stat[stabilt - res.plan.T_0]) / inn["SNKS_snitt"]
def skala(inn: Inndata, res: Programresultat, *, u_e: float = 0.0) -> Skala:
"""S31 per year and M6 for the path in ``res``.

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)