Jump to content


Photo

Savings Coumpound Interest (With Monthly Contribultion)


  • Please log in to reply
6 replies to this topic

#1 Skylight_lady

Skylight_lady

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 05 December 2012 - 11:33 AM

Hi Guys,

I'm trying to get a monthly contribution added to the saving coumpound interest.

The original code i have is:
$IntTotal = ($balance*(pow(1+$Rate,$terms)-1));

The above code allows me to calculate the interest total without a monthly contribution added. How do i insert the monthly contribution into that? Is there another way to write this in php?

Thanks

#2 SocialCloud

SocialCloud

    Advanced Member

  • Members
  • PipPipPip
  • 613 posts

Posted 05 December 2012 - 12:13 PM

What do you mean by a monthly contribution?

#3 Psycho

Psycho

    Advanced Member

  • Gurus
  • 10,821 posts
  • LocationCanada

Posted 05 December 2012 - 12:25 PM

Is the monthly contribution supposed to be included with the interest calculation or not?

If yes
$IntTotal = ( ($balance + $contribution) * (pow(1 + $Rate, $terms) - 1) );

If no
$IntTotal = ($balance * (pow(1 + $Rate, $terms) - 1) ) + $contribution;

The quality of the responses received is directly proportional to the quality of the question asked.

I do not always test the code I provide, so there may be some syntax errors. In 99% of all cases I found the solution to your problem here: http://www.php.net

#4 Skylight_lady

Skylight_lady

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 05 December 2012 - 12:47 PM

Well it's supposed to be exactly like http://www.aib.ie/pe...CFYRF2wodo18AFg

If you roll over the last year and see the growth. Then all over the above calculation are wrong. It's only correct if i set the contribution to "0" value

#5 Psycho

Psycho

    Advanced Member

  • Gurus
  • 10,821 posts
  • LocationCanada

Posted 05 December 2012 - 02:27 PM

Well, you're not going to get exactly the same without knowing their formula. But, using the formulas at this site, I was able to create a formula that gets a result within about a dollar difference from the site you linked using different combinations of values. The problem is determining exactly when and how they calculate the interest and when they are calculating when the monthly contribution is made. Those determinations will change the interest calculations.

$principle = 5000;
$monthly_amt = 200;
$years = 6;
$rate = 3.5;

$periods_per_year = 12;
$periods = $years * $periods_per_year;
$interest = $rate / 100 / $periods_per_year;

$future_value = (pow(( 1 + $interest), $periods) * $principle)
			 + ( $monthly_amt * ( ( pow( (1 + $interest), $periods) - 1) / $interest ) );

echo "Start: $ $principle<br>\n";
echo "Monthly: $ $monthly_amt<br>\n";
echo "Years: $years<br>\n";
echo "Rate: $rate %<br><br>\n";
echo "Total: $ $future_value<br>\n";


Edited by Psycho, 05 December 2012 - 02:29 PM.

The quality of the responses received is directly proportional to the quality of the question asked.

I do not always test the code I provide, so there may be some syntax errors. In 99% of all cases I found the solution to your problem here: http://www.php.net

#6 Skylight_lady

Skylight_lady

    Advanced Member

  • Members
  • PipPipPip
  • 129 posts

Posted 06 December 2012 - 10:43 AM

Interesting !! But it's too short of the Growth amount. Ive been using the values:
Balance = 20000
MonthlyAmount = 500
InterestRate = 3
Years = 4

The correct formula is as follows:
Year1 = (Balance + (MonthlyAmount * 12)) * InterestRate;
Year2 = (Year1 + (MonthlyAmount * 12)) * InterestRate;
Year3 = (Year2 + (MonthlyAmount * 12)) * InterestRate;

The end of year balance, is added to 12 months repayments and multiplied by the interest rate.

However, if i used the simple maths it won't correct it. Thereforem a more complicated formula is required like the "pow"

#7 Psycho

Psycho

    Advanced Member

  • Gurus
  • 10,821 posts
  • LocationCanada

Posted 06 December 2012 - 11:33 AM

I don't think you understand how interest is calculated. The formulas you just posted are NOT correct. Interest is not calculated at the end of the year. It is commonly calculated each month, also known as the compounding period. So, if the interest rate is 3% and there are 12 compounding periods for the year, the bank will calculate the interest each month using 1/12th of the interest rate - .25%. Using the formula you have above you are applying the total interest at the end of the year. If that was the case you could simply make a huge deposit on Dec. 30th of each year and get a years worth of interest on it. By the same token, if you have $10,000 in the bank all year and then withdrew it on Dec. 30th you wouldn't get any interest. That is why interest is calculated monthly (typically). But, I think banks actually calculate the interest on the average daily balance. That is why it is important to know WHEN the monthly contribution is added. If it is added at the beginning or the end of the month it will affect the interest amount.

The formulas you just posted would only be "partially" correct if the compounding period was yearly - which I have never seen.

Calculating the interest for a year would look more like this when written out in long form:
Month1Balance = (StartBalance + MonthlyAmount) * InterestRate
Month2Balance = (Month1Balance + MonthlyAmount) * InterestRate
Month3Balance = (Month2Balance + MonthlyAmount) * InterestRate
etc. . . .

But, because of average daily balance is what I think is really used, that would be the case if the monthly contribution is added right after the interest calculation each month.
The quality of the responses received is directly proportional to the quality of the question asked.

I do not always test the code I provide, so there may be some syntax errors. In 99% of all cases I found the solution to your problem here: http://www.php.net




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com