quantpylib.hft.features
flow_pnl(trades)
Calculates the pnl of the a set of trades.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trades
|
ndarray
|
2d-array of trades as |
required |
Returns:
Type | Description |
---|---|
np.ndarray: The timestamps, running PnLs and cumulative volumes. |
impact_price(ob, notional)
Calculate the volume-weighted price for a given notional amount.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ob
|
ndarray
|
The order book levels as an array of [price, volume]. |
required |
notional
|
float
|
The notional amount. |
required |
Returns:
Name | Type | Description |
---|---|---|
float |
The volume-weighted price. |
rolling_vol(mids, n, exp=False)
Calculate rolling volatility of the mid prices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mids
|
ndarray
|
Array of mid prices. |
required |
n
|
int
|
The size of the rolling window. |
required |
exp
|
bool
|
Whether to use exponential weighting. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
np.ndarray: An array of rolling volatilities. |
trade_imbalance(trades, decay_function=lambda sample: exponential_weights(arr=sample, unique_values=True, normalize=True))
Calculate the trade imbalance for a given set of trades w.r.t. some decay function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trades
|
ndarray
|
2d-array of trades as |
required |
decay_function
|
function
|
The decay function. Defaults to |
lambda sample: exponential_weights(arr=sample, unique_values=True, normalize=True)
|
vamp(bids, asks, notional=None, bid_notional=None, ask_notional=None)
Calculate the Volume Adjusted Mid Price (VAMP).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bids
|
ndarray
|
Array of bid levels as [price, volume]. |
required |
asks
|
ndarray
|
Array of ask levels as [price, volume]. |
required |
notional
|
float
|
The notional amount for both sides of the orderbook (each). Defaults to None. |
None
|
bid_notional
|
float
|
The notional amount for bids. Defaults to |
None
|
ask_notional
|
float
|
The notional amount for asks. Defaults to |
None
|
Returns:
Name | Type | Description |
---|---|---|
float |
The calculated VAMP. |
vol(sample, exp=False)
Calculate the sample volatility.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample
|
ndarray
|
The input sample. |
required |
exp
|
bool
|
Whether to use exponential weighting. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
float |
The calculated sample volatility. |