C# Option Pricing Function for Excel


quantShorts

First up, we have a C# option pricing function using Black-Scholes for euro put/call options. We’ll export the function to Excel and try it with some test data.

Brief background:

We have the Black-Scholes equation:

Image

Solving for boundary/terminal conditions gives us the call option:

Image

And by put-call parity, the put option is:

Image

  •  N is the cumulative distribution function of the standard normal distribution
  •  T -t is the time to maturity
  •  S is the spot price of the underlying asset
  •  K is the strike price
  •  r is the risk free rate (annual rate, expressed in terms of continuous compounding)
  •   σ is the volatility of returns of the underlying asset

(source: Wikipedia)

I adapted this C# code as follows, in a class library project:

To export to excel we need (also need to include a GUID in the class header):

 

We also have to enable registering for COM Interop in our project’s build properties. Now when we build our solution…

View original post 189 more words