Home » Code » More Black Scholes

More Black Scholes

Dr. Johnson, Computational Finance, C++ – Coding Black Scholes Formula, here. Let’s illustrate some of the ILP concepts just in the gcc world. Here’s some scalar Black Scholes code. We could pick any valuation model and do the same thing. Black Scholes is reasonably straightforward because it is just closed form expression evaluation.

double callOptionPrice(double S,double t,double X,double r,double sigma,double T)
{
  double d1=(log(S/X) + (r+sigma*sigma/2.)*(T-t))/(sigma*sqrt(T-t));
  double d2=(log(S/X) + (r-sigma*sigma/2.)*(T-t))/(sigma*sqrt(T-t));
  return normalDistribution(d1)*S - normalDistribution(d2)*X*exp(-r*(T-t));
}

int main()
{
  cout << "Call Option Price = " << callOptionPrice(1,0,1,0.05,0.2,1) << endl;
  return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: