Special Relativity in Financial Modeling 1.0.0
Lorentz transforms, spacetime classification, and geodesic price paths for quantitative finance
Loading...
Searching...
No Matches
momentum.hpp
Go to the documentation of this file.
1#pragma once
2// Forward declaration: SIMD acceleration module needs friend access to
3// construct LorentzFactor objects from pre-computed scalar values without
4// an extra scalar sqrt per element. This is a purely internal trust
5// boundary; the public API is unchanged.
6namespace srfm::simd { struct SimdGammaCompute; }
7
8/**
9 * @file momentum.hpp
10 * @brief Momentum-Velocity Signal Processor (AGT-03 / SRFM)
11 *
12 * Module: src/momentum/
13 * Owner: AGT-03 (Builder) — 2026-02-28
14 *
15 * Responsibility
16 * --------------
17 * Compute relativistic momentum signals for financial time-series:
18 *
19 * p_rel = γ · m_eff · v_market
20 *
21 * where
22 * β (BetaVelocity) = normalised market velocity, |β| ∈ [0, BETA_MAX_SAFE)
23 * γ (LorentzFactor) = 1/√(1−β²) ≥ 1
24 * m_eff (EffectiveMass) = ADV / ADV_baseline (liquidity proxy)
25 * v_market = raw signal value
26 *
27 * Higher liquidity → higher m_eff → momentum harder to shift; this mirrors
28 * the relativistic mechanic where higher rest-mass resists acceleration.
29 *
30 * Design Constraints
31 * ------------------
32 * • Zero raw pointers in the public API.
33 * • All fallible operations return std::optional (no exceptions thrown).
34 * • All public methods are noexcept.
35 * • Thread-safe: RelativisticSignalProcessor is stateless.
36 *
37 * NOT Responsible For
38 * -------------------
39 * • Sourcing ADV data (caller provides EffectiveMass)
40 * • Signal persistence (stateless)
41 * • Cross-asset normalisation
42 *
43 * Note on upstream headers
44 * ------------------------
45 * AGT-01 (src/lorentz/) and AGT-02 (src/manifold/) had not yet landed in
46 * this repository at the time AGT-03 shipped. The Lorentz primitives are
47 * therefore defined here. When AGT-01's header is available, replace the
48 * BetaVelocity / LorentzFactor definitions with an #include of that header.
49 */
50
51#include <cmath>
52#include <optional>
53#include <span>
54#include <vector>
55
56namespace srfm::momentum {
57
58// ── Constants ─────────────────────────────────────────────────────────────────
59
60/// Upper bound for safe β values. At β = 1.0 γ → ∞; values at or above
61/// this threshold are rejected to keep all arithmetic finite.
62inline constexpr double BETA_MAX_SAFE = 0.9999;
63
64// ── BetaVelocity ──────────────────────────────────────────────────────────────
65
66/**
67 * @brief Normalised market velocity β = price_velocity / c_market.
68 *
69 * Invariant: std::isfinite(value()) && std::abs(value()) < BETA_MAX_SAFE.
70 * Construct exclusively via BetaVelocity::make().
71 */
73public:
74 /**
75 * @brief Validate and construct a BetaVelocity.
76 * @param value Candidate β value.
77 * @return std::nullopt when |value| ≥ BETA_MAX_SAFE or value is non-finite.
78 */
79 [[nodiscard]] static std::optional<BetaVelocity>
80 make(double value) noexcept;
81
82 /// Returns the raw β value.
83 [[nodiscard]] double value() const noexcept { return value_; }
84
85private:
86 explicit BetaVelocity(double v) noexcept : value_{v} {}
87 double value_{0.0};
88};
89
90// ── LorentzFactor ─────────────────────────────────────────────────────────────
91
92/**
93 * @brief Pre-computed Lorentz factor γ = 1/√(1−β²). Always ≥ 1.0.
94 *
95 * Obtained exclusively from lorentz_gamma(BetaVelocity).
96 * Default value is 1.0 (the Newtonian limit at β = 0).
97 */
99public:
100 /// Default-constructs to the Newtonian identity γ = 1.
101 LorentzFactor() noexcept : value_{1.0} {}
102
103 /// Returns the raw γ value.
104 [[nodiscard]] double value() const noexcept { return value_; }
105
106private:
107 friend std::optional<LorentzFactor>
108 lorentz_gamma(BetaVelocity beta) noexcept;
109
110 /// Internal SIMD module — constructs LorentzFactor from a pre-validated
111 /// gamma value without re-computing sqrt. Caller guarantees v >= 1.0 and
112 /// std::isfinite(v).
114
115 explicit LorentzFactor(double v) noexcept : value_{v} {}
116 double value_{1.0};
117};
118
119// ── EffectiveMass ─────────────────────────────────────────────────────────────
120
121/**
122 * @brief ADV-based effective mass proxy.
123 *
124 * m_eff = adv / adv_baseline.
125 * Invariant: value() > 0 and std::isfinite(value()).
126 * Construct via EffectiveMass::make() or EffectiveMass::from_adv().
127 */
129public:
130 /**
131 * @brief Validate and construct an EffectiveMass.
132 * @return std::nullopt when value ≤ 0 or non-finite.
133 */
134 [[nodiscard]] static std::optional<EffectiveMass>
135 make(double value) noexcept;
136
137 /**
138 * @brief Construct from raw ADV and a baseline ADV.
139 *
140 * m_eff = adv / adv_baseline.
141 * @return std::nullopt when either argument is non-positive or non-finite.
142 */
143 [[nodiscard]] static std::optional<EffectiveMass>
144 from_adv(double adv, double adv_baseline) noexcept;
145
146 /// Returns the raw m_eff value.
147 [[nodiscard]] double value() const noexcept { return value_; }
148
149private:
150 explicit EffectiveMass(double v) noexcept : value_{v} {}
151 double value_{1.0};
152};
153
154// ── Signal types ──────────────────────────────────────────────────────────────
155
156/// A raw (pre-correction) market signal value.
157struct RawSignal {
158 double value{0.0};
159};
160
161/**
162 * @brief A gamma-corrected relativistic momentum signal.
163 *
164 * adjusted_value = γ · m_eff · raw_value
165 */
167 double raw_value{0.0};
168 LorentzFactor gamma{}; ///< Lorentz factor applied during correction.
169 double adjusted_value{0.0}; ///< γ · m_eff · raw_value
170};
171
172// ── Physics kernels ───────────────────────────────────────────────────────────
173
174/**
175 * @brief Compute Lorentz factor γ = 1/√(1−β²).
176 *
177 * @param beta Validated normalised market velocity.
178 * @return LorentzFactor with γ ≥ 1.0, or std::nullopt if result is
179 * non-finite (unreachable after BetaVelocity validation, but
180 * explicit for defence-in-depth).
181 */
182[[nodiscard]] std::optional<LorentzFactor>
183lorentz_gamma(BetaVelocity beta) noexcept;
184
185/**
186 * @brief Apply relativistic momentum correction: p_rel = γ · m_eff · raw.
187 *
188 * Mirrors applyMomentumCorrection() from the SRFM C++ reference.
189 *
190 * @param raw_signal Un-corrected market signal (any finite double).
191 * @param beta Validated normalised market velocity.
192 * @param m_eff ADV-based effective mass.
193 * @return {adjusted_value, gamma} pair, or std::nullopt if γ fails.
194 */
195[[nodiscard]] std::optional<std::pair<double, LorentzFactor>>
196apply_momentum_correction(double raw_signal,
197 BetaVelocity beta,
198 EffectiveMass m_eff) noexcept;
199
200/**
201 * @brief Relativistic velocity composition: β_result = (β₁+β₂)/(1+β₁β₂).
202 *
203 * Preserves the sub-luminal invariant.
204 * @return std::nullopt if the composed result would be ≥ BETA_MAX_SAFE.
205 */
206[[nodiscard]] std::optional<BetaVelocity>
207compose_velocities(BetaVelocity beta1, BetaVelocity beta2) noexcept;
208
209/**
210 * @brief Recover the proper (un-dilated) value: proper = dilated / γ.
211 *
212 * @return std::nullopt if γ computation fails.
213 */
214[[nodiscard]] std::optional<double>
215inverse_transform(double dilated_value, BetaVelocity beta) noexcept;
216
217// ── RelativisticSignalProcessor ───────────────────────────────────────────────
218
219/**
220 * @brief Converts raw market signals to gamma-corrected relativistic signals.
221 *
222 * Stateless. All signals in a batch share the same beta / m_eff frame.
223 * Thread-safe: process() and process_one() are const and noexcept.
224 *
225 * @example
226 * @code
227 * auto beta = BetaVelocity::make(0.6).value();
228 * auto m_eff = EffectiveMass::make(1.0).value();
229 * std::array<RawSignal,2> raw{{{100.0},{-50.0}}};
230 * RelativisticSignalProcessor proc;
231 * auto out = proc.process(raw, beta, m_eff);
232 * // out[0].adjusted_value ≈ 125.0 (γ=1.25, m_eff=1)
233 * @endcode
234 */
236public:
237 RelativisticSignalProcessor() noexcept = default;
238
239 /**
240 * @brief Process a batch of raw signals.
241 *
242 * Gamma is computed once and reused for every signal in the batch.
243 *
244 * @param signals Span of raw signal values (zero or more).
245 * @param beta Normalised market velocity for this processing frame.
246 * @param m_eff ADV-based effective mass for this frame.
247 * @return Vector of RelativisticSignal (one per input), in order.
248 * Returns std::nullopt only if γ computation yields a non-finite
249 * result (unreachable with a valid BetaVelocity).
250 */
251 [[nodiscard]] std::optional<std::vector<RelativisticSignal>>
252 process(std::span<const RawSignal> signals,
253 BetaVelocity beta,
254 EffectiveMass m_eff) const noexcept;
255
256 /**
257 * @brief Process a single raw signal (convenience wrapper).
258 *
259 * @return RelativisticSignal, or std::nullopt if γ fails.
260 */
261 [[nodiscard]] std::optional<RelativisticSignal>
262 process_one(RawSignal signal,
263 BetaVelocity beta,
264 EffectiveMass m_eff) const noexcept;
265};
266
267} // namespace srfm::momentum
Normalised market velocity β = price_velocity / c_market.
Definition momentum.hpp:72
double value() const noexcept
Returns the raw β value.
Definition momentum.hpp:83
static std::optional< BetaVelocity > make(double value) noexcept
Validate and construct a BetaVelocity.
Definition momentum.cpp:18
ADV-based effective mass proxy.
Definition momentum.hpp:128
static std::optional< EffectiveMass > from_adv(double adv, double adv_baseline) noexcept
Construct from raw ADV and a baseline ADV.
Definition momentum.cpp:33
static std::optional< EffectiveMass > make(double value) noexcept
Validate and construct an EffectiveMass.
Definition momentum.cpp:27
double value() const noexcept
Returns the raw m_eff value.
Definition momentum.hpp:147
Pre-computed Lorentz factor γ = 1/√(1−β²). Always ≥ 1.0.
Definition momentum.hpp:98
LorentzFactor() noexcept
Default-constructs to the Newtonian identity γ = 1.
Definition momentum.hpp:101
friend std::optional< LorentzFactor > lorentz_gamma(BetaVelocity beta) noexcept
Compute Lorentz factor γ = 1/√(1−β²).
Definition momentum.cpp:42
double value() const noexcept
Returns the raw γ value.
Definition momentum.hpp:104
std::optional< RelativisticSignal > process_one(RawSignal signal, BetaVelocity beta, EffectiveMass m_eff) const noexcept
Process a single raw signal (convenience wrapper).
Definition momentum.cpp:101
std::optional< std::vector< RelativisticSignal > > process(std::span< const RawSignal > signals, BetaVelocity beta, EffectiveMass m_eff) const noexcept
Process a batch of raw signals.
Definition momentum.cpp:77
std::optional< double > inverse_transform(double dilated_value, BetaVelocity beta) noexcept
Recover the proper (un-dilated) value: proper = dilated / γ.
Definition momentum.cpp:68
std::optional< std::pair< double, LorentzFactor > > apply_momentum_correction(double raw_signal, BetaVelocity beta, EffectiveMass m_eff) noexcept
Apply relativistic momentum correction: p_rel = γ · m_eff · raw.
Definition momentum.cpp:50
std::optional< BetaVelocity > compose_velocities(BetaVelocity beta1, BetaVelocity beta2) noexcept
Relativistic velocity composition: β_result = (β₁+β₂)/(1+β₁β₂).
Definition momentum.cpp:60
std::optional< LorentzFactor > lorentz_gamma(BetaVelocity beta) noexcept
Compute Lorentz factor γ = 1/√(1−β²).
Definition momentum.cpp:42
constexpr double BETA_MAX_SAFE
Definition momentum.hpp:62
A raw (pre-correction) market signal value.
Definition momentum.hpp:157
A gamma-corrected relativistic momentum signal.
Definition momentum.hpp:166
double adjusted_value
γ · m_eff · raw_value
Definition momentum.hpp:169
LorentzFactor gamma
Lorentz factor applied during correction.
Definition momentum.hpp:168
Internal factory helper for constructing LorentzFactor objects from pre-computed gamma scalars (frien...