core.test_black_scholes

Tests for Black-Scholes Option Pricing

MATHEMATICAL BACKGROUND

The Black-Scholes model prices European-style options under specific assumptions. These tests verify the implementation of put and call option pricing used for hedge cost estimation.

KEY FORMULAS

The d1 and d2 intermediate values:

d₁ = [ln(S/K) + (r + σ²/2)T] / (σ√T)

d₂ = d₁ - σ√T

Where: S = Spot price (current underlying price) K = Strike price T = Time to expiration (years) σ = Volatility (annualized, e.g., 0.70 = 70%) r = Risk-free interest rate (annualized)

Put Option Price: P = Ke^(-rT)N(-d₂) - SN(-d₁)

Call Option Price: C = SN(d₁) - Ke^(-rT)N(d₂)

Output Convention: Our functions return P/S (price ratio), not absolute price. This allows direct percentage interpretation of hedge cost.

MODEL ASSUMPTIONS

The Black-Scholes model assumes:

  1. Log-normal price distribution: Asset prices follow geometric Brownian motion dS = μS dt + σS dW

  2. Constant volatility: σ remains constant over the option's life (In practice, implied volatility varies by strike - the "volatility smile")

  3. No arbitrage: The market is efficient with no risk-free profits

  4. Continuous trading: Assets can be traded continuously

  5. No dividends: The underlying pays no dividends during option life

  6. European-style exercise: Options can only be exercised at expiration

  7. Risk-free rate is constant: r remains unchanged

GREEKS CONTEXT (for reference)

Delta (Δ): Rate of change of option price with respect to spot Put Delta = N(d₁) - 1 (always negative for puts) Call Delta = N(d₁)

Gamma (Γ): Rate of change of delta with respect to spot Γ = N'(d₁) / (Sσ√T)

Vega (ν): Sensitivity to volatility ν = S√T N'(d₁)

Theta (Θ): Time decay Θ_put = -Sσ N'(d₁)/(2√T) + rKe^(-rT)N(-d₂)

STANDARD TEST PARAMETERS

Parameter Value Description
Spot (S) 3050 ETH price in USD
Strike (K) Varies Put strike prices
Time (T) 0.29 ~106 days to expiry
Vol (σ) 0.70 70% annualized volatility
Rate (r) 0.00 Zero risk-free rate (crypto)

EXCEL VERIFICATION GUIDE

For a mathematician to verify these tests in Excel:

  1. Setup Cells: Define the input parameters S, K, T, σ, r in specific cells (e.g., B1 to B5).
  2. Intermediate Calculations: Calculate d1 and d2 using the standard formulas.
  3. CDF Calculation: Use NORM.S.DIST(z, TRUE) for N(z).
  4. Final Price: Implement the Put or Call formula.
  5. Ratio: Divide the final price by Spot (S).

See individual test functions for copy-paste Excel formulas.

FUNCTIONS TESTED

  1. black_scholes_put(K, T, S, σ, r) → P/S

    • Returns put price as fraction of spot
    • Used for calculating hedge premium costs
  2. black_scholes_call(K, T, S, σ, r) → C/S

    • Returns call price as fraction of spot
    • Used for comparison/validation

NUMERICAL VALIDATION

Results can be verified against:

  • Online Black-Scholes calculators (e.g., option-price.com)
  • Financial libraries (scipy.stats for normal CDF)
  • Put-call parity: C - P = S - Ke^(-rT)
def test_black_scholes_put():

Test Black-Scholes Put Pricing

Verifies the price of a Deep Out-of-the-Money (OTM) Put Option. This is critical for hedging as we buy OTM puts to protect against downside.

Formula

$$P = K e^{-rT} N(-d_2) - S N(-d_1)$$

Returns $P/S$ (Price as fraction of spot).

Test Data

Inputs:

  • Spot ($S$): 3050
  • Strike ($K$): 2200 (Deep OTM)
  • Time ($T$): 0.2904109589 years (~106 days)
  • Volatility ($\sigma$): 70% (0.70)
  • Risk-free Rate ($r$): 0%

Expected Output:

  • Absolute Price ($P$): $\approx 103.19$ USD
  • Price Ratio ($P/S$): $\approx 0.0338$ (3.38%)

Interpretation: Buying protection at $2200 costs ~3.4% of the capital.

EXCEL REPRODUCTION

To verify this test in Excel, use the following setup:

1. Input Parameters (Cells A1:B5)

Cell Parameter Value
B1 Spot (S) 3050
B2 Strike (K) 2200
B3 Time (T) 0.2904109589
B4 Vol (σ) 0.70
B5 Rate (r) 0

2. Intermediate Calculations (Cells A6:B8)

Cell Name Formula Description
B6 d1 =(LN(B1/B2)+(B5+B4^2/2)*B3)/(B4*SQRT(B3)) Standard d1
B7 d2 =B6-B4*SQRT(B3) Standard d2

3. Put Price Calculation (Cells A8:B10)

Cell Name Formula Expectation
B8 N(-d1) =NORM.S.DIST(-B6,TRUE) ~0.1457
B9 N(-d2) =NORM.S.DIST(-B7,TRUE) ~0.2489
B10 Put Price =B2*EXP(-B5*B3)*B9 - B1*B8 ~103.19

4. Final Ratio Verification (Cells A11:B11)

Cell Name Formula Expectation
B11 Price/Spot =B10/B1 ~0.0338
def test_black_scholes_call():

Test Black-Scholes Call Pricing

Verifies the price of an Out-of-the-Money (OTM) Call Option.

Formula

$$C = S N(d_1) - K e^{-rT} N(d_2)$$

Test Data

Inputs:

  • Spot ($S$): 3050
  • Strike ($K$): 3200
  • Time ($T$): 0.2904109589 years
  • Volatility ($\sigma$): 70%

Expected Output:

  • Price Ratio ($C/S$): $\approx 0.13$ (13%)

EXCEL REPRODUCTION

To verify this test in Excel, use the following setup:

1. Input Parameters (Cells A1:B5)

Cell Parameter Value
B1 Spot (S) 3050
B2 Strike (K) 3200
B3 Time (T) 0.2904109589
B4 Vol (σ) 0.70
B5 Rate (r) 0

2. Intermediate Calculations (Cells A6:B8)

Cell Name Formula Description
B6 d1 =(LN(B1/B2)+(B5+B4^2/2)*B3)/(B4*SQRT(B3)) Standard d1
B7 d2 =B6-B4*SQRT(B3) Standard d2

3. Call Price Calculation (Cells A8:B10)

Cell Name Formula Expectation
B8 N(d1) =NORM.S.DIST(B6,TRUE) ~0.43
B9 N(d2) =NORM.S.DIST(B7,TRUE) ~0.29
B10 Call Price =B1*B8 - B2*EXP(-B5*B3)*B9 ~396.00

4. Final Ratio Verification (Cells A11:B11)

Cell Name Formula Expectation
B11 Price/Spot =B10/B1 ~0.13
def test_put_monotonicity():

Test Put Option Monotonicity

Verifies the financial property that Put prices strictly increase with Strike price.

Property

$$\frac{\partial P}{\partial K} > 0$$

Logic: A Put option gives the right to sell. The right to sell at a higher price ($K_1$) must be more valuable than the right to sell at a *lower* price ($K_2$).

Test Case:

  • $P(K=2200) > P(K=2000)$
def test_expired_option():

Test Expiry Boundary Condition

Verifies that at time $T=0$, the option price equals its Intrinsic Value.

Formula

$$P(T=0) = \max(K - S, 0)$$

Test Data

Inputs:

  • Spot ($S$): 2400
  • Strike ($K$): 2600 (In-The-Money)
  • Time ($T$): 0

Expected Output:

  • Intrinsic Value: $2600 - 2400 = 200$
  • Price Ratio: $200 / 2400 \approx 0.08333$