در بازار اختیار معامله یاد بگیر که ضرر نکنی ...سود خودش راهشو پیدا میکنه و وارد میشه
0

کد VBA بلک شولز

کد VBA بلک شولز

:Guide

Stock : قیمت سهم پایه

 Exercise : قیمت اعمال

Time : زمان باقی مانده تا سررسید

Interest : سود بانکی یا انتظار بازدهی

Divyield : سود تقسیمی

Sigma : نوسان پذیری

Function dOne(stock, exercise, Time, _
interest, divyield, sigma)
    dOne = (Log(stock / exercise) + _
    (interest - divyield) * Time) / _
    (sigma * Sqr(Time)) + 0.5 * sigma * _
    Sqr(Time)
End Function

Function dTwo(stock, exercise, Time, _
interest, divyield, sigma)
    dTwo = dOne(stock, exercise, Time, _
    interest, divyield, sigma) - sigma * _
    Sqr(Time)
End Function

Function BSMertonCall(stock, exercise, Time, _
interest, divyield, sigma)
    BSMertonCall = stock * Exp(-divyield * _
    Time) * Application.NormSDist _
    (dOne(stock, exercise, Time, _
    interest, divyield, sigma)) - exercise * _
    Exp(-Time * interest) * Application.NormSDist _
    (dTwo(stock, exercise, Time, interest, _
    divyield, sigma))
End Function

'Put pricing function uses put-call
'parity theorem
Function BSMertonPut(stock, exercise, Time, _
interest, divyield, sigma)
    BSMertonPut = BSMertonCall(stock, exercise, _
    Time, interest, divyield, sigma) + _
    exercise * Exp(-interest * Time) - _
    stock * Exp(-divyield * Time)
End Function

'The standard normal probability density,
'this is N'(x)
Function normaldf(X)
    normaldf = Exp(-X ^ 2 / 2) / _
    (Sqr(2 * Application.Pi()))
End Function

Function DeltaCall(stock, exercise, Time, _
interest, divyield, sigma)
    DeltaCall = Exp(-divyield * Time) * _
    Application.NormSDist(dOne(stock, exercise, _
    Time, interest, divyield, sigma))
End Function

Function DeltaPut(stock, exercise, Time, _
interest, divyield, sigma)
    DeltaPut = -Exp(-divyield * Time) * _
    Application.NormSDist(-dOne(stock, _
    exercise, Time, interest, divyield, _
    sigma))
End Function

Function OptionGamma(stock, exercise, Time, _
interest, divyield, sigma)
    temp = dOne(stock, exercise, Time, _
    interest, divyield, sigma)
    OptionGamma = Exp(-divyield * Time) * _
    Application.Norm_S_Dist(temp, 0) / _
    (stock * sigma * Sqr(Time))
End Function

Function Vega(stock, exercise, Time, _
interest, divyield, sigma)
    Vega = stock * Sqr(Time) * _
    normaldf(dOne(stock, exercise, _
    Time, interest, divyield, sigma)) _
    * Exp(-divyield * Time)
End Function
Function ThetaCall(stock, exercise, Time, interest, divyield, sigma)

    ThetaCall = -stock * normaldf _
    (dOne(stock, exercise, Time, _
    interest, divyield, sigma)) * _
    sigma * Exp(-divyield * Time) / _
    (۲ * Sqr(Time)) + divyield * stock * _
    Application.NormSDist(dOne(stock, _
    exercise, Time, interest, _
    divyield, sigma)) * Exp(-divyield * Time) _
    - interest * exercise * Exp(-interest * _
    Time) * Application.NormSDist _
    (dTwo(stock, exercise, Time, _
    interest, divyield, sigma))

   
End Function

Function ThetaPut(stock, exercise, Time, _
interest, divyield, sigma)
    ThetaPut = -stock * normaldf _
    (dOne(stock, exercise, _
    Time, interest, divyield, sigma)) * _
    sigma * Exp(-divyield * Time) / _
    (۲ * Sqr(Time)) - divyield * stock _
    * Application.NormSDist(-dOne(stock, _
    exercise, Time, interest, divyield, _
    sigma)) * Exp(-divyield * Time) _
    + interest * exercise * Exp _
    (-interest * Time) * Application.NormSDist _
    (-dTwo(stock, exercise, Time, _
    interest, divyield, sigma))
End Function

Function RhoCall(stock, exercise, Time, _
interest, divyield, sigma)
    RhoCall = exercise * Time * _
    Exp(-interest * Time) * _
    Application.NormSDist(dTwo _
    (stock, exercise, Time, interest, _
    divyield, sigma))
End Function

Function RhoPut(stock, exercise, Time, _
interest, divyield, sigma)
    RhoPut = -exercise * Time * _
    Exp(-interest * Time) * _
    Application.NormSDist(-dTwo _
    (stock, exercise, Time, interest, _
    divyield, sigma))
End Function



 

 

 

 

ارسال دیدگاه

نشانی ایمیل شما منتشر نخواهد شد.