quantpylib.utilities.cringbuffer
RingBuffer
A circular buffer implementation using numpy arrays.
dtype
property
Returns the data type of the buffer elements.
Returns:
Type | Description |
---|---|
data-type: The data type of the buffer elements. |
is_full
property
Checks if the buffer is full.
Returns:
Name | Type | Description |
---|---|---|
bool |
True if the buffer is full, False otherwise. |
maxlen
property
Returns the maximum length of the buffer.
Returns:
Name | Type | Description |
---|---|---|
int |
The maximum number of elements the buffer can hold. |
shape
property
Returns the shape of the buffer.
Returns:
Name | Type | Description |
---|---|---|
tuple |
The shape of the buffer. |
__array__()
Returns the buffer as a numpy array.
Returns:
Type | Description |
---|---|
numpy.ndarray: The buffer as a numpy array. |
__getitem__(item)
Returns the element(s) at the specified index or slice.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
item
|
int or slice
|
The index or slice to retrieve. |
required |
Returns:
Type | Description |
---|---|
The element(s) at the specified index or slice. |
__init__(capacity, dtype=float)
Initializes the RingBuffer with a specified capacity and data type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
capacity
|
int
|
The maximum number of elements the buffer can hold. |
required |
dtype
|
data - type
|
Desired data-type for the array. Default is np.float64. |
float
|
Raises:
Type | Description |
---|---|
ValueError
|
If the capacity is not a positive integer. |
__iter__()
Returns an iterator over the buffer.
Returns:
Name | Type | Description |
---|---|---|
iterator |
An iterator over the buffer. |
__len__()
Returns the number of elements in the buffer.
Returns:
Name | Type | Description |
---|---|---|
int |
The number of elements in the buffer. |
__repr__()
Returns a string representation of the buffer.
Returns:
Name | Type | Description |
---|---|---|
str |
A string representation of the buffer. |
append(value)
Appends a value to the right end of the buffer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
The value to append. |
required |
appendleft(value)
Appends a value to the left end of the buffer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
The value to append. |
required |
clear()
Clears the buffer.
peek()
Returns the rightmost element without removing it.
Returns:
Type | Description |
---|---|
The rightmost element. |
Raises:
Type | Description |
---|---|
IndexError
|
If the buffer is empty. |
peekleft()
Returns the leftmost element without removing it.
Returns:
Type | Description |
---|---|
The leftmost element. |
Raises:
Type | Description |
---|---|
IndexError
|
If the buffer is empty. |
pop()
Removes and returns the rightmost element.
Returns:
Type | Description |
---|---|
The rightmost element. |
Raises:
Type | Description |
---|---|
IndexError
|
If the buffer is empty. |
popleft()
Removes and returns the leftmost element.
Returns:
Type | Description |
---|---|
The leftmost element. |
Raises:
Type | Description |
---|---|
IndexError
|
If the buffer is empty. |