Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Incorrect DiscountRateIdv and DiscountRate assignments in CapitalIvestment calcualtion #228

Closed
trevorb1 opened this issue Jun 12, 2024 · 1 comment · Fixed by #236
Labels
bug Something isn't working

Comments

@trevorb1
Copy link
Member

The Issue

In the results processing we correctly assign DiscountRateIdv the value of DiscountRate if no DiscountRateIdv is given; see below.

def capital_investment(self) -> pd.DataFrame:
"""CapitalInvestment
Notes
-----
From the formulation::
r~REGION, t~TECHNOLOGY, y~YEAR,
CapitalCost[r,t,y] * NewCapacity[r,t,y] * CapitalRecoveryFactor[r,t] *
PvAnnuity[r,t] ~VALUE;
"""
try:
capital_cost = self["CapitalCost"]
new_capacity = self["NewCapacity"]
operational_life = self["OperationalLife"]
if "DiscountRateIdv" in self.keys():
discount_rate = self["DiscountRateIdv"]
else:
discount_rate = self["DiscountRate"]
regions = self["REGION"]["VALUE"].to_list()
technologies = self.get_unique_values_from_index(
[
capital_cost,
new_capacity,
],
"TECHNOLOGY",
)
except KeyError as ex:
raise KeyError(self._msg("CapitalInvestment", str(ex)))
crf = capital_recovery_factor(
regions, technologies, discount_rate, operational_life
)
pva = pv_annuity(regions, technologies, discount_rate, operational_life)
capital_investment = capital_cost.mul(new_capacity, fill_value=0.0)
capital_investment = capital_investment.mul(crf, fill_value=0.0).mul(
pva, fill_value=0.0
)
data = capital_investment
if not data.empty:
data = data.groupby(by=["REGION", "TECHNOLOGY", "YEAR"]).sum()
return data[(data != 0).all(1)]

However, as flagged by @robertodawid in this comment, if a DiscountRateIdv is given, the DiscountRate value passed into both the capital recovery factor and PV Annuity calculation will be the DiscountRateIdv value. This is incorrect. CRF should use the DiscountRateIdv but the PV Annuity should still use the DiscountRate value.

Expected Behavior

No response

Steps To Reproduce

No response

Log output

No response

Operating System

Linux

What version of otoole are you running?

1.1.2

Possible Solution

Add in a variable called discount_rate_idv, which is what the conditional assigns. Pass this in the CRF calculation, and just the discount_rate into the PVA calculation.

Not sure if this will cause issues with the change in index levels, but we have a comment here that seems to address this already.

Anything else?

No response

@trevorb1 trevorb1 added the bug Something isn't working label Jun 12, 2024
@trevorb1
Copy link
Member Author

trevorb1 commented Oct 4, 2024

@robertodawid This should be fixed now! :)

@trevorb1 trevorb1 closed this as completed Oct 4, 2024
@trevorb1 trevorb1 linked a pull request Oct 4, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant