Fix swapped annuity parameters in stochastic-optimization.ipynb example#1398
Merged
Fix swapped annuity parameters in stochastic-optimization.ipynb example#1398
Conversation
Co-authored-by: fneum <[email protected]>
Copilot
AI
changed the title
[WIP] Fix swapped annuity lifetime and discount rate in docs example
Fix swapped annuity parameters in stochastic-optimization.ipynb example
Oct 15, 2025
fneum
approved these changes
Oct 15, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a bug in the
stochastic-optimization.ipynbexample notebook where the parameters to theannuity()function were swapped, causing incorrect calculation of annualized capital costs.The Issue
The
annuity()function signature is:However, the notebook was calling it with reversed parameters:
The Fix
Changed the parameter order to match the function signature:
Impact
With the example values from the notebook (DR=0.03, LIFE=25):
annuity(25, 0.03)= 268.48 (vastly overestimated!)annuity(0.03, 25)= 0.0574 (correct value)The bug was causing a massive overestimation of annualized capital costs by over 300,000%.
Verification
All other notebooks in the repository correctly use
annuity(discount_rate, lifetime), including:capacity-expansion-planning-single-node.ipynbmyopic-pathway.ipynb3-node-cem.ipynbexample-3.ipynbThe test file
test/conftest.pyalso uses the correct parameter order.Fixes #issue_number
Original prompt
Fixes #1397
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.