An option pricing model implementation guide with code starts with one idea: an option is worth what it might pay out in the future, discounted back to today, and the Black-Scholes formula turns that idea into a number you can compute. This guide builds that model in Python, explains every input, and checks the answer against put-call parity.

You need no finance degree and no special software: the code uses only the Python standard library. This guide is educational and is not financial advice.

Key takeaways

  • An option pricing model estimates the fair value of an option from five inputs.
  • The Black-Scholes formula prices European options, which can only be exercised at expiry.
  • The five inputs are the share price, the strike price, the time to expiry, the interest rate and the volatility.
  • The code in this guide uses only the Python standard library and runs as written.
  • Put-call parity gives a simple check that the call and put values are consistent.
  • The model leaves out dividends, early exercise and sudden price jumps, so treat its output as an estimate.

What an option pricing model does

An option is a contract that gives its holder the right, but not the obligation, to buy or sell a share at a set price before a set date. A call option gives the right to buy, and a put option gives the right to sell. The set price is the strike price, the set date is the expiry, and the amount paid is the premium. The pricing question is simple to ask and hard to answer: what should that premium be?

An option pricing model answers that question by working out what the option might be worth in the future and discounting that value back to today. If the share ends up above the strike, a call pays the difference; if it ends up below, the call pays nothing. The model weighs every possible future share price by how likely it is, then averages the payoffs and discounts them. The result is a fair value, the price at which a buyer and a seller would trade if they agreed with the model’s assumptions.

The five inputs

Every option pricing model needs the same five inputs, and understanding them matters more than memorising the formula. The first is the current share price, written as S. The second is the strike price, written as K, the price at which the holder can buy or sell. The third is the time to expiry, written as T, measured in years, so six months is 0.5 and three months is 0.25.

The fourth input is the risk-free interest rate, written as r, the return on a safe investment such as a government bond. The fifth is the volatility, written as sigma, which measures how much the share price is expected to move. Volatility is the hardest input to pin down, because it is a forecast, not a fact, usually estimated from past price moves or from the prices of options already trading.

The Black-Scholes formula in plain English

The Black-Scholes formula, published by Fischer Black, Myron Scholes and Robert Merton in 1973, is the best-known option pricing model. It prices European options, which can only be exercised on the expiry date, and it assumes the share price moves smoothly, the rate and the volatility stay fixed, and the share pays no dividends. Those assumptions are simplifications, but the formula is still the standard starting point.

The formula works in two steps. First, it computes two numbers, d1 and d2, from the five inputs. The number d1 measures how far the option is from the money, adjusted for time and volatility, and d2 is d1 shifted down by the volatility. Second, it feeds d1 and d2 through the cumulative normal distribution, written as N, which turns them into probabilities, and combines them with the share price and the strike price to give the option value.

For a call, the value is the share price times N of d1, minus the strike price discounted at the risk-free rate times N of d2. For a put, the value follows from the call value through put-call parity: a call minus a put equals the share price minus the discounted strike price. Parity is a useful check: if your values do not satisfy it, something in the code is wrong.

A screen showing analytics charts and user figures.
An option pricing model turns a handful of inputs into a number you can act on.

The code: a Black-Scholes model in Python

The code below implements the model in plain Python, using only the standard library. The function norm_cdf computes the cumulative normal distribution from the error function in the math module, so no extra packages are needed. The function black_scholes_call computes d1 and d2 and returns the call value, and black_scholes_put uses put-call parity for the put.

import math

def norm_cdf(x):
    return 0.5 * (1.0 + math.erf(x / math.sqrt(2.0)))

def black_scholes_call(S, K, T, r, sigma):
    d1 = (math.log(S / K) + (r + 0.5 * sigma ** 2) * T) / (sigma * math.sqrt(T))
    d2 = d1 - sigma * math.sqrt(T)
    return S * norm_cdf(d1) - K * math.exp(-r * T) * norm_cdf(d2)

def black_scholes_put(S, K, T, r, sigma):
    return black_scholes_call(S, K, T, r, sigma) - S + K * math.exp(-r * T)

call = black_scholes_call(100, 100, 1.0, 0.05, 0.2)
put = black_scholes_put(100, 100, 1.0, 0.05, 0.2)
print(round(call, 4))
print(round(put, 4))

Run the code with Python 3 and it prints 10.4506 for the call and 5.5735 for the put. Those are the values for a share at 100, a strike of 100, one year to expiry, an interest rate of 5 per cent and a volatility of 20 per cent. The option is at the money, since the share price equals the strike.

Each line of the code maps to a piece of the formula. The line for d1 takes the log of the share price over the strike, adds the drift term, and divides by the volatility scaled by the square root of time. The line for d2 subtracts the volatility term from d1. If you change any input, the values move as the theory predicts: a higher share price raises the call, a higher strike lowers it, more time raises both, and higher volatility raises both.

Running it and checking the answer

The first check is put-call parity. For the example above, the call minus the put is 10.4506 minus 5.5735, which is 4.8771. The share price minus the discounted strike is also 4.8771. The two sides match, which confirms that the call and put functions are consistent.

The second check is a strike sweep: price the same call at several strikes and confirm the values fall as the strike rises. A higher strike means the holder pays more to exercise, so the call must be worth less.

for strike in [90, 95, 100, 105, 110]:
    print(strike, round(black_scholes_call(100, strike, 1.0, 0.05, 0.2), 2))

This prints 90 for 16.7, 95 for 13.35, 100 for 10.45, 105 for 8.02 and 110 for 6.04. The values fall steadily as the strike rises, and the at-the-money value of 10.45 matches the earlier example. A third check is the boundary case: with no time left, a call is worth the share price minus the strike if that is positive, and nothing otherwise.

What the model leaves out

Black-Scholes is a starting point, not the whole story. It assumes the share pays no dividends, but many shares do, and a dividend lowers the value of a call because the share price drops on the ex-dividend date. It assumes the volatility stays fixed, but in practice volatility changes, and options with different strikes often trade at different implied volatilities, a pattern known as the volatility smile.

It also assumes the share price moves smoothly, with no sudden jumps, and it prices European options only. American options, which can be exercised at any time before expiry, need a different method, and the usual choice is a binomial tree, which steps the share price up and down and works backwards from expiry. Monte Carlo simulation is another option: it generates thousands of possible price paths, values the option on each one, and averages the results.

The Greeks, briefly

The Greeks are the sensitivities of an option’s value to each input, and they are how traders manage risk. Delta measures how much the option value moves when the share price moves by one unit. For a call, delta sits between zero and one: close to one for a deep in-the-money call and close to zero for a far out-of-the-money call. Gamma measures how fast delta itself changes as the share price moves. Theta measures how much value the option loses as time passes, and it is usually negative. Vega measures the sensitivity to volatility, and it is positive for both calls and puts. Rho measures the sensitivity to the interest rate. You can compute delta from the code above, since the call delta is simply N of d1.

Option pricing models compared

Model Handles early exercise Speed Complexity Best for
Black-Scholes No Fast Low European options, quick checks
Binomial tree Yes Medium Medium American options, dividends
Monte Carlo With care Slow High Complex payoffs, many variables

Your option pricing checklist

  • Write down the five inputs first.
  • Use time to expiry in years.
  • Keep the share price and strike in the same units.
  • Test the code on the example: call 10.4506, put 5.5735.
  • Verify put-call parity for every set of inputs.
  • Run a strike sweep and confirm the values fall.
  • Test the boundary case with time close to zero.
  • Try changing the volatility and watch both values rise.
  • Remember the model ignores dividends and jumps.
  • Use the model to compare options, not to predict the market.

Frequently asked questions

What is an option pricing model?

An option pricing model estimates the fair value of an option from five inputs: the share price, the strike price, the time to expiry, the interest rate and the volatility.

What does the Black-Scholes formula calculate?

The Black-Scholes formula calculates the fair value of a European call or put option from the five inputs, computing two numbers, d1 and d2, and combining them with the normal distribution.

Do I need special software to run the code in this guide?

No. The code uses only the Python standard library, so it runs with a plain Python 3 installation.

What is put-call parity?

Put-call parity says that a call minus a put equals the share price minus the discounted strike price. If your values do not satisfy it, something in the code is wrong.

Why does higher volatility raise an option’s value?

Higher volatility means bigger price moves, which make it more likely that the option ends up paying out. The downside is capped at nothing, so the extra upside raises the value.

Can the Black-Scholes model price American options?

No. Black-Scholes prices European options, which can only be exercised at expiry. American options are usually priced with a binomial tree or Monte Carlo simulation.

The bottom line

An option pricing model turns five inputs into a fair value, and the Black-Scholes formula is the clearest place to start: a short Python function, two checks in put-call parity and a strike sweep, and the Greeks to show how the value moves. Build the model, test it against the examples here, and use it to compare options rather than to predict the market. For a break from the numbers, try our guide to card shows near me, our guide to Comfort Dental, or our guide to the meaning of Deenie.