Effective interest rate
If you are do a car loan of 100 000 Money. The loan is for 48 months and you pay 2 400 Money every month. What is the effective interest?
We guess that it is somewhere around 3%.
let principal = 100000;let payment = 2400;let numberOfMonths = 48;let guess = 003;let interest = EffectiveInterestCalculator;console; // 0.07115
Correct answer is 7.12%
What if the payments are not equal? The first payment has an administration fee of 400 Money and we like to pay the rest of the loan after 36 months. So the 36th payment will be 31 200 Money.
let principal = 100000;let payment = 2400;let guess = 003;let startDate = '2017-04-30';let payments ='2017-04-30': payment + 400'2017-05-31': payment'2017-06-30': payment'2017-07-31': payment// More dates'2019-12-31': payment'2020-01-31': payment'2020-02-28': payment'2020-03-31': 31200;let interest = EffectiveInterestCalculator;console; // 0.084870
Correct answer is 8.49%
We are using the same formula that Excel's XIRR function is using. We are also using NewtonRaphsons method to numerically find the interest we are looking for.
# Install depnendenciesnpm install# Build a mnified filenpm run build
To run the test
# Build the project (no minified files)npm run dev# Run test oncenpm run test# Start test listenernpm run watch