// Estimate / InferenceResult / Provenance — the common output contract of every RAID estimator. #pragma once #include #include #include #include #include #include "raid/core/types.hpp" namespace raid { struct Provenance { std::string dataset_id; // e.g. market_bars.stock.1m.raw i64 dataset_version{-1}; // X-Dataset-Version (−1 = synthetic / unknown) std::vector request_ids; // X-Request-ID values std::vector input_hashes; // SHA-256 of input files / fixtures std::string code_version; // git short SHA + RAID_VERSION std::string source; // "FirstRate Data via FinData OS" | "synthetic" nlohmann::json extra; nlohmann::json to_json() const; }; struct Convergence { bool converged{false}; int iterations{0}; int function_evaluations{0}; f64 gradient_norm{std::numeric_limits::quiet_NaN()}; int status_code{0}; std::string message; nlohmann::json to_json() const; }; struct InferenceResult { std::vector std_errors; std::vector t_stats; std::vector p_values; Eigen::MatrixXd covariance; std::string covariance_type; // classical | hc0..hc3 | hac_bartlett(L) | cluster | qmle_sandwich | hessian f64 small_sample_correction{1.0}; nlohmann::json to_json() const; }; struct Estimate { std::string model; // registry key, e.g. "har.rv", "garch.gjr.t" std::vector names; std::vector coefficients; f64 loss{std::numeric_limits::quiet_NaN()}; // −loglik or RSS depending on the model (documented per model) std::optional inference; Convergence convergence; std::vector warnings; f64 runtime_seconds{0}; Backend backend{Backend::cpu}; Precision precision{Precision::fp64}; Provenance provenance; usize n_obs{0}; nlohmann::json extra; // model-specific (sigma2 path, forecasts, diagnostics) /// A failed optimisation is never a success: ok() requires convergence. bool ok() const { return convergence.converged && !coefficients.empty(); } nlohmann::json to_json() const; }; } // namespace raid