Tutorial :Is there a Java API or built-in function for solving annuity problems?



Question:

I was asked by my boss to create a module for calculating reverse compound.

The question is: if I want to achieve $1.000.000,00 in 24 months with interest rate 18%/year (or 1.5%/month). how much money do I have to save every month?

I searched on the internet, but found nothing except people referring to the Excel formula. Do you know what the mathematical formula is for this case?

I am using Java for this module. Is there any Java library or API?


Solution:1

Let us say that you are investing D dollars at the beginning of each month for M months earning an interest rate of r compounded monthly. We will set i = r / 12. At the end of M months you will have

D * (1 + i)^M + D * (1 + i)^(M - 1) + D * (1 + i)^(M - 2) + ...      D * (1 + i)  

in your account. This is because the D dollars in the first month are invested for M months, the D dollars in the second month are invested for M-1 months, and so on. This is a geometric progression and simplifies to

D * (1 + i) * ((1 + i)^M - 1) / i.  

Therefore, if you want X in your account at the end of M months you solve

X = D * (1 + i) * ((1 + i)^M - 1) / i  

for D to obtain

D = X * i / ((1 + i) * ((1 + i)^M - 1)).  

You don't really need an API here to solve this as you can see the solution is quite simple. The concept that you might want to read about here is that of annuities.


Solution:2

If you are not doing it for lending purposes, the simple formulae posted in other answers will probably be good enough.

If this is for any kind of financial activity, beware of any simple calculation for compound interest. If it is for any lending you are probably required to conform to strict rules (e.g in the UK the rate must be quoted in the form of an APR).

The calculations need to take into account:

  • the variable days in a month
  • whether interest is applied daily or monthly
  • what day the borrowing was drawn down
  • the day of the month payment has been taken.
  • other stuff I can't remember but you'd better look up for your contract to be legally binding

In practice this needs a form of iteration to find the regular and final payments.


Solution:3

The formula you want is S = R * [(1+i)^n - 1] / i where

S = the required amount at the end (1,000,000)  R = the regular payment (what you want)  i = the periodic rate of interest (0.015)  n = the number of time periods (24)  

so your answer R = 1000000 * .015 / (1.015^24 - 1) (~= 34924.10)

EDIT:

This assumes payments are at the end of each period, if payments are made at the beginning of each period, then divide your answer by (1+i)


Solution:4

I think this gets you what you want. Its even LGPL, even though if you are getting 18% returns on your money, price shouldn't matter ;-).


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »