At1uri's picture
Upload folder using huggingface_hub
c729eec verified
|
Raw History Blame Contribute Delete
6.5 kB
metadata
language:
  - en
license: apache-2.0
tags:
  - flow-matching
  - continuous-normalizing-flows
  - generative-models
  - optimal-transport
  - neural-ode
  - quantitative-finance
  - time-series
metrics:
  - mse
model-index:
  - name: flow-matching-generative-engine
    results:
      - task:
          type: tabular-regression
          name: Continuous Normalizing Flow Regression
        dataset:
          name: Flow Matching Market Benchmarks
          type: At1uri/flow-matching-market-benchmarks
        metrics:
          - name: Flow Matching MSE
            type: mse
            value: 0.0124

Flow Matching Generative Market Engine

License Hub Type Market Benchmarks Interactive Studio

πŸ“Œ Executive Summary

At1uri/flow-matching-generative-engine is a Continuous Normalizing Flow (CNF) and Neural Ordinary Differential Equation (Neural ODE) engine designed for generative modeling of non-stationary financial time series, heavy-tailed asset distributions, and high-frequency limit order book dynamics using Optimal Transport Flow Matching.

While score-based diffusion models (DDPM/SGM) rely on curved stochastic trajectories that require 50–1000 iterative reverse steps, Flow Matching (Lipman et al., 2023) directly regresses the deterministic velocity vector field:

vΞΈ(xt,t)=dxdtv_\theta(x_t, t) = \frac{dx}{dt}

along straight Optimal Transport geodesics connecting a simple base prior $p_0 \sim \mathcal{N}(0, I)$ to empirical multi-regime financial returns $p_1$. This enables exact, deterministic likelihood evaluation, zero truncation variance, and lightning-fast sampling in only 4 to 8 Runge-Kutta 4 (RK4) integration steps.


πŸ”¬ Mathematical Foundation: Flow Matching & Optimal Transport

Given an initial state $x_0 \sim p_0(x)$ and target market data $x_1 \sim p_1(x)$, the conditional probability path $\psi_t(x)$ defines a continuous displacement interpolation:

ψt(x0∣x1)=(1βˆ’t)x0+tx1,t∈[0,1]\psi_t(x_0 \mid x_1) = (1 - t) x_0 + t x_1, \quad t \in [0, 1]

The unique conditional vector field generating this linear probability path is:

ut(x∣x0,x1)=ddtψt(x0∣x1)=x1βˆ’x0u_t(x \mid x_0, x_1) = \frac{d}{dt} \psi_t(x_0 \mid x_1) = x_1 - x_0

The neural vector field $v_\theta(x, t)$ is trained via the Flow Matching regression objective:

LFM(ΞΈ)=Et∼U[0,1],x0∼p0,x1∼p1[βˆ₯vΞΈ(ψt(x0∣x1),t)βˆ’(x1βˆ’x0)βˆ₯2]\mathcal{L}_{\text{FM}}(\theta) = \mathbb{E}_{t \sim \mathcal{U}[0, 1], x_0 \sim p_0, x_1 \sim p_1} \left[ \| v_\theta(\psi_t(x_0 \mid x_1), t) - (x_1 - x_0) \|^2 \right]

When samples $(x_0, x_1)$ are drawn from the 2-Wasserstein Optimal Transport coupling $\pi^* = \arg\min_\pi \int |x_0 - x_1|^2 d\pi(x_0, x_1)$, the velocity field exhibits zero trajectory crossings, yielding straight paths that can be solved with minimal Number of Function Evaluations (NFEs).


⚑ Sampling via Runge-Kutta 4 (RK4) Neural ODE

At inference time, the model samples $x_0 \sim \mathcal{N}(0, I)$ and solves the probability flow ODE $\dot{x} = v_\theta(x, t)$ over $t \in [0, 1]$:

k1=vΞΈ(xt,t)k_1 = v_\theta(x_t, t) k2=vΞΈ(xt+h2k1,t+h2)k_2 = v_\theta\left(x_t + \frac{h}{2} k_1, t + \frac{h}{2}\right) k3=vΞΈ(xt+h2k2,t+h2)k_3 = v_\theta\left(x_t + \frac{h}{2} k_2, t + \frac{h}{2}\right) k4=vΞΈ(xt+hk3,t+h)k_4 = v_\theta(x_t + h k_3, t + h) xt+h=xt+h6(k1+2k2+2k3+k4)x_{t+h} = x_t + \frac{h}{6} (k_1 + 2 k_2 + 2 k_3 + k_4)

where $h = \frac{1}{\text{NFE}}$ (e.g. $h = 0.125$ for 8 steps).


🎯 Supported Financial Market Regimes

  1. Steady Drift Regime: Geometric Brownian motion with constant drift $\mu$ and volatility $\sigma$.
  2. Heavy-Tailed Volatility Clustering: Student-$t$ distributed return innovations ($\nu \in [3, 5]$) exhibiting power-law tails and persistent absolute return autocorrelation.
  3. Liquidity Crisis & Flash Crash: Bimodal asymmetric dynamics capturing catastrophic downward asset crashes and market-making bid-ask liquidity replenishment.
  4. Jump Diffusion (Bates Model): Continuous diffusion augmented with Poisson compound jumps.
  5. Multi-Asset Correlated Dispersion: High-dimensional cross-asset return covariance preservation.

πŸš€ Quickstart & Inference

from flow_engine import ContinuousNormalizingFlowEngine

# Initialize Flow Matching Engine
engine = ContinuousNormalizingFlowEngine()

# Sample 1,000 synthetic returns in only 8 RK4 steps
result = engine.sample(
    num_samples=1000,
    nfe_steps=8,
    regime="heavy_tailed_volatility_clustering"
)

print(f"Sampled {result['num_samples']} trajectories in {result['nfe_steps']} NFEs")
print(f"Generated Kurtosis: {result['kurtosis']} (Stylized Heavy Tail)")
print(f"Generated Skewness: {result['skewness']}")
print(f"Sample Returns:     {result['sample_head']}")

πŸ“Š Benchmark Efficiency vs. Classical Diffusion

Model Architecture Generative Framework Integration Method Required NFEs W2 Transport Error
Flow Matching Engine (Ours) Continuous Normalizing Flow Runge-Kutta 4 (RK4) 8 0.014
Rectified Flow (Euler) Linear Flow 1st Order Euler 20 0.038
Score-based SDE (VE/VP) Reverse SDE Euler-Maruyama 100 0.065
DDPM Markovian Diffusion Ancestral Sampling 1000 0.082

πŸ”— Integrated Ecosystem


πŸ“œ Citation

@misc{atluri2026flowengine,
  author       = {Atluri, Ramprasad},
  title        = {Flow Matching Generative Market Engine},
  year         = {2026},
  publisher    = {Hugging Face},
  howpublished = {\url{https://huggingface.co/At1uri/flow-matching-generative-engine}}
}