|
|
|
|
|
|
Excel
|
Black Scholes Formula
|
|
Ease of Use
|
Intermediate
|
Version tested with
|
Excel XP
|
Submitted by:
|
thefrasers
|
Description:
|
Use this add-in to generate simple Black-Scholes-Merton (BSM) prices, Deltas, and Gammas for a simple option. Some basic option knowledge is assumed. Under no circumstances should this programme be relied upon in a live market situation.
|
Discussion:
|
This stops people from typing in lots of rather tedious mathematical formulae whenever an option price is calculated. I use this a lot in teaching; there are lots of issues around BSM, so you should only look at this as an example of how options prices and behavior are generated rather than any type of trading tool.
I am a VBA Newbie, so the code may well be inefficient (I think default values could be used) - but it does work.
*Use at your own risk*
|
Code:
|
instructions for use
|
Option Compare Text
Option Explicit
Option Base 0
Global Const Pi = 3.14159265358979
Public Function Littlen(X As Double) As Double
Littlen = 1 / Sqr(2 * Pi) * Exp(-X ^ 2 / 2)
End Function
Function BlackScholes(SpotPrice As Double, Strike As Double, Rate As Double, _
Time As Double, Dividend As Double, Vol As Double, CallPut As String, Reg0Fut1 As Integer, Output As Integer) As Double
Dim volrootime As Double
Dim d1 As Double
Dim d2 As Double
Dim DiscF As Double
Dim DivF As Double
Dim Optprice As Double
Dim topline1 As Double
Dim topline2 As Double
Dim topline As Double
Dim Price As Double
Dim Delta As Double
Dim Gamma As Double
DiscF = Exp(-Rate * Time)
DivF = Exp(-Dividend * Time)
volrootime = (Time ^ 0.5) * Vol
If Reg0Fut1 = 0 Then
topline1 = Log(SpotPrice / Strike)
topline2 = ((Rate - Dividend) + ((Vol ^ 2) / 2)) * Time
topline = topline1 + topline2
d1 = topline / volrootime
d2 = d1 - volrootime
If CallPut = "C" Then
Price = (SpotPrice * DivF * Application.NormSDist(d1)) - _
(Strike * DiscF * Application.NormSDist(d2))
Delta = DivF * Application.NormSDist(d1)
Gamma = (Littlen(d1) * DivF) / (SpotPrice * volrootime)
Else
Price = Strike * DiscF * WorksheetFunction.NormSDist(-d2) - _
SpotPrice * DivF * WorksheetFunction.NormSDist(-d1)
Delta = DivF * (Application.NormSDist(d1) - 1)
Gamma = (Littlen(d1) * DivF) / (SpotPrice * volrootime)
End If
Else
topline1 = Log(SpotPrice / Strike)
topline2 = ((Vol ^ 2) / 2) * Time
topline = topline1 + topline2
d1 = topline / volrootime
d2 = d1 - volrootime
If CallPut = "C" Then
Price = DiscF * ((SpotPrice * Application.NormSDist(d1)) - _
(Strike * Application.NormSDist(d2)))
Delta = DiscF * Application.NormSDist(d1)
Gamma = (Littlen(d1) * DiscF) / (SpotPrice * volrootime)
Else
Price = DiscF * ((Strike * Application.NormSDist(-d2)) - _
(SpotPrice * Application.NormSDist(-d1)))
Delta = DiscF * (Application.NormSDist(d1) - 1)
Gamma = (Littlen(d1) * DiscF) / (SpotPrice * volrootime)
End If
End If
Select Case Output
Case 0
BlackScholes = Price
Case 1
BlackScholes = Delta
Case 2
BlackScholes = Gamma
End Select
End Function
|
How to use:
|
- Open the Excel VBA page (Alt-F11)
- Start a new module (Insert-Module)
- Copy and paste the code.
- Close VBE
- A user-defined function should be created (BlackScholes). If you insert the function it asks for these inputs ...
- SpotPrice = asset price
- Strike = strike price
- Rate = interest rate governing period to expiry (annualised continuously compounded)
- Time = time to expiry in years
- Dividend = dividend/income rate of asset until expiry (annualised continuously compounded)
- Vol = implied volatility
- CallPut = C for call, P for put
- Type User inputs whether it is an 'ordinary' option (type 0), or an option on a futures contract (type 1 (Black 76 model))
- Output : user decides what outputs are required. 0 = price, 1= Delta, 2 = Gamma.
|
Test the code:
|
- Try out the following option...
- Asset Price = 100
- Strike = 100
- Time = 0.25
- Vol = 25%
- Rate = 5%
- Div = 1%
- For a regular call option, the price should be 5.458423181, the Delta should be 55.527%, and the gamma should be 0.031514097. If it was a call on futures the values would be 4.921641213, 51.840%, and 0.031457423.
- For a regular put option, the values are 4.465890991, -44.224%, and 0.031514097.
- For a put on futures the values will be identical to those for the call (put call parity) except for the delta which is -46.918%.
|
Sample File:
|
BS Examp.zip 10.89KB
|
Approved by mdmackillop
|
This entry has been viewed 319 times.
|
|