NextStatNextStat

NextStat for Quants & Risk Analysts

Portfolio risk, causal inference, and model validation

You build models for pricing, risk, and regulatory compliance. NextStat gives you a Rust-speed inference engine with econometrics primitives (Panel FE, DiD, IV/2SLS, AIPW), time series (Kalman filter/smoother, EM, forecasting), and a validation report designed for SR 11-7 model risk management — all callable from Python.

Why NextStat for Finance?

Most quant stacks glue together R, Python statsmodels, and ad-hoc C++ for speed. NextStat replaces the compute layer: one engine that runs GLMs, panel regressions, Kalman filters, and Bayesian NUTS at Rust speed — with deterministic validation artifacts your model risk team can audit.

What You Already Know → What NextStat Calls It

Finance / EconNextStat APIUse Case
Panel regression (entity FE)nextstat.panel_fe()Fund return attribution, cross-sectional asset pricing
Difference-in-Differencesnextstat.did()Policy impact on trading costs, fee changes
IV / 2SLSnextstat.iv_2sls()Endogeneity correction in demand estimation
Doubly-robust estimator (AIPW)nextstat.aipw()ATE estimation with model misspecification protection
Kalman filter / smoothernextstat.kalman_filter()State estimation, volatility tracking, signal extraction
EM parameter estimationnextstat.kalman_em()Fit state-space model parameters from observed data
Forecasting with intervalsnextstat.kalman_forecast()Multi-step ahead predictions with Gaussian prediction bands
Robust / cluster SEnextstat.ols(robust=True)HC0–HC3, entity/time clustering for panel data

Quickstart: Panel Regression + Kalman Forecast

import nextstat
import numpy as np

# --- Panel regression with entity fixed effects ---
y = np.array([...])        # returns: (N*T,)
X = np.array([...])        # features: (N*T, k)
entity = np.array([...])   # entity IDs: (N*T,)

result = nextstat.panel_fe(y, X, entity_ids=entity, robust=True)
print(f"Coefficients: {result.params}")
print(f"Cluster-robust SE: {result.std_errors}")
print(f"R² (within): {result.r_squared_within:.4f}")

# --- Kalman filter for state estimation ---
ys = np.array([...])  # observed prices: (T, obs_dim)

# Define state-space matrices (local level model)
F = np.eye(1)           # state transition
H = np.ones((1, 1))     # observation
Q = np.eye(1) * 0.01    # state noise
R = np.eye(1) * 0.1     # observation noise

states = nextstat.kalman_filter(ys, F, H, Q, R)
smoothed = nextstat.kalman_smooth(ys, F, H, Q, R)
forecast = nextstat.kalman_forecast(ys, F, H, Q, R, steps=20)

Causal Inference: DiD + Event Study

# Difference-in-Differences with TWFE
did_result = nextstat.did(
    y=outcomes,
    treat=treatment_indicator,
    post=post_period,
    X=controls,
    entity_ids=firms,
    time_ids=quarters,
)
print(f"ATT: {did_result.att:.4f} ± {did_result.att_se:.4f}")

# IV/2SLS for endogeneity
iv_result = nextstat.iv_2sls(
    y=demand,
    X_endog=price,
    X_exog=controls,
    Z=instruments,
)
print(f"IV estimate: {iv_result.params}")
print(f"First-stage F: {iv_result.first_stage_f:.1f}")

Model Validation for SR 11-7

NextStat generates validation_report.json — a machine-readable artifact with dataset SHA-256 hashes, model specification, environment fingerprint, and per-suite pass/fail results. Designed for model risk management review under SR 11-7 and similar frameworks.

# Generate validation report (CLI)
nextstat validation-report \
  --apex2 tmp/apex2_master_report.json \
  --workspace workspace.json \
  --out validation_report.json \
  --pdf validation_report.pdf \
  --deterministic

Performance: Why Rust Matters for Quant Workloads

Workloadvs PythonNote
MLE fit (100-param model)37–880× fastervs ROOT/RooFit and pyhf on profile scans
Batch toy generation (GPU)10,000 toys in 7msMetal + CUDA (zero-copy with PyTorch)
Kalman filter (T=10k)~5× fasterRust BLAS-free, no Python overhead per step
Panel FE (N=10k, T=100)~3× fasterDemean + OLS in compiled code

Next Steps

  • EconometricsPanel FE, DiD, IV/2SLS, AIPW reference Econometrics
  • Time SeriesKalman filter, EM, forecasting Time Series
  • Regression & GLMOLS, logistic, Poisson, robust SE Regression & GLM
  • Validation ReportAudit-ready JSON+PDF artifacts Validation Report
  • Agentic ToolsLLM tool definitions for AI-driven analysis Agentic Tools
  • Server APISelf-hosted GPU inference for shared compute Server API
  • GlossaryHEP ↔ DS ↔ Quant ↔ Bio term mapping Glossary