HP Financial Calculators » HP 30b » HP 30b Black-Scholes Equation » Black-Scholes Equation Implementation on Microsoft VB

# Black-Scholes Equation Implementation on VB

Black-Scholes in Visual Basic:

`'' The Black and Scholes (1973) Stock option formulaPublic Function BlackScholes(CallPutFlag As String, S As Double, X _As Double, T As Double, r As Double, v As Double) As DoubleDim d1 As Double, d2 As Doubled1 = (Log(S / X) + (r + v ^ 2 / 2) * T) / (v * Sqr(T))d2 = d1 - v * Sqr(T)If CallPutFlag = "c" ThenBlackScholes = S * CND(d1) - X * Exp(-r * T) * CND(d2)ElseIf CallPutFlag = "p" ThenBlackScholes = X * Exp(-r * T) * CND(-d2) - S * CND(-d1)End IfEnd Function''' The cumulative normal distribution functionPublic Function CND(X As Double) As DoubleDim L As Double, K As DoubleConst a1 = 0.31938153: Const a2 = -0.356563782: Const a3 = 1.781477937:Const a4 = -1.821255978: Const a5 = 1.330274429L = Abs(X)K = 1 / (1 + 0.2316419 * L)CND = 1 - 1 / Sqr(2 * Application.Pi()) * Exp(-L ^ 2 / 2) CND = CND * (a1 * K + a2 * K ^ 2 + a3 * K ^ 3 + a4 * K ^ 4 + a5 * K ^ 5)If X < 0 ThenCND = 1 - CNDEnd IfEnd Function`

Updated On: 10.01.08

1. On 07-Apr-2019, Bill wrote:
In the above function what is the variable S , X , T , r , and v ?