Black & Scholes

Nyptop

Active Member
Licensed User
Longtime User
I have this code (bare in mind that S= Stock price, X=Strike price, T=Years to maturity, r= Risk-free rate, v=Volatility):

Sub button5_click As Button
'// The Black and Scholes (1973) Stock option formula

S = edittext1.Text
X = edittext2.Text
T = edittext4.Text
r = edittext3.Text
v = edittext5.Text


d1 = (Logarithm(10,(S / X)) + (r + v ^ 2 / 2) * T) / (v * Sqrt(T))
d2 = d1 - v * Sqrt(T)
BlackScholes = S * CND(d1) - X * Exp(-r * T) * CND(d2)


'// The cumulative normal distribution function



Const a1 = 0.31938153: Const a2 = -0.356563782: Const a3 = 1.781477937:
Const a4 = -1.821255978: Const a5 = 1.330274429

L = Abs(X)
K = 1 / (1 + 0.2316419 * L)
CND = 1 - 1 / Sqrt(2 * 3.14159) * Exp(-L ^ 2 / 2) * (a1 * K + a2 * K ^ 2 + a3 * K ^ 3 + a4 * K ^ 4 + a5 * K ^ 5)

If X < 0 Then
CND = 1 - CND
End If
End Sub




Is the keyword 'power' a natural logarithm. Is there anything else I'm doing wrong?
 

Nyptop

Active Member
Licensed User
Longtime User
The problem I think is that when I save the layout file for scroll view it doesn't appear in the files folder.
 
Upvote 0

magalt

Member
Licensed User
Longtime User
The problem I think is that when I save the layout file for scroll view it doesn't appear in the files folder.

Hi Nyptop
I remember you my errors in "Option calculator2.zip"
I corrected the code with "Option calculator3.zip"

------

Errors in module Call are:
Wrong
d1 = (Logarithm(S / X, cE) + (r + (Power(v, 2)/2) * T1)) / (v * Sqrt(T1))

Correct
d1 = (Logarithm(S / X, cE) + (r + Power(v, 2)/2) * T1) / (v * Sqrt(T1))


Wrong
BlackScholes = S * CND1 - X * Power(cE, -r * T) * CND2

Correct
BlackScholes = S * CND1 - X * Power(cE, -r * T1) * CND2

------

Errors in module Put are:
Wrong
d1 = (Logarithm(S / X, cE) + (r + (Power(v, 2)/2) * T1)) / (v * Sqrt(T1))

Correct
d1 = (Logarithm(S / X, cE) + (r + Power(v, 2)/2) * T1) / (v * Sqrt(T1))


Wrong
BlackScholes = - S * CND1 + X * Power(cE, -r * T) * CND2

Correct
BlackScholes = - S * CND1 + X * Power(cE, -r * T1) * CND2

Marco
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Attached you find a modified version of your program, with everything in one Activity.

I have not checked the equations mentioned by magalt.

I would even combine the two calculations into one routine and display both results at the same time. But that's just my opinion.

Best regards.
 

Attachments

  • OptionCalc4.zip
    9.2 KB · Views: 214
Upvote 0
Top