Cost
costs
¶
Cost calculation utilities for PyPSA.
- Home Overview Release Notes v1.0.7 13th January 2026 Enhancements
Functions:
-
annuity–Calculate the annuity factor for given discount rate and lifetime.
-
periodized_cost–Calculate fixed costs for the modeled horizon from capital or overnight cost.
pypsa.costs.annuity
¶
annuity(discount_rate: float | Series, lifetime: float | Series) -> float | Series
Calculate the annuity factor for given discount rate and lifetime.
Converts overnight investment cost to an annualized cost using the formula:
Special cases:
- Zero discount rate: returns
1/lifetime(simple depreciation) - Infinite lifetime with r > 0: returns the discount rate
- Infinite lifetime with r <= 0: returns 0
- Negative discount rates are allowed (penalizes the present)
Parameters:
-
discount_rate(float | Series) –Discount rate as decimal (e.g., 0.07 for 7%).
-
lifetime(float | Series) –Asset lifetime in years. Must be positive.
Returns:
-
float | Series–Annual annuity factor to multiply overnight cost by.
Examples:
>>> import pypsa
>>> pypsa.costs.annuity(0.07, 25)
0.0858...
>>> pypsa.costs.annuity(0.0, 20) # 0% discount rate = simple depreciation
0.05
>>> pypsa.costs.annuity(-0.02, 20)
0.040...
- Home Overview Release Notes v1.0.7 13th January 2026 Enhancements
pypsa.costs.periodized_cost
¶
periodized_cost(capital_cost: float | Series, overnight_cost: float | Series, discount_rate: float | Series, lifetime: float | Series, fom_cost: float | Series | None = None, nyears: float | Series = 1.0) -> float | Series
Calculate fixed costs for the modeled horizon from capital or overnight cost.
This function calculates the total fixed cost for the modeled horizon n.nyears by:
- If
overnight_costis provided (not NaN): annuitize it usingdiscount_rateandlifetime, then scale bynyearsand addfom_cost. - If
overnight_costis NaN: usecapital_costdirectly (already scaled to the model horizon) and addfom_cost.
Parameters:
-
capital_cost(float | Series) –Investment cost per unit of capacity for the modeled horizon.
-
overnight_cost(float | Series) –Overnight (upfront) investment cost. If NaN, capital_cost is used.
-
discount_rate(float | Series) –Discount rate as decimal. Used only when overnight_cost is provided.
-
lifetime(float | Series) –Asset lifetime in years.
-
fom_cost(float | Series, default:None) –Fixed operation and maintenance cost per unit of capacity for the modeled horizon. Default None.
-
nyears(float | Series, default:1.0) –Modeled time horizon in years. Used only to scale annuitized overnight costs. If provided as a Series indexed by investment period, all values must be identical when overnight_cost is used. Default 1.0.
Returns:
-
float | Series–Fixed cost per unit of capacity for the modeled horizon.
Examples:
Using overnight cost with annuitization:
>>> periodized_cost(
... capital_cost=0,
... overnight_cost=1000,
... discount_rate=0.07,
... lifetime=25,
... nyears=1.0,
... )
85.81...
Falling back to capital_cost when overnight_cost is NaN:
>>> periodized_cost(
... capital_cost=100,
... overnight_cost=np.nan,
... discount_rate=0.07,
... lifetime=25,
... )
100
- Home Overview Release Notes v1.0.7 13th January 2026 Enhancements