Inside Laboratory: Backtesting Engine and Allocation Architecture

How Laboratory uses context engineering, sequential daily decisions, portfolio memory, and constrained allocation to integrate regime analysis into a durable backtesting workflow.

Joseph Henry Nkeng | Founder & Managing Director at Valhko, Σternal Product Lead

May 6, 202618 min read
backtestingportfolio constructioncontext engineeringregime analysisΣternal
Abstract visual for Laboratory backtesting engine and allocation architecture

Abstract

Laboratory is built around dated decisions. Each historical day is reconstructed as its own information environment, processed through the same cycle logic used for portfolio operation, carried forward through portfolio memory, and recorded in a journal that can be revisited later.

That structure speaks to a familiar problem in regime-aware quantitative investing. The literature has shown for decades that returns, volatilities, correlations, and policy transmission change across states of the world Ang and Bekaert (2004), Ang and Timmermann (2012). The harder part begins after that insight: deciding how state information should enter a portfolio process in a way that remains coherent when the run is over and the reasoning has to be read back.

Laboratory approaches that problem through context engineering. It gathers regime-relevant evidence, orders it, interprets it, and carries it into allocation in a form that stays legible after the fact.

A Backtest Built Day by Day

Laboratory is a journal-first, daily-cycle backtesting system. A full run begins with an inception date, reconstructs the relevant context for each business day, updates portfolio memory, translates that context into an allocation decision, and stores the result as part of a durable run history.

This matters because the portfolio does not move through history as a single statement. It moves through time one day at a time. Each decision inherits a prior book, a prior memory, a prior context, and a prior set of constraints.

The simplest way to read the system is through its layers.

  1. 1Historical context is reconstructed for a specific day.
  2. 2That context is translated into structured signals and interpretations.
  3. 3Portfolio memory decides how much continuity or change should carry into the next step.
  4. 4The allocator expresses that view under explicit constraints.
  5. 5The journal preserves what was known, how it was read, and what the portfolio did.

Together, those layers give the backtest continuity, structure, and a readable record of why the portfolio changed.

Historical Anchoring

The first discipline in the architecture is historical anchoring. Each cycle is built from a dated information set.

If the cycle date is a stress day in March 2020, the market-state analysis, brief context, and selected custom context windows are all resolved around that day and within that historical information set. Once present knowledge begins to leak into past decisions, the backtest stops saying much about how the process would actually have behaved.

In practice, this means the backtest is built around bounded context windows. The state layer is resolved as of the historical date, and supporting context follows the same rule, whether it captures short-horizon market texture or a longer custom research window. The point is to preserve the historical vantage point with enough rigor that the resulting allocation decision still makes sense when read later.

This is also where the literature keeps the workflow honest. If regime analysis is meant to improve conditional reasoning, then the integrity of the information set matters as much as the model itself Bloom (2009), Baker, Bloom, and Davis (2016).

A Durable Run

The current architecture treats a full backtest as a durable object.

When a user launches a full run in Laboratory, the system stores a run-level snapshot of the relevant settings, prepares the work for asynchronous execution, and processes the portfolio day by day. Some context artifacts can be prepared ahead of use where that improves efficiency, but the portfolio itself still advances sequentially. Portfolio memory, continuity constraints, and realized choices on one day shape what can happen on the next.

In practical terms, the run can be monitored, resumed, stopped, and reviewed without losing the thread of the process. That stability matters because the backtest carries its own history, state, and review trail across time.

The Daily Cycle

The heart of Laboratory is the daily cycle. A full backtest is the repeated application of that cycle across business days.

The cycle now moves through a layered context and allocation process.

1. State characterization

The cycle begins with a state layer. Decode provides a structured representation of the environment: broad regime similarity, macro dimensions, and historical framing. That gives the process a coherent starting point.

On its own, a state label rarely carries enough information for a portfolio decision. It needs context around what is reinforcing, complicating, or destabilizing that state.

2. Context accumulation

Laboratory can enrich the state layer with brief context and selected custom research reports. Those additions carry details that a compressed state representation cannot hold on its own: policy tone, funding conditions, breadth deterioration, leadership changes, narrative asymmetries, and early transition signals.

That material does not pass through as raw prose. It is translated into more structured directional signals and combined with the state layer so the portfolio process can work with it directly.

3. Deterministic market overlays

Beyond decode and narrative context, the cycle also applies deterministic market overlays. These layers describe the market's present condition and broader perception: broad re-risking, defensive stress, narrow leadership, or something more mixed.

That gives the process a more direct read on market structure and spreads interpretation across several complementary layers.

4. Themes, shocks, and agentic context

Once the state and contextual signals are assembled, Laboratory infers a higher-order context layer. Themes and shocks help translate the day into tradeable structures: which developments appear persistent, which look urgent, which expression channels matter, and which parts of the asset universe are most exposed.

Those layers feed into what the system treats as agentic context. The portfolio is therefore responding to a fuller context object built from state, market structure, narrative signals, thematic interpretation, and shock transmission.

Portfolio Memory

Portfolio memory now sits close to the center of the process.

Its job is to answer a difficult question: has the environment changed enough to justify a meaningful portfolio adjustment, or does continuity still deserve the larger weight? A great many facts can arrive on a given day without materially altering the portfolio thesis. The system needs a way to separate informational motion from genuine thesis change.

Memory carries the portfolio's existing view, forms a candidate update, assesses materiality, and determines the action budget that should govern the next allocation step. In practice that affects turnover, per-asset changes, and the distinction between holding, refining, rebalancing, and urgently repositioning.

Allocation

The allocator is a translation layer under constraints.

Its task is to take the structured output of the cycle - state, contextual signals, themes, shocks, and active memory - and convert that into a target portfolio. That conversion happens through scoring, sleeves, buckets, target bands, risk caps, and stability controls.

The portfolio that emerges still carries judgment, though it does so within a bounded structure.

Several parts of that discipline matter:

  • assets are evaluated within a broader cross-asset universe and expressed through relative opportunity sets,
  • sleeve and bucket structure help preserve the economic meaning of exposures,
  • position caps and minimum sizes prevent the book from drifting into incoherent granularity,
  • turnover controls and action budgets limit overreaction,
  • stability mechanisms reduce churn after recent exits or abrupt reversals,
  • cash can appear tactically, though the broader design still seeks a portfolio expression rather than habitual underdeployment.

Regime analysis becomes more useful when it enters the allocator through a disciplined translation layer and a clear set of portfolio constraints.

The Journal

Every backtesting system eventually produces performance summaries. The journal remains the more distinctive artifact in Laboratory.

Each day stores the context that informed the decision, the hypothesis, the rationale, the portfolio before and after the change, the resulting trades, the memory snapshot, and the realized portfolio path around that decision. Over the life of a run, the journal becomes an inspectable chain of dated judgments.

That makes it much easier to see whether the process itself remained coherent through time. The journal preserves how the portfolio got where it did.

What Changed in the Current Architecture

The current implementation is fuller in a few important ways.

Full backtests now run as durable historical processes. Context preparation has become part of the architecture in its own right. The allocator works with a broader context stack that includes market-state overlays, market-perception overlays, inferred themes, inferred shocks, and portfolio memory. Memory itself now affects whether and how the portfolio changes. Run history is also preserved through a sturdier journal structure, which makes comparison and review easier.

Why This Matters

The literature already suggests that state dependence matters. What is often missing is a workflow that can carry that insight into daily portfolio decisions with enough structure, continuity, and historical discipline.

That is where context engineering matters. Better context accumulation, better sequencing of evidence, better translation into portfolio terms, and better continuity control can improve decision quality. Over time, those incremental gains may matter as much as any single signal.

Closing Reflections

Within Laboratory, a backtest unfolds as a dated sequence of decisions shaped by historical context, structured interpretation, portfolio memory, and constrained allocation.

The challenge in regime-aware investing is the everyday work of carrying context into portfolio decisions without losing discipline, continuity, or historical perspective. Laboratory is one attempt to do that carefully.

References

  1. 1Ang, A., and G. Bekaert (2004). "How Do Regimes Affect Asset Allocation?" Financial Analysts Journal.
  2. 2Ang, A., and A. Timmermann (2012). "Regime Changes and Financial Markets." Annual Review of Financial Economics.
  3. 3Bloom, N. (2009). "The Impact of Uncertainty Shocks." Econometrica.
  4. 4Baker, S. R., N. Bloom, and S. J. Davis (2016). "Measuring Economic Policy Uncertainty." Quarterly Journal of Economics.