1// Estimate / InferenceResult / Provenance — the common output contract of every RAID estimator.2#pragma once3#include <string>4#include <vector>5#include <optional>6#include <Eigen/Dense>7#include <nlohmann/json.hpp>8#include "raid/core/types.hpp"910namespace raid {1112struct Provenance {13 std::string dataset_id; // e.g. market_bars.stock.1m.raw14 i64 dataset_version{-1}; // X-Dataset-Version (−1 = synthetic / unknown)15 std::vector<std::string> request_ids; // X-Request-ID values16 std::vector<std::string> input_hashes; // SHA-256 of input files / fixtures17 std::string code_version; // git short SHA + RAID_VERSION18 std::string source; // "FirstRate Data via FinData OS" | "synthetic"19 nlohmann::json extra;20 nlohmann::json to_json() const;21};2223struct Convergence {24 bool converged{false};25 int iterations{0};26 int function_evaluations{0};27 f64 gradient_norm{std::numeric_limits<f64>::quiet_NaN()};28 int status_code{0};29 std::string message;30 nlohmann::json to_json() const;31};3233struct InferenceResult {34 std::vector<f64> std_errors;35 std::vector<f64> t_stats;36 std::vector<f64> p_values;37 Eigen::MatrixXd covariance;38 std::string covariance_type; // classical | hc0..hc3 | hac_bartlett(L) | cluster | qmle_sandwich | hessian39 f64 small_sample_correction{1.0};40 nlohmann::json to_json() const;41};4243struct Estimate {44 std::string model; // registry key, e.g. "har.rv", "garch.gjr.t"45 std::vector<std::string> names;46 std::vector<f64> coefficients;47 f64 loss{std::numeric_limits<f64>::quiet_NaN()}; // −loglik or RSS depending on the model (documented per model)48 std::optional<InferenceResult> inference;49 Convergence convergence;50 std::vector<std::string> warnings;51 f64 runtime_seconds{0};52 Backend backend{Backend::cpu};53 Precision precision{Precision::fp64};54 Provenance provenance;55 usize n_obs{0};56 nlohmann::json extra; // model-specific (sigma2 path, forecasts, diagnostics)57 /// A failed optimisation is never a success: ok() requires convergence.58 bool ok() const { return convergence.converged && !coefficients.empty(); }59 nlohmann::json to_json() const;60};6162} // namespace raid63