Special Relativity in Financial Modeling 1.0.0
Lorentz transforms, spacetime classification, and geodesic price paths for quantitative finance
Loading...
Searching...
No Matches
geodesic.cpp
Go to the documentation of this file.
1/// @file src/tensor/geodesic.cpp
2/// @brief Geodesic equation integrator using 4th-order Runge-Kutta — AGT-04
3///
4/// Integrates the geodesic ODE:
5/// dx^λ/dτ = u^λ
6/// du^λ/dτ = −Γ^λ_{μν} u^μ u^ν
7///
8/// Natural price paths in curved financial spacetime are geodesics — the
9/// trajectories that extremise proper time given the covariance geometry.
10
11#include "srfm/tensor.hpp"
12#include "srfm/constants.hpp"
13
14namespace srfm::tensor {
15
16// ─── Construction ─────────────────────────────────────────────────────────────
17
19 double step_size,
20 double christoffel_h)
21 : metric_(metric)
22 , christoffel_(metric, christoffel_h)
23 , step_size_(step_size) {}
24
25// ─── Private: RK4 Step ────────────────────────────────────────────────────────
26
27GeodesicState GeodesicSolver::rk4_step(const GeodesicState& state) const {
28 // ODE derivative: given state (x, u), return (dx/dτ, du/dτ).
29 auto derivative = [this](const GeodesicState& s) -> GeodesicState {
30 const SpacetimePoint& x = s.position;
31 const FourVelocity& u = s.velocity;
32
33 // du^λ/dτ = −Γ^λ_{μν} u^μ u^ν
34 auto gamma = christoffel_.compute(x);
35 FourVelocity accel = -1.0 * christoffel_.contract(gamma, u);
36
37 // dx^λ/dτ = u^λ
38 return GeodesicState{u, accel};
39 };
40
41 const double h = step_size_;
42
43 GeodesicState k1 = derivative(state);
44 GeodesicState k2 = derivative(state + (h / 2.0) * k1);
45 GeodesicState k3 = derivative(state + (h / 2.0) * k2);
46 GeodesicState k4 = derivative(state + h * k3);
47
48 // Classic RK4 combination: weighted average of four slope estimates
49 return state + (h / 6.0) * (k1 + 2.0 * k2 + 2.0 * k3 + k4);
50}
51
52// ─── integrate ────────────────────────────────────────────────────────────────
53
54std::vector<GeodesicState> GeodesicSolver::integrate(
55 const SpacetimePoint& x0,
56 const FourVelocity& u0,
57 int steps) const
58{
59 std::vector<GeodesicState> trajectory;
60 trajectory.reserve(static_cast<size_t>(steps) + 1);
61
62 GeodesicState current{x0, u0};
63 trajectory.push_back(current);
64
65 for (int i = 0; i < steps; ++i) {
66 current = rk4_step(current);
67 trajectory.push_back(current);
68 }
69
70 return trajectory;
71}
72
73// ─── norm_squared ─────────────────────────────────────────────────────────────
74
76 const FourVelocity& u) const {
77 return metric_.spacetime_interval(x, u);
78}
79
80} // namespace srfm::tensor
FourVelocity contract(const ChristoffelArray &gamma, const FourVelocity &u) const
ChristoffelArray compute(const SpacetimePoint &x) const
double norm_squared(const SpacetimePoint &x, const FourVelocity &u) const
Definition geodesic.cpp:75
std::vector< GeodesicState > integrate(const SpacetimePoint &x0, const FourVelocity &u0, int steps) const
Definition geodesic.cpp:54
GeodesicSolver(const MetricTensor &metric, double step_size=constants::DEFAULT_GEODESIC_STEP, double christoffel_h=constants::DEFAULT_FD_STEP)
Definition geodesic.cpp:18
double spacetime_interval(const SpacetimePoint &x, const FourVelocity &dx) const
Physical and financial constants for the SRFM system.
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
Position and 4-velocity state on the manifold.
Definition tensor.hpp:521
SpacetimePoint position
x^μ: position in financial spacetime
Definition tensor.hpp:522
Tensor Calculus & Covariance Engine — AGT-04 public API.