4#include "./time_index.hpp"
8#include <algotradelib/core>
37 BarField::TRADED_VALUE,
49 return static_cast<std::size_t
>(field);
67 case BarField::VOLUME:
69 case BarField::TRADED_VALUE:
70 return "traded_value";
77 "all_bar_fields must list every BarField"
101 : instrument_(std::move(
instrument)), index_(std::move(index)) {
102 values_ = math::Matrix::Constant(
113 std::size_t
rows() const noexcept {
return index_.size(); }
182 throw std::out_of_range(
"frame row is past the end");
199 throw std::out_of_range(
"frame row is past the end");
229 std::vector<TimeIndex::Instant> stamps;
230 stamps.reserve(series.
bars_.size());
231 for (
const auto& bar : series.
bars_) {
232 stamps.push_back(bar.timestamp_);
236 for (std::size_t row = 0; row < series.
bars_.size(); ++row) {
237 const auto& bar = series.
bars_[row];
246 frame.
set(row, BarField::VOLUME,
to_scalar(bar.volume_));
247 if (bar.traded_value_) {
248 frame.
set(row, BarField::TRADED_VALUE,
to_scalar(*bar.traded_value_));
One instrument's bars as numeric columns: one row per bar, one column per BarField.
const TimeIndex & time() const noexcept
Returns the instants of the rows.
std::size_t columns() const noexcept
Returns the number of columns.
const InstrumentId & instrument() const noexcept
Returns the instrument the frame describes.
math::SeriesView close() const
Returns the close column.
math::SeriesView volume() const
Returns the volume column.
SeriesFrame()=default
Constructs an empty frame.
Scalar at(std::size_t row, BarField field) const
Reads one value.
void set(std::size_t row, BarField field, Scalar value)
Writes one value.
math::SeriesView open() const
Returns the open column.
std::size_t rows() const noexcept
Returns the number of rows.
math::SeriesView high() const
Returns the high column.
math::MatrixView values() const
Returns all values.
SeriesFrame(TimeIndex index, InstrumentId instrument={})
Constructs a frame with one row per instant, every value missing().
math::SeriesView low() const
Returns the low column.
math::SeriesView column(BarField field) const
Returns one field's column.
The instants a frame's rows correspond to, strictly ascending.
TimeIndex()=default
Constructs an empty index.
std::size_t size() const noexcept
Returns the number of instants.
Conversions between exact Decimal64 values and the analytics Scalar.
The linear algebra types of the math module: Matrix, Vector, SeriesView, MutableSeriesView,...
Returns, rolling statistics, indicators and performance metrics over numeric series.
constexpr std::array< BarField, 6 > all_bar_fields
Every BarField, in declaration order.
BarField
A bar field, used as a column of a SeriesFrame.
constexpr std::string_view bar_field_name(BarField field) noexcept
Returns a lowercase display name for a field, such as "close".
constexpr std::size_t bar_field_count
The number of BarField values, and so of columns in a SeriesFrame.
Scalar missing()
Returns the value that stands for "no observation"; see math::missing.
constexpr std::size_t bar_field_index(BarField field) noexcept
Returns the column position of a field in a SeriesFrame.
Scalar to_scalar(const Decimal64 &value)
Converts an exact decimal to the nearest Scalar.
SeriesFrame from_bars(const BarSeries &series)
Converts a bar series into a frame of Scalar columns.
double Scalar
The floating-point type the analytics and math layers compute in (double).
Eigen::Matrix< Scalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
A dense, column-major matrix of Scalar.
Eigen::Index Index
The signed index type of rows and columns.
Eigen::Ref< const Matrix > MatrixView
A read-only reference to a whole matrix.
Eigen::Ref< const Vector > SeriesView
A read-only reference to one series.
The library: broker-neutral types (core), and the modules below.
constexpr bool lists_every_value(const std::array< Enum, N > &values, IsEnumerator is_enumerator) noexcept
Tests whether a list holds every value of an enum exactly once, in any order.
The bars of one instrument and interval, oldest first.
InstrumentId instrument_
The instrument.
std::vector< Bar > bars_
The bars, oldest first.
Identifies an instrument: its country, venue and symbol.