The Greeks and Option Risk Management › Greeks Calculator

Michael BrenndoerferNovember 29, 20255 min read
Quantitative FinanceAll chapters
Part 5 of 15Stochastic Calculus and Pricing Theory
Chapter 31The Greeks and Option Risk Management › Greeks Calculator
Reading section 11 of 14 · Greeks Calculator · 5 minSection 11 of 14 · 5 min

Book contents

Section 11 of 14 · 5 min read

The Greeks and Option Risk Management › Greeks CalculatorOne section · Sections in this chapter11 / 14 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Let's bring everything together in a complete implementation that calculates all Greeks and visualizes the risk profile of an option position. We encapsulate the logic in a class to manage the parameters and calculations cleanly, and gives methods for each Greek and a summary report:

In[35]:
Code
import numpy as np
from scipy.stats import norm


class BlackScholesGreeks:
    """Complete Black-Scholes Greeks calculator."""

    def __init__(self, S, K, T, r, sigma, option_type="call"):
        self.S = S
        self.K = K
        self.T = max(T, 1e-10)  # Avoid division by zero
        self.r = r
        self.sigma = sigma
        self.option_type = option_type

        # Calculate d1 and d2
        sqrt_T = np.sqrt(self.T)
        self.d1 = (np.log(S / K) + (r + 0.5 * sigma**2) * self.T) / (
            sigma * sqrt_T
        )
        self.d2 = self.d1 - sigma * sqrt_T

    def price(self):
        """Calculate option price."""
        if self.option_type == "call":
            return self.S * norm.cdf(self.d1) - self.K * np.exp(
                -self.r * self.T
            ) * norm.cdf(self.d2)
        else:
            return self.K * np.exp(-self.r * self.T) * norm.cdf(
                -self.d2
            ) - self.S * norm.cdf(-self.d1)

    def delta(self):
        """Calculate delta."""
        if self.option_type == "call":
            return norm.cdf(self.d1)
        else:
            return norm.cdf(self.d1) - 1

    def gamma(self):
        """Calculate gamma."""
        return norm.pdf(self.d1) / (self.S * self.sigma * np.sqrt(self.T))

    def theta(self):
        """Calculate theta (per year)."""
        term1 = -self.S * norm.pdf(self.d1) * self.sigma / (2 * np.sqrt(self.T))
        if self.option_type == "call":
            term2 = (
                -self.r * self.K * np.exp(-self.r * self.T) * norm.cdf(self.d2)
            )
        else:
            term2 = (
                self.r * self.K * np.exp(-self.r * self.T) * norm.cdf(-self.d2)
            )
        return term1 + term2

    def vega(self):
        """Calculate vega."""
        return self.S * np.sqrt(self.T) * norm.pdf(self.d1)

    def rho(self):
        """Calculate rho."""
        if self.option_type == "call":
            return (
                self.K * self.T * np.exp(-self.r * self.T) * norm.cdf(self.d2)
            )
        else:
            return (
                -self.K * self.T * np.exp(-self.r * self.T) * norm.cdf(-self.d2)
            )

    def all_greeks(self):
        """Return all Greeks as a dictionary."""
        return {
            "Price": self.price(),
            "Delta": self.delta(),
            "Gamma": self.gamma(),
            "Theta (daily)": self.theta() / 365,
            "Vega (per 1%)": self.vega() / 100,
            "Rho (per 1%)": self.rho() / 100,
        }
In[36]:
Code
# Parameters
S, K, T, r, sigma = 100, 100, 0.25, 0.05, 0.20

# Example usage
call_option = BlackScholesGreeks(S, K, T, r, sigma, option_type="call")
put_option = BlackScholesGreeks(S, K, T, r, sigma, option_type="put")
Out[37]:
Console
ATM Options (S=100, K=100, T=3 months, r=5%, σ=20%)
============================================================

Metric                          Call             Put
------------------------------------------------------------
Price                         4.6150          3.3728
Delta                         0.5695         -0.4305
Gamma                         0.0393          0.0393
Theta (daily)                -0.0287         -0.0152
Vega (per 1%)                 0.1964          0.1964
Rho (per 1%)                  0.1308         -0.1161

The table demonstrates the fundamental parity relationships. Gamma and vega are identical for calls and puts with the same parameters, showing that curvature and volatility risks are independent of direction. Delta values diverge, which reflects the opposing directional views, while theta remains negative for both long positions.

In[38]:
Code
# Create comprehensive Greeks visualization
S_range = np.linspace(70, 130, 200)
K, T, r, sigma = 100, 0.25, 0.05, 0.20

greeks_data = {"delta": [], "gamma": [], "theta": [], "vega": []}

for S in S_range:
    opt = BlackScholesGreeks(S, K, T, r, sigma, "call")
    greeks_data["delta"].append(opt.delta())
    greeks_data["gamma"].append(opt.gamma())
    greeks_data["theta"].append(opt.theta() / 365)
    greeks_data["vega"].append(opt.vega() / 100)
Out[39]:
Visualization
S-shaped line chart of call delta rising from zero to one as stock price crosses the $100 strike.
Call option delta versus underlying price. The delta ranges from 0 to 1, exhibiting the characteristic S-curve shape that steepens around the strike price.
Out[40]:
Visualization
Bell-shaped gamma curve peaking near the $100 strike and approaching zero in both wings.
Call option gamma versus underlying price. Gamma peaks at-the-money where the option's value is most sensitive to price changes, and approaches zero for deep ITM or OTM options.
Out[41]:
Visualization
Negative daily-theta curve with its deepest time-decay trough near the $100 strike.
Call option theta versus underlying price. Time decay is most severe (most negative) for at-the-money options, which reflects the higher cost of holding the optionality where it is most useful.
Out[42]:
Visualization
Bell-shaped vega curve peaking near the $100 strike and declining in both wings.
Call option vega versus underlying price. Like gamma, vega peaks at-the-money, indicating that at-the-money options are most sensitive to changes in implied volatility.

The profile shows how each Greek behaves as the stock price changes. Delta rises from 0 to 1 as the option goes from OTM to ITM. Gamma peaks where delta changes fastest (ATM). Theta is most negative ATM where time value is highest. Vega also peaks ATM, showing that volatility sensitivity is concentrated near the strike.