Skip to main content

Overview

BULK’s risk engine runs inline with the matching engine, evaluating every order and position change in real time. It is not a batch process or a background job - risk is assessed at the point of execution, before fills are confirmed. The engine is built on four interconnected systems: regime detection, lambda surfaces, portfolio margin, and cascade adjustment.

Regime Detection

BULK classifies the current market environment into one of 9 regimes using a Hidden Markov Model. Each regime encodes direction and volatility: Regime classification is continuous and real-time. The engine also tracks regime duration, which feeds into the time-decay function for margin transitions.

Lambda Surfaces

Lambda (λ\lambda) is BULK’s generalized risk parameter. Instead of static margin tiers, BULK uses lambda surfaces - continuous 3D functions that map to a maintenance margin rate: λi=f(leverage,  impact,  regime)\lambda_i = f(\text{leverage},\; \text{impact},\; \text{regime}) Each asset has its own lambda surface. The surface is interpolated bilinearly, meaning margin requirements change continuously as position size, leverage, or market conditions change - no discrete jumps at tier boundaries.

Time Decay

When a regime change is detected, margin requirements don’t jump instantaneously. They follow a time-decay curve: λ(t)=λorigin⋅pt+λend⋅(1−pt)\lambda(t) = \lambda_{\text{origin}} \cdot p^t + \lambda_{\text{end}} \cdot (1 - p^t) Where λorigin\lambda_{\text{origin}} is the rate at the time of the regime transition, λend\lambda_{\text{end}} is the new regime’s target, pp is the decay factor, and tt is time elapsed. This prevents unnecessary liquidation cascades from brief regime flickers. See Margin for the full regime table and how time decay works in practice.

Portfolio Margin

For accounts with multiple positions, BULK computes a correlation-adjusted effective notional that captures diversification and hedging benefits.

Effective Portfolio Notional

For each position ii, the signed notional is sNi=sign(Qi)⋅∣Qi∣⋅PisN_i = \text{sign}(Q_i) \cdot |Q_i| \cdot P_i. The effective portfolio notional accounts for correlations: Neff2=∑isNi2+2∑i<jsNi⋅sNj⋅ρijN_{\text{eff}}^2 = \sum_i sN_i^2 + 2 \sum_{i \lt j} sN_i \cdot sN_j \cdot \rho_{ij} Where ρij\rho_{ij} is the real-time correlation coefficient between assets ii and jj. When positions hedge each other (correlated assets, opposing directions), the cross terms become negative and NeffN_{\text{eff}} shrinks well below the sum of individual notionals. Hedging discounts of up to 70% are achievable on correlated pairs.

Portfolio Maintenance Margin

For each position, the signed margin component is: Mi=sign(Qi)⋅λi⋅∣Qi∣⋅PiM_i = \text{sign}(Q_i) \cdot \lambda_i \cdot |Q_i| \cdot P_i The correlation component uses the same correlation structure: Mcorrelated=max⁡(0,  ∑iMi2+2∑i<jMi⋅Mj⋅ρij)M_{\text{correlated}} = \sqrt{\max\left(0,\; \sum_i M_i^2 + 2\sum_{i \lt j} M_i \cdot M_j \cdot \rho_{ij}\right)} The final maintenance margin adds a per-position reserve for liquidation cost not already represented by impact: Mp=Mcorrelated+∑iNi⋅Residual Reservei,bps⋅10−4M_p = M_{\text{correlated}} + \sum_i N_i \cdot \text{Residual Reserve}_{i,\text{bps}} \cdot 10^{-4} The reserve has a market-specific floor and scales with closeout impact. See Margin for the complete calculation.

Marginal Contributions

For each position, the engine computes partial derivatives: ∂Mp∂Mi∝∑jMj⋅ρijMp\frac{\partial M_p}{\partial M_i} \propto \frac{\sum_j M_j \cdot \rho_{ij}}{M_p} This tells the liquidation optimizer how much each position contributes to overall portfolio risk. Candidate reductions also include their change in liquidation reserve, so correlation benefit and closeout cost both affect selection. See Liquidations for the full optimizer algorithm.

Cascade Adjustment

The system incorporates liquidation impact feedback into margin and equity. It maintains size-indexed curves for:
  • Current cost of sweeping the closing side of the book
  • Additional cost if the resulting move triggers nearby liquidation levels
Impact-adjusted PnL includes the full current sweep cost plus a configured fraction of positive incremental cascade cost. If a current sweep observation is unavailable, the full cascade estimate is used. The remaining all-in closeout reserve is added to maintenance margin. This prevents a thin or concentrated market from appearing safe merely because mark-price PnL has not yet realized its execution cost.

Background Risk Recomputation

In addition to inline risk checks at execution time, BULK runs background risk recomputation cycles that:
  • Update portfolio margins as mark prices change (even without new orders)
  • Detect accounts approaching maintenance margin thresholds
  • Trigger liquidation when impact-adjusted closeout equity falls below MpM_p while mark-price position PnL is negative
This ensures that risk is managed continuously, not just at the moment of order submission. See Price Indices for how the mark price is computed.

Comparison to Existing Systems

See Margin, Liquidations, and Portfolio Margining for detailed specifications.