How Can I Use the Excel Rate Function Correctly in PHP?
<p>The last time I posted this question I got spanked by you guys because it was not clear what I was asking…I blew it, sorry. So let me try again.</p>

<p>I am trying to mimic the Excel Rate function in PHP. I did obtain some code that does function correctly for other Excel functions but is erratic with the Rate function.</p>

<p>There are two steps involved:</p>

<p><strong>1. Calculate the payment</strong></p>

<pre><code>PMT($rate/12, $nper*12, $pv, $fv, $type)
$rate = .08 // interest rate
$nper = 30 // loan term in years
$pv = (100000 + 4000) // loan amt + loan fees
$fv = 0
$type = 0
PMT = -$763.12 // my PHP result and Excel result
</code></pre>

<p><strong>2. Calculate the rate</strong> </p>

<pre><code>RATE($nper, $pmt, $pv, $fv, $type, $guess)
$nper = 360
$pmt = -763.12 // must remain negative in formula
$pv = 100000 // loan amt only (excludes loan fees)
$fv = 0
$type = 0
$guess = 0.09 // excel default is 0.10 but it doesn’t work so I lowered
RATE = 0.00701507 // Excel result (correct)
RATE = 0.0048541 // my PHP result (incorrect)
</code></pre>

<p>Okay, here’s the catch. When the interest rate is changed from 0.08 to 0.07 the result is a lower PMT of $691.91 which then makes both RATE’s almost identical.</p>

<pre><code>RATE = 0.0061609831 // Excel
RATE = 0.0061609269 // my PHP
</code></pre>

<p><strong>My question is this</strong>: Have any of you used the Excel RATE function in PHP? Were you successful then please share your formula with me. Or did you encounter this problem and find a way to fix it then please tell me what you did. Thank you.</p>
