![]() |
algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
|
The most recent observations of a few fields, for a strategy fed one bar at a time. More...
#include <algotradelib/src/analytics/series_buffer.hpp>
Public Types | |
| using | Instant = TimeIndex::Instant |
| The instant type observations are stamped with. | |
Public Member Functions | |
| SeriesBuffer (std::size_t capacity, std::size_t fields=bar_field_count) | |
| Constructs an empty buffer. | |
| std::size_t | capacity () const noexcept |
| Returns the most observations the buffer holds. | |
| std::size_t | fields () const noexcept |
| Returns the number of values per observation. | |
| std::size_t | size () const noexcept |
| Returns the number of observations held. | |
| bool | empty () const noexcept |
| Tests whether the buffer is empty. | |
| bool | full () const noexcept |
| Tests whether the buffer holds capacity() observations. | |
| std::size_t | compactions () const noexcept |
| Returns how many times the buffer moved its contents to the front of its storage. | |
| void | push (Instant when, math::SeriesView row) |
| Appends one observation, dropping the oldest if the buffer is full. | |
| void | push (Instant when, const std::vector< Scalar > &row) |
| Appends one observation, dropping the oldest if the buffer is full. | |
| void | push (const Bar &bar) |
| Appends one bar, dropping the oldest observation if the buffer is full. | |
| math::SeriesView | column (std::size_t field) const |
| Returns one field's values, oldest first. | |
| math::SeriesView | column (BarField field) const |
| Returns one bar field's values, oldest first. | |
| Scalar | at (std::size_t position, std::size_t field) const |
| Reads one value. | |
| Instant | instant (std::size_t position) const |
| Returns the instant of one observation. | |
| Instant | newest_instant () const |
| Returns the instant of the newest observation. | |
| void | clear () noexcept |
| Discards every observation; the storage is kept. | |
The most recent observations of a few fields, for a strategy fed one bar at a time.
Holds up to capacity() observations. Until it is full, each push adds one; after that, each push also drops the oldest. Check full() before computing an indicator whose window is the capacity, so it is never computed from fewer observations than its window.
column() returns the trailing values of one field, oldest first, as one contiguous view of the buffer's own storage. Storage is allocated once at construction and never grows. The trailing statistics themselves are the rolling_* functions in rolling.hpp.
Definition at line 30 of file series_buffer.hpp.
The instant type observations are stamped with.
Definition at line 33 of file series_buffer.hpp.
|
inline |
Constructs an empty buffer.
| capacity | The most observations the buffer holds. |
| fields | The number of values per observation; the default holds every BarField. |
Definition at line 42 of file series_buffer.hpp.
|
inline |
Reads one value.
| position | The observation, counting from 0 for the oldest held. |
| field | The field's column position. |
| std::out_of_range | if position or field is past the end. |
Definition at line 199 of file series_buffer.hpp.
|
inlinenoexcept |
Returns the most observations the buffer holds.
Definition at line 56 of file series_buffer.hpp.
Referenced by SeriesBuffer().
|
inlinenoexcept |
Discards every observation; the storage is kept.
Definition at line 235 of file series_buffer.hpp.
|
inline |
|
inline |
|
inlinenoexcept |
Returns how many times the buffer moved its contents to the front of its storage.
Definition at line 86 of file series_buffer.hpp.
|
inlinenoexcept |
Tests whether the buffer is empty.
Definition at line 74 of file series_buffer.hpp.
|
inlinenoexcept |
Returns the number of values per observation.
Definition at line 62 of file series_buffer.hpp.
Referenced by SeriesBuffer().
|
inlinenoexcept |
Tests whether the buffer holds capacity() observations.
Definition at line 80 of file series_buffer.hpp.
|
inline |
Returns the instant of one observation.
| position | The observation, counting from 0 for the oldest held. |
| std::out_of_range | if position is past the end. |
Definition at line 215 of file series_buffer.hpp.
|
inline |
Returns the instant of the newest observation.
| std::out_of_range | if the buffer is empty. |
Definition at line 227 of file series_buffer.hpp.
Referenced by push().
|
inline |
Appends one bar, dropping the oldest observation if the buffer is full.
The bar's fields go to the columns in BarField order; a bar with no open or traded value stores missing() there.
| bar | The bar; its timestamp_ must be later than the newest observation. |
| std::invalid_argument | if the buffer was not built with bar_field_count fields, or the bar is not later than the newest observation. |
Definition at line 147 of file series_buffer.hpp.
|
inline |
Appends one observation, dropping the oldest if the buffer is full.
| when | The observation's instant; must be later than the newest one held. |
| row | The observation's values, exactly fields() of them. |
| std::invalid_argument | if row has the wrong size or when is not later than the newest observation. |
Definition at line 129 of file series_buffer.hpp.
|
inline |
Appends one observation, dropping the oldest if the buffer is full.
| when | The observation's instant; must be later than the newest one held. |
| row | The observation's values, exactly fields() of them. |
| std::invalid_argument | if row has the wrong size or when is not later than the newest observation. |
Definition at line 96 of file series_buffer.hpp.
|
inlinenoexcept |
Returns the number of observations held.
Definition at line 68 of file series_buffer.hpp.