Hasbrouck Price Impact
Install and import#
npm install fintech-algorithmsimport { hasbrouckPriceImpact } from "fintech-algorithms/market-microstructure/order-flow-and-impact/hasbrouck-price-impact";Signature#
hasbrouckPriceImpact(inputRows, horizon)Estimates a bivariate VAR(1) in signed flow and midpoint return, identifies a one-unit flow innovation recursively with flow ordered first, and sums the return responses through a declared horizon. The result is the cumulative midpoint response that follows a flow innovation after dynamic feedback; it is not a permanent/transient decomposition and it does not identify informed trades.
Parameters#
| Name | Type | Notes |
|---|---|---|
inputRows | Row[] | At least eight ordered interval records, each carrying a finite signed_flow and a finite mid_change_bps. There is no midpoint path per trade; one return observation per interval is used. |
horizon | number | Number of response steps after the contemporaneous step. The trace holds horizon + 1 rows, indexed 0 through horizon.min: 0 · max: 100 · integer: true optional |
Returns#
{ model, state, observation_count, horizon, flow_equation, return_equation, flow_innovation_variance, return_flow_innovation_covariance, contemporaneous_return_response_bps, cumulative_price_impact_bps, trace }
Both fitted equations with their intercept and lag coefficients, the flow innovation variance and return/flow innovation covariance used for the recursive identification, the contemporaneous and cumulative response in basis points, and a per-step trace of flow_response, return_response_bps and cumulative_impact_bps. All numbers are rounded to ten decimal places.
Errors#
- When fewer than eight rows are supplied, or a row is not an object — throws
- When horizon is not an integer from 0 through 100 — throws
- When a row omits signed_flow or mid_change_bps, or the value is not finite — throws
- When the regression design is singular — throws
- When the residual degrees of freedom are not positive — throws
- When the flow innovation variance is not positive — throws
Complexity: time O(n + horizon),
space O(n + horizon).
Worked example#
executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.
Input#
[
{
"id": "H001",
"interval_end": 0,
"signed_flow": -1.8,
"mid_change_bps": -0.404
},
{
"id": "H002",
"interval_end": 1,
"signed_flow": 0.17,
"mid_change_bps": -0.43029818
},
{
"id": "H003",
"interval_end": 2,
"signed_flow": -0.3405,
"mid_change_bps": -0.03967215
}
]Showing 3 of 60 elements.
10Call#
hasbrouckPriceImpact(inputRows, horizon)Returns#
object with 11 fields: model, state, observation_count, horizon, flow_equation, return_equation, flow_innovation_variance, return_flow_innovation_covariance, …
{
"model": "hasbrouck-var1-flow-first",
"state": "estimated",
"observation_count": 60,
"horizon": 10,
"flow_equation": {
"intercept": -0.0138732152,
"flow_lag": 0.0401141764,
"return_lag": -0.7889548599
},
"return_equation": {
"intercept": -0.0042458851,
"flow_lag": 0.232390819,
"return_lag": -0.0460365216
},
"flow_innovation_variance": 0.9887794778,
"return_flow_innovation_covariance": 0.1786454708,
"contemporaneous_return_response_bps": 0.1806727129,
"cumulative_price_impact_bps": 0.3417920234,
"trace": [
{
"id": "H000",
"index": 0,
"flow_response": 1,
"return_response_bps": 0.1806727129,
"cumulative_impact_bps": 0.1806727129,
"side": "positive-impact",
"reason": "recursive-var1-response"
},
{
"id": "H001",
"index": 1,
"flow_response": -0.1024284385,
"return_response_bps": 0.2240732757,
"cumulative_impact_bps": 0.4047459887,
"side": "positive-impact",
"reason": "recursive-var1-response"
},
{
"id": "H002",
"index": 2,
"flow_response": -0.1808925323,
"return_response_bps": -0.0341189829,
"cumulative_impact_bps": 0.3706270058,
"side": "positive-impact",
"reason": "recursive-var1-response"
}
]
}Other exports#
This module also exports
orderFlowImbalance, queueImbalance, kyleLambda, pin, vpin, runTopic. Every module additionally exports run as an alias of its
primary function, and a meta object carrying its catalog id, domain, family,
shape and article URL.
Diagrams#
Calculation flow#
Hasbrouck Price Impact Calculation Flow
flowchart LR
A["Point-in-time source records"] --> B["Validate clocks, sequence, and finality"]
B --> C["Apply Hasbrouck Price Impact profile"]
C --> D["Preserve trace and diagnostics"]
D --> E["Report bounded output"]
E --> F["Compare profiles"]
F --> G["Reject unsupported inference"]
How it works#
This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.