You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Check out the new article: Feature Engineering for ML (Part 5): Microstructural Features in Python.
This article implements the Chapter 19 microstructure suite in afml.features.microstructure and explains a two-layer design for OHLCV-only and tick-augmented workflows. We cover Roll and Corwin–Schultz spread/volatility, Kyle's, Amihud's, and Hasbrouck's lambdas, VPIN, and bar‑level imbalance features, all in Numba‑accelerated kernels. A single np.searchsorted pass resolves bar boundaries, enabling prange parallelization and producing a bar‑indexed feature matrix ready for downstream ML models.
Standard OHLCV features assume that price formation is exogenous: the market opens, trades happen, and the bar records the outcome. Microstructure theory takes the opposite view. It models the trading process itself as the mechanism through which private information enters prices. Two participants are assumed: an informed trader who knows the true asset value and acts on that knowledge, and an uninformed market maker who provides liquidity without that knowledge. The spread and the price impact coefficient are the equilibrium outcomes of this strategic interaction.
The tick rule is the earliest classification tool in this framework. It assigns a direction bt ∈ {−1, +1} to each trade based on whether the transaction price moved up, down, or was unchanged from the prior trade. The raw series {bt} is a feature in its own right, but the chapter identifies five productive transformations: a Kalman filter on the expected future direction Et[bt+1]; structural break detection on those predictions (covered in Part 7 of this series); entropy of the {bt} sequence (Chapter 18, covered in the next article); t-values from the Wald-Wolfowitz runs test on {bt}; and fractional differentiation of the cumulative series Σibi (Chapter 5, Part 1 of this series). All five transformations encode different aspects of how directional information accumulates within a bar or across bars.
Author: Patrick Murimi Njoroge