The Option-Graph Project Option-Graph.com

The Black-Scholes Visual Basic Function

    Now we get to the guts of the whole program - a function that can take all the relevant inputs, and return the theoretical value of a call or put option.

     The Black-Scholes option pricing model is described in many online sources including wikipedia, and is also given by Lawrence G. McMillan in his book "Options as a Strategic Investment".

     The original Black-Scholes was only for non-dividend paying stocks. We will be using a version that can take dividend information if it exists and calculate APPROXIMATE option values for dividend paying stocks.

     If the stock does not pay a dividend (if you enter 0.00 for the dividend when using the program), the original Black-Scholes formula is used automatically and option prices calculated by the program should closely match the actual market.

     While the approximate values on options on dividend paying stocks are usually quite accurate and match the actual market within a few cents, there are times when the theoretical price is some distance away from the actual market.

     Always double-check the actual market if you want to trade options on a dividend paying stock, especially if the dividend is large, there is a long time to expiration, or the ex-dividend date is very close.

     Copy and paste the code below into the OptionCalcs module, below the words "end function" of the changeexpiration() function.

Function optionvalue(ByVal stockprice As Single, ByVal strikeprice As Single, ByVal timeremain As Single, ByVal interestrate As Single, ByVal iv As Single, ByVal dividend As Single, ByVal opttype As String) As Single

'Black-Scholes function with dividend approximation

'avoid one possible divide by zero error
If timeremain <= 0 Then
timeremain = 0.0000001
End If

Dim dividendyield As Single = dividend / stockprice
Dim a, b, c, d1, d2 As Single
a = Math.Log(stockprice / strikeprice)
b = ((interestrate - dividendyield) + 0.5 * iv ^ 2) * timeremain
c = iv * Math.Sqrt(timeremain)
d1 = (a + b) / c
d2 = d1 - iv * Math.Sqrt(timeremain)

If opttype.Contains("Call") Then
Return stockprice * Math.Exp(-dividendyield * timeremain) * NORMSDIST(d1) - strikeprice * Math.Exp(-interestrate * timeremain) * NORMSDIST(d2)
Else
Return strikeprice * Math.Exp(-interestrate * timeremain) * NORMSDIST(-d2) - stockprice * Math.Exp(-dividendyield * timeremain) * NORMSDIST(-d1)
End If

End Function

Save your project.

     

Home Page Downloads
Previous Step: The changeexpiration() Function
Next Step: The FindIV() Function

Copyright 2017 option-info.com Privacy Policy

Questions, corrections, suggestions, comments to: this contact

Want to learn options, find strategies? Visit www.option-info.com