Skip to main content
Mutaba Systems

Architecture

Built for correctness first

The first version is a modular monolith: one deployable application with strict module boundaries, enforced by automated architecture tests. Services are only extracted when a measurable requirement justifies it.

Module flow

Risk is a gate between strategy and execution

Strategies never talk to brokers or create fills. They express intent as target portfolio weights, and every order passes through risk before it can reach the execution simulator.
  1. Step 1

    Market data

    Bars bounded at the decision time

  2. Step 2

    Strategy

    Emits target weights only

  3. Step 3

    Portfolio construction

    Turns weights into whole-share orders

  4. Step 4

    Risk gate

    Approves or rejects with a named rule

  5. Step 5

    Order management

    Explicit order state machine

  6. Step 6

    Execution (simulated)

    Next-open fills, slippage, commission

  7. Step 7

    Ledger

    Append-only journal, reconciled

  8. Step 8

    Analytics

    Documented formulas, nulls when undefined

Backtest timeline

Decide at the close, fill at the next open

A strategy that sees today’s closing price cannot also trade at that price. The engine processes each trading session in this fixed order.
  1. 1. Open

    Apply corporate actions

    Splits effective today adjust positions before trading.

  2. 2. Open

    Fill yesterday’s approved orders

    Sells fill before buys, at the open plus adverse slippage.

  3. 3. Close

    Mark to market

    Positions are valued at today’s closing price.

  4. 4. After close

    Strategy decides

    Uses bars up to and including today’s close, never later.

  5. 5. After close

    Build orders and run risk

    Each order is approved or rejected with a reason.

  6. 6. Next open

    Approved orders wait

    Nothing fills at a price the strategy already saw.

Look-ahead guard

Future data is unreachable, not just discouraged

Strategies read prices through a market data view bounded at the decision time. Asking for a later bar raises an error, so look-ahead bias fails loudly in tests instead of quietly inflating results.
Data visibility at decision timeBars from the start of the series through the decision time are visible to the strategy. Bars after the decision time are blocked and raise an error if requested.Decision time (close of day d)Visible to the strategyBlocked: raises an error

Order management

Orders move through an explicit state machine

Every transition is listed in a transition table. Invalid transitions throw an error and are covered by tests, so a cancellation that crosses with a fill, or a duplicate execution report, cannot corrupt state.

Main path

  1. Created
  2. Pending validation
  3. Approved
  4. Pending submission
  5. Submitted
  6. Acknowledged
  7. Partially filled
  8. Filled

The simulator in v0.1 fills orders in full, so Acknowledged and Partially filled exist in the model but are not yet exercised by the simulator.

Terminal exits

Rejected
A risk rule or validation fails, or a buy is unaffordable at the fill price.
Cancelled
A cancellation is confirmed (via Pending cancel).
Expired
The order is still pending after the last session.
Failed
An unexpected execution error occurs.

Portfolio ledger

Balances are derived from an append-only journal

Cash and holdings are never edited directly. Every financial event is appended to a journal, and positions, cash and FIFO tax lots are a projection of it. Reconciliation rebuilds the projection from scratch and compares.

Journal (append-only)

  1. DepositInitial capital
  2. BuyExecution id, quantity, price
  3. FeeCommission for that execution
  4. Split2-for-1, lot cost basis unchanged
  5. SellFIFO lots, realized P&L

Projection

  • Cash balance
  • Positions by instrument
  • FIFO tax lots and cost basis
  • Realized P&L

Reconcile

Rebuild from the journal and compare with the running state. Duplicate execution ids are ignored, so replaying a fill never creates a second position.

Financial precision

Policies, written down

Money and prices

Decimal arithmetic, never binary floating point, for balances. Cash rounds to the cent per transaction. Fill prices round to four decimal places.

Identifiers

Instruments have permanent internal identifiers. A ticker is an attribute that can change, not a primary key.

Prices and adjustments

Raw prices and corporate actions are stored separately. Adjusted and unadjusted prices are never silently substituted for each other.

Current simplifications are documented rather than hidden: a single currency (USD), whole shares only, and same-day settlement in simulation.