30 m_price_volume +=
price.to_double() *
static_cast<double>(
shares);
37 [[nodiscard]]
auto value() const ->
double {
39 return std::numeric_limits<double>::quiet_NaN();
41 return m_price_volume /
static_cast<double>(m_volume);
47 [[nodiscard]]
auto volume() const noexcept -> std::uint64_t {
return m_volume; }
56 double m_price_volume {0.0};
57 std::uint64_t m_volume {0};
72 if (m_has_sample &&
timestamp > m_last_timestamp) {
73 const double elapsed =
static_cast<double>(
timestamp - m_last_timestamp);
74 m_price_time += m_last_price * elapsed;
75 m_total_time += elapsed;
77 m_last_price =
price.to_double();
85 [[nodiscard]]
auto value() const ->
double {
86 if (m_total_time <= 0.0) {
87 return m_has_sample ? m_last_price : std::numeric_limits<double>::quiet_NaN();
89 return m_price_time / m_total_time;
102 double m_price_time {0.0};
103 double m_total_time {0.0};
104 double m_last_price {0.0};
105 std::uint64_t m_last_timestamp {0};
106 bool m_has_sample {
false};
Running time-weighted average price.
auto add(StandardPrice price, std::uint64_t timestamp) -> void
Records that the price became price at timestamp (ns).
auto value() const -> double
The current TWAP, or NaN when no span has elapsed.
auto reset() noexcept -> void
Clears the accumulation (start a new interval).
Running volume-weighted average price.
auto reset() noexcept -> void
Clears the accumulation (start a new interval).
auto add(StandardPrice price, std::uint64_t shares) -> void
Adds an execution of shares at price to the accumulation.
auto volume() const noexcept -> std::uint64_t
The total shares accumulated so far.
auto value() const -> double
The current VWAP, or NaN when no volume has been added.
Strongly typed, fixed-point price representation for ITCH price fields.