Special Relativity in Financial Modeling 1.0.0
Lorentz transforms, spacetime classification, and geodesic price paths for quantitative finance
Loading...
Searching...
No Matches
geodesic_signal.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file include/srfm/geodesic_signal.hpp
4/// @brief Geodesic Deviation Signal — AGT-07 public API.
5///
6/// # Module: Geodesic Deviation
7///
8/// ## Responsibility
9/// Compute, for each bar in a price series, the Euclidean distance between the
10/// actual market position in financial spacetime and the position predicted by
11/// the geodesic equation integrated from the series start.
12///
13/// geodesic_deviation_i = ||x_actual_i[1:3] − x_geodesic_i[1:3]||₂
14///
15/// where components [1], [2], [3] are the spatial (price, volume, momentum)
16/// dimensions of the SpacetimePoint.
17///
18/// ## Physical Interpretation
19/// The geodesic traces the "natural" price path: free-fall through the curved
20/// financial spacetime determined by the asset covariance geometry. A large
21/// deviation from the geodesic indicates the market is being pulled away from
22/// its natural trajectory by external forces (news, liquidity shocks).
23/// Mean-reversion hypothesis: large deviations should be followed by a return
24/// toward the geodesic (reversion to the natural path).
25///
26/// ## Guarantees
27/// - All methods are noexcept
28/// - Returns GeodesicSignal{0.0, 0.0, false} for pathological inputs
29/// - First bar always returns deviation = 0.0 (reference point)
30/// - No dynamic allocation beyond the returned vector
31
32#include "srfm/tensor.hpp"
33#include "srfm/manifold.hpp"
34
35#include <vector>
36
37namespace srfm::tensor {
38
39// ─── GeodesicSignal ───────────────────────────────────────────────────────────
40
41/// Per-bar geodesic deviation signal.
42///
43/// Produced by GeodesicDeviationCalculator::compute for each bar in a price
44/// series. The deviation measures how far the actual market position is from
45/// the geodesic-predicted position in the spatial subspace.
47 double geodesic_deviation; ///< ||x_actual[1:3] − x_geodesic[1:3]||₂
48 double proper_time; ///< Proper time τ at this bar (bar_index × step_size)
49 bool is_valid; ///< false if geodesic integration failed for this bar
50};
51
52// ─── GeodesicDeviationCalculator ─────────────────────────────────────────────
53
54/// Computes geodesic deviation for a sequence of market events.
55///
56/// Algorithm
57/// ---------
58/// 1. Convert the sequence of SpacetimeEvent objects into SpacetimePoints.
59/// 2. Estimate an initial four-velocity u₀ from the first two events.
60/// 3. Integrate the geodesic equation from x₀ for (n−1) steps via RK4.
61/// 4. At each bar i, compute spatial deviation:
62/// dev_i = (actual_spatial_i − geodesic_spatial_i).norm()
63/// where spatial components are indices [1, 2, 3].
64///
65/// # Example
66/// ```cpp
67/// auto metric = srfm::tensor::MetricTensor::make_minkowski(1.0, 0.2);
68/// srfm::tensor::GeodesicDeviationCalculator calc(metric);
69///
70/// std::vector<srfm::manifold::SpacetimeEvent> events = ...;
71/// auto signals = calc.compute(events);
72///
73/// for (std::size_t i = 0; i < signals.size(); ++i) {
74/// if (signals[i].is_valid) {
75/// fmt::print("bar {} deviation = {:.4f}\n", i, signals[i].geodesic_deviation);
76/// }
77/// }
78/// ```
79///
80/// # Panics
81/// This class never panics.
83public:
84 /// Construct with a metric tensor and RK4 proper-time step.
85 ///
86 /// # Arguments
87 /// * `metric` — Position-dependent metric encoding market covariance
88 /// * `step_size` — Proper-time step dτ for geodesic integration
90 const MetricTensor& metric,
91 double step_size = constants::DEFAULT_GEODESIC_STEP) noexcept;
92
93 /// Compute geodesic deviation for a sequence of spacetime events.
94 ///
95 /// # Arguments
96 /// * `events` — Ordered sequence of market observations as SpacetimeEvents.
97 /// Must be in chronological order (ascending time coordinate).
98 ///
99 /// # Returns
100 /// Vector of GeodesicSignal, one per input event:
101 /// - events[0]: deviation = 0.0 (reference point), is_valid = true
102 /// - events[i]: actual deviation from geodesic at step i
103 ///
104 /// Returns an empty vector if events is empty.
105 /// Returns a single {0.0, 0.0, true} if events has exactly one element.
106 [[nodiscard]] std::vector<GeodesicSignal>
107 compute(const std::vector<manifold::SpacetimeEvent>& events) const noexcept;
108
109private:
110 /// Convert a SpacetimeEvent to an Eigen SpacetimePoint.
111 [[nodiscard]] static SpacetimePoint
112 to_point(const manifold::SpacetimeEvent& ev) noexcept;
113
114 /// Estimate initial four-velocity from the displacement between two events.
115 /// Returns the unit-normalised tangent vector, or the canonical basis e₀
116 /// if the displacement is degenerate (zero or non-finite).
117 [[nodiscard]] static FourVelocity
118 estimate_velocity(const SpacetimePoint& p0,
119 const SpacetimePoint& p1) noexcept;
120
121 /// Spatial norm of the deviation (components [1,2,3] only).
122 [[nodiscard]] static double
123 spatial_deviation(const SpacetimePoint& actual,
124 const SpacetimePoint& geodesic) noexcept;
125
126 const MetricTensor& metric_;
127 GeodesicSolver solver_;
128};
129
130} // namespace srfm::tensor
std::vector< GeodesicSignal > compute(const std::vector< manifold::SpacetimeEvent > &events) const noexcept
Spacetime Market Manifold — AGT-02 public API (implemented by AGT-06).
static constexpr double DEFAULT_GEODESIC_STEP
Default proper-time step for geodesic integration.
Definition constants.hpp:40
Eigen::Vector< double, SPACETIME_DIM > FourVelocity
A tangent vector at a spacetime point (four-velocity: dx^μ/dτ).
Definition types.hpp:44
Eigen::Vector< double, SPACETIME_DIM > SpacetimePoint
Definition types.hpp:41
A point in 4D spacetime (t, x, y, z).
bool is_valid
false if geodesic integration failed for this bar
double geodesic_deviation
||x_actual[1:3] − x_geodesic[1:3]||₂
double proper_time
Proper time τ at this bar (bar_index × step_size)
Tensor Calculus & Covariance Engine — AGT-04 public API.