\section{Pseudocode} \label{app:pseudocode} The five algorithms below follow the control flow of the code line by line; names in typewriter font are the corresponding functions. $\Delta$ is the dividend interval, $T$ the number of ticks. \begin{algorithm}[H] \caption{Tick loop (\code{Simulation.run}, \code{experiments/runner.py})} \label{alg:tick} \footnotesize\begin{algorithmic}[1] \State build streams from the master seed; draw fundamentals, population, accounts, latencies; register accounts \State $\text{pending\_liq} \gets \emptyset$; record $P_0$ \For{$t = 0,\dots,T-1$} \State $\text{exchange.time} \gets t$ \If{$t>0$ and $t \bmod \Delta = 0$} \State $D \gets \code{fund.step()}$ \Comment{pay $D_n$, reveal $x_n$, update public filter, draw latent $x_{n+1}$} \State pay $\operatorname{round}(D_k)$ cents per lot of every asset $k$; check conservation \EndIf \State \code{apply\_shocks}$(t)$ \Comment{after the dividend: a jump stays latent until news or the next dividend} \ForAll{news items drawn this tick} \State update the public filter with the item's value and stated noise \EndFor \ForAll{$(i,\text{act}) \in \text{pending\_liq}$} \State \code{exchange.submit}$(i,\text{act},t)$ \EndFor; $\text{pending\_liq}\gets\emptyset$ \State $u \gets$ \code{activation} stream, one uniform per slot \State $A_c \gets \{i \text{ classical}: u_i < \text{activity}_i\}$; shuffle $A_c$ with the \code{shuffle} stream \State $A_\ell \gets \{i \text{ LLM}: (t-\text{offset}_i) \bmod \text{interval} = 0,\ t \ge \texttt{warmup}/2\}$, minus agents at their decision cap \State $\text{tw} \gets$ last 30 trades per asset \ForAll{$i \in A_c$} \State $o \gets$ \code{observe}$(i,t,\text{tw})$ \Comment{book depth 5, 60-tick mids, trades, dividend, $V^{\mathrm{pub}}$, $\hat x$, news, fresh private signal, account, open orders} \State $a \gets \text{policy}_i.\code{decide}(o,\text{rng}_i)$; \textbf{if} $a$ is not hold \textbf{then} \code{exchange.submit}$(i,a,t)$ \EndFor \If{$A_\ell \neq \emptyset$} \State build observations for all $i\in A_\ell$; update each agent's equity-change history \State $(a_i, \text{rec}_i)_{i\in A_\ell} \gets$ \code{llm\_policy.decide\_batch} \Comment{Algorithm~\ref{alg:llm}, thread pool of width 8} \ForAll{$i \in A_\ell$} \State submit $a_i$ if not hold; update memory and cohort channel from $\text{rec}_i$ \EndFor \EndIf \State \code{exchange.process\_until}$(t+1)$ \Comment{arrivals with time $ 0.5\,\text{mid}_k$ \EndIf \If{buy and limit} \State $\text{need} \gets p\,q + \max(\text{fee}_{\rm taker},\text{fee}_{\rm maker}) + q$; \textbf{reject} \code{insufficient\_cash} if need $>$ buying power \State reserve need cents on $c_i$ and on $o$ \Comment{buying power = free cash, or free cash $+(L-1)\,$equity if leveraged} \ElsIf{buy and market} \State \textbf{reject} \code{no\_liquidity} if no ask; $q \gets$ largest $q'\le q$ whose notional plus taker fee on the total fits in buying power, walking the asks; \textbf{reject} \code{insufficient\_cash} if $q=0$ \Else \Comment{sell} \State $h \gets$ free (unreserved) holdings; \textbf{if} $q>h$ \textbf{then} \textbf{reject} \code{insufficient\_shares} if $h\le0$ else $q\gets h$ \Comment{no short selling} \State \textbf{reject} \code{no\_liquidity} if market and no bid; reserve $q$ lots \EndIf \If{position limit set and tag $\ne$ liquidation} \State \textbf{release and reject} \code{position\_limit} if $|\text{pos}+\text{side}\,(\text{same-side resting}+q)| >$ limit \EndIf \If{margin check on, $L_i>1$ and tag $\ne$ liquidation} \State gross$' \gets$ gross exposure with asset $k$ revalued at the post-trade position and price ($p$ or mid) \State \textbf{release and reject} \code{leverage\_cap} if equity $\le0$ or gross$' > L_i\,$equity \EndIf \State log \code{accept} \If{call-auction mode} \State \textbf{if} market \textbf{then} convert to a limit at the band edge, tag \code{ioc}, reserve cash for buys; rest $o$ in $B_k$; \textbf{return} \EndIf \State fills $\gets B_k.\code{match}(o)$ \Comment{walk the opposite side while crossing; price--time priority; resting price} \ForAll{fill $(r, p', q')$} \State fees: taker $=\operatorname{round}(p'q'\cdot 2/10^4)$ on $o$, maker $=0$ on $r$; move $p'q'$ cents and $q'$ lots; release the reservations consumed (all of it on the last fill); log \code{trade}; update last price and tick volume; check conservation \EndFor \If{$o$ has remaining quantity} \State \textbf{if} limit \textbf{then} rest $o$ in $B_k$ \textbf{else} release the reservation, cancel the remainder (\code{ioc}); count a rejection if nothing filled \EndIf \State \code{maybe\_halt}$(k)$: if a breaker is set and $|\text{last}/\text{mid}_{t-10}-1|>$ threshold, halt $k$ for 20 ticks and cancel all resting orders (releasing reservations) \end{algorithmic} \end{algorithm} \begin{algorithm}[H] \caption{Margin check and liquidation (\code{Exchange.margin\_check}, \code{\_liquidate}; submitted by the runner at $t+1$)} \label{alg:margin} \footnotesize\begin{algorithmic}[1] \State marks $\gets$ midpoint of every asset (fallback: last trade, reference) \ForAll{accounts $c$ not frozen} \State $E \gets$ cash $+\sum_k Q_k\,\text{mark}_k$; $G \gets \sum_k |Q_k|\,\text{mark}_k$; \textbf{continue} if $G\le0$ \If{$E\le0$} \State freeze $c$; log \code{bankrupt}; $f\gets1$ \Comment{full liquidation; no further orders accepted} \ElsIf{$L_c>1$ and $E/G < m$ ($m=0.25$)} \State log \code{margin\_call}; $f\gets$ liquidation fraction ($0.5$) \Else \State \textbf{continue} \EndIf \State act $\gets$ cancel every resting order of $c$; for each asset with $Q_k\ne0$ add a market order for $\max(1,\lfloor f|Q_k|\rfloor)$ lots on the side that reduces $|Q_k|$, tagged \code{liquidation} \State log \code{liquidate}; append $(c,\text{act})$ to the list returned to the runner \EndFor \State \Return list \Comment{the runner submits these at the start of tick $t+1$; liquidation orders bypass the frozen, position-limit and leverage checks} \end{algorithmic} \end{algorithm} \begin{algorithm}[H] \caption{LLM decision pipeline (\code{LLMPolicy.decide\_one}, \code{\_call}, \code{to\_action}, \code{llm/policy.py})} \label{alg:llm} \footnotesize\begin{algorithmic}[1] \Require observation $o$, provider $\pi$, model $M$, prompt id $\psi$ \State $S \gets$ \code{system\_prompt}$(\psi, o)$; $U \gets$ \code{user\_message}$(o, \text{adaptive})$ \Comment{Appendix~\ref{app:prompts}} \If{$\pi=$ library} \State text $\gets$ recorded decision of a random one of the 5 nearest neighbours of \code{features}$(o)$, limit price rescaled to the midpoint; cached $\gets$ true \Else \State key $\gets$ SHA-256$(\pi\,|\,M\,|\,\text{version}\,|\,S\,|\,U)$ \If{cache enabled and key present} \State text $\gets$ cached response; cached $\gets$ true \ElsIf{frozen-only or halted for budget} \State error $\gets$ \code{frozen\_miss} / \code{budget\_halt} \ElsIf{budget cap reached} \State halt for budget; error $\gets$ \code{USD cap reached} \Else \State result $\gets$ provider$(\pi).\code{complete}(S,U,M,\text{effort}=\text{low},\text{max\_output}=1200,\text{cache\_key}=\code{ma-v1-}\psi)$ \State \textbf{if} text non-empty and no error \textbf{then} store (key, $S$, $U$, text, usage) in the cache \EndIf \EndIf \State cost $\gets$ \code{budget.record}(tokens, latency, cached) \Comment{0 for cached hits; priced from the model table otherwise} \State \textbf{if} error \textbf{then} dec $\gets$ none \textbf{else} (dec, err) $\gets$ \code{parse\_decision}(text) \Comment{lenient JSON, strict pydantic schema} \State (action, valid, reason) $\gets$ \code{to\_action}(dec, $o$) if dec else (hold, false, err) \Comment{rules of Appendix~\ref{app:prompts}} \State count invalid and failures \State record $(t, i, \pi, M, \psi, \text{valid}, \text{reason}, \text{decision fields}, \text{tokens}, \text{latency}, \text{cost}, \text{cached}, \text{error})$ \Statex \hspace{\algorithmicindent} together with the prompt SHA, the request id, \code{features}$(o)$ and the relative limit price \State \Return (action with meta \{valid, reason, rationale, confidence, llm\_action, provider, model\}, record) \end{algorithmic} \end{algorithm} \begin{algorithm}[H] \caption{Matched-seed design runner (\code{run\_design}, \code{cell\_config}, \code{\_run\_one}, \code{experiments/design.py})} \label{alg:design} \footnotesize\begin{algorithmic}[1] \Require design file with \code{base}, \code{seeds}, design-level \code{overrides}, \code{cells} (name, overrides, treatment) and optional \code{factors} \State cells $\gets$ listed cells $\cup$ full factorial product of the factor levels (overrides merged, labels joined); keep only \code{--cells} if given \State seeds $\gets$ explicit list or $\{\text{start},\dots,\text{start}+n-1\}$; truncate to \code{--max-seeds} if given \ForAll{cell $c$, seed $s$} \State cfg $\gets$ base configuration; apply design overrides then cell overrides (dotted keys; sections merged, leaf dictionaries replaced); set name $\gets$ design/cell, seed $\gets s$, treatment $\gets$ design labels $\cup$ cell labels \State job $\gets$ (cfg as JSON, \code{results/runs///seed}, cache path) \EndFor \ForAll{jobs, sequentially if workers $\le1$ else in a process pool of the given width} \If{\code{outcomes.json} exists in the run directory} \State reuse it \Comment{an interrupted design resumes without new API calls} \Else \State build the LLM policy (shared SQLite cache) if \code{llm\_share}$>0$; run Algorithm~\ref{alg:tick}; save config, manifest and frames \State outcomes $\gets$ \code{run\_outcomes}(result); write \code{outcomes.json} \EndIf \EndFor \State write \code{outcomes.parquet} (one row per run) and \code{design.json} (expanded cells, seeds, run count, wall-clock) \end{algorithmic} \end{algorithm} \noindent Because every cell of a design is run on the same seed list and the only streams touched by $\varphi$ are the LLM assignment and the LLM agents' own generators, the control and each treatment of a given seed share the dividend path, the news, the endowments, latencies and activation draws of every non-replaced slot (common random numbers); the paired estimators of the analysis exploit this matching seed by seed.