63template<std::
size_t N = 3u>
65 static_assert(
N >= 1u,
"BetaCalculator: N must be at least 1");
66 static_assert(
N <= 64u,
"BetaCalculator: N must be at most 64 (compile-time array limit)");
90 if (!std::isfinite(close) || close <= 0.0)
return;
92 if (prev_close_ > 0.0 && std::isfinite(prev_close_)) {
94 const double lr = std::log(close / prev_close_);
95 returns_[ret_pos_] =
lr;
96 ret_pos_ = (ret_pos_ + 1u) %
N;
97 if (ret_count_ <
N) ++ret_count_;
114 if (ret_count_ <
N)
return 0.0;
118 for (std::size_t
i = 0u;
i <
N; ++
i) sum += returns_[
i];
119 const double velocity = sum /
static_cast<double>(
N);
122 const double raw = velocity / c_market_;
159 std::array<double,N> returns_{};
160 std::size_t ret_pos_{0};
161 std::size_t ret_count_{0};
162 double prev_close_{0.0};
163 std::size_t close_count_{0};
Online β estimator with a sliding window of N log-returns.
double beta() const noexcept
Current β estimate.
double c_market() const noexcept
Configured market speed-of-light constant.
void reset() noexcept
Reset all state as if no ticks have been seen.
BetaCalculator(double c_market=DEFAULT_C_MARKET) noexcept
Construct with a market speed-of-light calibration constant.
void update(double close) noexcept
Ingest one new close price and update the rolling log-return buffer.
bool warmed_up() const noexcept
Whether enough data has been seen to produce a reliable β.
std::size_t ret_count() const noexcept
Number of log-returns accumulated (capped at N).
std::size_t close_count() const noexcept
Number of close prices ingested so far.
constexpr double DEFAULT_C_MARKET
constexpr double BETA_MAX_SAFE
Maximum safe |β| — mirrors srfm::momentum::BETA_MAX_SAFE.