High-Frequency Trading and Latency Arbitrage › Key Parameters

Michael BrenndoerferJanuary 1, 20267 min read
Quantitative FinanceAll chapters
Part 12 of 15Market Making and High-Frequency Trading
Chapter 66High-Frequency Trading and Latency Arbitrage › Key Parameters
Reading section 12 of 18 · Key Parameters · 7 minSection 12 of 18 · 7 min

Book contents

Section 12 of 18 · 7 min read

High-Frequency Trading and Latency Arbitrage › Key ParametersOne section · Sections in this chapter12 / 18 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

The key parameters for HFT market maker simulation are:

  • n_periods: Number of time periods simulated, with more periods producing more precise long-term performance estimates.
  • true_price_vol: True price volatility per period (percentage), representing market uncertainty that creates both risk and opportunity for market makers.
  • spread_bps: Bid-ask spread quoted by market maker (basis points), determining gross profit per round-trip trade and representing compensation for providing liquidity.
  • inventory_limit: Maximum inventory position (shares), a risk control preventing excessive exposure to directional price movements.
  • fill_probability: Probability of quote being filled each period (0 to 1), representing trading frequency and interaction with order flow.
  • adverse_selection_bps: Loss per fill due to informed traders (basis points), representing the cost of providing liquidity to better-informed counterparties who trade when prices are about to move.
Out[25]:
Visualization
Line chart of HFT market maker mark-to-market P&L rising steadily from zero over 1,000 time periods, showing consistent spread capture.
Mark-to-market profit over 1,000 periods for a high-frequency market maker quoting 2 basis point spreads. P&L rises sharply during the first half of the simulation, peaks above $2,500, and then gives back part of those gains, illustrating both spread-capture profits and meaningful drawdown risk.
Line chart with teal fill showing inventory ranging from roughly -500 shares to the 1,000-share cap over 1,000 periods, with a horizontal dashed line at zero.
Inventory position over the 1,000-period horizon. The position reaches the 1,000-share limit repeatedly during the first 600 periods, then crosses below zero and finishes positive. The extended time at the cap shows that the simulated quote-skewing rule does not consistently maintain near-neutral inventory.

Order Anticipation and Signal Detection

As a sophisticated market maker, you analyze incoming order flow to detect patterns that predict future price movements. This involves:

Order book imbalance: When there are substantially more bids than asks (or vice versa), prices tend to move in the direction of the imbalance.

Trade flow toxicity: Large, aggressive orders often precede continued price movement in the same direction. Detecting toxic flow allows you to widen spreads or reduce exposure.

Cross-market signals: Price movements in related instruments (futures, options, correlated stocks) can predict movements in the target instrument.

In[26]:
Code
def calculate_order_imbalance_signal(
    bid_sizes: np.ndarray, ask_sizes: np.ndarray, n_levels: int = 5
):
    """
        Calculate order book imbalance as a predictive signal.

        The imbalance is calculated as:

    $$
    \text{Imbalance} = \frac{\sum_{i=1}^{n} w_i B_i - \sum_{i=1}^{n} w_i A_i}{\sum_{i=1}^{n} w_i B_i + \sum_{i=1}^{n} w_i A_i}
    $$

    where:

    - $B_i$: bid size at level $i$ (number of shares in orders waiting to buy at the $i$-th best bid price)
    - $A_i$: ask size at level $i$ (number of shares in orders waiting to sell at the $i$-th best ask price)
    - $w_i = 1/i$: weight for level $i$ (dimensionless), giving more influence to levels closer to the current market
    - $n$: number of price levels included (typically 5-10 levels)
    - Numerator: weighted difference between bid and ask sizes (shares)
    - Denominator: total weighted order book size (shares)

    The formula constructs a normalized imbalance metric between negative 1 and positive 1:

    **Numerator (weighted difference):**

    The numerator computes the weighted difference between bid and ask sizes:

    $$
    \text{Weighted difference} = \sum_{i=1}^{n} w_i B_i - \sum_{i=1}^{n} w_i A_i
    $$

    This quantity has the following properties:

    - Positive when bid sizes exceed ask sizes (more buying pressure)
    - Negative when ask sizes exceed bid sizes (more selling pressure)
    - Near zero when bid and ask sizes are balanced

    **Denominator (total weighted size):**

    The denominator sums the total weighted order book size on both sides of the market:

    $$
    \text{Total weighted size} = \sum_{i=1}^{n} w_i B_i + \sum_{i=1}^{n} w_i A_i
    $$

    This serves as the normalization factor. By dividing the weighted difference by the total weighted size, we obtain a metric that is comparable across different securities regardless of their typical order sizes. A stock with 100,000 shares in the book produces the same imbalance metric as a stock with 10,000 shares if the relative bid-ask balance is identical.

    **Weighting scheme intuition:**

    The weighting $w_i = 1/i$ reflects that nearby orders matter more for predicting immediate price movements. Consider why:

    - A 1,000 share bid at level 1 (the best bid) is highly informative because it will execute first
    - A 1,000 share bid at level 5 is less informative because four other price levels must trade first
    - Orders closer to the current price have higher execution probability and thus more predictive power

    The $1/i$ weighting implements this intuition:

    - Level 1 receives weight 1.0 (maximum influence)
    - Level 2 receives weight 0.5 (half the influence)
    - Level 3 receives weight 0.33 (one-third the influence)
    - And so on, with influence declining as distance from the market increases

    **Interpreting the imbalance value:**

    - Values near positive 1: strong buying pressure, predicting upward price movement
    - Values near negative 1: strong selling pressure, predicting downward price movement
    - Values near 0: balanced order flow with no clear directional signal
    - Magnitude indicates strength: an imbalance of 0.8 suggests a stronger signal than an imbalance of 0.3

        Parameters:
        -----------
        bid_sizes : Array of bid sizes at each price level
        ask_sizes : Array of ask sizes at each price level
        n_levels : Number of levels to include in calculation
    """
    # Use top n levels with distance weighting
    weights = 1 / np.arange(1, n_levels + 1)
    weights = weights / weights.sum()

    weighted_bid = np.sum(bid_sizes[:n_levels] * weights)
    weighted_ask = np.sum(ask_sizes[:n_levels] * weights)

    # Imbalance: positive means more bids (bullish), negative means more asks (bearish)
    imbalance = (weighted_bid - weighted_ask) / (weighted_bid + weighted_ask)

    return imbalance


# Example order book
np.random.seed(42)
bid_sizes = np.array([500, 800, 1200, 600, 900])  # More aggressive buying
ask_sizes = np.array([400, 500, 700, 800, 600])

imbalance = calculate_order_imbalance_signal(bid_sizes, ask_sizes)
Out[27]:
Console
Order Book Imbalance Analysis
========================================

Order Book (top 5 levels):
Level    Bid Size     Ask Size    
--------------------------------
1        500          400         
2        800          500         
3        1200         700         
4        600          800         
5        900          600         

Weighted Imbalance: 0.1506
Interpretation: Bullish (more bid pressure)

The weighted imbalance indicates directional pressure. The weighting gives more influence to the best prices (level 1 receives full weight, level 2 receives 50%, etc.), and this imbalance suggests short-term price pressure. Market makers would use this signal to adjust their quotes to lean against the expected move.

Out[28]:
Visualization
Diverging horizontal bar chart with teal bars extending right for bid sizes and coral bars extending left for ask sizes across five price levels, separated by a vertical center line.
Order book imbalance visualization comparing bid sizes (right) and ask sizes (left) across five price levels. Distance-based weights give level 1 the most influence and progressively discount deeper levels. The positive weighted imbalance indicates greater bid pressure in this simulated book; market makers can use that signal to adjust quotes against the expected move.