Special Relativity in Financial Modeling 1.0.0
Lorentz transforms, spacetime classification, and geodesic price paths for quantitative finance
Loading...
Searching...
No Matches
manifold.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file include/srfm/manifold.hpp
4/// @brief Spacetime Market Manifold — AGT-02 public API (implemented by AGT-06).
5///
6/// # Module: Market Manifold
7///
8/// ## Responsibility
9/// Embed OHLCV bar data into the 4-dimensional financial spacetime manifold and
10/// compute the invariant spacetime interval ds² between market events.
11///
12/// ## The Core Idea
13/// Each market observation (bar) is treated as a spacetime event with four
14/// coordinates: (time, price, volume, momentum). The interval between two
15/// events determines whether the market movement is:
16/// - Timelike (ds² < 0): causal, subluminal — the market "moved" at β < 1
17/// - Lightlike (ds² = 0): signal propagation at the speed of information
18/// - Spacelike (ds² > 0): stochastic, superluminal — no causal link possible
19///
20/// ## Interval Formula
21/// ds² = −c²·Δt² + ΔP² + ΔV² + ΔM²
22///
23/// where c = SPEED_OF_INFORMATION (normalised to 1.0 in natural units).
24///
25/// ## Guarantees
26/// - All functions are `noexcept` and return `std::optional` for fallible ops
27/// - No dynamic allocation
28/// - Thread-safe: all methods are stateless / const
29
30#include "srfm/constants.hpp"
31
32#include <optional>
33#include <string>
34
35// Forward declaration — avoids circular include with normalizer.hpp.
36namespace srfm {
37class CoordinateNormalizer;
38} // namespace srfm
39
40namespace srfm::manifold {
41
42// ─── SpacetimeEvent ───────────────────────────────────────────────────────────
43
44/// A single market observation embedded as a 4-vector in financial spacetime.
45///
46/// Coordinates:
47/// [0] time — bar index or fractional seconds (market-time axis)
48/// [1] price — normalised mid-price (spatial axis 1)
49/// [2] volume — normalised traded volume (spatial axis 2)
50/// [3] momentum — price momentum indicator, e.g. ROC (spatial axis 3)
51struct SpacetimeEvent {
52 double time; ///< Market time coordinate (bar index or timestamp)
53 double price; ///< Price spatial coordinate
54 double volume; ///< Volume spatial coordinate
55 double momentum; ///< Momentum spatial coordinate
56};
57
58// ─── IntervalType ─────────────────────────────────────────────────────────────
59
60/// Causal character of a spacetime interval.
61enum class IntervalType {
62 Timelike, ///< ds² < 0 — causal market movement (β < c)
63 Lightlike, ///< ds² ≈ 0 — information propagation at c
64 Spacelike, ///< ds² > 0 — stochastic regime (no causal link)
65};
66
67/// Convert IntervalType to a human-readable string.
68[[nodiscard]] const char* to_string(IntervalType t) noexcept;
69
70// ─── SpacetimeInterval ────────────────────────────────────────────────────────
71
72/// Computes the Minkowski-signature spacetime interval between two market events.
73///
74/// All methods are static and operate on value types — no heap allocation.
76public:
77 /// Compute ds² = −c²·Δt² + ΔP² + ΔV² + ΔM²
78 ///
79 /// # Arguments
80 /// * `a` — origin event
81 /// * `b` — destination event
82 /// * `c_market` — speed of information (default: SPEED_OF_INFORMATION = 1.0)
83 ///
84 /// # Returns
85 /// The raw signed interval squared. Negative → timelike; zero → lightlike;
86 /// positive → spacelike. Returns `nullopt` if any coordinate is non-finite.
87 [[nodiscard]] static std::optional<double>
88 compute(const SpacetimeEvent& a,
89 const SpacetimeEvent& b,
90 double c_market = constants::SPEED_OF_INFORMATION) noexcept;
91
92 /// Classify an already-computed interval squared value.
93 ///
94 /// Uses `FLOAT_EPSILON` as the lightlike tolerance band.
95 [[nodiscard]] static IntervalType
96 classify(double interval_squared) noexcept;
97};
98
99// ─── MarketManifold ───────────────────────────────────────────────────────────
100
101/// High-level interface to the financial spacetime manifold.
102///
103/// Wraps SpacetimeInterval with convenience methods for common pipeline
104/// queries: causal character, normalised velocity, and regime classification.
106public:
107 /// Compute the spacetime interval between two events and classify it.
108 ///
109 /// # Returns
110 /// `nullopt` if any coordinate is non-finite.
111 [[nodiscard]] static std::optional<IntervalType>
113 const SpacetimeEvent& b) noexcept;
114
115 /// Compute the normalised 3-velocity β = |Δspace| / (c · |Δtime|).
116 ///
117 /// This is the financial analogue of the relativistic β = v/c used by
118 /// BetaCalculator. It measures how fast the "spatial" (price/vol/momentum)
119 /// coordinates change relative to the market time axis.
120 ///
121 /// # Returns
122 /// β in [0, BETA_MAX_SAFE), or `nullopt` if:
123 /// - Δt = 0 (simultaneous events — undefined velocity)
124 /// - Any coordinate is non-finite
125 [[nodiscard]] static std::optional<double>
126 beta(const SpacetimeEvent& a,
127 const SpacetimeEvent& b,
128 double c_market = constants::SPEED_OF_INFORMATION) noexcept;
129
130 /// True if the trajectory from `a` to `b` is causal (timelike or lightlike).
131 [[nodiscard]] static bool
133 const SpacetimeEvent& b) noexcept;
134
135 /// Normalize `curr_raw` via `normalizer`, then classify the interval
136 /// between `prev_normalized` and the resulting normalized event.
137 ///
138 /// This is the canonical pipeline entry point. Every SpacetimeEvent is
139 /// normalized before SpacetimeInterval::compute is called, preventing
140 /// raw coordinate scale differences (price ~100, volume ~1e6) from
141 /// dominating the interval computation.
142 ///
143 /// # Arguments
144 /// * `normalizer` — Rolling z-score normalizer (updated in place)
145 /// * `prev_normalized` — Previous event, already normalized
146 /// * `curr_raw` — Current event with raw market coordinates
147 ///
148 /// # Returns
149 /// Interval type of the normalized trajectory, or `nullopt` if any
150 /// coordinate is non-finite after normalization.
151 [[nodiscard]] static std::optional<IntervalType>
154 const SpacetimeEvent& curr_raw) noexcept;
155};
156
157} // namespace srfm::manifold
static bool is_causal(const SpacetimeEvent &a, const SpacetimeEvent &b) noexcept
True if the trajectory from a to b is causal (timelike or lightlike).
static std::optional< double > beta(const SpacetimeEvent &a, const SpacetimeEvent &b, double c_market=constants::SPEED_OF_INFORMATION) noexcept
static std::optional< IntervalType > classify(const SpacetimeEvent &a, const SpacetimeEvent &b) noexcept
static std::optional< IntervalType > process(srfm::CoordinateNormalizer &normalizer, const SpacetimeEvent &prev_normalized, const SpacetimeEvent &curr_raw) noexcept
static IntervalType classify(double interval_squared) noexcept
static std::optional< double > compute(const SpacetimeEvent &a, const SpacetimeEvent &b, double c_market=constants::SPEED_OF_INFORMATION) noexcept
Physical and financial constants for the SRFM system.
static constexpr double SPEED_OF_INFORMATION
Definition constants.hpp:37
const char * to_string(IntervalType t) noexcept
Convert IntervalType to a human-readable string.
IntervalType
Causal character of a spacetime interval.
Definition manifold.hpp:61
@ Timelike
ds² < 0 — causal market movement (β < c)
@ Spacelike
ds² > 0 — stochastic regime (no causal link)
@ Lightlike
ds² ≈ 0 — information propagation at c
A point in 4D spacetime (t, x, y, z).
double volume
Volume spatial coordinate.
Definition manifold.hpp:54
double price
Price spatial coordinate.
Definition manifold.hpp:53
double time
Market time coordinate (bar index or timestamp)
Definition manifold.hpp:52
double momentum
Momentum spatial coordinate.
Definition manifold.hpp:55