SPB Git

spb/wp40_uqo

Public MIT
3.0 KB · 55 lines cpp
1// Realized measures from intraday returns (per session). Definitions (registry keys realized.*), with M intraday2// returns r_1..r_M of one session:3//   RV   = Σ r_j²                                                   (Andersen–Bollerslev–Diebold–Labys 2003)4//   BPV  = μ₁⁻² · (M/(M−1)) · Σ_{j=2}^{M} |r_j||r_{j−1}|,  μ₁ = √(2/π)   (Barndorff-Nielsen & Shephard 2004; the finite-sample5//          factor M/(M−1) is optional: `bpv_finite_sample` — highfrequency::rBPCov applies it by default (makeReturns scaling))6//   RSV− = Σ r_j² 1{r_j<0},  RSV+ = Σ r_j² 1{r_j>0}                 (Barndorff-Nielsen–Kinnebrock–Shephard 2010)7//   RQ   = (M/3) · Σ r_j⁴                                             (Barndorff-Nielsen & Shephard 2002; BPQ 2016 HARQ)8//   J    = max(RV − BPV, 0), relative jump = J / RV                  (Andersen–Bollerslev–Diebold 2007 proxy, no test)9//   TriPV = μ_{4/3}⁻³ · (M/(M−2)) · Σ |r_j|^{4/3}|r_{j−1}|^{4/3}|r_{j−2}|^{4/3},  μ_{4/3} = 2^{2/3} Γ(7/6)/Γ(1/2)10//   BNS ratio test statistic (Tier C, Huang–Tauchen 2005 log version) is NOT implemented in Tier A.11// Realized covariance: RCov_{ab} = Σ_j r_{a,j} r_{b,j} on synchronized grids (same session, same timestamps).12#pragma once13#include <span>14#include <vector>15#include <string>16#include <Eigen/Dense>17#include "raid/core/types.hpp"18#include "raid/core/plan.hpp"19#include "raid/data/returns.hpp"20#include "raid/data/panel.hpp"21#include "raid/backend/backend.hpp"2223namespace raid::est {2425struct RealizedOptions {26  bool bpv_finite_sample{true};27  bool annualize{false};        // multiply variances by `periods_per_year`28  f64 periods_per_year{252.0};29  ExecutionPlan plan{};30};3132struct RealizedMeasures {33  std::vector<Date> sessions;34  std::vector<usize> n_returns;     // M per session35  std::vector<f64> rv, bpv, rsv_neg, rsv_pos, rq, jump, tripv;36  std::vector<f64> daily_return;    // Σ r_j (open-to-close log return when log returns are used)37  backend::KernelStats stats;       // backend / precision / timing of the batched part38  std::vector<std::string> warnings;39};4041/// Per-session realized measures for one instrument from intraday returns (data::IntradayReturns).42RealizedMeasures realized_measures(const data::IntradayReturns& ir, const RealizedOptions& opt = {});43/// Batched over a CSR batch of return segments (one segment = one session or one series), returns the same vectors.44RealizedMeasures realized_measures_batch(const backend::Batch& b, const RealizedOptions& opt = {});4546/// Realized covariance / correlation of N aligned return series (T × N dense).47struct RealizedCov { Eigen::MatrixXd cov; Eigen::MatrixXd corr; usize n_obs; };48RealizedCov realized_covariance(const Eigen::Ref<const Eigen::MatrixXd>& R);4950/// Finite-sample constants exposed for tests and the paper appendix.51constexpr f64 kMu1 = 0.7978845608028654;      // √(2/π)52f64 mu_p(f64 p);                               // E|Z|^p for Z ~ N(0,1)5354}  // namespace raid::est55
Files · 114c1f28e7a32db3097a169b3ffc45c8b166be67
Menu

Theme