Special Relativity in Financial Modeling 1.0.0
Lorentz transforms, spacetime classification, and geodesic price paths for quantitative finance
Loading...
Searching...
No Matches
geodesic_n.hpp
Go to the documentation of this file.
1#pragma once
2/**
3 * @file geodesic_n.hpp
4 * @brief RK4 geodesic integrator for an (N+1)-dimensional Lorentzian manifold.
5 *
6 * Module: include/srfm/tensor/
7 * Stage: 4 — N-Asset Manifold
8 *
9 * ## Responsibility
10 * Numerically integrate the geodesic equation
11 *
12 * d²x^λ/dτ² = -Γ^λ_μν (dx^μ/dτ)(dx^ν/dτ)
13 *
14 * as the first-order system
15 *
16 * dx^λ/dτ = u^λ
17 * du^λ/dτ = -Σ_{μν} Γ^λ_μν u^μ u^ν
18 *
19 * using a classic 4th-order Runge–Kutta scheme.
20 *
21 * ## Guarantees
22 * - Thread-safe: GeodesicSolverN is stateless.
23 * - All public methods are noexcept.
24 * - All fallible operations return std::optional.
25 *
26 * ## NOT Responsible For
27 * - Adaptive step-size control.
28 * - Parallel transport of other tensors along the geodesic.
29 */
30
31#include "christoffel_n.hpp"
32#include "n_asset_manifold.hpp"
33
34#include <optional>
35#include <vector>
36#include <Eigen/Dense>
37
38namespace srfm::tensor {
39
40// ── State type ────────────────────────────────────────────────────────────────
41
42/**
43 * @brief Position and 4-velocity state on the manifold.
44 *
45 * Both vectors must have length equal to the manifold dimension (N+1).
46 */
47struct GeodesicState {
48 Eigen::VectorXd x; ///< Position coordinates.
49 Eigen::VectorXd u; ///< Tangent vector (4-velocity, dx/dτ).
50};
51
52// ── Solver ────────────────────────────────────────────────────────────────────
53
54/**
55 * @brief RK4 integrator for geodesics on an NAssetManifold.
56 */
58public:
59 // ── Construction ─────────────────────────────────────────────────────────
60
61 /**
62 * @brief Construct from manifold and Christoffel symbol provider.
63 *
64 * Both objects must outlive this solver.
65 *
66 * @param manifold The underlying NAssetManifold.
67 * @param christoffel Christoffel symbol computation object.
68 */
69 GeodesicSolverN(const NAssetManifold& manifold,
70 const ChristoffelN& christoffel) noexcept;
71
72 // ── Integration ───────────────────────────────────────────────────────────
73
74 /**
75 * @brief Advance the geodesic by one RK4 step of proper-time dtau.
76 *
77 * Computes k1..k4 for both position and velocity, then combines:
78 * s_new = s + (dtau/6)(k1 + 2k2 + 2k3 + k4)
79 *
80 * @param s Current state (position + velocity).
81 * @param dtau Proper-time step size (may be negative for backward integration).
82 * @return Updated state, or std::nullopt if Christoffel evaluation fails.
83 */
84 [[nodiscard]] std::optional<GeodesicState>
85 step(const GeodesicState& s, double dtau) const noexcept;
86
87 /**
88 * @brief Integrate the geodesic for n_steps steps of size dtau.
89 *
90 * Returns a vector of n_steps states (not including the initial state).
91 *
92 * @param initial Starting state.
93 * @param dtau Proper-time step size.
94 * @param n_steps Number of steps to take.
95 * @return Vector of states, or std::nullopt if any step fails.
96 */
97 [[nodiscard]] std::optional<std::vector<GeodesicState>>
99 double dtau,
100 int n_steps) const noexcept;
101
102 /**
103 * @brief Measure the maximum deviation of a trajectory from a straight line.
104 *
105 * Computes the straight line from traj.front() to traj.back() and
106 * returns the maximum Euclidean distance in the spatial (price) components
107 * from any intermediate point to the corresponding point on that line.
108 *
109 * This provides a measure of how non-geodesic the trajectory is in flat space.
110 *
111 * @param traj Trajectory of geodesic states.
112 * @return Max deviation, or std::nullopt if fewer than 2 states.
113 */
114 [[nodiscard]] std::optional<double>
115 geodesic_deviation(const std::vector<GeodesicState>& traj) const noexcept;
116
117 /**
118 * @brief Return the manifold dimension.
119 *
120 * @return manifold_.dim().
121 */
122 [[nodiscard]] int dim() const noexcept;
123
124private:
125 // ── Internal helpers ──────────────────────────────────────────────────────
126
127 /**
128 * @brief Evaluate the geodesic equation RHS at state s.
129 *
130 * Returns (u, -Γ^λ_μν u^μ u^ν) as a pair (dx_dot, du_dot).
131 *
132 * @param s Current state.
133 * @return Derivatives (dx/dτ, du/dτ), or std::nullopt on failure.
134 */
135 [[nodiscard]] std::optional<std::pair<Eigen::VectorXd, Eigen::VectorXd>>
136 rhs(const GeodesicState& s) const noexcept;
137
138 /**
139 * @brief Advance a state by a scaled derivative vector.
140 *
141 * new_state.x = s.x + scale * dx
142 * new_state.u = s.u + scale * du
143 *
144 * @param s Base state.
145 * @param dx Position derivative.
146 * @param du Velocity derivative.
147 * @param scale Scaling factor.
148 * @return New state.
149 */
150 [[nodiscard]] static GeodesicState
151 advance(const GeodesicState& s,
152 const Eigen::VectorXd& dx,
153 const Eigen::VectorXd& du,
154 double scale) noexcept;
155
156 // ── Data members ──────────────────────────────────────────────────────────
157
158 const NAssetManifold& manifold_; ///< Underlying manifold.
159 const ChristoffelN& christoffel_; ///< Christoffel symbol provider.
160};
161
162// ── Inline trivial accessors ──────────────────────────────────────────────────
163
164inline int GeodesicSolverN::dim() const noexcept {
165 return manifold_.dim();
166}
167
168} // namespace srfm::tensor
Christoffel symbol computation for an NAssetManifold.
Computes Christoffel symbols Γ^λ_μν for an NAssetManifold.
RK4 integrator for geodesics on an NAssetManifold.
std::optional< std::vector< GeodesicState > > integrate(GeodesicState initial, double dtau, int n_steps) const noexcept
Integrate the geodesic for n_steps steps of size dtau.
int dim() const noexcept
Return the manifold dimension.
std::optional< double > geodesic_deviation(const std::vector< GeodesicState > &traj) const noexcept
Measure the maximum deviation of a trajectory from a straight line.
std::optional< GeodesicState > step(const GeodesicState &s, double dtau) const noexcept
Advance the geodesic by one RK4 step of proper-time dtau.
(N+1)-dimensional Lorentzian manifold for N financial assets.
int dim() const noexcept
Returns the full manifold dimension = n_assets + 1.
N-Asset Lorentzian Manifold for Special Relativistic Financial Mechanics.
Position and 4-velocity state on the manifold.
Definition tensor.hpp:521
Eigen::VectorXd x
Position coordinates.
Eigen::VectorXd u
Tangent vector (4-velocity, dx/dτ).