Page 1 of 1

Formula Help

Posted: Wed Mar 31, 2010 5:41 pm
by JakeJ
I am using a php class you may be familiar with called financial_class.php. It imitates the financial functions of Excel and there is an extensive list of functions.

The problem I'm having is that the RATE() function is not returning the correct number. I'm getting a much smaller number than Excel returns.

I'm not really in the position to recreate one on my own so I'm wondering if anyone has written a function that returns RATE() as found in Excel. It solves for an interest rate needed based on a period of time, periodic payments, current balance and optionally (an option I need) a target amount.

All help with this is appreciated.

Re: Formula Help

Posted: Fri Apr 02, 2010 3:38 pm
by tr0gd0rr
I had to do some equations just recently. I wish I would have found financial_class.php!

Here is my code: http://sandbox.kendsnyder.com/rate/. It may not be perfect; compare against Excel RATE results.

Re: Formula Help

Posted: Fri Apr 02, 2010 8:43 pm
by JakeJ
I'll pop it in to my code tonight and let you know how it goes.

Thanks!

Re: Formula Help

Posted: Sat Apr 03, 2010 3:53 pm
by JakeJ
Sorry to say but your solution didn't work for me since I needed to calculate a target interest rate based on a future amount.

I came up with a fairly quick solution to it though.

Using the FV() function in the financial class I mentioned before, I was able to loop through a series of FV()'s until the number approximated my target amount. Here's the code.

Code: Select all

//Calculates the interest rate required to reach a certain goal.
//Rate is multiplied by 12 for annualizing
//$payment and $pv should be negative numbers
Function retirementrate($nper, $payment, $pv, $target) {
$rate = .001;
$x = 0;
While ($x <= $target) {
	$x = FV($rate,$nper,$payment,$pv);
	If ($x <= $target * .97) {
		$rate = $rate + .00001;
	} 
	Else {
		$rate = $rate +.000000001;
	}
	If ($rate >= 1) { break; }
}

$rate = $rate * 12;
Return $rate;
}