📄 Technical White Paper: For the formal neuro-symbolic specification, mathematical proofs, and system architecture, see the ThomasAi & Local Foundation Model Technical White Paper.
ThomasAi is the autonomous neural decision and continuous learning engine of TradingSystem. It operates as a local connectome in papercompmoomoo/data/brain.sqlite3, accelerated on Apple Silicon via Apple Accelerate SIMD matrix mathematics (crates/engine/src/accelerate.rs) and Darwin QoS thread scheduling (crates/engine/src/darwin_qos.rs).
The neural connectome consists of nodes organized into hierarchical functional layers:
- Sensory Layer (
sensory): 21+ real-time market and temporal sensors evaluated strictly on closed 15-minute bars:- Relative Volume (RVOL 20-bar baseline).
- Opening thrust (% extension from prior close).
- Volatility squeeze (ATR ratio / Bollinger contraction).
- Cohort trend & sector momentum (% change over trailing sessions).
- Temporal features (day-of-week, session half-day phase).
- Symbol-specific sensory neuron representing historical identity.
- Archetype Layer (
archetype): Pattern recognition nodes that synthesize sensory clusters into market behavioral regimes (e.g. Breakout Surge, Reversal Flush, Trend Continuation, Volume Fade). - Decision Layer (
decision): Aggregates archetype activations into operational impulses (conviction,abstain). - Reflex Layer (
reflex): Protective sub-circuits that execute risk constraints:bear_sentry: Detects adverse market-wide or symbol selling pressure; vetoes entry when active.floor_reflex: Determines dynamic break-even triggers and trail ratchets.risk_tier: Sets dynamic position size scaling (0.25x to 1.5x nominal notional).
- Outcome Layer (
outcome): Ground-truth evaluation nodes mapping realized trade P&L and counterfactual results.
- Each node fires using a bounded non-linear activation:
$$\text{Activation}(S) = \frac{S}{S + \text{threshold}} \quad (S \ge 0)$$ This guarantees outputs strictly bounded in$[0, 1)$ , naturally zero when input excitation is absent. - Inter-layer propagation is computed as vectorized matrix-vector products:
$$Y = \text{Activation}(W \cdot X)$$ accelerated via macOScblas_dgemvin Apple Accelerate framework. -
Entry Decision Gate:
A candidate is admitted only if:
$$\text{evidenced} \land (\text{conviction} > \max(\text{bear}, \text{abstain}) + \text{margin})$$ Without real evidence (unrecognized symbol with no sensed features), the network stays completely silent and never enters.
ThomasAi continuously learns from all historical and live data without waiting for sessions:
- Executed by the 15-minute background loop (
ops/learn_loop.sh/com.thomasai.learn). - Connects atomically to
papercompmoomoo/data/brain.sqlite3,papercompmoomoo/data/journal.sqlite3,data/common15m.sqlite3, anddata/thomas.sqlite3. -
Ingestion: Ingests all recently completed forward candidates, backtests, bars, candlestick patterns, discovered skills, and closed trades from
journal.sqlite3. -
Hebbian Synaptic Reinforcement:
- For winning trades, the active synapses (
$X_i \cdot Y_j$ ) that contributed to the entry decision are strengthened. - For losing trades or bear-trap failures, active synapses are penalized/attenuated.
- For winning trades, the active synapses (
-
Synaptic Apoptosis (Pruning):
- Synapses whose weights decay below the significance floor are pruned to prevent catastrophic interference and preserve network sparsity.
- Runs walk-forward cross-sectional training across all Nasdaq symbols in
common15m.sqlite3. - Holdout Rigor: Strictly isolates the last 20 calendar days as an untouchable holdout set (
--holdout-days 20). - Skill Discovery (
brain_skillstable):- Identifies named skill pathways where specific sensor combinations demonstrated statistically significant positive expectancy.
- Measures holdout win rate and win/loss ratio across independent decisions.
- Autonomous Margin Optimization (
improve_policy):- Evaluates candidate entry conviction margins on the first half of the holdout and adopts a new margin only if it outperforms the previous policy on the unseen second half by at least 1 percentage point.
- Teaching Forward Outcomes:
- Ingests true counterfactuals (two-hour performance of entries skipped by teacher objections) to continuously tune the network against false negatives.
Every decision, evaluation, and outcome is durably recorded in data/debrief.sqlite3 across four structured tables:
Captures the complete lifecycle of every candidate:
- Plan Stage:
session,symbol,strategy,rank,score,weight,take_profit_pct,stop_loss_pct,trail_pct,staged,regime,alpha_mode. - ThomasAi Readings:
thomasai_conviction,thomasai_bear_penalty,thomasai_floor_reflex,network_guided. - Committee Review:
review_action,review_note,teacher_votes,market_evidence. - Execution:
ordered_ms,fill_price,shares,closed_ms,exit_price,pnl_pct,exit_reason. - Session Ground Truth:
session_open,session_high,session_low,session_close,session_volume,session_return_pct.
High-resolution audit log of every operational decision taken by any bot instance:
ts_ms,session,symbol,stage(plan,entry,exit,review,discovery),action(order,skip,exit,hold),reason,detail(JSON),instance(moocomporgainers).
Teacher track-record scorecard linking each teacher's verdict (agree vs object) to the actual realized session return, enabling dynamic weighting.
During position monitoring, real-time tick and 1-minute streams compute:
- Maximum Favorable Excursion (MFE %): Peak unrealized gain achieved during the trade.
- Maximum Adverse Excursion (MAE %): Maximum unrealized drawdown experienced before exit.
- Holding Efficiency: Ratio of realized P&L to peak potential MFE, quantifying exit quality.
# Run one autonomous neural learning step
./target/release/thomas neural-step
# Train sensor pathways with a 20-day holdout
./target/release/thomas neural-train --per-symbol 12 --holdout-days 20
# Evaluate a forward neural pass on live candidates
./target/release/thomas neural-decide --symbols AAPL,NVDA,TSLA
# Inspect learned skills, deliberation consensus, and synaptic weights
./target/release/thomas learningsThomasAi's decision layers are anchored directly in 4 foundational peer-reviewed discoveries from NeurIPS proceedings (stored permanently as immutable hard facts in brain.sqlite3 via SQLite triggers):
-
Online Optimization under Delayed Bandit Feedback (Wan et al., NeurIPS Vol. 37):
- Eliminates
$\mathcal{O}(d \cdot T)$ synchronous feedback regret during trade holding. - Decoupled blocked FIFO state updates provably achieve the minimax lower bound:
$$\mathcal{R}(T) \le \mathcal{O}\left(\sqrt{n} T^{3/4} + \sqrt{d T}\right)$$ - Prevents synaptic thrashing during volatile intra-bar noise.
- Eliminates
-
Snell Envelope Martingale Optimal Stopping (NeurIPS Vol. 38, continuous MDPs):
- Formulates exit execution on excursion diffusion
$dX_t = \mu_t dt + \sigma_t dW_t$ :$$\tau^* = \inf \left{ t \ge 0 ;\middle|; X_t \ge \sup_{\tau \ge t} \mathbb{E}[X_\tau \mid \mathcal{F}_t] \right}$$ - Realized as a dynamic parabolic giveback clamp in
exit_mind.pyandbracket.rs:$$g(M_t, \sigma_t) = \min\left(\delta_{\max}, \max\left(\delta_{\text{cost}}, 0.18 M_t^{0.75} + 0.10 \sigma_t\right)\right)$$ - Enforces a
$+0.15%$ break-even cost floor once runners clear$+0.75%$ MFE.
- Formulates exit execution on excursion diffusion
-
Exogenous Covariate Decoupling via 2D Kinematic Kalman Filters (NeurIPS Vol. 37 TimeXer):
- Tracks continuous-discrete microstructural velocity
$v_t$ and second-order kinematic acceleration$a_t = \frac{dv_t}{dt}$ . - Evaluates relative acceleration against benchmark index SPY/QQQ:
$\Delta a = a_t - a_{\text{benchmark}} > 0$ . - Screens live gainers and breakout candidates at inception; rejects late chasing (
$> 2.2%$ from consolidation base) and requires Close Location Value$\text{CLV} \ge 0.65$ .
- Tracks continuous-discrete microstructural velocity
-
Non-Exchangeable Conformal Risk Prediction & Drawdown Bounds (NeurIPS Vol. 37 & 38):
- Computes non-asymptotic, distribution-free drawdown bounds: $$\mathbb{P}\left(\text{Drawdown}{t+1} \le \hat{D}{\text{conformal}}\right) \ge 1 - \delta$$
- Wires interval width into fractional Kelly position sizing: $$f^* = \kappa \cdot \frac{p \cdot b - q}{b} \cdot \max\left(0, 1 - \frac{\hat{D}{\text{conformal}}}{D{\max}}\right)$$
- Position sizes dynamically and automatically contract before portfolio drawdowns can materialize.
-
Hardware AMX BLAS Acceleration (
crates/engine/src/accelerate.rs):- Accelerates online RLS covariance and synaptic updates using Apple Silicon AMX matrix coprocessor routines (
cblas_dger,cblas_daxpy,cblas_dgemv,vDSP_dotprD) with deterministic scalar fallback verification.
- Accelerates online RLS covariance and synaptic updates using Apple Silicon AMX matrix coprocessor routines (
In addition to the native Rust connectome, ThomasAi incorporates an on-device Apple MLX language model (Qwen2.5-1.5B 4-bit) and Apple Foundation Model (AFM) for qualitative setup analysis, knowledge distillation, and position exit evaluation.
For full setup instructions, training dataset compilation, continuous LoRA fine-tuning, holdout evaluation, and discrimination AUC gating, see the dedicated guide: