Skip to content

Rakeshks7/hawkes-process-hft-microstructure

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hawkes Processes for Order Flow Modeling

License: MIT Python Status

Overview

This project implements a Univariate Hawkes Process to model the arrival times of high-frequency trades (tick data). Unlike Poisson processes, which assume event independence, Hawkes processes capture the "self-exciting" nature of financial markets where a large trade increases the probability of subsequent trades.

This tool is designed to estimate the Branching Ratio ($n$), a critical metric in market microstructure that quantifies the degree of reflexivity (endogeneity) in the order book.

Key Features:

  • Recursive MLE: Custom $O(N)$ Log-Likelihood implementation (vs. naive $O(N^2)$).
  • Ogata's Thinning: Simulation engine for generating synthetic "flash crash" scenarios.
  • Criticality Detection: Automated calculation of market stability metrics.

Mathematical Theory

The conditional intensity function $\lambda(t)$ is defined as:

$$\lambda(t) = \mu + \sum_{t_i < t} \alpha e^{-\beta(t - t_i)}$$

Where:

  • $\mu$: Background intensity (exogenous events, e.g., news).
  • $\alpha$: Excitation parameter (immediate impact of a trade).
  • $\beta$: Decay rate (how fast the market "forgets" the trade).

The Branching Ratio ($n$) determines market stability: $$n = \frac{\alpha}{\beta}$$

  • If $n &lt; 1$: Sub-critical (Stable).
  • If $n \ge 1$: Super-critical (Unstable / Flash Crash Prone).

Project Structure

  • src/model.py: Core Hawkes logic, including the recursive log-likelihood function.
  • src/data_gen.py: Synthetic tick data generator using Ogata's Thinning Algorithm.
  • src/analytics.py: Visualization tools for intensity curves and criticality reporting.

Disclaimer

Educational Use Only. This software is for research and educational purposes. It is not intended to be used as a standalone trading system or financial advice. The "Criticality" metrics derived here are theoretical constructs and may not predict all market anomalies.

About

A high-performance implementation of univariate Hawkes Processes for modeling self-exciting order flow in financial markets. Features O(N) recursive MLE calibration and criticality detection.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages