Mathematical Coherence

Live audit of every number in the APEX pipeline. The page re-runs every mathematical invariant against current DB state on each request — no cached proofs, no silent drift.

WHAT THIS PAGE PROVES

The engine audits itself. When you see score 38 for NVDA, every formula that produced it is checked against its mathematical definition here. If weights stop summing to 1, or a correlation exceeds its legal range, or a regime posterior drifts off the unit simplex — you see a red FAIL label.

Green PASS = mathematical law holds. Each row below is a physical/mathematical invariant the engine must satisfy — not a prediction, an equation. Prediction accuracy on realised returns is tracked separately on the Track Record page as forward-return history accumulates.

INVARIANT CHECKS
7/7
All invariants hold
CONSTANTS
8/22/3
LIT / OPER / HEUR (of 33)
UNIVERSE
234
134 with pattern · 234 with Q
SECTOR BENCH
9
sectors × 6 metrics live

Live mathematical invariants

Each row below is an automatic law the engine must satisfy. If every check is PASS, the math is self-consistent end to end.

PASS
BOCPD posterior normalization: Σ q_r = 1
In plain English: The three market-regime probabilities (bull / transition / bear) must sum to 100%. Like a pie chart without missing slices.
q_risk_on + q_transition + q_risk_off = 1.00000
PASS
Stability = 1 − exp(−E[r] / STABILITY_TAU)
In plain English: The "regime stability" number must be derivable from "days in current regime" via the exact formula — no back-door writes.
computed 0.9998 vs derived from E[r]=168.7 → 0.9998 (gap 0.0000)
PASS
All 66 factor correlations ρ ∈ [−1, +1]
In plain English: Every pair-wise factor correlation is bounded between −1 and +1 by mathematical law. Out-of-range values would indicate a computation error.
max |ρ| across 66 pairs = 0.4945
PASS
Grinold-Kahn effective breadth formula
In plain English: The "number of effectively independent factors" must follow the textbook Grinold-Kahn (1999) formula. We have 12 raw factors but some duplicate each other — N_eff is the honest count.
N_eff stored = 6.64 vs formula-derived = 6.64 (avg_ρ = 0.073)
PASS
Copula tail-dep λ ∈ [0, 1] for every regime
In plain English: Tail-dependence is a probability in [0, 1] — "never co-crash" to "always co-crash". Out-of-range would be a physics violation.
1 regimes checked. max avg_λ_U = 0.000
PASS
Prior factor weights sum to 1
In plain English: The 12 factor weights in the composite must sum to 100% — a weighted average cannot exceed its total weight. Otherwise the composite is biased.
Σ w_prior = 1.00000
PASS
All tickers carry BOCPD posterior
In plain English: Every ticker in the database carries its regime-probability triple. Any ticker without it would indicate a pipeline failure.
234/234 stock_universe rows have regime_q_* populated

How the engine works (in plain English)

The engine uses one input (one year of S&P 500 daily returns) to drive six coordinated decisions. All six rest on the same probabilistic view of the market state — not six independent models averaged together. This is what we mean by a coherent Bayesian framework.

1
Read one year of S&P 500
What it does: Load 251 days of close prices, compute daily log-returns.
Why it matters: The market pulse that everything else hangs off.
2
Infer the market regime
What it does: BOCPD (Adams-MacKay 2007) outputs three probabilities: bull / sideways / bear. Currently ~61% / 0% / 39%.
Why it matters: One "regime" quantity feeds the six decisions below so they all agree with each other.
3
Weight the 12 factors by regime
What it does: Each of the 12 factor families (quality, momentum, etc.) has regime-specific weights; we blend them by the BOCPD probabilities.
Why it matters: Momentum matters more in bull markets, quality more in bear. The mix shifts smoothly, not in jumps.
4
Match against 15 academic setups
What it does: The Confluence Engine inspects the 12-factor cocktail. When it matches a published setup (VALUE_TRAP, SHORT_SQUEEZE, etc.) the pattern overrides the weighted composite.
Why it matters: A set of factor values carries more information than their sum — patterns catch joint conditions.
5
Amplify or damp by tail-alignment
What it does: Check history: do this pattern's factors actually co-move in the tails? If yes, pattern confidence × 1.75. If no, × 0.5.
Why it matters: A one-off factor coincidence is not enough — we need the factors to co-crash structurally over calibration history.
6
Price the confidence interval
What it does: Interval width depends on (a) market regime (volatility), (b) pattern strength (tail-alignment bin), (c) per-ticker confidence.
Why it matters: We admit where we're sure and where we're guessing — not a flat ± 15 for everyone.
The elegance: the regime probabilities from step 2 feed steps 3, 4, 5 and 6. Not "six independent computations averaged" but one signal, six coordinated decisions. When the market flips from bull to bear, all six decisions are reconsidered at once — not in isolation.

Factor correlation matrix — 6.6 effectively independent factors of 12

What this shows. The matrix displays the pair-wise Spearman rank-correlation between our 12 factor scores. Green = factors move the same way, red = opposite ways, white = near-independent.

Why it matters. If two factors duplicate each other (ρ close to 1), counting them as two independent votes is double-counting. The Grinold-Kahn formula collapses the matrix into a single effective-breadth number: N_eff = 6.6 of 12. That\'s the honest factor count — not the naïve 12.

Parameters: avg |ρ| = 0.073 · worst pair |ρ| = 0.494 · sample = 878 observations.

qualitvaluemomentinsideinterasectorpeadaccruaspillooptionnlpshort_
quality-0.11-0.040.00-0.07-0.190.02-0.03-0.09-0.030.020.24
value-0.110.060.000.150.140.04-0.070.05-0.040.18-0.10
momentum-0.040.060.00-0.020.300.030.150.350.130.04-0.03
insider0.000.000.000.000.000.000.000.000.000.000.00
interact-0.070.15-0.020.000.080.02-0.070.070.030.06-0.02
sector-0.190.140.300.000.080.00-0.130.490.010.03-0.08
pead0.020.040.030.000.020.00-0.040.03-0.020.120.13
accruals-0.03-0.070.150.00-0.07-0.13-0.04-0.050.080.10-0.15
spillove-0.090.050.350.000.070.490.03-0.05-0.030.020.02
options-0.03-0.040.130.000.030.01-0.020.08-0.03-0.11-0.02
nlp0.020.180.040.000.060.030.120.100.02-0.11-0.09
short_in0.24-0.10-0.030.00-0.02-0.080.13-0.150.02-0.02-0.09

Constants ledger — full transparency

Every number in the engine is tagged with a grade:

LITERATURE (8)
From a cited published paper. Cannot be changed without contradicting the source.
OPERATING (22)
Operating points calibrated on internal data. Auto-tunable once OOS returns accumulate.
HEURISTIC (3)
Labelled educated guesses, flagged for systematic replacement. Only 3 remain — all waiting on forward-return history for MLE fit.
GROUPNAMEVALUEGRADEJUSTIFICATION
BOCPDHAZARD_LAMBDA60LITERATUREConstant-hazard H(r)=1/λ. 60d ≈ 3 months matches Hamilton's estimated regime duration on post-war US data.Hamilton 1989, NBER recession avg duration
BOCPDSTABILITY_TAU20OPERATINGstability = 1 − exp(−E[r]/τ). τ=20 ⇒ 95% stability at E[r]≈60d. Matches HMM 10% off-diagonal transition band.Internal calibration
BOCPDDIRECTION_KAPPA2.5LITERATURELogistic slope on Sharpe-like z. κ=2.5 gives 92%/8% split at z=1 — "strong evidence" per Kass-Raftery BF scale.Kass & Raftery 1995, Bayes factor strength scale
BOCPDSHRINKAGE_N050OPERATINGTail-dep shrinkage anchor: w = n/(n+N0). N0=50 so n=50 → raw:prior = 50:50, n=200 → 80:20.Internal
BOCPDNIG_PRIOR{"mu":0,"kappa":0.01,"alpha":1,"beta":1}OPERATINGμ₀=0, κ₀=0.01 (minimal), α=β=1 (inverse-gamma with moderate mass near unit variance — matches % returns).Weakly informative NIG
KALMANSIGMA_OMEGA_SQ0.01HEURISTICBaseline β random-walk noise. To be MLE-calibrated once forward returns accumulate (sigma_omega should be the one that maximises likelihood on forward returns).Internal
KALMANGAMMA_CP10OPERATINGQ_t = σ²_ω·(1 + γ·changeProb). γ=10 ⇒ changeProb=0.1 doubles Q; 0.5 inflates Q×6. Verified on CP-shift synthetic.Internal synthetic calibration
KALMANSIGMA_EPS_SQ625HEURISTICσ_ε=25 ≈ typical cross-sectional percentile dispersion. Will auto-fit from residual variance pass once OOS data exists.Internal
KALMANC0_DIAG1OPERATINGModerately uninformative prior on β. σ_0=1 per factor in z-per-point units.Weakly informative prior
KALMANBLEND_MATURITY_OBS1000OPERATINGDLM/Markowitz blend λ_DLM = min(1, obs/1000). 1000 obs ≈ 4 months of full-universe days — at this point the filter has seen enough data to trust over priors.Internal
MARKOWITZALPHA_RISK_OFF0.7OPERATINGIn crashes factors co-move mostly in tails — tail-dep dominates Σ.Internal
MARKOWITZALPHA_RISK_ON0.4OPERATINGIn booms co-movement is less structural; partial tail weight.Internal
MARKOWITZALPHA_TRANSITION0.25OPERATINGMidway blend of both tails.Internal
MARKOWITZALPHA_ALL0OPERATINGNeutral baseline = pure Spearman ρ Σ.Internal
MARKOWITZRIDGE_INITIAL0.05LITERATUREStandard starting ridge for near-singular correlation matrices.Tikhonov regularization, Hoerl-Kennard 1970
MARKOWITZRIDGE_CAP1OPERATINGAuto-tune doubles ridge until matrix inverts, capped at 1 (full-identity regulariser).Internal
CONFLUENCETAU_REFERENCE0.25LITERATUREAnchor tail-alignment for γ = 1 (neutral). λ=0.25 is roughly the t-copula ν=3, ρ=0.5 baseline — "moderate" empirical tail dep.Kraskov-Stögbauer-Grassberger 2004 moderate-dependence threshold
CONFLUENCEGAMMA_FLOOR0.5OPERATINGCap confidence-scale below so pattern never completely nullified.Internal
CONFLUENCEGAMMA_CEIL1.75OPERATINGCap above so extreme tail-alignment (λ>0.5) doesn't dominate the other confidence inputs.Internal
MONDRIANMIN_BIN_SAMPLES20LITERATUREPer-bin conformal needs ≥ ⌈(n+1)(1−α)⌉ ≥ 20 for α=0.05 to guarantee coverage ≥ 1 − α − 1/(n+1).Vovk et al 2003 + Angelopoulos-Bates 2021
MONDRIANTAIL_BUCKET_TIGHT0.25LITERATUREPartition boundary co-calibrated with Confluence τ_ref so patterns and conformal see the same tail semantics.Matches τ_ref
MONDRIANTAIL_BUCKET_MODERATE0.1OPERATINGBetween tight and loose — "detectable but not structural" tail-dep.Internal
CONFORMALPRIOR_HALFWIDTH15HEURISTICFallback when no calibration exists. To be replaced by bootstrap on first 30 residuals (2026-05-16+).Internal
CONFORMALCONFIDENCE_FACTOR_MIN0.6OPERATINGAt confidence 100, interval is 60% of marginal halfwidth.Internal
CONFORMALCONFIDENCE_FACTOR_MAX1.4OPERATINGAt confidence 0, interval is 140% of marginal halfwidth.Internal
CONFORMALMIN_CALIBRATION_N30LITERATUREBelow n=30 the conformal coverage bound 1-α-1/(n+1) is too loose to trust.Vovk et al 2005
CONFORMALTAIL_INFLATION_SENSITIVITY0.5OPERATINGhalfwidth ×= 1 + 0.5·λ. At λ=0.3 interval widens 15%, matching published stress-vs-normal spread across factor model drawdowns.Internal
COMPOSITEZ_PER_POINT15OPERATING2σ ticker ≈ composite 80, 1σ ≈ 65. Preserves 0-100 clipped spread for UI consistency.Internal v8 calibration
COMPOSITEZ_CLIP4OPERATINGCap per-factor z at ±4σ — beyond this it's outlier or data error.Internal
COMPOSITECLIP_LOWER5OPERATINGFloor to avoid "0/100" extremes that confuse UX.Internal
COMPOSITECLIP_UPPER95OPERATINGCeiling for the same reason.Internal
BAYESSHRINKAGE_ANCHOR200OPERATINGBayesian shrinkage ρ = n/(n+200). n=200 → 50/50 prior+data. n=1000 → 83/17 data.Internal
BAYESMIN_PER_FACTOR30LITERATUREBelow 30 per-factor observations, Spearman IC std is too high to trust.Standard IC statistical sig threshold
Page is server-rendered on each request — no caching. Invariants recompute live from Supabase state.