Special Relativity in Financial Modeling 1.0.0
Lorentz transforms, spacetime classification, and geodesic price paths for quantitative finance
Loading...
Searching...
No Matches
n_asset_interval.hpp
Go to the documentation of this file.
1#pragma once
2/**
3 * @file n_asset_interval.hpp
4 * @brief Spacetime interval computations for N-asset events.
5 *
6 * Module: include/srfm/manifold/
7 * Stage: 4 — N-Asset Manifold
8 *
9 * ## Responsibility
10 * Provide spacetime event types and compute the Lorentzian interval
11 *
12 * ds² = g_μν Δx^μ Δx^ν
13 *
14 * between pairs of N-asset events, classifying them as TIMELIKE, SPACELIKE,
15 * or LIGHTLIKE based on the sign and magnitude of ds².
16 *
17 * ## Classification Thresholds
18 * - |ds²| < 1e-10 → LIGHTLIKE
19 * - ds² < 0 → TIMELIKE
20 * - ds² > 0 → SPACELIKE
21 *
22 * ## Guarantees
23 * - All public methods are noexcept.
24 * - All fallible operations return std::optional.
25 * - No raw pointers.
26 *
27 * ## NOT Responsible For
28 * - Causality enforcement.
29 * - Geodesic distance (see geodesic_n.hpp).
30 */
31
32#include "../tensor/n_asset_manifold.hpp"
33
34#include <optional>
35#include <span>
36#include <vector>
37#include <cmath>
38#include <Eigen/Dense>
39
40namespace srfm::manifold {
41
43
44// ── Threshold ─────────────────────────────────────────────────────────────────
45
46/// |ds²| below this value is classified as LIGHTLIKE.
47inline constexpr double LIGHTLIKE_THRESHOLD = 1e-10;
48
49// ── Event type ────────────────────────────────────────────────────────────────
50
51/**
52 * @brief A spacetime event: a moment in time with N asset prices.
53 */
55 double t; ///< Time coordinate.
56 Eigen::VectorXd prices; ///< N asset price coordinates.
57
58 /**
59 * @brief Concatenate (t, prices) into a single (N+1)-vector.
60 *
61 * @return Vector [t, prices[0], prices[1], ..., prices[N-1]].
62 */
63 [[nodiscard]] Eigen::VectorXd to_coords() const noexcept;
64
65 /**
66 * @brief Factory: validate and construct an NAssetEvent.
67 *
68 * Validates that prices is non-empty.
69 *
70 * @param t Time coordinate.
71 * @param prices Asset price vector (must be non-empty).
72 * @return Constructed event, or std::nullopt if prices is empty.
73 */
74 [[nodiscard]] static std::optional<NAssetEvent>
75 make(double t, Eigen::VectorXd prices) noexcept;
76};
77
78// ── Interval type ─────────────────────────────────────────────────────────────
79
80/// Classification of a Lorentzian spacetime interval.
81enum class IntervalType {
82 TIMELIKE, ///< ds² < 0 (causal separation; price change < time*c_market).
83 SPACELIKE, ///< ds² > 0 (space-like; price change > time*c_market).
84 LIGHTLIKE, ///< |ds²| < threshold (on the light cone).
85};
86
87// ── Interval result ───────────────────────────────────────────────────────────
88
89/**
90 * @brief Result of a single interval computation.
91 */
93 double ds_sq; ///< Squared interval ds².
94 IntervalType type; ///< TIMELIKE, SPACELIKE, or LIGHTLIKE.
95 double magnitude; ///< sqrt(|ds²|).
96};
97
98// ── Interval computation ──────────────────────────────────────────────────────
99
100/**
101 * @brief Computes spacetime intervals between N-asset events.
102 *
103 * Stateless: all methods are const and noexcept.
104 */
106public:
107 /// Default constructor.
108 NAssetInterval() noexcept = default;
109
110 /**
111 * @brief Compute ds² = g_μν Δx^μ Δx^ν between two events.
112 *
113 * Δx = b.to_coords() - a.to_coords().
114 *
115 * @param a First event.
116 * @param b Second event.
117 * @param manifold The NAssetManifold providing the metric.
118 * @return IntervalResult, or std::nullopt on dimension mismatch.
119 */
120 [[nodiscard]] std::optional<IntervalResult>
121 compute(const NAssetEvent& a,
122 const NAssetEvent& b,
123 const NAssetManifold& manifold) const noexcept;
124
125 /**
126 * @brief Compute intervals from a reference event to many events.
127 *
128 * Equivalent to calling compute(ref, events[i], manifold) for each i.
129 *
130 * @param ref Reference event.
131 * @param events Span of target events.
132 * @param manifold The NAssetManifold.
133 * @return Vector of IntervalResults (same length as events),
134 * or std::nullopt if any individual computation fails.
135 */
136 [[nodiscard]] std::optional<std::vector<IntervalResult>>
137 batch_from_reference(const NAssetEvent& ref,
138 std::span<const NAssetEvent> events,
139 const NAssetManifold& manifold) const noexcept;
140
141private:
142 /**
143 * @brief Classify a ds² value.
144 *
145 * @param ds_sq Squared interval.
146 * @return LIGHTLIKE if |ds_sq| < LIGHTLIKE_THRESHOLD,
147 * TIMELIKE if ds_sq < 0, SPACELIKE otherwise.
148 */
149 [[nodiscard]] static IntervalType classify(double ds_sq) noexcept;
150};
151
152// ── Inline helpers ────────────────────────────────────────────────────────────
153
154inline IntervalType NAssetInterval::classify(double ds_sq) noexcept {
155 if (std::abs(ds_sq) < LIGHTLIKE_THRESHOLD) {
156 return IntervalType::LIGHTLIKE;
157 }
158 return ds_sq < 0.0 ? IntervalType::TIMELIKE : IntervalType::SPACELIKE;
159}
160
161} // namespace srfm::manifold
Computes spacetime intervals between N-asset events.
NAssetInterval() noexcept=default
Default constructor.
(N+1)-dimensional Lorentzian manifold for N financial assets.
IntervalType
Causal character of a spacetime interval.
Definition manifold.hpp:61
@ TIMELIKE
ds² < 0 (causal separation; price change < time*c_market).
@ LIGHTLIKE
|ds²| < threshold (on the light cone).
@ SPACELIKE
ds² > 0 (space-like; price change > time*c_market).
constexpr double LIGHTLIKE_THRESHOLD
|ds²| below this value is classified as LIGHTLIKE.
Result of a single interval computation.
double ds_sq
Squared interval ds².
IntervalType type
TIMELIKE, SPACELIKE, or LIGHTLIKE.
A spacetime event: a moment in time with N asset prices.
static std::optional< NAssetEvent > make(double t, Eigen::VectorXd prices) noexcept
Factory: validate and construct an NAssetEvent.
Eigen::VectorXd prices
N asset price coordinates.
Eigen::VectorXd to_coords() const noexcept
Concatenate (t, prices) into a single (N+1)-vector.