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

Add IRR to cashloan and migrate functions to lib_financial.h #1223

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

cpaulgilman
Copy link
Collaborator

@cpaulgilman cpaulgilman commented Oct 18, 2024

Fix #638

1. Add IRR output to cashloan

  • IRR output available for Residential and Commercial financial models.
  • Add nominal discount rate output to help with identifying nominal discount rate that results in NPV = 0 (useful for parametrics on real discount rate)
  • Note that default Residential and Commercial cases use 100% debt, so IRR is NaN for default configurations because initial investment is zero
  • Not modifying SAM UI to add IRR to Metrics table on Summary tab, so it is only available in Data Tables because IRR metric is a bit ambiguous for projects that do not earn revenue

2. Move financial model functions to lib_financial for all financial models

Task SO CS TPO HD MP EPF LPF SLB TPO H CashLoan
Compare functions to SO before moving NA NA NA
Check depreciation_sched_custom() NA NA
Delete using namespace libfin from cmod
Delete libfin functions from cmod
Convert npv()to libfin::
Convert irr()to libfin::
Convert min()to libfin:: NA
Convert max()to libfin:: NA
Convert ppmt()to libfin:: NA NA
Convert payback() to libfin:: NA NA NA NA NA NA NA *

* Note that Third Party Ownership - Host model has payback cashflows but does not use the payback() function to calculate payback period.

Question

That there are special min() and max() functions defined in lib_financial. I changed all calls to min() and max() in the financial cmods to libfin::min() and libfin::max() to avoid conflict, but should any of those be std::min() or std::max() instead?

Copy link
Collaborator

@sjanzou sjanzou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Mac and Linux GitHub Actions to pass, please add the following to the lib_financial.cpp file for DBL_MAX to be defined:

DBL_MAX is defined in float.h and was previously included at the top of each financial compute module as
#ifndef WIN32
#include <float.h>
#endif

}

double scale_factor = irr_scale_factor(cf_vector, count);
double residual = DBL_MAX;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DBL_MAX was not defined and is causing the Linux and MacOS tests to fail.

DBL_MAX is defined in float.h and was previously included at the top of each financial compute module as
#ifndef WIN32
#include <float.h>
#endif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants