![]() |
algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
|
The instants a frame's rows correspond to, strictly ascending. More...
#include <algotradelib/src/analytics/time_index.hpp>
Public Types | |
| using | Instant = std::chrono::system_clock::time_point |
| The instant type of the index. | |
Public Member Functions | |
| TimeIndex ()=default | |
| Constructs an empty index. | |
| TimeIndex (std::vector< Instant > stamps) | |
| Constructs an index over a sequence of instants. | |
| std::size_t | size () const noexcept |
| Returns the number of instants. | |
| bool | empty () const noexcept |
| Tests whether the index is empty. | |
| const Instant & | at (std::size_t position) const |
| Returns the instant of one row. | |
| const std::vector< Instant > & | stamps () const noexcept |
| Returns all instants. | |
| std::optional< std::size_t > | find (const Instant &when) const |
| Finds the row of an exact instant. | |
| std::optional< std::size_t > | asof (const Instant &when) const |
| Finds the latest row at or before an instant ("as of" lookup). | |
Friends | |
| bool | operator== (const TimeIndex &lhs, const TimeIndex &rhs) |
| Compares two indices instant by instant. | |
| bool | operator!= (const TimeIndex &lhs, const TimeIndex &rhs) |
| Compares two indices for inequality. | |
The instants a frame's rows correspond to, strictly ascending.
Maps an instant to a row position. Lookups (find, asof) are binary searches, meant for asking about one instant at a time.
Definition at line 20 of file time_index.hpp.
| using algotradelib::analytics::TimeIndex::Instant = std::chrono::system_clock::time_point |
The instant type of the index.
Definition at line 23 of file time_index.hpp.
|
default |
Constructs an empty index.
Referenced by algotradelib::analytics::from_bars(), algotradelib::analytics::Panel::from_bars(), operator!=, and operator==.
|
inlineexplicit |
Constructs an index over a sequence of instants.
| stamps | The instants, one per row, strictly ascending. |
| std::invalid_argument | if stamps is not strictly ascending. |
Definition at line 34 of file time_index.hpp.
|
inline |
Finds the latest row at or before an instant ("as of" lookup).
Never looks forward, so it is safe to use in a backtest.
| when | The instant to look up. |
Definition at line 97 of file time_index.hpp.
|
inline |
Returns the instant of one row.
| position | The row position. |
| std::out_of_range | if position is past the end. |
Definition at line 61 of file time_index.hpp.
|
inlinenoexcept |
Tests whether the index is empty.
Definition at line 52 of file time_index.hpp.
|
inline |
Finds the row of an exact instant.
| when | The instant to find. |
Definition at line 80 of file time_index.hpp.
|
inlinenoexcept |
Returns the number of instants.
Definition at line 46 of file time_index.hpp.
Referenced by algotradelib::analytics::Panel::from_bars().
|
inlinenoexcept |
Returns all instants.
Definition at line 72 of file time_index.hpp.
Referenced by TimeIndex().
Compares two indices for inequality.
| lhs | The first index. |
| rhs | The second index. |
Definition at line 121 of file time_index.hpp.
Compares two indices instant by instant.
| lhs | The first index. |
| rhs | The second index. |
Definition at line 111 of file time_index.hpp.