Black-Scholes Pricing and Greeks in VBA

RonAkke

New Member
Joined
Apr 22, 2014
Messages
3
Hi all,

Here are functions which will calculate the Black-Scholes call value as well as all of it's greeks in VBA (delta, gamma, vega, theta and rho).

The functions for the Black-Scholes put price and greeks are available here. Enjoy!

Code:
Function CallPrice(StockPrice As Double, StrikePrice As Double, TimeToExpiration As Double, Volatility As Double, RiskFreeRate As Double, DividendYield As Double)
    
    Dim d(2) As Double
    
    d(1) = (Log(StockPrice / StrikePrice) + (RiskFreeRate - DividendYield + (Volatility ^ 2) / 2) * TimeToExpiration) / (Volatility * Sqr(TimeToExpiration))
    d(2) = d(1) - Volatility * Sqr(TimeToExpiration)
    CallPrice = StockPrice * Exp(-DividendYield * TimeToExpiration) * Application.WorksheetFunction.NormSDist(d(1)) - _
        StrikePrice * Exp(-RiskFreeRate * TimeToExpiration) * Application.WorksheetFunction.NormSDist(d(2))

End Function

Function CallDelta(StockPrice As Double, StrikePrice As Double, TimeToExpiration As Double, Volatility As Double, RiskFreeRate As Double, DividendYield As Double)
    
    CallDelta = Exp(-DividendYield * TimeToExpiration) * Application.WorksheetFunction.NormSDist _
        ((Log(StockPrice / StrikePrice) + (RiskFreeRate - DividendYield + (Volatility ^ 2) / 2) * TimeToExpiration) / (Volatility * Sqr(TimeToExpiration)))
        
End Function

Function CallTheta(StockPrice As Double, StrikePrice As Double,  TimeToExpiration As Double, Volatility As Double, RiskFreeRate As  Double, DividendYield As Double)

    CallTheta = -(StockPrice * Exp(-DividendYield * TimeToExpiration) * (1 / (Sqr(2 * Application.Pi())) * Exp(-(d(1) ^ 2) / 2)) * Volatility) / (2 * Sqr(TimeToExpiration)) _
        - (RiskFreeRate * StrikePrice * Exp(-RiskFreeRate * TimeToExpiration) * Application.WorksheetFunction.NormSDist(d(2))) _
        + (DividendYield * StockPrice * Exp(-DividendYield * TimeToExpiration) * Application.WorksheetFunction.NormSDist(d(1)))
        
End Function

Function CallGamma(StockPrice As Double, StrikePrice As Double, TimeToExpiration As Double, Volatility As Double, RiskFreeRate As Double, DividendYield As Double)
    
    Dim d(1) As Double

    d(1) = (Log(StockPrice / StrikePrice) + (RiskFreeRate - DividendYield + (Volatility ^ 2) / 2) * TimeToExpiration) / (Volatility * Sqr(TimeToExpiration))
    CallGamma = Exp(-DividendYield * TimeToExpiration) * (1 / (Sqr(2 * Application.Pi())) * Exp(-(d(1) ^ 2) / 2)) _
        / (StockPrice * Volatility * Sqr(TimeToExpiration))

End Function

Function CallVega(StockPrice As Double, StrikePrice As Double, TimeToExpiration As Double, Volatility As Double, RiskFreeRate As Double, DividendYield As Double)
    
    Dim d(1) As Double

    d(1) = (Log(StockPrice / StrikePrice) + (RiskFreeRate - DividendYield + (Volatility ^ 2) / 2) * TimeToExpiration) / (Volatility * Sqr(TimeToExpiration))

    CallVega = StockPrice * Exp(-DividendYield * TimeToExpiration) * (1 / (Sqr(2 * Application.Pi())) * Exp(-(d(1) ^ 2) / 2)) * Sqr(TimeToExpiration)

End Function

Function CallRho(StockPrice As Double, StrikePrice As Double, TimeToExpiration As Double, Volatility As Double, RiskFreeRate As Double, DividendYield As Double)
    
    Dim d(2) As Double

    d(1) = (Log(StockPrice / StrikePrice) + (RiskFreeRate - DividendYield + (Volatility ^ 2) / 2) * TimeToExpiration) / (Volatility * Sqr(TimeToExpiration))
    d(2) = d(1) - Volatility * Sqr(TimeToExpiration)
    CallRho = StrikePrice * TimeToExpiration * Exp(-RiskFreeRate * TimeToExpiration) * Application.WorksheetFunction.NormSDist(d(2))

End Function
 
Last edited:

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,222,115
Messages
6,164,014
Members
451,867
Latest member
csktwyr

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top