Ofi
Quick Reference
| Property | Value |
|---|---|
| Dimension | signal |
| Category | order_flow |
| Version | v0.9.0 (Beta) |
| Output Column | ofi |
Order Flow Imbalance - measures net order flow
Formula
cumsum((diff(best_bid_size, window) - diff(best_ask_size, window)), 0)
CDM Inputs
| Column | CDM Table | Description |
|---|---|---|
best_bid_size | cdm_lob_snapshot | Order book snapshot data 鈥?depth levels, bid/ask prices and sizes |
best_ask_size | cdm_lob_snapshot | Order book snapshot data 鈥?depth levels, bid/ask prices and sizes |
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
decay | float [0.0, 1.0] | 0.95 | Decay factor for exponential moving average |
window | integer [1, 100] | 1 | Lookback window for differences |
Output
Column: ofi
Order flow imbalance (decaying sum of bid/ask flow)
Market Intuition & Trading Rationale
OFI (Order Flow Imbalance) is the most direct measure of aggressive buying vs. selling pressure at the microstructure level. It computes cumsum(螖bid_size - 螖ask_size) 鈥?the net change in resting liquidity at the best prices. When bid size increases (limit buy orders added), OFI rises; when ask size increases (limit sell orders added), OFI falls. Unlike trade-based signals which measure what did trade (past), OFI measures what wants to trade (present intent).
OFI is faster than price 鈥?it captures intent before a transaction moves the market. A spike in OFI means one side of the book is being aggressively replenished or consumed, revealing directional pressure that hasn't yet been reflected in the trade price. This makes OFI a leading indicator for short-horizon price moves, typically in the 100ms鈥?s range.
The cumulative sum acts as a directional accumulator. Positive OFI that persists over multiple updates means sustained buying pressure 鈥?not just a single large limit order. Negative OFI means sustained selling pressure. The window parameter controls the lookback for bid/ask size differences; larger windows smooth over more updates but introduce latency.
Usage Cases
- HFT directional signal: Trade in the direction of OFI at sub-second horizons. OFI predicts the next trade direction and the next mid-price move with high accuracy over 100ms鈥?s windows, especially when absolute OFI is large relative to its recent volatility.
- Flow confirmation: Use OFI direction to confirm or fade trade-based signals. When
trade_signand OFI agree (both positive or both negative), the directional signal is higher conviction. When they disagree, the market is mixed 鈥?the aggressive side differs from the passive side. - Liquidity stress detection: Large negative spikes in OFI (rapid ask size increases) signal sellers flooding the book. Large positive spikes signal buyers accumulating. Both are leading indicators for short-term directional moves.
- core feature: OFI is the primary signal feature in
order_flow_imbalanceandorder_flow_accumulationpacks, where it's z-score normalized and paired with quality and stability diagnostics.
YAML Definition
name: ofi
description: Order Flow Imbalance - measures net order flow
category: order_flow
version: v0.9.0 (Beta)
dimension: signal
status: Pre-release
required_inputs:
- best_bid_size
- best_ask_size
output_column: ofi
output_description: Order flow imbalance (decaying sum of bid/ask flow)
tags:
- flow
- imbalance
- microstructure
- order_flow
- composition
parameters:
decay:
type: float
description: Decay factor for exponential moving average
required: false
default: 0.95
constraints:
min: 0.0
max: 1.0
window:
type: integer
description: Lookback window for differences
required: false
default: 1
constraints:
min: 1
max: 100
formula: cumsum((diff(best_bid_size, window) - diff(best_ask_size, window)), 0)