Skip to content

Commit

Permalink
Avoid division by 0 for annuity_factor calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Bachibouzouk committed Apr 25, 2024
1 parent b990e6d commit cbffd9f
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/multi_vector_simulator/C2_economic_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ def annuity_factor(project_life, discount_factor):
discountfactor \cdot (1 + discount factor)^{project life}}
"""
annuity_factor = 1 / discount_factor - 1 / (
discount_factor * (1 + discount_factor) ** project_life
)
if discount_factor != 0:
annuity_factor = 1 / discount_factor - 1 / (
discount_factor * (1 + discount_factor) ** project_life
)
else:
annuity_factor = project_life
return annuity_factor


Expand All @@ -71,9 +74,13 @@ def crf(project_life, discount_factor):
:param discount_factor: weighted average cost of capital, which is the after-tax average cost of various capital sources
:return: capital recovery factor, a ratio used to calculate the present value of an annuity
"""
crf = (discount_factor * (1 + discount_factor) ** project_life) / (
(1 + discount_factor) ** project_life - 1
)
if discount_factor != 0:
crf = (discount_factor * (1 + discount_factor) ** project_life) / (
(1 + discount_factor) ** project_life - 1
)
else:
crf = 1 / project_life

return crf


Expand Down

0 comments on commit cbffd9f

Please sign in to comment.