Special Relativity in Financial Modeling 1.0.0
Lorentz transforms, spacetime classification, and geodesic price paths for quantitative finance
Loading...
Searching...
No Matches
lorentz_transform.hpp
Go to the documentation of this file.
1#pragma once
2/**
3 * @file lorentz_transform.hpp
4 * @brief Stateful Lorentz transformation for (bar_index, normalised_price) events.
5 *
6 * Module: include/srfm/stream/
7 * Owner: AGT-10 (Builder) — 2026-03-01
8 *
9 * Responsibility
10 * --------------
11 * Apply the 1+1-dimensional Lorentz boost to streaming tick coordinates.
12 *
13 * Each tick is treated as an event at spacetime coordinates:
14 *
15 * t = bar_index (sequence number, playing the role of time)
16 * x = normalised_close (z-score from CoordinateNormalizer, playing "space")
17 *
18 * The boost is parameterised by β from BetaCalculator:
19 *
20 * γ = 1 / √(1 − β²)
21 * t' = γ · (t − β·x)
22 * x' = γ · (x − β·t)
23 *
24 * These prime coordinates feed into SpacetimeManifold for interval computation.
25 *
26 * Guarantees
27 * ----------
28 * • Stateful: stores the previous transformed coordinates for interval calc.
29 * • noexcept: transform() is noexcept.
30 * • Returns identity transform (t'=t, x'=x) when β=0 (Newtonian limit).
31 * • Never produces non-finite output for valid inputs (β < BETA_MAX_SAFE).
32 *
33 * NOT Responsible For
34 * -------------------
35 * • Computing β (BetaCalculator)
36 * • Computing Δs² (SpacetimeManifold)
37 * • Signal scaling (signal_processor)
38 */
39
40#include <cmath>
41
42namespace srfm::stream {
43
44// ── TransformedEvent ──────────────────────────────────────────────────────────
45
46/**
47 * @brief Lorentz-boosted spacetime event coordinates.
48 *
49 * Produced by LorentzTransform::transform() and consumed by SpacetimeManifold.
50 */
52 double t_prime{0.0}; ///< Boosted time coordinate.
53 double x_prime{0.0}; ///< Boosted space coordinate.
54 double gamma{1.0}; ///< Lorentz factor applied (γ ≥ 1).
55 double beta{0.0}; ///< Market velocity applied (β).
56};
57
58// ── LorentzTransform ──────────────────────────────────────────────────────────
59
60/**
61 * @brief Applies a 1+1D Lorentz boost to tick coordinates.
62 *
63 * Maintains no persistent inter-tick state beyond what SpacetimeManifold needs.
64 * Stateless in the physics sense — transform() is a pure mathematical operation
65 * given (t, x, β).
66 *
67 * @code
68 * LorentzTransform lt;
69 * auto ev = lt.transform(bar_idx, norm_close, beta_calc.beta());
70 * // ev.t_prime, ev.x_prime feed into SpacetimeManifold
71 * @endcode
72 */
74public:
75 LorentzTransform() noexcept = default;
76
77 /**
78 * @brief Compute the Lorentz-boosted coordinates for a single tick event.
79 *
80 * @param t Raw time coordinate (bar index, cast to double).
81 * @param x Normalised space coordinate (z-score close price).
82 * @param beta Market velocity β ∈ (−BETA_MAX_SAFE, +BETA_MAX_SAFE).
83 * If |β| ≥ 1 or non-finite, treated as 0 (identity boost).
84 *
85 * @return TransformedEvent with boosted (t', x'), γ, and β recorded.
86 *
87 * @note noexcept — pure arithmetic, no allocation.
88 */
89 [[nodiscard]] TransformedEvent transform(double t, double x,
90 double beta) const noexcept {
91 // Guard against invalid β — fall back to identity boost.
92 if (!std::isfinite(beta) || beta <= -1.0 || beta >= 1.0) {
93 return TransformedEvent{t, x, 1.0, 0.0};
94 }
95
96 const double gamma = 1.0 / std::sqrt(1.0 - beta * beta);
97
98 // Guarded against non-finite γ (unreachable with valid β, defence-in-depth).
99 if (!std::isfinite(gamma)) {
100 return TransformedEvent{t, x, 1.0, 0.0};
101 }
102
103 const double t_prime = gamma * (t - beta * x);
104 const double x_prime = gamma * (x - beta * t);
105
106 return TransformedEvent{t_prime, x_prime, gamma, beta};
107 }
108
109 /**
110 * @brief Compute γ = 1/√(1−β²) for a given β.
111 *
112 * Convenience function; returns 1.0 for invalid inputs.
113 *
114 * @note noexcept.
115 */
116 [[nodiscard]] static double lorentz_gamma(double beta) noexcept {
117 if (!std::isfinite(beta) || beta <= -1.0 || beta >= 1.0) return 1.0;
118 const double g = 1.0 / std::sqrt(1.0 - beta * beta);
119 return std::isfinite(g) ? g : 1.0;
120 }
121
122 /**
123 * @brief Inverse Lorentz boost: recover (t, x) from (t', x') given β.
124 *
125 * Uses the inverse transformation:
126 * t = γ · (t' + β·x')
127 * x = γ · (x' + β·t')
128 *
129 * @note noexcept.
130 */
131 [[nodiscard]] TransformedEvent inverse(double t_prime, double x_prime,
132 double beta) const noexcept {
133 return transform(t_prime, x_prime, -beta);
134 }
135};
136
137} // namespace srfm::stream
Applies a 1+1D Lorentz boost to tick coordinates.
TransformedEvent transform(double t, double x, double beta) const noexcept
Compute the Lorentz-boosted coordinates for a single tick event.
TransformedEvent inverse(double t_prime, double x_prime, double beta) const noexcept
Inverse Lorentz boost: recover (t, x) from (t', x') given β.
LorentzTransform() noexcept=default
static double lorentz_gamma(double beta) noexcept
Compute γ = 1/√(1−β²) for a given β.
Lorentz-boosted spacetime event coordinates.
double beta
Market velocity applied (β).
double x_prime
Boosted space coordinate.
double t_prime
Boosted time coordinate.
double gamma
Lorentz factor applied (γ ≥ 1).