quantpylib.hft.trades
Trades
__init__(buffer_size=100)
A class representing a buffer for storing trade logs with attributes for timestamp, price, size, and direction.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
buffer_size |
int
|
The size of the buffer for storing trades. Defaults to 100. |
100
|
append(trade=None, ts=None, price=None, size=None, dir=None)
Append a new trade to the buffer. A trade is specified by the arguments ts,price,size,dir or with the 4-tuple (ts,price,size,dir).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ts |
int
|
The timestamp of the trade. Defaults to None. |
None
|
price |
float
|
The price of the trade. Defaults to None. |
None
|
size |
float
|
The size of the trade. Defaults to None. |
None
|
dir |
int
|
The direction of the trade, 1 or -1. Defaults to None. |
None
|
trade |
tuple
|
A tuple representing the trade (ts,price,size,dir). |
None
|
buffer_len()
Get the length of the trade buffer.
Returns:
Name | Type | Description |
---|---|---|
int |
The length of the trade buffer. |
clear_buffer()
Clear the trade buffer.
get_buffer()
Get the current contents of the trade buffer.
Returns:
Type | Description |
---|---|
np.ndarray: The array of trades in the buffer. |
get_imbalance(n=None, default=0.0, decay_function=None)
Get the trade imbalance over the last n trades.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
int
|
The number of trades to consider. Defaults to the whole stored buffer. |
None
|
default |
float
|
The default value to return if the buffer has less than |
0.0
|
decay_function |
function
|
The decay function to apply to the samples. Defaults to exponential decay. |
None
|
load_buffer(trade_buffer)
staticmethod
Load a Trades object from an existing buffer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trade_buffer |
RingBuffer
|
An existing buffer containing trade logs. |
required |
Returns:
Name | Type | Description |
---|---|---|
Trades |
The loaded Trades object. |
load_numpy_arr(trades_array)
staticmethod
Load a Trades object from existing numpy arrays.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trades_array |
ndarray
|
Array containing trade logs with each row containing |
required |
Returns:
Name | Type | Description |
---|---|---|
Trades |
The loaded Trades object. |