Skylight_lady Posted December 5, 2012 Share Posted December 5, 2012 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 Quote Link to comment Share on other sites More sharing options...
MDCode Posted December 5, 2012 Share Posted December 5, 2012 What do you mean by a monthly contribution? Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 5, 2012 Share Posted December 5, 2012 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; Quote Link to comment Share on other sites More sharing options...
Skylight_lady Posted December 5, 2012 Author Share Posted December 5, 2012 Well it's supposed to be exactly like http://www.aib.ie/personal/savings/Savings-Calculator?gclid=CMyTpKLng7QCFYRF2wodo18AFg 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 Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 5, 2012 Share Posted December 5, 2012 (edited) 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 December 5, 2012 by Psycho Quote Link to comment Share on other sites More sharing options...
Skylight_lady Posted December 6, 2012 Author Share Posted December 6, 2012 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" Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 6, 2012 Share Posted December 6, 2012 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.