Analytics
stochPathSim.analytics
Closed-form and semi-analytic pricing formulas.
bachelier_greeks
bachelier_greeks(F, K, T, df, sigma_n, option_type='call')
Normal-model forward delta, gamma, vega and theta.
Accepts broadcastable arrays, including negative forwards and strikes. Delta/gamma differentiate with respect to the forward, vega is per unit of absolute normal volatility, and theta is minus the expiry derivative with forward and discount factor held fixed (per year). It excludes discount-factor carry and is not a spot-price theta.
Requires finite inputs, positive T, df and sigma_n. At expiry or zero volatility the smooth Greeks are not defined by this function.
bachelier_implied_vol
bachelier_implied_vol(price, F, K, T, df, option_type='call')
Normal implied volatility; nan outside the no-arbitrage bounds.
bachelier_price
bachelier_price(F, K, T, df, sigma_n, option_type='call')
Bachelier (normal model) price of a European option on a forward.
black76_price
black76_price(F, K, T, df, sigma, option_type='call')
Black-76 price of a European option on a forward.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
F
|
float or array_like
|
Forward and strike. |
required |
K
|
float or array_like
|
Forward and strike. |
required |
T
|
float or array_like
|
Time to expiry in years. |
required |
df
|
float or array_like
|
Discount factor to the payment date. |
required |
sigma
|
float or array_like
|
Lognormal volatility. |
required |
option_type
|
('call', 'put')
|
|
"call"
|
bs_greeks
bs_greeks(S, K, T, r, sigma, option_type='call', q=0.0)
Black-Scholes greeks: delta, gamma, vega, theta (per year) and rho.
Vega and rho are per unit change (not per 1%).
bs_implied_vol
bs_implied_vol(price, S, K, T, r, option_type='call', q=0.0)
Black-Scholes implied volatility by Brent's method on [1e-6, 5].
Returns nan for prices outside the no-arbitrage bounds. Accepts arrays.
bs_price
bs_price(S, K, T, r, sigma, option_type='call', q=0.0)
Black-Scholes price of a European option with continuous dividend yield q.
displaced_diffusion_greeks
displaced_diffusion_greeks(F, K, T, df, sigma, shift, option_type='call')
Forward delta, gamma, vega and frozen-discount theta.
Vega is per unit change in displaced relative volatility sigma; theta is -d(price)/dT with F and df held fixed. The function requires T>0 and sigma>0; for K + shift <= 0 the payoff is linear and the corresponding Greeks are exact (zero gamma, vega and theta).
displaced_diffusion_price
displaced_diffusion_price(F, K, T, df, sigma, shift, option_type='call')
Discounted European option on a displaced-lognormal forward.
S_T + shift is lognormal with initial value F + shift, zero drift, and volatility sigma. Thus the shifted-strike payoff reduces exactly to Black-76. Negative original forwards and strikes are supported. If K + shift <= 0, the option is always in (or out of) the money; the resulting price is its discounted forward intrinsic value.
F is a forward at expiry, NOT a spot subject to risk-free drift. Supports broadcastable scalar and array inputs, including T=0 and sigma=0.
heston_char_func
heston_char_func(u, S, T, r, q, v0, kappa, theta, xi, rho)
Characteristic function E[exp(i u ln S_T)] under the risk-neutral measure.
Uses the "little Heston trap" formulation of Albrecher et al. (2007), which avoids the branch-cut discontinuity of the original formula.
heston_price
heston_price(S, K, T, r, q, v0, kappa, theta, xi, rho, option_type='call', upper=200.0)
European option price in the Heston model by Gil-Pelaez inversion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
S
|
float
|
Spot, strike, expiry, risk-free rate and dividend yield. |
required |
K
|
float
|
Spot, strike, expiry, risk-free rate and dividend yield. |
required |
T
|
float
|
Spot, strike, expiry, risk-free rate and dividend yield. |
required |
r
|
float
|
Spot, strike, expiry, risk-free rate and dividend yield. |
required |
q
|
float
|
Spot, strike, expiry, risk-free rate and dividend yield. |
required |
v0
|
float
|
Initial variance, mean-reversion speed, long-run variance, vol of vol and correlation. |
required |
kappa
|
float
|
Initial variance, mean-reversion speed, long-run variance, vol of vol and correlation. |
required |
theta
|
float
|
Initial variance, mean-reversion speed, long-run variance, vol of vol and correlation. |
required |
xi
|
float
|
Initial variance, mean-reversion speed, long-run variance, vol of vol and correlation. |
required |
rho
|
float
|
Initial variance, mean-reversion speed, long-run variance, vol of vol and correlation. |
required |
option_type
|
('call', 'put')
|
|
"call"
|
upper
|
float
|
Upper limit of the Fourier integrals. |
200.0
|
kou_char_func
kou_char_func(u, S, T, r, q, sigma, lam, p_up, eta_up, eta_down)
Characteristic function of ln S_T under the risk-neutral measure.
kou_price
kou_price(S, K, T, r, sigma, lam, p_up, eta_up, eta_down, option_type='call', q=0.0, upper=500.0)
European option price under the Kou model by Gil-Pelaez Fourier inversion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lam
|
float
|
Jump intensity, probability of an upward jump and the up/down exponential rates
( |
required |
p_up
|
float
|
Jump intensity, probability of an upward jump and the up/down exponential rates
( |
required |
eta_up
|
float
|
Jump intensity, probability of an upward jump and the up/down exponential rates
( |
required |
eta_down
|
float
|
Jump intensity, probability of an upward jump and the up/down exponential rates
( |
required |
upper
|
float
|
Upper limit of the Fourier integrals. |
500.0
|
merton_price
merton_price(S, K, T, r, sigma, lam, jump_mean, jump_std, option_type='call', q=0.0, n_terms=100)
European option price under Merton's jump diffusion with log-normal jumps.
The price is a Poisson-weighted sum of Black-Scholes prices (Merton, 1976).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lam
|
float
|
Jump intensity per year. |
required |
jump_mean
|
float
|
Mean and standard deviation of the normal log-jump size. |
required |
jump_std
|
float
|
Mean and standard deviation of the normal log-jump size. |
required |
n_terms
|
int
|
Number of terms kept in the series. |
100
|
nig_price
nig_price(S, K, T, r, alpha, beta, delta, option_type='call', q=0.0)
European NIG call or put via SciPy's NIG CDF/survival function.
Scalar inputs. alpha, beta, delta use the same per-year
parameterisation as :class:~stochPathSim.processes.NormalInverseGaussian.
Exponential tilting changes beta to beta+1 under the stock measure.
Discounted stock and strike times the corresponding exercise probabilities
give the price, without Monte Carlo error. SciPy evaluates the distribution
functions numerically, so small numerical integration errors are possible.
T and delta may be zero. S and K must be positive. The model's first-moment domain is required; a finite second moment is not necessary for pricing.
cir_zcb
cir_zcb(r, t, T, kappa, theta, sigma)
Cox-Ingersoll-Ross zero-coupon bond price P(t, T) given r at t.
g2pp_integral_variance
g2pp_integral_variance(tau, a, b, sigma, eta, rho)
Variance of int_t^{t+tau} (x_s + y_s) ds given the factors at t.
g2pp_zcb
g2pp_zcb(x, y, t, T, a, b, sigma, eta, rho, curve)
G2++ zero-coupon bond price P(t, T) given the factors x and y at t.
At t = 0 with x = y = 0 this equals curve.discount(T).
hull_white_caplet
hull_white_caplet(T_reset, T_pay, strike, a, sigma, curve, notional=1.0, floorlet=False)
Hull-White caplet (or floorlet) on the simply compounded rate over [T_reset, T_pay].
A caplet is 1 + K tau puts on the T_pay bond struck at 1 / (1 + K tau).
hull_white_zcb
hull_white_zcb(r, t, T, a, sigma, curve)
Hull-White zero-coupon bond price P(t, T) given the short rate r at t.
curve is the initial :class:~stochPathSim.curves.ZeroCurve (or a flat rate).
hull_white_zcb_option
hull_white_zcb_option(T_option, T_bond, strike, a, sigma, curve, option_type='call')
Hull-White European option on a zero-coupon bond, valued at time 0.
vasicek_zcb
vasicek_zcb(r, t, T, kappa, theta, sigma)
Vasicek zero-coupon bond price P(t, T) given the short rate r at t.
vasicek_zcb_option
vasicek_zcb_option(r0, T_option, T_bond, strike, kappa, theta, sigma, option_type='call')
European option expiring at T_option on a zero-coupon bond maturing at T_bond.
sabr_implied_vol
sabr_implied_vol(F, K, T, alpha, beta, rho, nu, shift=0.0)
Lognormal (Black) implied volatility from Hagan's SABR expansion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
F
|
float or array_like
|
Forward and strike. |
required |
K
|
float or array_like
|
Forward and strike. |
required |
T
|
float
|
Time to expiry. |
required |
alpha
|
float
|
SABR parameters. |
required |
beta
|
float
|
SABR parameters. |
required |
rho
|
float
|
SABR parameters. |
required |
nu
|
float
|
SABR parameters. |
required |
shift
|
float
|
Shift for the shifted-SABR variant: the formula is applied to |
0.0
|
black_scholes
Black-Scholes, Black-76 and Bachelier closed forms.
black76_price
black76_price(F, K, T, df, sigma, option_type='call')
Black-76 price of a European option on a forward.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
F
|
float or array_like
|
Forward and strike. |
required |
K
|
float or array_like
|
Forward and strike. |
required |
T
|
float or array_like
|
Time to expiry in years. |
required |
df
|
float or array_like
|
Discount factor to the payment date. |
required |
sigma
|
float or array_like
|
Lognormal volatility. |
required |
option_type
|
('call', 'put')
|
|
"call"
|
bs_price
bs_price(S, K, T, r, sigma, option_type='call', q=0.0)
Black-Scholes price of a European option with continuous dividend yield q.
bs_greeks
bs_greeks(S, K, T, r, sigma, option_type='call', q=0.0)
Black-Scholes greeks: delta, gamma, vega, theta (per year) and rho.
Vega and rho are per unit change (not per 1%).
bs_implied_vol
bs_implied_vol(price, S, K, T, r, option_type='call', q=0.0)
Black-Scholes implied volatility by Brent's method on [1e-6, 5].
Returns nan for prices outside the no-arbitrage bounds. Accepts arrays.
bachelier_price
bachelier_price(F, K, T, df, sigma_n, option_type='call')
Bachelier (normal model) price of a European option on a forward.
bachelier_implied_vol
bachelier_implied_vol(price, F, K, T, df, option_type='call')
Normal implied volatility; nan outside the no-arbitrage bounds.
bachelier_greeks
bachelier_greeks(F, K, T, df, sigma_n, option_type='call')
Normal-model forward delta, gamma, vega and theta.
Accepts broadcastable arrays, including negative forwards and strikes. Delta/gamma differentiate with respect to the forward, vega is per unit of absolute normal volatility, and theta is minus the expiry derivative with forward and discount factor held fixed (per year). It excludes discount-factor carry and is not a spot-price theta.
Requires finite inputs, positive T, df and sigma_n. At expiry or zero volatility the smooth Greeks are not defined by this function.
displaced
European pricing and forward Greeks in the shifted-lognormal model.
displaced_diffusion_price
displaced_diffusion_price(F, K, T, df, sigma, shift, option_type='call')
Discounted European option on a displaced-lognormal forward.
S_T + shift is lognormal with initial value F + shift, zero drift, and volatility sigma. Thus the shifted-strike payoff reduces exactly to Black-76. Negative original forwards and strikes are supported. If K + shift <= 0, the option is always in (or out of) the money; the resulting price is its discounted forward intrinsic value.
F is a forward at expiry, NOT a spot subject to risk-free drift. Supports broadcastable scalar and array inputs, including T=0 and sigma=0.
displaced_diffusion_greeks
displaced_diffusion_greeks(F, K, T, df, sigma, shift, option_type='call')
Forward delta, gamma, vega and frozen-discount theta.
Vega is per unit change in displaced relative volatility sigma; theta is -d(price)/dT with F and df held fixed. The function requires T>0 and sigma>0; for K + shift <= 0 the payoff is linear and the corresponding Greeks are exact (zero gamma, vega and theta).
heston
Semi-analytic Heston (1993) option prices.
heston_char_func
heston_char_func(u, S, T, r, q, v0, kappa, theta, xi, rho)
Characteristic function E[exp(i u ln S_T)] under the risk-neutral measure.
Uses the "little Heston trap" formulation of Albrecher et al. (2007), which avoids the branch-cut discontinuity of the original formula.
heston_price
heston_price(S, K, T, r, q, v0, kappa, theta, xi, rho, option_type='call', upper=200.0)
European option price in the Heston model by Gil-Pelaez inversion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
S
|
float
|
Spot, strike, expiry, risk-free rate and dividend yield. |
required |
K
|
float
|
Spot, strike, expiry, risk-free rate and dividend yield. |
required |
T
|
float
|
Spot, strike, expiry, risk-free rate and dividend yield. |
required |
r
|
float
|
Spot, strike, expiry, risk-free rate and dividend yield. |
required |
q
|
float
|
Spot, strike, expiry, risk-free rate and dividend yield. |
required |
v0
|
float
|
Initial variance, mean-reversion speed, long-run variance, vol of vol and correlation. |
required |
kappa
|
float
|
Initial variance, mean-reversion speed, long-run variance, vol of vol and correlation. |
required |
theta
|
float
|
Initial variance, mean-reversion speed, long-run variance, vol of vol and correlation. |
required |
xi
|
float
|
Initial variance, mean-reversion speed, long-run variance, vol of vol and correlation. |
required |
rho
|
float
|
Initial variance, mean-reversion speed, long-run variance, vol of vol and correlation. |
required |
option_type
|
('call', 'put')
|
|
"call"
|
upper
|
float
|
Upper limit of the Fourier integrals. |
200.0
|
kou
Kou (2002) double-exponential jump-diffusion option prices.
kou_char_func
kou_char_func(u, S, T, r, q, sigma, lam, p_up, eta_up, eta_down)
Characteristic function of ln S_T under the risk-neutral measure.
kou_price
kou_price(S, K, T, r, sigma, lam, p_up, eta_up, eta_down, option_type='call', q=0.0, upper=500.0)
European option price under the Kou model by Gil-Pelaez Fourier inversion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lam
|
float
|
Jump intensity, probability of an upward jump and the up/down exponential rates
( |
required |
p_up
|
float
|
Jump intensity, probability of an upward jump and the up/down exponential rates
( |
required |
eta_up
|
float
|
Jump intensity, probability of an upward jump and the up/down exponential rates
( |
required |
eta_down
|
float
|
Jump intensity, probability of an upward jump and the up/down exponential rates
( |
required |
upper
|
float
|
Upper limit of the Fourier integrals. |
500.0
|
merton
Merton (1976) jump-diffusion option prices.
merton_price
merton_price(S, K, T, r, sigma, lam, jump_mean, jump_std, option_type='call', q=0.0, n_terms=100)
European option price under Merton's jump diffusion with log-normal jumps.
The price is a Poisson-weighted sum of Black-Scholes prices (Merton, 1976).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lam
|
float
|
Jump intensity per year. |
required |
jump_mean
|
float
|
Mean and standard deviation of the normal log-jump size. |
required |
jump_std
|
float
|
Mean and standard deviation of the normal log-jump size. |
required |
n_terms
|
int
|
Number of terms kept in the series. |
100
|
nig
European option pricing under exponential NIG using tilted NIG probabilities.
nig_price
nig_price(S, K, T, r, alpha, beta, delta, option_type='call', q=0.0)
European NIG call or put via SciPy's NIG CDF/survival function.
Scalar inputs. alpha, beta, delta use the same per-year
parameterisation as :class:~stochPathSim.processes.NormalInverseGaussian.
Exponential tilting changes beta to beta+1 under the stock measure.
Discounted stock and strike times the corresponding exercise probabilities
give the price, without Monte Carlo error. SciPy evaluates the distribution
functions numerically, so small numerical integration errors are possible.
T and delta may be zero. S and K must be positive. The model's first-moment domain is required; a finite second moment is not necessary for pricing.
rates
Closed-form bond and option prices for short-rate models.
vasicek_zcb
vasicek_zcb(r, t, T, kappa, theta, sigma)
Vasicek zero-coupon bond price P(t, T) given the short rate r at t.
vasicek_zcb_option
vasicek_zcb_option(r0, T_option, T_bond, strike, kappa, theta, sigma, option_type='call')
European option expiring at T_option on a zero-coupon bond maturing at T_bond.
cir_zcb
cir_zcb(r, t, T, kappa, theta, sigma)
Cox-Ingersoll-Ross zero-coupon bond price P(t, T) given r at t.
hull_white_zcb
hull_white_zcb(r, t, T, a, sigma, curve)
Hull-White zero-coupon bond price P(t, T) given the short rate r at t.
curve is the initial :class:~stochPathSim.curves.ZeroCurve (or a flat rate).
hull_white_zcb_option
hull_white_zcb_option(T_option, T_bond, strike, a, sigma, curve, option_type='call')
Hull-White European option on a zero-coupon bond, valued at time 0.
hull_white_caplet
hull_white_caplet(T_reset, T_pay, strike, a, sigma, curve, notional=1.0, floorlet=False)
Hull-White caplet (or floorlet) on the simply compounded rate over [T_reset, T_pay].
A caplet is 1 + K tau puts on the T_pay bond struck at 1 / (1 + K tau).
g2pp_integral_variance
g2pp_integral_variance(tau, a, b, sigma, eta, rho)
Variance of int_t^{t+tau} (x_s + y_s) ds given the factors at t.
g2pp_zcb
g2pp_zcb(x, y, t, T, a, b, sigma, eta, rho, curve)
G2++ zero-coupon bond price P(t, T) given the factors x and y at t.
At t = 0 with x = y = 0 this equals curve.discount(T).
sabr
Hagan et al. (2002) SABR implied volatility.
sabr_implied_vol
sabr_implied_vol(F, K, T, alpha, beta, rho, nu, shift=0.0)
Lognormal (Black) implied volatility from Hagan's SABR expansion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
F
|
float or array_like
|
Forward and strike. |
required |
K
|
float or array_like
|
Forward and strike. |
required |
T
|
float
|
Time to expiry. |
required |
alpha
|
float
|
SABR parameters. |
required |
beta
|
float
|
SABR parameters. |
required |
rho
|
float
|
SABR parameters. |
required |
nu
|
float
|
SABR parameters. |
required |
shift
|
float
|
Shift for the shifted-SABR variant: the formula is applied to |
0.0
|