Special Relativity in Financial Modeling · C++20

Every bar is an event in spacetime.

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.

The zip holds four .exe tools, ten tickers of sample data and demo.bat: unzip and double-click it.

Research code, not financial advice. The chart below is the real output of regime_validator on the SPY daily bars committed in the repo.

SPY daily close · each segment coloured by the interval the C++ core assigned it
 
 
interval
β (capped)
window

Hover or tap a bar. Arrow keys step through bars when the chart has focus.

timelike, ds² < 0 spacelike, ds² > 0 light cone at the selected bar

Labels come from build/regime_validator --input validation/data/SPY_1m.csv (rolling z-score normaliser, window 20). Dates 2021-03 to 2026-02.

How it works

From a price bar to a label, in four steps.

No physics needed. Each figure is recomputed from the C++ formulas on the bundled SPY data, and every label matches the regime_validator output.

Four steps: take one bar; rescale close, volume and momentum to standard deviations from the last 20 bars; measure the step from the previous bar; compare it to the speed limit c = 1. Under it is timelike, over it is spacelike. Four steps: take one bar; rescale close, volume and momentum to standard deviations from the last 20 bars; measure the step from the previous bar; compare it to the speed limit c = 1. Under it is timelike, over it is spacelike.

The Lorentz factor γ

β is the step as a fraction of the speed limit. γ = 1/√(1 − β²) stays near 1 for calm bars and shoots up near the limit. srfm --backtest sizes positions by γ, clamped to 1x to 3x.

Gamma against beta: flat near 1, 2.29 at beta 0.9, 7.09 at beta 0.99, with ticks for the 295 timelike SPY bars. Gamma against beta: flat near 1, 2.29 at beta 0.9, 7.09 at beta 0.99, with ticks for the 295 timelike SPY bars.

The spacetime interval on real bars

The last 60 SPY daily bars: 18 under the speed limit (timelike), 42 over it (spacelike). The last 60 SPY daily bars: 18 under the speed limit (timelike), 42 over it (spacelike).
Quick start

Clone, build, test. No keys, no vcpkg.

CMake 3.25+ and a C++20 compiler. Eigen is vendored; GoogleTest, Google Benchmark and fmt are fetched on first configure.

git clone https://gitlab.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

On Windows keep the clone path short (MSBuild has a 260-character path limit for its intermediate files).

 regime_validator, SPY
$ ./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
What the core computes

Velocity, interval, curvature.

β and γ

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.

γ = 1 / √(1 − β²)

Interval class

MarketManifold::process z-scores time, price, volume and momentum over a rolling window, computes the Minkowski interval to the previous bar and classifies it.

ds² = −c²dt² + dP² + dV² + dM²

Geodesics

MetricTensor, Christoffel symbols by finite differences or dual numbers, an RK4 geodesic solver, and a deviation signal between the observed path and the geodesic.

x¨μ + Γμνρ ẋν ẋρ = 0

Use it as a library

// 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));
}
 ./build/lorentz_basics
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
The one empirical question

Are spacelike bars followed by more variance?

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.

tickertimelikespacelikevar SL / TLLevene pBartlett pCohen d

Daily bars (the files are named *_1m.csv but hold daily data). p-values are per ticker, before Bonferroni correction.

The SRFM family

Four repositories, one idea.

C++ core · you are hereSpecial-Relativity-in-Financial-Modelingβ, γ, interval labels, Christoffel symbols, geodesic deviation, validation scripts.
Research labsrfm-labBlack-hole signal, Monte Carlo backtests, a paper trader and an idea engine.
Python SDKsrfm-pythonA pandas df.srfm accessor and a Polars wrapper.
The papersrfm-paper-implPreprint, figure scripts and a Rust reference of the formulas.
Read this first

Research code, not financial advice.

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.