0

Hello guys, I need help with this. When I run it, I get a blank page. Please Me out.

<?php
//The Main Program
$call_put_flag="c";
$S=50;
$X=52;
$T=0.5;
$r=0.05;
$v=0.15;
BlackScholes ($call_put_flag, $S, $X, $T, $r, $v);
//echo $call_put_flag, $S, $X, $T, $r, $v;

//Commulative function
function CND ($x) {

$Pi = 3.141592653589793238;

$a1 = 0.319381530;

$a2 = -0.356563782;

$a3 = 1.781477937;

$a4 = -1.821255978;

$a5 = 1.330274429;

$L = abs($x);

$k = 1 / ( 1 + 0.2316419 * $L);

$p = 1 - 1 /  pow(2 * $Pi, 0.5) * exp( -pow($L, 2) / 2 ) * ($a1 * $k + $a2 * pow($k, 2)+ $a3 * pow($k, 3) + $a4 * pow($k, 4) + $a5 * pow($k, 5) );

if ($x >= 0) { 

print $p;

} else {

print 1-$p;

}

}
//BlackScholes calculation
function BlackScholes ($call_put_flag, $S, $X, $T, $r, $v) 
{

$d1 = ( log($S / $X) + ($r + pow($v, 2) / 2) * $T ) / ( $v * pow($T, 0.5) );

$d2 = $d1 - $v * pow($T, 0.5);

if ($call_put_flag == 'c') {

print $S * CND($d1) - $X * exp( -$r * $T ) * CND($d2); //Call Option

} else { 

print $X * exp( -$r * $T ) * CND(-$d2) - $S * CND(-$d1); //Put Option

}

?>
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by muhito
0

A blank page usually means that you had a syntax problem and the program didn't run. If you use an editor that has built in syntax checking (like Netbeans) it will help you find these errors. Indenting your code makes it easier to see some kinds of problems visually.

In this case, you are missing the final bracket for the BlackScholes function.

0

A blank page usually means that you had a syntax problem and the program didn't run. If you use an editor that has built in syntax checking (like Netbeans) it will help you find these errors. Indenting your code makes it easier to see some kinds of problems visually.

In this case, you are missing the final bracket for the BlackScholes function.

Thanks so much.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.