Theta: a European option's value as calendar time passes¶
A European option's theta, its value's change as calendar time passes, everything else held: -S phi(d1) sigma / (2 sqrt(T P)) - r K e^(-rT) N(d2) for a call, -S phi(d1) sigma / (2 sqrt(T P)) + r K e^(-rT) N(-d2) for a put (Hull's, with sigma sqrt(T / P) for sigma sqrt(T)).
In the money unit of S and K a year of calendar time (the kernel is generic over the money); a day's is the game's to divide out. Source: Hull, Options, Futures, and Other Derivatives, 9th ed. (Pearson, 2014), ch. 19. Checked against a reference in numpy, which has its own tests.
- Source
- Hull, Options, Futures, and Other Derivatives, 9th ed. (2014), ch. 19.
- Proof
- reference, invariant.
option_theta.trait
namespace lusine.finance;
float<_/year> option_theta(bool call, float<_> spot, float<_> strike, float<year^-1> rate, float volatility,
float<year> period, float<year> years)
{
let a = d1(spot, strike, rate, volatility, period, years);
let b = d2(spot, strike, rate, volatility, period, years);
let decay = -spot * normal_pdf(x = a) * volatility / (2.0 * sqrt(years * period));
let carry = rate * strike * exp(-rate * years);
if (call) return decay - carry * normal_cdf(x = b);
return decay + carry * normal_cdf(x = -b);
}
Uses, without proving it here: finance.d1, finance.d2, finance.normal_pdf, finance.normal_cdf.
-S phi(d1) sigma / (2 sqrt(T)) - r K e^(-rT) N(d2) for a call, + r K e^(-rT) N(-d2) for a put, a year of calendar time's.
import os, sys
root = os.getcwd()
while not os.path.isfile(os.path.join(root, 'docsite.json')):
root = os.path.dirname(root)
sys.path.insert(0, os.path.join(root, 'tools'))
import numpy as np
import matplotlib.pyplot as plt
from scipy.special import ndtr
from scipy.stats import norm
from lusine import trait_run
EPS = float(np.finfo(np.float32).eps) # Trait's float is binary32
YEAR = 31557600.0 # lusine's year row, the Julian year in seconds: the host speaks base units
The kernel¶
The law as the library states it, and as this page runs it.
print(trait_run.source('finance/option_theta.trait'))
// lusine.finance.option_theta: a European option's theta, its value's change as calendar time passes, everything else
// held: -S phi(d1) sigma / (2 sqrt(T P)) - r K e^(-rT) N(d2) for a call, -S phi(d1) sigma / (2 sqrt(T P)) +
// r K e^(-rT) N(-d2) for a put (Hull's, with sigma sqrt(T / P) for sigma sqrt(T)). In the money unit of S and K a
// year of calendar time (the kernel is generic over the money); a day's is the game's to divide out.
// Source: Hull, Options, Futures, and Other Derivatives, 9th ed. (Pearson, 2014), ch. 19.
// Checked against a reference in numpy, which has its own tests.
namespace lusine.finance;
float<_/year> option_theta(bool call, float<_> spot, float<_> strike, float<year^-1> rate, float volatility,
float<year> period, float<year> years)
{
let a = d1(spot, strike, rate, volatility, period, years);
let b = d2(spot, strike, rate, volatility, period, years);
let decay = -spot * normal_pdf(x = a) * volatility / (2.0 * sqrt(years * period));
let carry = rate * strike * exp(-rate * years);
if (call) return decay - carry * normal_cdf(x = b);
return decay + carry * normal_cdf(x = -b);
}
The program¶
A lattice of options, one an item, the kernel bound over them: the prices in euros, the rate a year, the volatility over a period (a year here, Hull's), the life in years. The host speaks the base units, so a time is stored in seconds and a rate per second, and theta, stored in euros a second, is read back in euros a year. kernel below is that call; closed is the independent account, Black-Scholes in float64 with scipy's exact normal distribution, at the parameters as the device holds them. held rounds them so.
CALL = True
BS = """namespace bs;
lusine.version version = { { number = 1 } };
struct option {
host bool call; host float<EUR> spot; host float<EUR> strike; host float<year^-1> rate; host float volatility;
host float<year> period; host float<year> years;
float<EUR/year> option_theta;
};
lattice<option, 1> options(spacing = 1 m, boundary = wall);
void main()
{
options.option_theta = lusine.finance.option_theta(options.call, options.spot, options.strike, options.rate, options.volatility,
options.period, options.years);
}
"""
print(BS)
def held(call, spot, strike, rate, volatility, years, period=1.0):
"""The parameters as the device holds them, in the host's units (euros, a year, years): each rounded to binary32 in
the base units it is stored in."""
f = lambda v, scale=1.0: np.float32(np.asarray(v, dtype=float) * scale).astype(float) / scale
return (np.asarray(call, dtype=bool), f(spot), f(strike), f(rate, 1 / YEAR), f(volatility), f(years, YEAR),
f(period, YEAR))
def kernel(call, spot, strike, rate, volatility, years, period=1.0):
"""The kernel's option_theta for each option: prices in euros, the rate a year, the volatility over `period` years and the
life in years, stored in the base units (seconds); the result back in euros a year, one an option (a
single option's alone)."""
n = max(np.size(a) for a in (call, spot, strike, rate, volatility, years, period))
run = trait_run.Program(['finance/option_theta.trait'], BS, {'bs.options': [n]})
for field, v in (('call', call), ('spot', spot), ('strike', strike), ('rate', np.asarray(rate) / YEAR),
('volatility', volatility), ('period', np.asarray(period) * YEAR),
('years', np.asarray(years) * YEAR)):
run.store('bs.options', field, np.broadcast_to(np.asarray(v), (n,)))
out = run.steps('bs.main', 1, [('bs.options', 'option_theta')])[0][0] * YEAR
return out if n > 1 else float(out[0])
def closed(call, spot, strike, rate, volatility, years, period=1.0):
"""The independent account: Black-Scholes in float64 with scipy's exact normal distribution, at the parameters
the device holds."""
c, S, K, r, v, T, P = held(call, spot, strike, rate, volatility, years, period)
s = v * np.sqrt(T / P)
a = (np.log(S / K) + (r + 0.5 * (v * v / P)) * T) / s
b = a - s
df = K * np.exp(-r * T)
return -S * norm.pdf(a) * v / (2 * np.sqrt(T * P)) + np.where(c, -r * df * ndtr(b), r * df * ndtr(-b))
rng = np.random.default_rng(391)
N = 1000
SPOT, STRIKE = rng.uniform(20, 200, N), rng.uniform(20, 200, N)
RATE, VOL, LIFE = rng.uniform(-0.02, 0.15, N), rng.uniform(0.05, 0.9, N), rng.uniform(0.02, 5.0, N)
CALLS = rng.random(N) < 0.5
namespace bs;
lusine.version version = { { number = 1 } };
struct option {
host bool call; host float<EUR> spot; host float<EUR> strike; host float<year^-1> rate; host float volatility;
host float<year> period; host float<year> years;
float<EUR/year> option_theta;
};
lattice<option, 1> options(spacing = 1 m, boundary = wall);
void main()
{
options.option_theta = lusine.finance.option_theta(options.call, options.spot, options.strike, options.rate, options.volatility,
options.period, options.years);
}
Reference: Hull's example¶
Hull's printed values (Options, Futures, and Other Derivatives, 9th ed., 2014) are quoted from sources that were opened, the book itself not: Example 15.6 (S0 = 42, K = 40, r = 10%, sigma = 20%, six months) as QFRM's BS_Simple documentation cites it, and ch. 19's running example (S0 = 49, K = 50, r = 5%, sigma = 20%, 20 weeks) as the black-scholes-greeks README quotes it. Each is held to half a unit in the last digit printed.
t = kernel(True, 49.0, 50.0, 0.05, 0.20, 20 / 52)
assert abs(t - (-4.31)) <= 0.005, t
print(f'ch. 19: theta {t:.4f} a year (-4.31), {t / 365:.4f} a calendar day')
ch. 19: theta -4.3053 a year (-4.31), -0.0118 a calendar day
Reference: scipy's Black-Scholes¶
A thousand options, calls and puts: each theta within 1e-6 of its spot a year from the float64 account.
t = kernel(CALLS, SPOT, STRIKE, RATE, VOL, LIFE)
err = np.abs(t - closed(CALLS, SPOT, STRIKE, RATE, VOL, LIFE)) / SPOT
assert np.max(err) <= 1e-6, np.max(err)
print(f'largest error {np.max(err):.2e} of the spot a year')
largest error 9.45e-08 of the spot a year
Invariant: the Black-Scholes equation¶
Theta, delta and gamma together satisfy theta + r S delta + sigma^2 S^2 gamma / 2 = r V for every option. Here theta is this kernel's and the rest the float64 account's, so the equation holds to theta's own error.
t = kernel(CALLS, SPOT, STRIKE, RATE, VOL, LIFE)
c, S, K, r, v, T, P = held(CALLS, SPOT, STRIKE, RATE, VOL, LIFE)
s = v * np.sqrt(T / P)
a = (np.log(S / K) + (r + 0.5 * v * v) * T) / s
b = a - s
delta = np.where(c, ndtr(a), ndtr(a) - 1)
gamma = norm.pdf(a) / (S * s)
value = np.where(c, S * ndtr(a) - K * np.exp(-r * T) * ndtr(b), K * np.exp(-r * T) * ndtr(-b) - S * ndtr(-a))
gap = np.abs(t + r * S * delta + 0.5 * v * v * S * S * gamma - r * value) / SPOT
assert np.max(gap) <= 1e-6, np.max(gap)
print(f'the equation holds within {np.max(gap):.1e} of the spot a year')
the equation holds within 9.4e-08 of the spot a year