quantpylib.hft.stats
intensity(lob_timestamps, lob_mids, trades, alpha_0=0, kappa_0=0)
Calculate the trading intensity in a Limit Order Boosk.
The function takes the historical data of the LOB timestamps, mid prices, and trades, then calculates the liquidity of the orderbook by fitting an exponential decay model for A = alpha * exp ( - kappa * delta ), where A is the trade amount, alpha is scale, kappa is decay rate, and delta is price distance to mid. Large values of kappa implies is related with higher liquidity and tighter spreads.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lob_timestamps
|
ndarray
|
Array of LOB timestamps. |
required |
lob_mids
|
ndarray
|
Array of LOB mid prices. |
required |
trades
|
ndarray
|
Array of trade data with columns for timestamp, price, and amount. |
required |
alpha_0
|
float
|
Initial guess for the alpha parameter in the exponential decay model. Defaults to 0. |
0
|
kappa_0
|
float
|
Initial guess for the kappa parameter in the exponential decay model. Defaults to 0. |
0
|
Returns:
Name | Type | Description |
---|---|---|
tuple |
A tuple containing the estimated alpha and kappa parameters. Returns (None, None) if no valid data is found. |
Algorithm
- Initialize arrays to store quote and trade events.
- Populate quote events with timestamps and mid prices from the LOB.
- Populate trade events with timestamps, prices, and amounts from the trade data.
- Combine quote and trade events, and sort them by timestamp.
- Calculate the distance between trade prices and the last observed mid price from the quotes.
- Aggregate the trade amounts by the calculated distance levels.
- Fit an exponential decay model to the aggregated data to estimate the alpha and kappa parameters.