Special Relativity in Financial Modeling 1.0.0
Lorentz transforms, spacetime classification, and geodesic price paths for quantitative finance
Loading...
Searching...
No Matches
momentum.cpp
Go to the documentation of this file.
1/**
2 * @file momentum.cpp
3 * @brief Implementation of the Momentum-Velocity Signal Processor (AGT-03).
4 *
5 * See momentum.hpp for the full module contract and physics basis.
6 */
7
8#include "momentum.hpp"
9
10#include <cmath>
11#include <utility>
12
13namespace srfm::momentum {
14
15// ── BetaVelocity ──────────────────────────────────────────────────────────────
16
17std::optional<BetaVelocity>
18BetaVelocity::make(double value) noexcept {
19 if (!std::isfinite(value)) return std::nullopt;
20 if (std::abs(value) >= BETA_MAX_SAFE) return std::nullopt;
21 return BetaVelocity{value};
22}
23
24// ── EffectiveMass ─────────────────────────────────────────────────────────────
25
26std::optional<EffectiveMass>
27EffectiveMass::make(double value) noexcept {
28 if (!std::isfinite(value) || value <= 0.0) return std::nullopt;
29 return EffectiveMass{value};
30}
31
32std::optional<EffectiveMass>
33EffectiveMass::from_adv(double adv, double adv_baseline) noexcept {
34 if (!std::isfinite(adv) || adv <= 0.0) return std::nullopt;
35 if (!std::isfinite(adv_baseline) || adv_baseline <= 0.0) return std::nullopt;
36 return make(adv / adv_baseline);
37}
38
39// ── Physics kernels ───────────────────────────────────────────────────────────
40
41std::optional<LorentzFactor>
43 const double b = beta.value();
44 const double gamma_val = 1.0 / std::sqrt(1.0 - b * b);
45 if (!std::isfinite(gamma_val)) return std::nullopt;
46 return LorentzFactor{gamma_val};
47}
48
49std::optional<std::pair<double, LorentzFactor>>
50apply_momentum_correction(double raw_signal,
51 BetaVelocity beta,
52 EffectiveMass m_eff) noexcept {
53 auto gamma_opt = lorentz_gamma(beta);
54 if (!gamma_opt) return std::nullopt;
55 const double adjusted = gamma_opt->value() * m_eff.value() * raw_signal;
56 return std::make_pair(adjusted, *gamma_opt);
57}
58
59std::optional<BetaVelocity>
61 const double b1 = beta1.value();
62 const double b2 = beta2.value();
63 const double composed = (b1 + b2) / (1.0 + b1 * b2);
64 return BetaVelocity::make(composed);
65}
66
67std::optional<double>
68inverse_transform(double dilated_value, BetaVelocity beta) noexcept {
69 auto gamma_opt = lorentz_gamma(beta);
70 if (!gamma_opt) return std::nullopt;
71 return dilated_value / gamma_opt->value();
72}
73
74// ── RelativisticSignalProcessor ───────────────────────────────────────────────
75
76std::optional<std::vector<RelativisticSignal>>
78 std::span<const RawSignal> signals,
79 BetaVelocity beta,
80 EffectiveMass m_eff) const noexcept {
81
82 // Compute γ once; reuse for every signal in the batch.
83 auto gamma_opt = lorentz_gamma(beta);
84 if (!gamma_opt) return std::nullopt;
85 const LorentzFactor gamma = *gamma_opt;
86 const double scale = gamma.value() * m_eff.value();
87
88 std::vector<RelativisticSignal> out;
89 out.reserve(signals.size());
90 for (const auto& sig : signals) {
91 out.push_back(RelativisticSignal{
92 sig.value,
93 gamma,
94 scale * sig.value
95 });
96 }
97 return out;
98}
99
100std::optional<RelativisticSignal>
102 RawSignal signal,
103 BetaVelocity beta,
104 EffectiveMass m_eff) const noexcept {
105
106 auto gamma_opt = lorentz_gamma(beta);
107 if (!gamma_opt) return std::nullopt;
108 const double adjusted = gamma_opt->value() * m_eff.value() * signal.value;
109 return RelativisticSignal{signal.value, *gamma_opt, adjusted};
110}
111
112} // namespace srfm::momentum
Normalised market velocity β = price_velocity / c_market.
Definition momentum.hpp:72
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
Pre-computed Lorentz factor γ = 1/√(1−β²). Always ≥ 1.0.
Definition momentum.hpp:98
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
Momentum-Velocity Signal Processor (AGT-03 / SRFM)
A raw (pre-correction) market signal value.
Definition momentum.hpp:157
A gamma-corrected relativistic momentum signal.
Definition momentum.hpp:166