Forum Moderators: coopster
function example($A,$B)
{
$Q;
$A=$Q-$B;
}
I know this is wrong, but what do I need to change to solve for $Q?
- Danny
This might require numerous steps though.
Think through how you would logically solve it by hand/calculator. Include all the steps. Write this into PHP Code.
Your example is really too simple to be of any help:
A = Q - B; solve for Q
A + B = Q
/* Q = A + B */
function example($A, $B) {
return $A + $B;
} Perhaps if you gave us something closer to what you're actually trying to do or your actual equation, we might be able to better help.
$P=$C * (1-1/pow((1+$I),$N))/$I+$F*(1/pow((1+$I),$N))
where:
$P is price
$C is coupon payment
$I is yield to maturity
$N is number of payments
$F is Face Value
The equation cannot be simplified to equal $I because it has $I taken to different powers.
Here is a decent page:
[moneychimp.com...]
And here is one that even spells out in plain english steps how to calculate it by hand (which you can turn into code):
[ehow.com...]
Anyways here is the code I used for anyone who is interested:
<?php
$P = $_GET['P'];
$F = $_GET['F'];
$Coupon = $_GET['Coupon'];
$T = $_GET['T'];$C = $Coupon/100;
?><table><tr><td valign = "top">
<form name="bondyield">
<table>
<tr><td align="right">current price   </td><td><input type="text" size="10" name="P" value="<?php echo $P?>"></td></tr>
<tr><td align="right">face value   </td><td><input type="text" size="10" name="F" value="<?php echo $F?>"></td></tr>
<tr><td align="right">coupon rate   </td><td><input type="text" size="10" name="Coupon" value="<?php echo $Coupon?>"></td></tr>
<tr><td align="right">years to maturity   </td><td><input type="text" size="10" name="T" value="<?php echo $T?>"></td></tr>
<tr><td></td><td><input type="submit" value="get quote"></td></tr>
</table>
</form name="bondyield">
<p><?
if ($P>0 and $F>0 and $T>0 and $C>0) {$CY = $F*$C/$P;
$YTM = (($C*$F)+($F-$P)/$T)/(($F+$P)/2);echo "Current Yield: " . $CY . "<br>";
echo "YTM" . $YTM;} else {
echo "Please enter all four variables";
}?>