Solver Black Scholes Option Pricing
Algebra
->
Finance
-> Solver Black Scholes Option Pricing
Log On
Algebra in Finance
Algebra
Solvers
Solvers
Lessons
Lessons
Answers archive
Answers
Source code of 'Black Scholes Option Pricing'
This Solver (Black Scholes Option Pricing)
was created by by
PrateekJain(0)
:
View Source
,
Show
,
Put on YOUR site
About PrateekJain
:
==section input To calculate the price of a call/put option, please enter the following details: Stock Price (S): $ *[input S=80] Exercise Price (X): $ *[input X=100] Risk free interest rate (r): *[input r=5]% per annum Time to maturity(T): *[input T=1] years Volatility (Annualized standard deviation) ({{{sigma}}}): *[input V=30]% Yield (Dividend) to Maturity (y): *[input y=10]% ==section solution perl print "The Black Scholes Pricing formulas for European options are (where c is the call price and p is the Put price): <center> {{{c = Se^(-yT)N(d[1]) - Xe^(-rT)N(d[2])}}} {{{p = Xe^(-rT)N(-d[2]) - Se^(-yT)N(-d[1])}}} {{{d[1] = (ln(S/K)+(r + sigma^2/2)T)/(sigma*sqrt(T))}}} {{{d[2] = d[1] - sigma*sqrt(T)}}} </center>"; $r = $r/100; $V=$V/100; $y = $y/100; $SX=$S/$X; $logSX = ($SX**$SX - 1)/$SX; $SXi = 1/$SX; $logSXi = ($SXi**$SXi - 1)/$SXi; $logSX = ($logSX-$logSXi)/2; $d1=($logSX + ($r-$y+$V**2/2)*$T)/($V*sqrt($T)); $d2=$d1 - $V*sqrt($T); if($d1 <= 1) { $Nd1 = 0.5 - 1/sqrt(2*3.14159265)*($d1-1/7*$d1**3); } else { $Nd1 = (1+$d1)*(1/sqrt(2*3.14159265)*exp(-$d1**2/2))/(1+$d1+$d1**2); } $Nd1 = 1 - $Nd1; if($d2 <= 1) { $Nd2 = 0.5 - 1/sqrt(2*3.14159265)*($d2-1/7*$d2**3); } else { $Nd2 = (1+$d2)*(1/sqrt(2*3.14159265)*exp(-$d2**2/2))/(1+$d2+$d2**2); } $Nd2 = 1 - $Nd2; $c = $S*exp(-$y*$T)*$Nd1 - $X*exp(-$r*$T)*$Nd2; $p = $c - $S*exp(-$y*$T) + $X*exp(-$r*$T); $c = sprintf("%.3f", $c); $p = sprintf("%.3f", $p); print "<br/>where N(x) is the cumulative normal distribution.<br/>"; print "Thus the price of European options using these formulas would be:<br/>"; print "Call Price (c) = $c <br/>"; print "Put Price (p) = $p <br/>"; ==section output c ==section check S=80 X=100 r=5 T=1 V=30 y=10 c=2.205