Calculate Black Scholes Option Price In Python

Sharing is caring!

Last Updated on April 30, 2022 by Jay

This tutorial will walk through how to calculate the Black Scholes Merton (BSM) model option price in Python.

We are going to use two libraries for the calculation: scipy and numpy. Type the following in a command prompt to install them.

pip install scipy numpy

The Black Scholes Formula

We are going to use a simplified formula and assume no dividend.

In general, the Black Scholes Merton formula gives a theoretical value for European-style options which can only be exercised at the expiration date.

Most of the stock options in the US market are American-style, which can be exercised any time before the expiration date. I just want to make this clear – we could use the Black Scholes formula to model American-style options, but it’s not going to be theoretically accurate. That said, even the BS formula is just an estimate, it would be unrealistic to expect 100% accuracy anyways.

Black Scholes Merton Option Pricing Formula
Black Scholes Merton Option Pricing Formula
  • C – Call option price
  • P – Put option price
  • S – Stock price
  • K – Strike price
  • r – risk-free rate
  • t – time to expiration in years
  • σ – volatility
  • N() – the standard normal cumulative distribution function

Black Scholes Merton Option Price Calculation In Python

As the above formula implies, we need to first solve d1 and d2 before we can calculate the option prices. Let’s implement the Nobel prize-winning formula in Python:

import scipy.stats
from numpy import sqrt, log, exp, pi

N = scipy.stats.norm.cdf
d1 = (log(S/K) + (r+sigma**2/2)*t) / (sigma*sqrt(t))
d2 = d1 - sigma * sqrt(t)

def bs_price(c_p, S, K, r, t, sigma):
    if c_p == 'c':
        return N(d1) * S - N(d2) * K * exp(-r*t)
    elif c_p == 'p':
        return N(-d2) * K * exp(-r*t) - N(-d1) * S
        return "Please specify call or put options."

The Reality Of Option Pricing

Although we could calculate the Black Scholes Option Price using Python (or simply using a calculator), the reality is that the BS formula does not determine option prices (lol).

Those with experience with the stock & options market would understand, that the demand and supply of an asset determine its value/price. So why bother with the formula and why it’s worth the Nobel prize?

It’s because the Black Scholes Merton formula is not only the first of its kind, but it provides a framework for evaluating risks associated with stocks and their options.

Additional Resources

Calculate Option Implied Volatility In Python

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *