On Wed, 17 Jan 2001, Paul Cohen wrote:
> Hello all,
>
> I am trying to build an IRR calculator using PHP. The number of cash flow
> streams I will have at any time will vary, so I am using a loop to build the
> formula. Then I am iterating to solve the equation and output the solution.
>
> As most of you know, I am solving the following for r:
>
> 0=SUM SERIES(CF(i)/{(1+r)^n))
>
> I can build my formula sucessfully with the following;
>
> $form="";
> while ($row=mysql_fetch_array($result)){
> $form.="$CF/pow((1+'$r'),$N)";
> }
>
> But it recognizes $form as a string, so when I put it in my "solution for r"
> loop:
>
> for($r=-1.00; $r<=1.00; $r=$r+.0001){
> if($form>-.001 && $form < .001){
> $IRR=round($r*100, 2);
> }
> }
> echo "$IRR%<br>";
>
>
> BTW, I have also tried building the $form as a variable, but since I don't
> have a value for $r it just puts in zero and sets $form equal to the right
> side of the equation. Therfore, instead of inserting a formula into my
> "solution for r" loop, it inserts a constant for $form.
>
> I think my solution is to build the formula as a string and then insert it
> into my "solution for r" loop, convert it back to a real formula and then
> iterate for the solution. Is this possible? If not, any suggestions?
>
Your best bet is to write a function to do that. Look in the PHP manual for
details.
--
Ignacio Vazquez-Abrams <[EMAIL PROTECTED]>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]