// Returns from prices / bars. Session-aware: by default no return is computed across a session boundary // (the first bar of each session has no intraday return); overnight returns are optional and explicit. #pragma once #include #include #include "raid/core/types.hpp" #include "raid/data/bar_series.hpp" namespace raid::data { enum class ReturnKind { log, arithmetic }; /// Plain returns of a price vector (r_t = log(p_t/p_{t-1}) or p_t/p_{t-1} − 1), size n−1. std::vector returns(std::span prices, ReturnKind kind = ReturnKind::log); struct IntradayReturns { std::vector r; // concatenated intraday returns, session by session std::vector session_offsets; // per session: offsets into r (n_sessions + 1) std::vector session_dates; std::vector overnight; // close(prev session) → first price of session (NaN for the first session), one per session std::vector open_to_close; // open-to-close daily return (from first bar open to last bar close) std::vector close_to_close; // daily close-to-close return (NaN for first) std::span session(usize k) const { return std::span(r).subspan(static_cast(session_offsets[k]), static_cast(session_offsets[k + 1] - session_offsets[k])); } }; /// Intraday close-to-close bar returns within each session, plus daily summaries. `use_open_first` makes the first /// return of a session open→close of the first bar instead of skipping it (not the default; documented in the registry). IntradayReturns intraday_returns(const BarSeries& bars, ReturnKind kind = ReturnKind::log, bool use_open_first = false); } // namespace raid::data