A C++20 library that gives each OHLCV bar a price velocity β, a Lorentz factor γ and a spacetime interval, then labels it timelike or spacelike. Metric tensors, Christoffel symbols and geodesic deviation sit on top.
Research code, not financial advice. The chart below is the real output of regime_validator on the SPY daily bars committed in the repo.
Hover or tap a bar. Arrow keys step through bars when the chart has focus.
Labels come from build/regime_validator --input validation/data/SPY_1m.csv (rolling z-score normaliser, window 20). Dates 2021-03 to 2026-02.
CMake 3.25+ and a C++20 compiler. Eigen is vendored; GoogleTest, Google Benchmark and fmt are fetched on first configure.
git clone https://github.com/Mattbusel/Special-Relativity-in-Financial-Modeling srfm cd srfm cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release cmake --build build --parallel ctest --test-dir build --output-on-failure --timeout 120 ./build/regime_validator --input validation/data/SPY_1m.csv --output spy_regime.csv --ticker SPY
git clone https://github.com/Mattbusel/Special-Relativity-in-Financial-Modeling C:\src\srfm cd C:\src\srfm cmake -B build -A x64 cmake --build build --config Release --parallel ctest --test-dir build -C Release --output-on-failure --timeout 120 build\Release\regime_validator.exe --input validation\data\SPY_1m.csv --output spy_regime.csv --ticker SPY
On Windows keep the clone path short (MSBuild has a 260-character path limit for its intermediate files).
$ ./build/regime_validator --input validation/data/SPY_1m.csv --output spy_regime.csv --ticker SPY [SPY] Loaded 1256 bars [SPY] Classified 1245 bars TIMELIKE: 295 (23.6948%) SPACELIKE: 950 (76.3052%) LIGHTLIKE: 0 (0%) [SPY] Output written to spy_regime.csv $ tail -3 spy_regime.csv SPY,1252,Spacelike,0.0084382760,0.0084382760,0.9999000000,1.1822581722 SPY,1253,Spacelike,0.0055544060,-0.0055544060,0.9999000000,2.1046695934 SPY,1254,Spacelike,0.0048019696,-0.0048019696,0.9999000000,1.0605882118 # columns: ticker,bar_index,interval_type,next_bar_abs_return,next_bar_return,beta,geodesic_deviation
BetaCalculator turns a window of prices into a velocity against the market's speed of information; LorentzTransform::gamma gives the Lorentz factor, with β clamped below 0.9999.
MarketManifold::process z-scores time, price, volume and momentum over a rolling window, computes the Minkowski interval to the previous bar and classifies it.
MetricTensor, Christoffel symbols by finite differences or dual numbers, an RK4 geodesic solver, and a deviation signal between the observed path and the geodesic.
// examples/lorentz_basics.cpp
using srfm::BetaVelocity;
using srfm::lorentz::LorentzTransform;
using namespace srfm::manifold;
for (double b : {0.0, 0.5, 0.9, 0.99})
if (auto g = LorentzTransform::gamma(BetaVelocity{b}))
std::printf("beta = %.2f gamma = %.4f\n", b, g->value);
const SpacetimeEvent a{0.0, 100.0, 1.0, 0.0};
const SpacetimeEvent slow{1.0, 100.4, 1.0, 0.0};
const SpacetimeEvent fast{1.0, 103.0, 1.0, 0.0};
for (const auto* b : {&slow, &fast}) {
auto ds2 = SpacetimeInterval::compute(a, *b);
auto cls = MarketManifold::classify(a, *b);
std::printf("dP = %+.1f ds2 = %+.2f %s\n",
b->price - a.price, *ds2, to_string(*cls));
}beta = 0.00 gamma = 1.0000 beta = 0.50 gamma = 1.1547 beta = 0.90 gamma = 2.2942 beta = 0.99 gamma = 7.0888 dP = +0.4 ds2 = -0.84 Timelike dP = +3.0 ds2 = +8.00 Spacelike
Slightly, and not robustly. Pooled over ten tickers, next-bar return variance after a spacelike bar is about 1.26 times the variance after a timelike bar. Bartlett's test calls that highly significant, but Bartlett assumes normal returns; Levene's test, which does not, gives p ≈ 0.10, and the effect size is tiny. Numbers below are recomputed from today's build with validation/analyze_q1.py.
| ticker | timelike | spacelike | var SL / TL | Cohen d |
|---|
Daily bars (the files are named *_1m.csv but hold daily data). p-values are per ticker, before Bonferroni correction.
This repository explores a mathematical analogy; it does not claim that markets obey special relativity. Nothing here is a tested trading strategy, and no result on this page should be read as one. The unit tests check that the maths is computed correctly, not that it makes money.