Free web development scripts for the webmasterDevelopment Scripts


 
 Site Navigation
 o Development Scripts
 o Text Only Edition
 o PHP.net News
 o Tutorials
 o Register an account
 o New entries this week
 o Affiliates/Links
 o Contact Us
 o About us
 o Advanced Search

 Browse Path
 o 1 user online
 o Most users online: 67
 o Home
  o Perl
   o Miscellaneous
    o Script

 Member Login
User Name
Password

 Standards
Valid XHTML 1.0!
Valid 
CSS!

 Recommended Links
 o PHP Freaks
 o Designer Baby Clothes
 o White Watch Store
 o iPad 64gb 3g
 o OxyScripts
 o Invoice Software
 o Free Wedding Websites
 o Invoice Software
 o UK Business Franchises

Black-Scholes Option Pricing Model (Rated 5)

Description:

Black-Scholes is a model used to calculate the value of an option, by considering the stock price, strike price and expiration date, risk-free return, and the standard deviation of the stock's return.

Code starts here


=head2 BlackScholes

Routine to implement the Black and Scholes (1973) option pricing formula.

# usage
$price = GBlackScholes($call_put_flag, $S, $X, $T, $r, $b, $v);

Here C<$call_put_flag> is either 'c' or 'p' for a call or put respectively,

=cut

sub BlackScholes {
my ($call_put_flag, $S, $X, $T, $r, $v) = @_;

# calculate some auxiliary values
my $d1 = ( log($S/$X) + ($r+$v**2/2)*$T ) / ( $v * $T**0.5 );
my $d2 = $d1 - $v * $T**0.5;

if ($call_put_flag eq 'c') {
return $S * &CND($d1) - $X * exp( -$r * $T ) * &CND($d2);
}
else { # ($call_put_flag eq 'p')
return $X * exp( -$r * $T ) * &CND(-$d2) - $S * &CND(-$d1);
}

}

=head2 CND

Approximate the cumulative normal distribution. That is, the value
of the integral of the standard normal density from minus infinity
to C<$x>.

# usage
$p = &CND($x);

=cut

sub CND {
my $x = shift;

# the percentile under consideration

my $Pi = 3.141592653589793238;

# Taylor series coefficients
my ($a1, $a2, $a3, $a4, $a5) = (0.319381530, -0.356563782, 1.781477937, -1.821255978, 1.330274429);

# use symmetry to perform the calculation to the right of 0
my $L = abs($x);

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

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

# then return the appropriate value
return ($x >= 0) ? $CND : 1-$CND;

}


Submitted by Devscripts on 06-03-2003 20:30


Recent Additions (from all categories)

(PHP) T Shirt Printing Software

(PHP) Youtube Video Organizer Script

(PHP) MP3z - MP3 Search Engine Script

(PHP) Recipez- PHP Recipe Script

(ASP) Stop image hotlinking and downloading. Web image protection is easy with Image Trapper.

Top Rated Scripts

(Javascripts) Javascript Delayed Redirection Rating: 5

(PHP) Random Links and images with PHP & MySQL Rating: 5

(PHP) RSS/XML news feed headline grabber! Rating: 5

(PHP) Random Signatures/Avatars Rating: 5

(Javascripts) Detecting Client Web Browser Rating: 5

© Copyright 2003 - Devscripts.net