PIN
Install and import
npm install fintech-algorithmsimport { pin } from "fintech-algorithms/market-microstructure/order-flow-and-impact/pin";Signature
pin(inputRows, starts, balancedNoise, iterations)Probability of informed trading, estimated by maximum likelihood on daily buy and sell counts. Notoriously hard to optimise — the likelihood has flat regions and local optima, which is why the starting points are a parameter.
Parameters
| Name | Type | Notes |
|---|---|---|
inputRows | Row[] | Daily buy and sell trade counts. |
starts | number[][] | Starting parameter vectors. Multiple starts are the standard defence against local optima; a single start frequently converges somewhere wrong. |
balancedNoise | number | Initial guess for the balanced uninformed arrival rate. min: 0 |
iterations | number | Maximum optimiser iterations. min: 1 · integer: true |
Returns
{ pin, alpha, mu, epsilon_buy, epsilon_sell, converged, … }
The PIN estimate with every structural parameter and a convergence flag — an unconverged PIN is not an estimate.
Errors
- When no starting vector is supplied — throws
Complexity: time O(days × iterations × starts),
space O(days).
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": "D001",
"day": 1,
"buys": 12,
"sells": 29
},
{
"id": "D002",
"day": 2,
"buys": 14,
"sells": 12
},
{
"id": "D003",
"day": 3,
"buys": 16,
"sells": 13
}
]Showing 3 of 60 elements.
3false120Call
pin(inputRows, starts, balancedNoise, iterations)Returns
object with 13 fields: model, state, observation_count, starts, balanced_noise, alpha, delta, mu, …
{
"model": "ekop-pin",
"state": "estimated",
"observation_count": 60,
"starts": 3,
"balanced_noise": false,
"alpha": 0.3335769653,
"delta": 0.3998646736,
"mu": 19.2332579136,
"epsilon_buy": 14.0464750051,
"epsilon_sell": 13.0377527714,
"log_likelihood": -335.6690937078,
"pin": 0.1915155787,
"trace": [
{
"id": "D001",
"index": 0,
"buys": 12,
"sells": 29,
"imbalance": -17,
"side": "sell-heavy",
"reason": "daily-count-input"
},
{
"id": "D002",
"index": 1,
"buys": 14,
"sells": 12,
"imbalance": 2,
"side": "buy-heavy",
"reason": "daily-count-input"
},
{
"id": "D003",
"index": 2,
"buys": 16,
"sells": 13,
"imbalance": 3,
"side": "buy-heavy",
"reason": "daily-count-input"
}
]
}Other exports
This module also exports
orderFlowImbalance, queueImbalance, kyleLambda, hasbrouckPriceImpact, 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
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.