Reflexive Equilibrium Fixed-point Learning for Endogenous eXchanges (ie. financial markets).
A machine learning framework for markets where the data distribution is not fixed, but is generated by the model itself. In OTC corporate bond markets, a dealer's quoting policy reshapes future trade flow, spreads, and liquidity, breaking the standard ML assumption that the data-generating process is independent of the learner.
REFLEX reframes learning as solving for a self-consistent equilibrium: a fixed point where the market dynamics induced by a trading policy are stable under repeated interaction with that same policy.
Built by Vignesh Nagarajan and Shriraghav Ashok.
AI / ML & Scientific Computing:
Language, Config, Testing & Verification:
Tooling & Docs:
Initial Prototype (archive/edl_simulator_v1):
- Endogenous Distribution Learning: replaces exogenous data
D_{t+1} = P(·|D_t)with a policy-dependent systemD_{t+1} = T(D_t, π_θ). - Learned market response operator
T_θ: a differentiable, trainable operator over stochastic market transitions, replacing hand-built simulators. - Structurally-anchored performative correction: the learned loop fits the market model's own response families to its deployment history and ascends the estimated corrected gradient - stable where blind retraining diverges.
- Fixed-point objective: solve
(π*, D*) = argmin_π E_D[R(π)] s.t. D = T(D, π). - Stability-aware training: penalizes distribution collapse, liquidity fragmentation, and instability under self-induced market adaptation.
- Implicit liquidity modeling: treats liquidity as a latent dynamical field induced by interaction, not an observed variable.
- Machine-checked theory: every load-bearing identity of the six closed-form results is re-derived numerically (66 proof certificates), with the logical skeletons formalised in Lean 4.
Five generations of the same idea, an endogenous market whose stability is governed by a single feedback parameter, each more structural than the last:
flowchart LR
A["edl_simulator_v1<br/>(HTML/JS mockup)<br/>analytical LQ model"]
--> B["endo_market_v1<br/>(Python / PyTorch)<br/>learned operator + RRM"]
--> C["endo_market_v2<br/>(Python / PyTorch)<br/>refined, result reproduced"]
--> D["endo_market_v3<br/>(+ real data)<br/>un-blinded ML + closed-form theory"]
--> E["endo_market_v4 / reflex<br/>(FINAL)<br/>structural PerfGD + theory 1.6 + tuning + verification"]
| edl_simulator_v1 | endo_market_v1 | endo_market_v2 | endo_market_v3 | endo_market_v4 (reflex) |
|
|---|---|---|---|---|---|
| Role | Earliest prototype | Legacy iteration | Superseded | Superseded (produced the 07-10-2026 run) | Current — FINAL |
| Implementation | HTML/JS browser mockup | Python (PyTorch, CPU) | Python (PyTorch, CPU) | Python (PyTorch + pandas, CPU), real-data calibrated | Same, + verification layer (numerical certificates + Lean 4 skeletons) |
| Market model | Analytical linear-quadratic OTC bond | Structural multi-bond simulator (uninformed + toxic flow) | Structural OTC simulator + latent liquidity field | Same + genuine N-dealer shared informed pool |
Same |
| Learner | Closed-form fixed point | Learned operator T_θ + RRM loop |
Same, refined | Un-blinded T_θ (windowed fit learns dD/dφ) + PerfGD-corrected loops (analytic & free-form learned) |
+ perfgd_structural: GLFT-anchored fits of the loop's own data; the learned loop that stabilises beyond the boundary |
| Control parameter | Adversarialness α |
Adversariality α ∈ [0,1] |
Feedback gain ε (α found to be confounded) |
ε, dealer count N, universe size d, market regime |
+ inner steps per deployment K (lazy deployment, theory 1.6) |
| Stability law | Stable iff α < α_c = 1; rate α^t |
m = K·α, boundary α* = 1/K |
m ≈ εβ/γ, boundary ε < γ/β |
Closed-form ε < γ/β, ε < γ/(N_eff·β), ρ(M) < 1 - predicted a-priori, then verified |
+ mu(K) = −m + c^K(1+m) (deadbeat / max-stable K; two-branch γ_eff) |
| Headline status | Validated at α = 0.45 |
Scaffolding done; α* result not reproduced |
Result reproduced (measured crossing later shown protocol-inflated; see its README) | Theory+ML+data unified; real-data fragility index; loop-level gap honestly documented | The gap closed: the structural learned loop settles at the realized performative optimum where blind RRM diverges; estimators tuned; theory machine-verified |
| Tests / artifacts | Sample run screenshot | 18 unit tests | 63 tests + phase-diagram PNG & sweep CSV | 110 tests + 9 experiments, full-profile verified 8/8 (curated in research/results/07-10-2026/) |
152 tests + 12 experiment entry points, full-profile verified 11/11 (curated in research/results/07-12-2026/) |
The progression: edl_simulator_v1 proved the concept (one parameter flips a
market between convergence and chaos) analytically; endo_market_v1 rebuilt it as a
learned-operator performative-prediction loop but couldn't cleanly tune the
transition; endo_market_v2 identified ε (not α) as the clean control and
reproduced the ε < γ/β stability boundary; endo_market_v3 unified the ML,
the closed-form theory and the real-data calibration and un-blinded the learned
operator - leaving one honestly-documented gap: the corrected learned loop
did not stabilise. endo_market_v4 closes that gap by anchoring the learned
response to the GLFT structural form (fit the theory's own response families
to the loop's deployment history, ascend the estimated corrected gradient),
adds the lazy-deployment theory (1.6), tunes the estimators, and wraps the
whole theory in a verification layer. The four prior generations are frozen in
archive/.
REFLEX/
|- README.md <- this file
|- CLAUDE.md <- orientation and conventions for AI coding agents
|- LICENSE <- Apache License 2.0
|- endo_market_v4/ <- CURRENT (FINAL): the self-contained `reflex` package
| |- README.md <- methodology, the six pillars, quickstart, honest caveats
| |- theory/ <- the six derivations (shipped copies) + code map
| |- lean/ <- Lean 4 formal skeletons of 1.1-1.6 (+ honest status)
| |- data/ <- calibration CSVs + daily master panel (provenance notes)
| |- configs/ <- default | smoke | sweep specs
| |- reflex/ <- the package: env (incl. N-dealer), policy (+GLFT baseline),
| | operator (un-blinded T_θ), theory (1.1–1.6), equilibrium
| | (4-mode loops incl. perfgd_structural + joint loop),
| | estimators (tuned ε triangulation + K-step probe),
| | calibration, objective, analysis (incl. fragility),
| | verification (proof certificates), utils
| |- experiments/ <- 12 entry points incl. run_all --profile smoke|full
| |- outputs/ <- CSVs + PNGs from the latest full-profile run
| \- tests/ <- 152 tests (142 fast + 10 slow)
|- literature/ <- two curated literature collections
| |- literature-vignesh/ <- 10 foundational papers + reading map (PDFs downloaded)
| \- literature-raghav/ <- same core + 8 extension papers + research roadmap
|- research/ <- the research program around endo_market_v4: theory, data, runs, analyses, paper
| |- README.md <- full methodology write-up and the To-Do checklist
| |- math-theory/ <- canonical derivations 1.1–1.6 (.md + .tex + PDFs)
| |- data_collection/ <- real macro + bond-factor dataset (raw/processed/master) + verification
| |- preprocessing/ <- cleaning, calibration fit (A,k), episode splits
| |- results/ <- executed paper-grade runs (07-10-2026 v3; 07-12-2026 v4)
| |- analysis/ <- written analyses of those runs (tables, figures, breakdowns)
| \- paper/ <- the ICAIF 2026 submission draft (ACM sigconf, double-blind)
\- archive/ <- the four frozen prior generations (see archive/README.md)
|- edl_simulator_v1/ <- earliest prototype (HTML/JS mockup)
|- endo_market_v1/ <- earliest Python iteration
|- endo_market_v2/ <- second generation (result absorbed into v3)
\- endo_market_v3/ <- third generation (produced the 07-10-2026 run)
A dealer's quoting policy φ induces the data distribution D(φ): tighter
quotes summon more informed ("toxic") flow that picks the dealer off. Under
repeated retraining (RRM), when does the policy↔distribution loop converge
vs. diverge - and can the loop be stabilised by un-blinding it, analytically
(closed-form PerfGD) or by learning (the v4 structural mode)?
The full-profile suite ran 8/8 in ~10 min CPU after a measurement-layer audit
fixed six probe/protocol defects; every number below is from the curated run
in research/results/07-10-2026/ (complete
illustrated report: REPORT.md).
- Real-data fragility (1.1 on 36 years of data): the closed-form
stability headroom
ε* = γ/βcollapses ~4.4× (IG) / ~4.3× (HY) from calm to crisis, HY sits >10× below IG in every regime, and the modulus at observed spreads falls into crisis (0.85 → 0.14): defensive widening, live on real data. The index saturates at a crisis plateau through the GFC and the COVID freeze (degenerate crisis fit, flagged). - Predict-then-verify (1.1 + 1.4): under the clean probe protocol the
measured modulus tracks the closed form within ~10–25% in the contracting
regime (0.39 vs 0.43 at
ε = 2), and the measured boundary crossing (ε* ≈ 3.17) sits left of the a-priori prediction (4.70) by almost exactly the realized-state correction (~2.8–3.0) that the triangulation measures independently. The robust certificates grade the grid stable → undecided → unstable exactly as the seed bands warrant. - Systemic risk on a genuine multi-dealer market (1.3): common-mode
amplification 1.74× / 3.16× vs the predicted
N_eff= 2 / 3, with the differential mode dead at full spillover: competition destabilises the market a factorN_effbefore any single dealer would. - Three-way
εtriangulation (1.1 §9): the Sinkhorn and CKS legs agree with each other within 14% and bracket the realized-state closed form at 2.3–2.7×, with the liquidity-inflation channel (realizedρ ≈ 2.3vs the a-priori 1.0) identified as the dominant correction. - Factor scaling (1.5):
ρ(M) ≈ 0.50flat from 8 to 128 bonds on data-calibrated per-bond dispersion; the truncation bound holds with orders of magnitude of slack; 0.07 s atd = 128via Woodbury. - The
αconfound (appendix): the adversariality sweep shows its full non-monotone hump (0.08 → 1.83 → 0.67), the quantitative case for the feedback gainεas the headline control variable.
- The loop-level gap is closed (1.2, v4): in the genuinely RRM-unstable
regime the blind loop fails to converge while
perfgd_structural- the learned loop with its response anchored to the GLFT structural families and fitted to its own deployment history - settles at the realized performative optimum, verified against independent structural fits (and strictly inside their blind stable point: the realized echo-chamber gap, closed). The free-form learned mode remains a documented negative result - anchoring, not capacity, is what closes the gap. - Lazy deployment (1.6): the K-step outer map
mu(K) = −m + c^K(1+m)fits the measured signed CRN K-probe curve with one parameter; laziness reads as a two-branch effective curvatureγ_eff(K)(inertia below the equal-modulus count, stiffness above), with deadbeat and max-stable step counts in closed form. - Estimator tuning: the Sinkhorn blur is tuned scale-relatively against
the exact 1-D quantile
W1(U-shaped bias curve, minimum at0.02 × sample std, baked in asreg="auto"); the robust ambiguity radius gets a distribution-free coverage calibration (z*smeasured conservative; the quantile radius matters for contaminated/railed-probe patterns). - Machine-checked theory: 66 numerical proof certificates re-derive every
load-bearing identity of 1.1–1.6 on raw and calibrated real-unit configs
(catching, en route, a real
λ_qbookkeeping subtlety in the 1-D helpers); the logical skeletons are formalised in Lean 4 (endo_market_v4/lean/; reviewed statements, compile pending a toolchain - honest status in its README).
Run everything with python -m experiments.run_all --profile smoke|full
(full profile: ~15-25 min CPU, deterministic from (config, seed)):
| Experiment | What it shows | Theory |
|---|---|---|
run_certificates |
66 numerical proof checks of every 1.1–1.6 identity (raw + calibrated) | all |
run_fragility |
The daily 1990–2026 fragility index on real data | 1.1 on data |
run_calibrated |
A-priori boundary per (rating × regime) from fitted (A, k, σ, h) |
1.1 + data |
run_sweep |
Predict-then-verify phase diagram: analytic overlay + measured median/IQR + robust bands | 1.1 + 1.4 |
run_perfgd |
Closed-form beyond-boundary demo + echo-chamber gaps + the four-mode ML loops (incl. the structural gap closure) | 1.2 |
run_dealers |
(N, ε) systemic surface m_N = N_eff·m₁; genuine shared-pool market probes |
1.3 |
run_universe |
ρ(M) at 128 correlated bonds via O(d·k²) Woodbury; truncation bound verified |
1.5 |
run_triangulation |
Three independent ε estimators (BR-slope / Sinkhorn / CKS) vs the closed form |
1.1 |
run_lazy_deploy |
The signed K-step map vs mu(K) = −m + c^K(1+m); γ_eff(K) |
1.6 |
run_tuning |
Sinkhorn blur bias curve + robust-radius coverage calibration | 1.1 + 1.4 |
run_single |
One outer loop in any mode with seam diagnostics | - |
See endo_market_v4/README.md for methodology,
layout, install/run and honest caveats. Prior generations:
archive/README.md; endo_market_v2's historical
headline result (and its post-audit correction) lives in
archive/endo_market_v2/README.md.
REFLEX/literature/ holds two curated collections at the intersection of
performative prediction / decision-dependent stochastic optimization and
optimal OTC market making. Each paper maps to a specific component of the
codebase and points at a concrete extension.
literature-vignesh/: the original 10 foundational papers and the reading map that ties each one to a piece of the codebase (the RRM loop, the operatorT_θ, the BR-slope modulus, the toxic-flow gate, inventory state, the scale-up caveats). PDFs are already downloaded underpdfs/.literature-raghav/: the same foundational core, expanded with deeper per-paper "critical reading notes" and a more opinionated research roadmap (specific theorems to prove, experiments to run, venues to target). Run itsdownload_pdfs.shto fetch the PDFs.
The throughline: Perdomo et al.'s performative-prediction theorem says
repeated retraining converges iff ε < γ/β. The optimization literature
sharpens that loop, makes it stateful, and makes ε explorable; the
market-microstructure control theory (Guéant-Lehalle-Fernández-Tapia,
Bergault-Guéant, Barzykin et al.) supplies the structure that lets γ, β,
and the toxic slope be derived from first principles rather than tuned.
REFLEX is the bridge that realizes the theorem structurally inside an OTC
bond market. Full per-paper notes and BibTeX live in each collection's
README.md and references.bib.
Where the simulator measures the stability boundary by sweeping, the
research/math-theory/ program derives it
in closed form from the simulator's own microstructure primitives - then verifies
each derivation against the code. All six results are derived and
implemented as dependency-light closed-form modules - authoritative versions in
endo_market_v4/reflex/theory/ (originals frozen
in archive/endo_market_v2), each with tests and numerical proof certificates:
| # | Result | Key object | Novelty |
|---|---|---|---|
| 1.1 | Analytic boundary | m = εβ/γ, stable iff ε < γ/β |
γ, β, ε are computed from GLFT fill-curve curvature + the toxic-flow slope dτ/dh, not treated as tuned Lipschitz constants - an a-priori boundary you can evaluate before running the loop. |
| 1.2 | PerfGD un-blinding | Δ = −β(h−ψ)ε(h), γ_PO |
The distribution response dD/dφ is supplied in closed form (no estimation), so the corrected loop is governed by the objective curvature γ_PO and converges where blind RRM diverges - past the boundary ε*. v4 addendum: the same correction with every ingredient estimated from deployment data (perfgd_structural) stabilises the actual learned loop. |
| 1.3 | Multi-dealer systemic risk | ε < γ/(N_eff·β), N_c = 1/m₁ |
A shared toxic pool makes competition a synchronised common-mode cobweb: the market destabilises a factor N_eff before any single dealer would - competition manufactures systemic fragility. |
| 1.4 | Robust boundary | ε̂_n + δ_n < γ/β, δ_n = O(1/√n) |
The parametric 1/√n radius is bought by the common-random-numbers probe (a naive difference gives only n^{−1/3}); the crossing is statistically hard to pin (n_req = O(Δ^{−2})), separating statistical from structural uncertainty. v4 addendum: a distribution-free coverage calibration of the radius. |
| 1.5 | Factor-model scaling | modulus matrix M = βΓ⁻¹E, ρ(M)<1 |
The curse of dimensionality is defused by the same factor structure that causes it - Γ is diagonal-plus-low-rank, so ρ(M) is O(d·k²) via Woodbury with a truncation error linear in the residual factor variance λ_{k+1}(C). |
| 1.6 | Lazy deployment (v4) | mu(K) = −m + c^K(1+m), γ_eff(K) |
The outer loop between the greedy-RGD and exact-RRM idealisations in one closed form: laziness interpolates the cobweb, can deadbeat it at finite K, keeps an m > 1 market stable up to K_max, and masquerades as a two-branch effective curvature. |
The novelty in one line. Performative-prediction theory (Perdomo et al., ICML
2020) proves repeated retraining converges iff ε < γ/β but treats γ, β, ε as
abstract constants of an unspecified loss. REFLEX pins them to a structural OTC
market-making model and turns that single point boundary into a predictive,
un-blindable, multi-dealer, statistically-robust, 100+-bond, lazily-deployed
one - every claim stated as a closed form, made falsifiable against the
simulator, and machine-checked by the verification layer. See
research/README.md for the full methodology and
research/math-theory/ for the derivations
(each with a compilable LaTeX companion) and the module-by-module code map.
research/data_collection/ and
research/preprocessing/ hold a
real, public, verified dataset used to calibrate the simulator's
microstructure regime - ~36 years of daily and ~70 years of monthly series
joined into REFLEX_MASTER_DATASET.csv:
- Macro / regime: CBOE VIX (σ proxy, regime classifier), EIA WTI crude, Fed H.15 10-year Treasury (DV01), Shiller S&P 500 / CAPE, gold + BLS CPI.
- Bond microstructure: Dickerson–Mueller–Robotti (2023 JFE) TRACE-derived
bond factors - the liquidity risk factor is the primary
εproxy - and monthly returns for 212 real-CUSIP corporate bonds (theD(φ)proxy). - Preprocessing: cleaning/winsorisation/ADF, reconstructed
(h, q, τ)proxies, an exponential-intensityλ(h)=A·e^{−k·h}fit per rating×regime, and lookahead-safe calibration / validation / held-out episode splits.
Honest provenance (stated in the paper, not a footnote): this is not
trade-level TRACE - dealer-side prints, per-dealer inventory q, and per-bond
A/k require WRDS TRACE Enhanced (access pending), so those quantities are
proxied from the closest free sources. See
data_collection/docs/REJECTED_SOURCES.md.
endo_market_v4 ships copies of the artifacts it consumes
(endo_market_v4/data/) so the package is
self-contained; regenerate everything from public sources with the pipeline's
four scripts.
Every document in the project and where it lives:
| Document | What it covers |
|---|---|
README.md |
This file: the project overview |
CLAUDE.md |
Orientation and conventions for AI coding agents (layout, gotchas, build/test/run) |
endo_market_v4/README.md |
The current package: methodology, the six pillars, quickstart, honest caveats |
endo_market_v4/theory/README.md |
Code map from the six derivations to reflex.theory (+ shipped derivation copies) |
endo_market_v4/lean/README.md |
The Lean 4 formal skeletons: scope, build instructions, honest compile status |
endo_market_v4/data/README.md |
Provenance of the shipped calibration artifacts |
research/README.md |
The full research-program methodology and the To-Do checklist (incl. ICAIF requirements) |
research/math-theory/README.md |
The six canonical derivations 1.1–1.6 (each .md + compilable .tex; PDFs for 1.1–1.5) |
research/data_collection/README.md |
Dataset sources and construction; docs/ holds DATA_CATALOGUE.md, VERIFICATION_LOG.md, REJECTED_SOURCES.md |
research/preprocessing/README.md |
Cleaning, enrichment, intensity fits, episode splits |
research/results/README.md |
Conventions for the dated run folders |
research/results/07-10-2026/REPORT.md |
The complete illustrated report of the v3 paper-grade run |
research/results/07-12-2026/REPORT.md |
The illustrated report of the v4 paper-grade run (11 experiments, incl. the gap closure) |
research/analysis/README.md |
Index of the analysis layer |
research/analysis/ANALYSIS-full-2026-07.md |
The master per-experiment analysis of the v3 run: tables, breakdowns, limitations |
research/analysis/pre-run-audit-2026-07.md |
The measurement-layer audit: six defects, root causes, fixes, reframings |
research/paper/README.md |
The ICAIF 2026 submission draft: contents, Overleaf build, ICAIF checklist mapping, camera-ready TODOs |
literature/literature-vignesh/README.md |
10 foundational papers, reading map, per-paper notes (+ references.bib) |
literature/literature-raghav/README.md |
18 papers with critical reading notes + research roadmap (+ references.bib) |
archive/README.md |
The four frozen prior generations: what each was, why superseded, provenance notes |
archive/endo_market_v3/README.md |
The superseded third generation (produced the 07-10-2026 run) |
archive/endo_market_v2/README.md |
The superseded second generation: mechanism, historical headline result + post-audit note |
archive/endo_market_v1/README.md |
The legacy first Python iteration |
archive/edl_simulator_v1/README.md |
The earliest analytical prototype (HTML/JS) |
The research program targets one novelty claim: derive the performativity stability boundary analytically from microstructure primitives instead of sweeping it by hand.
Where things stand (July 2026, v4 - the repo side is complete): theory
(1.1–1.6) derived + coded; the ML un-blinded and the loop-level gap closed
by the structural mode; the estimators tuned; the theory machine-verified (66
numerical certificates + Lean 4 skeletons); real-data calibration wired in;
the measurement layer audited (six probe/protocol defects found and fixed;
152/152 tests); paper-grade full-profile suites executed and curated
(research/results/07-10-2026/ for v3,
research/results/07-12-2026/ for v4).
- Analytic boundary (P1):
γ,β,dτ/dhin closed form (reflex/theory/analytic_boundary.py); the three-wayεtriangulation built, tuned and verified against the realized-state closed form (reflex/estimators/). - Un-blind the operator (P2): PerfGD-corrected loops with the analytic, free-form learned and structural
dD/dφ(reflex/theory/perfgd.py,reflex/equilibrium/loops.py,reflex/equilibrium/structural_response.py); closed form verified and the loop-level stabilisation demonstrated (the structural mode settles at the realized optimum beyond the boundary; the free-form mode remains the documented negative result). - Multi-dealer / systemic risk (P3): PSNE boundary
ε < γ/(N_eff·β), mean-field limit, and a genuineN-dealer market with amplification verified (reflex/theory/multi_dealer.py,reflex/env/multi_dealer.py). - Robust uncertainty (P4): robust
ε*withO(1/√n)radius; bands + certificates on every sweep; the v4 coverage-calibrated radius (reflex/theory/robust.py). - Scale and calibrate (P5): 128 correlated bonds via
O(d·k²)Woodbury with data-calibrated per-bond σ; regime-calibrated microstructure (reflex/theory/factor_scaling.py,reflex/calibration/); trade-level TRACE calibration pending WRDS access. - Lazy deployment (1.6, v4): the K-step map,
γ_eff, and the swept verification (reflex/theory/lazy_deploy.py,experiments/run_lazy_deploy.py). - Estimator tuning (v4): the Sinkhorn blur (scale-relative,
0.02×std) and the robust ambiguity radius (coverage-calibrated) (experiments/run_tuning.py). - Verification layer (v4): 66 numerical proof certificates (raw + calibrated configs) + the Lean 4 skeletons (
reflex/verification/,lean/; Lean compile pending a toolchain — honest status in its README). - Paper-grade full-profile runs → curated results: v3 (July 10, 8/8) and v4 (July 12, 11/11) in
research/results/. - Draft the ICAIF 2026 paper (ACM
sigconf, 8 pages, double-blind; deadline Aug 2, 2026) - the submission draft lives inresearch/paper/, scoped as settled in the analysis: closed forms + real-data fragility + probe-level verifications are the headline; the v4 structural stabilisation is reported against the realized-market benchmark with the A2-gap channels named. Compiled on Overleaf at exactly 8 pages (research/paper/REFLEX_Research_Paper.pdf). Remaining: the double-blind re-toggle + anonymized repo mirror, CMT submission. - Secure a research placement at a top AI lab (with affiliation).
- Vignesh will submit to ICAIF 2026 (ACM Intl. Conference on AI in Finance) or another main-track venue.
Full task breakdown across math, data, preprocessing, architecture, training,
and ICAIF submission requirements: the
To-Do section of research/README.md.
Licensed under the Apache License 2.0: free to use, modify, and distribute with attribution and notice of changes.



