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

Fixed error in Payback Period formula #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

B-D-T
Copy link

@B-D-T B-D-T commented Nov 17, 2020

Fix for finance.PP

Summary of the problem

The payback period calculation does not return the correct result. It includes and extra year, then subtracts the fractional final year instead of adding it.

Demonstration of the problem

The example, finance.PP(5, -50, 10, 13, 16, 19, 22);, says the pp is 3.42, but it should be 3.57895 (3 full years and .579 of the fourth year). We can see that in the cumulative return:

   0    1    2    3    4    <-- Years
-- | -- | -- | -- | -- | --
 -50   10   13   16   19    <-- Cash flows 
 -50  -40  -27  -11    8    <-- Cumulative return

After year 3, there is still $11 to recover. We'll get $19 in year 4, so we'll break even 11/19th of the way through year 4
(11/19 = 0.57895).

Solution

Small change in line 83 in finance.js:

Current: yearsCounter += (cumulativeCashFlow - arguments[i]) / arguments[i];
Fixed: yearsCounter += -1 + Math.abs((cumulativeCashFlow - arguments[i]) / arguments[i]);

The final fractional year was calculating incorrectly.
@B-D-T B-D-T mentioned this pull request Nov 17, 2020
@B-D-T
Copy link
Author

B-D-T commented Nov 17, 2020

This is connected to issue #51 I apologize for creating two pull requests (new to GH).

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

Successfully merging this pull request may close these issues.

1 participant