Probability Maths Flowchart
This document is a maths-first companion to the Probability page. It describes the intended statistical object as one terminal price distribution over a grid of terminal prices K, not one distribution per listed strike.
The model starts with the vanilla market-implied terminal distribution from the IV surface. It then optionally tilts that distribution with historical forward returns from similar gex_hourly gamma-regime states. Touch probabilities and candidate ranking inherit the same density-quality and stationarity gates.
Integrated Calculation Flow
Formula Notes
1. Vanilla terminal distribution
S_T ~ f_Q(K)
E_Q[S_T] = integral K f_Q(K)dK
F = S0 exp(rT)
2. IV surface to strike/IV points
K_i = strike_i
sigma_i = IV_i
If strike is missing, invert Black-Scholes delta:
d1 = N^-1(delta_call)
K = S0 exp((r + 0.5 sigma^2)T - d1 sigma sqrt(T))
For puts:
d1 = N^-1(1 - abs(delta_put))
3. Synthetic Black-Scholes calls
d1 = [ln(S0 / K) + (r + 0.5 sigma^2)T] / [sigma sqrt(T)]
d2 = d1 - sigma sqrt(T)
C(K,T) = S0 N(d1) - K exp(-rT) N(d2)
4. Breeden-Litzenberger density
f_Q(K) = exp(rT) d2C(K,T)/dK2
raw_density(K) = max(0, exp(rT) C''(K))
f_vanilla(K) = raw_density(K) / integral raw_density(K)dK
5. GEX-regime reweighting
R_K = (K - S0) / S0
R_t,h = (S_t+h - S_t) / S_t
L(R_K) = NormalPDF(R_K; mean(R_matches), std(R_matches))
raw f_cond(K) = f_vanilla(K) L(R_K)
f_cond(K) = raw f_cond(K) / integral raw f_cond(K)dK
6. GEX regime ranking and matching
percentile = count(gex_history <= current_gex) / N * 100
percentile < 25 => short_gamma
25 <= percentile <=75 => neutral
percentile > 75 => long_gamma
low_pct = max(0, percentile - 15)
high_pct = min(100, percentile + 15)
matching observations = rows with gex percentile in [low_pct, high_pct]
7. Stationarity check and blend
baseline = first half of R_matches
recent = second half of R_matches
KS_stat, p_value = KS_2sample(baseline, recent)
mean_shift_bps = (mean(recent) - mean(baseline)) * 10000
if len(R_matches) < 24:
status = insufficient
w = 0.70
elif p_value < 0.05 or abs(mean_shift_bps) > 15:
status = unstable
w = 0.45
else:
status = stable
w = 1.00
f_final(K) = w f_cond(K) + (1 - w) f_vanilla(K)
8. Touch probability
upside finish_probability = P(S_T >= target)
downside finish_probability = P(S_T <= target)
touch_probability ~= min(1, 2 * finish_probability)
This is a reflection-principle approximation, not a full barrier-pricing model.
9. Distribution moments and conditional shift
mean = integral K f(K)dK
variance = integral (K - mean)^2 f(K)dK
std = sqrt(variance)
conditional_shift = conditional_mean - vanilla_mean
conditional_shift_pct = conditional_shift / S0
10. Candidate ranking
payoff_call(K) = max(K - option_strike, 0)
payoff_put(K) = max(option_strike - K, 0)
expected_payoff = integral payoff(K) f_final(K)dK
edge_long = expected_payoff - premium
edge_short = premium - expected_payoff
The candidate screen then applies DTE, budget, open-interest, premium, and objective filters before ranking.
11. Quality and no-data flow
bad or sparse IV surface => withhold vanilla density and downstream outputs
too few matching GEX returns => return vanilla or partially blend toward vanilla
unstable stationarity => materially discount conditional overlay
missing option chain => withhold candidate ranking
Unavailable or discounted model states should be shown explicitly. They should not be silently converted into neutral probabilities or zero-valued metrics.
Worked Miniature Example
S0 = 80000
r = 4.5%
T = 7 / 365
historical_gex = [-120, -80, -30, 10, 25, 40, 55, 70, 95, 140]
current_gex = 100
count(gex <= 100) = 9
N = 10
percentile = 9 / 10 * 100 = 90
90 > 75 => long_gamma
R_matches = [-1.0%, -0.4%, 0.2%, 0.5%, 0.8%]
mean(R_matches) = 0.02%
std(R_matches) ~= 0.70%
K = 81600
R_K = (81600 - 80000) / 80000 = 2.0%
L(2.0%) = NormalPDF(0.020; mean=0.0002, std=0.0070)
f_vanilla(81600) = 0.00050
f_cond(81600) = 0.00080
w = 0.45
f_final(81600) = 0.45 * 0.00080 + 0.55 * 0.00050
= 0.000635
Interpretation: the regime evidence raises the density at that terminal price, but the stationarity/control layer only allows part of the conditional adjustment through.