getcracked
Blog / Technical

The Greeks Explained: Math & Code

Technical

If Black-Scholes is the engine, the Greeks are the dashboard. They tell you exactly how your PnL will change when key variables shift.


Key Concepts

Delta (Δ)

Change in Option Price / Change in Stock Price.

Interpretation: Roughly the probability needed to expire ITM.

Gamma (Γ)

Change in Delta / Change in Stock Price.

Interpretation: Acceleration or curvature of the PnL.

Theta (Θ)

Change in Option Price / Change in Time.

Interpretation: Cost of carry (rent) per day.

Vega (v)

Change in Option Price / Change in Volatility.

Interpretation: Sensitivity to implied volatility changes.

Calculating Greeks in Python

We can use scipy.stats.norm to implement the closed-form solutions for Black-Scholes Greeks.

1
import numpy as np
2
from scipy.stats import norm
3

4
def d1(S, K, T, r, sigma):
5
    return (np.log(S / K) + (r + 0.5 * sigma ** 2) * T) / (sigma * np.sqrt(T))
6

7
def d2(S, K, T, r, sigma):
8
    return d1(S, K, T, r, sigma) - sigma * np.sqrt(T)
9

10
def call_delta(S, K, T, r, sigma):
11
    return norm.cdf(d1(S, K, T, r, sigma))
12

13
def call_gamma(S, K, T, r, sigma):
14
    return norm.pdf(d1(S, K, T, r, sigma)) / (S * sigma * np.sqrt(T))
15

16
def call_vega(S, K, T, r, sigma):
17
    return S * norm.pdf(d1(S, K, T, r, sigma)) * np.sqrt(T)
18

19
def call_theta(S, K, T, r, sigma):
20
    p1 = - (S * norm.pdf(d1(S, K, T, r, sigma)) * sigma) / (2 * np.sqrt(T))
21
    p2 = - r * K * np.exp(-r * T) * norm.cdf(d2(S, K, T, r, sigma))
22
    return p1 + p2
23

24
# Example Usage
25
S, K, T, r, sigma = 100, 100, 1.0, 0.05, 0.20
26
print(f"Delta: {call_delta(S, K, T, r, sigma):.4f}")
27
print(f"Gamma: {call_gamma(S, K, T, r, sigma):.4f}")
28
print(f"Vega:  {call_vega(S, K, T, r, sigma):.4f}")
29
print(f"Theta: {call_theta(S, K, T, r, sigma):.4f}")
30

Practical Usage in Interviews

Why is Vega highest At-The-Money (ATM)?
Because ATM options have the most "uncertainty". Deep ITM options act like stock (Delta 1, low Vega). Deep OTM options act like nothing (Delta 0, low Vega). Only when you are ATM does a change in volatility drastically change the probability of finishing ITM.

What happens to Gamma as expiration approaches?
For ATM options, Gamma explodes towards infinity as $T \to 0$. Why? Because a tiny move in the stock price can instantly flip your Delta from 0 to 1 (or vice versa) if you are right at the strike at 3:59 PM on expiration Friday. This is called "Pin Risk".