Special Relativity in Financial Modeling 1.0.0
Lorentz transforms, spacetime classification, and geodesic price paths for quantitative finance
Loading...
Searching...
No Matches
engine.hpp
Go to the documentation of this file.
1#pragma once
2/**
3 * @file engine.hpp
4 * @brief Full SRFM pipeline engine: CSV → relativistic signal (AGT-13 / SRFM)
5 *
6 * Module: src/engine/
7 * Owner: AGT-13 (Adversarial hardening) — 2026-03-01
8 *
9 * Responsibility
10 * --------------
11 * Orchestrate the complete Special Relativity Financial Modelling pipeline:
12 *
13 * CSV bytes → parse prices → BetaCalculator → SpacetimeManifold
14 * → GeodesicSolver → RelativisticSignalProcessor → PipelineResult
15 *
16 * The Engine is the primary fuzzing surface: it must handle arbitrary byte
17 * sequences without crashing, UB, or infinite loops.
18 *
19 * Design Constraints
20 * ------------------
21 * • Accepts std::string_view (including binary garbage).
22 * • Returns std::nullopt for any unparseable or physically invalid input.
23 * • Must never abort, crash, or access out-of-bounds memory.
24 * • All public methods are noexcept.
25 *
26 * NOT Responsible For
27 * • Network I/O or file system access.
28 * • Multi-frame state (stateless).
29 */
30
31#include <array>
32#include <cmath>
33#include <optional>
34#include <string_view>
35#include <vector>
36
37#include "../manifold/spacetime_manifold.hpp"
38
39namespace srfm::engine {
40
42
43// ── PipelineResult ────────────────────────────────────────────────────────────
44
45/**
46 * @brief Full output of one Engine pipeline run.
47 */
49 double beta{0.0}; ///< Normalised market velocity β
50 double gamma{1.0}; ///< Lorentz factor γ ≥ 1
51 double rapidity{0.0}; ///< Rapidity φ = atanh(β)
52 double doppler{1.0}; ///< Doppler factor D(β) > 0
53 Regime regime{Regime::Newtonian}; ///< Relativistic regime classification
54 double relativistic_signal{0.0}; ///< γ-corrected representative signal
55 std::size_t price_count{0}; ///< Number of price observations parsed
56};
57
58// ── Engine ────────────────────────────────────────────────────────────────────
59
60/**
61 * @brief Stateless end-to-end SRFM pipeline engine.
62 *
63 * @example
64 * @code
65 * Engine engine;
66 * auto result = engine.process("100.0,101.0,102.5,101.8,103.0");
67 * if (result) {
68 * // result->beta ≈ relativistic velocity of this price window
69 * }
70 * @endcode
71 */
72class Engine {
73public:
74 Engine() noexcept = default;
75
76 /**
77 * @brief Process a CSV-like byte sequence through the full pipeline.
78 *
79 * Parsing rules:
80 * • Tokens are split on comma, newline, space, or tab.
81 * • Tokens that parse as finite positive doubles become price observations.
82 * • At least 2 valid price observations are required.
83 * • Non-numeric tokens are silently skipped.
84 *
85 * @param data Arbitrary byte sequence (may contain binary, NaN text, etc.)
86 * @return PipelineResult, or std::nullopt if fewer than 2 prices are found
87 * or if any physics computation fails.
88 */
89 [[nodiscard]] std::optional<PipelineResult>
90 process(std::string_view data) const noexcept;
91
92private:
93 /// Parse tokens from data into a vector of finite positive prices.
94 [[nodiscard]] std::vector<double>
95 parse_prices(std::string_view data) const noexcept;
96};
97
98} // namespace srfm::engine
Engine() noexcept=default
std::optional< PipelineResult > process(std::string_view data) const noexcept
Process a CSV-like byte sequence through the full pipeline.
Definition engine.cpp:60
Regime
Market relativistic regime classification.
Full output of one Engine pipeline run.
Definition engine.hpp:48
double rapidity
Rapidity φ = atanh(β)
Definition engine.hpp:51
double gamma
Lorentz factor γ ≥ 1.
Definition engine.hpp:50
double doppler
Doppler factor D(β) > 0.
Definition engine.hpp:52
Regime regime
Relativistic regime classification.
Definition engine.hpp:53
std::size_t price_count
Number of price observations parsed.
Definition engine.hpp:55
double beta
Normalised market velocity β
Definition engine.hpp:49
double relativistic_signal
γ-corrected representative signal
Definition engine.hpp:54