formula.cfored.com · docs · cbmas-orb-formulas v0.1

Architecture

How the formulas in this package compose into a working ORB trading pipeline. This document explains wiring, not implementation — for formula details see the searchable index at formula.cfored.com.

01 — PIPELINE STAGE MAP

Nine stages, one pass per session

Stage 1  market_fetch.py         → raw OHLCV per symbol (external)
Stage 2  london_premarket.py     → sqrt_impact · OFI · VWAP · basis · FVG
Stage 3  qc_analyze.py           → vol_acf · Markov · Wonham · Hurst · ADF
Stage 4  alpha_agent.py          → FAN · OU · zscore · EMA/TSMOM · HJB
Stage 5  portfolio_optimizer.py  → cvar_lp_solve_robust (Student's t)
Stage 6  risk_manager.py         → kelly · ev_gate · gamma_scalp · parity
Stage 7  rithmic_execute.py      → bracket orders via AMP/Rithmic (external)
Stage 8  pipeline_runner.py      → orchestration
Stage 9  firebase_auth_state.py  → sharpe · sortino · capm · VaR (NCC)
02 — DATA FLOW THROUGH THE CLUSTERS

From raw tape to the NCC report line

Raw market data
    ↓
microstructure ─┐
                ├─→ statistics.beta_update_bernoulli (π update)
mean_reversion ─┤    ↓
                ├─→ risk_sizing.ev_gate_check (Gate 5)
trend_following ┤    ↓
                └─→ risk_sizing.kelly_uncertain (sizing)
                         ↓
                    risk_sizing.cvar_lp_solve_robust (portfolio)
                         ↓
                    foundations.parametric_var_normal (report)
                         ↓
                    foundations.sharpe_ratio / capm_regression (NCC)
03 — THE 6-GATE EXECUTION SEQUENCE

Short-circuit order, every candidate entry

GateFormulaCheck
1(time-based)Wall clock in 07:00–08:30 PDT window
2hill_estimator → calibrate_nu_from_hillPBO ≥ 0.5 → 50% haircut
3(composite scorer)Confluence adjusted ≥ 6
4quality_estimatorQE minimum ≥ 0.50
5ev_gate_checkEV = π·R:R − (1−π) ≥ 0.25R
6(age-based)Position age 60/90 min cap
04 — WONHAM + HJB SAR (DUAL WITH PARABOLIC SAR)

An earlier-firing exit trigger

Wonham + HJB is an earlier-firing SAR trigger that complements — does not replace — the incumbent Parabolic SAR. Both run in parallel; Wonham fires when P(bull) drops through π** even while price is still near the high, whereas Parabolic SAR fires only after price starts to retrace.

                     ┌── Parabolic SAR flip → EXIT
Live tape ─→ qc_analyze ┤
                     └── wonham_step → π_t → sar_signal → EXIT
                                       (fires earlier)
Promotion policy. Run Wonham in shadow mode for 10+ sessions, compare exit timing against Parabolic SAR, promote only if the early-exit hypothesis is confirmed empirically.
05 — THE 15-FACTOR CONFLUENCE MATRIX (F01–F15)

Every factor mapped to its implementation

FactorPackage + function
F01 market statequalitative
F02 CVD levelmicrostructure.order_flow_imbalance
F03 ORB breakoutmean_reversion.zscore
F04 AR(1) φtrend_following.ts_momentum_regression
F05 Hurst Htrend_following.hurst_exponent
F06 playbook momentumqualitative
F07 macro regimequalitative
F08 TimesFMexternal forecast
F09 pre-session actionmicrostructure.price_impact
F10 overnight gapqualitative
F11 Claude confidenceexternal agent
F12 CVD slopemicrostructure.order_flow_imbalance (Δ)
F13 drawdown guardrailrisk_sizing.cvar_lp_solve_robust
F14 Wyckoff AMD phasetrend_following.fit_transition_matrix
F15 iFVG CE precisionmicrostructure.detect_bull_fvg + consequent_encroachment
06 — ACE POST-CLOSE LOOP (STAGE 9+)

The playbook updates itself overnight

16:00 PDT   angelic_audit.py       → 7-lens forensic review
            ace_reflector.py       → InsightBundle
            ace_curator.py         → delta_context_items.json
            (updates playbook_current.json overnight)

Beta-Bernoulli π update:
    prior     = playbook.pi_beta_params
    obs       = today.wins, today.trades
    posterior = beta_update_bernoulli(*prior, obs.wins, obs.trades)
    playbook.pi_beta_params = posterior   (auditable, single-line)
07 — EXTENSION POINTS

Where new formulas plug in cleanly

ExtensionWhere to addNotes
New confluence factormicrostructure/ or trend_following/Register with the composite scorer
Alternative scenario generatorrisk_sizing/robust_cvar.pyFollow the generate_students_t_scenarios signature
Additional Greekfoundations/Analytical form preferred over numerical
New session regimetrend_following/markov.py3-state chain in production; can extend to 4-state
Chandelier stoprisk_sizing/ (new module)Currently in commodity_orb.py — should be scaffolded
Parabolic SARtrend_following/ (new module)Currently referenced but not implemented
08 — NON-GOALS

What this library does not do

  • Connect to any broker or exchange — order routing (AMP/Rithmic bracket orders) lives entirely in the caller
  • Store any market data
  • Persist any state across function calls
  • Depend on any live external services
All functions are pure. All state that matters lives in the caller. A math library, not a trading system.