Special Relativity in Financial Modeling 1.0.0
Lorentz transforms, spacetime classification, and geodesic price paths for quantitative finance
Loading...
Searching...
No Matches
market_manifold.cpp
Go to the documentation of this file.
1/// @file src/manifold/market_manifold.cpp
2/// @brief MarketManifold — high-level financial spacetime manifold (AGT-06 stub).
3
4#include "srfm/manifold.hpp"
5#include "srfm/normalizer.hpp"
6
7#include <algorithm>
8#include <cmath>
9
10namespace srfm::manifold {
11
12// ─── MarketManifold::classify ─────────────────────────────────────────────────
13
14std::optional<IntervalType>
16 const SpacetimeEvent& b) noexcept {
17 auto ds2 = SpacetimeInterval::compute(a, b);
18 if (!ds2) {
19 return std::nullopt;
20 }
21 return SpacetimeInterval::classify(*ds2);
22}
23
24// ─── MarketManifold::beta ─────────────────────────────────────────────────────
25
26std::optional<double>
28 const SpacetimeEvent& b,
29 double c_market) noexcept {
30 if (!std::isfinite(a.time) || !std::isfinite(b.time) ||
31 !std::isfinite(a.price) || !std::isfinite(b.price) ||
32 !std::isfinite(a.volume) || !std::isfinite(b.volume) ||
33 !std::isfinite(a.momentum) || !std::isfinite(b.momentum) ||
34 !std::isfinite(c_market) || c_market <= 0.0) {
35 return std::nullopt;
36 }
37
38 const double dt = b.time - a.time;
39 if (std::abs(dt) < constants::FLOAT_EPSILON) {
40 // Simultaneous events — velocity undefined.
41 return std::nullopt;
42 }
43
44 const double dp = b.price - a.price;
45 const double dv = b.volume - a.volume;
46 const double dm = b.momentum - a.momentum;
47
48 // |Δspace| / (c · |Δtime|) → β in [0, ∞)
49 const double spatial_speed = std::sqrt(dp*dp + dv*dv + dm*dm) / std::abs(dt);
50 const double raw_beta = spatial_speed / c_market;
51
52 // Clamp to valid range [0, BETA_MAX_SAFE).
53 const double safe_beta = std::min(raw_beta, constants::BETA_MAX_SAFE - 1e-15);
54 return safe_beta;
55}
56
57// ─── MarketManifold::is_causal ────────────────────────────────────────────────
58
59bool
61 const SpacetimeEvent& b) noexcept {
62 auto result = classify(a, b);
63 if (!result) {
64 return false;
65 }
66 // Timelike and lightlike trajectories are both causal.
67 return (*result == IntervalType::Timelike ||
68 *result == IntervalType::Lightlike);
69}
70
71// ─── MarketManifold::process ──────────────────────────────────────────────────
72
73std::optional<IntervalType>
75 const SpacetimeEvent& prev_normalized,
76 const SpacetimeEvent& curr_raw) noexcept {
77 // Normalize the incoming raw event using the rolling window.
78 // This updates the normalizer's internal state with curr_raw's coordinates.
79 auto maybe_curr_norm = normalizer.normalize(curr_raw);
80
81 // If the normalizer has not yet warmed up, return no classification.
82 if (!maybe_curr_norm.has_value()) {
83 return std::nullopt;
84 }
85 const SpacetimeEvent& curr_norm = *maybe_curr_norm;
86
87 // Compute interval on the normalized coordinate pair.
88 // With z-scored coordinates each spatial axis contributes equally to ds².
89 return classify(prev_normalized, curr_norm);
90}
91
92} // 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
Spacetime Market Manifold — AGT-02 public API (implemented by AGT-06).
static constexpr double FLOAT_EPSILON
General floating-point comparison epsilon.
Definition constants.hpp:25
static constexpr double BETA_MAX_SAFE
Definition constants.hpp:17
@ Timelike
ds² < 0 — causal market movement (β < c)
@ Lightlike
ds² ≈ 0 — information propagation at c
CoordinateNormalizer — rolling z-score normalizer for SpacetimeEvent.
A point in 4D spacetime (t, x, y, z).