Live Nov 18 · Cohort 3Nov 18, 19:00 MSK — free hands-on AI agents live workshop · Live Cohort 3 starts Nov 23Join Nov 18 Live →Cohort 3 (Nov 23)
ReleaseInsight · On RadarHabr AI→ original

DiffQuant optimizes the Sharpe ratio directly through a differentiable trading simulator

Most ML models for trading learn to minimize MSE but are judged by the Sharpe ratio, and those are different problems. DiffQuant removes the gap: the entire path from market features to PnL and fees is built as a single differentiable graph, so the gradient flows through the real trading mechanics. On two held-out quarters, it posted Sharpe of +1.73 and +1.15 after fees. The code is open.

AI-processed from Habr AI; edited by Hamidun News
DiffQuant optimizes the Sharpe ratio directly through a differentiable trading simulator
Source: Habr AI. Collage: Hamidun News.
Listen to article
Article Fact Sheet & Key Figures
ParameterDetails
Primary sourceHabr AI ↗
Editor-in-Chief
Key metric #1Market features → a neural block that predicts the signal
Key metric #2Signal → a target position, subject to size and direction constraints
Key metric #3Position → step-by-step PnL with an explicit slippage and fee model

DiffQuant is an open-source prototype that tackles a basic contradiction in ML trading: models learn to minimize mean squared error but are judged by the Sharpe ratio. The authors closed that gap by turning the whole trading pipeline, from features to PnL and fees, into one differentiable graph.

The problem with surrogate objectives

In most ML systems for quantitative trading, the setup looks like this: train a neural network to predict returns or price direction by minimizing MSE or BCE. Then build a trading strategy on top of those predictions and evaluate it by the Sharpe ratio, the ratio of mean return to volatility.

The problem is that these two objectives are not mathematically linked. A better MSE does not guarantee a better Sharpe. In practice, the network spends capacity reducing prediction error in market regimes where it has no effect on the final trading result. A 15% improvement in forecast accuracy may produce no Sharpe gain at all, a problem documented both in academic work and among quant practitioners.

Partial fixes such as ranking loss functions, custom proxy metrics and post-hoc weighting do not address the core issue: during training, the gradient does not see the real trading mechanics.

How the differentiable simulator works

DiffQuant takes the direct route: the whole trading pipeline is implemented as a single computational graph of continuous operations:

  • Market features → a neural block that predicts the signal
  • Signal → a target position, subject to size and direction constraints
  • Position → step-by-step PnL with an explicit slippage and fee model
  • Cumulative PnL → the Sharpe ratio as a differentiable scalar loss function

The key technical question is how to make positioning and costs differentiable, since real trading operations are discrete. The authors use soft approximations: instead of sharp transitions between positions, they use continuous functions accurate enough for the gradient to pass through.

"This is not a finished trading system; it is a different problem formulation," the authors stress.

The result: the gradient of the Sharpe ratio propagates back through the whole pipeline to the neural network's weights. The model trains directly on the criterion by which it will be judged in production.

Sharpe +1.73 and +1.15 after fees

The prototype was tested on two consecutive held-out quarters, periods the model saw neither during training nor during hyperparameter tuning. Sharpe was +1.73 in the first quarter and +1.15 in the second, after accounting for real fees. Both values are above one, the accepted baseline for algorithmic strategies.

The code, data and full experimental protocol are publicly available. Anyone with access to comparable market data can reproduce the results. The authors deliberately avoided complications: no exotic architectures or unconventional features, only a change of loss function.

What this means

DiffQuant shows that framing the problem correctly matters more than choosing an architecture. If a strategy is judged by Sharpe in production, that is what training should optimize, not surrogates. For quant funds and independent researchers, this is a practical signal: the gap between the training objective and the real metric can be closed technically, and doing so changes not only the result but also what exactly the model learns.

Story

Key Questions Answered

What are the key details on The problem with surrogate objectives?

In most ML systems for quantitative trading, the setup looks like this: train a neural network to predict returns or price direction by minimizing MSE or BCE. Then build a trading strategy on top of those predictions and evaluate it by the Sharpe ratio, the ratio of mean return to volatility. The problem is that these two objectives are not mathematically linked. A better MSE does not guarantee a better Sharpe.

How the differentiable simulator works?

DiffQuant takes the direct route: the whole trading pipeline is implemented as a single computational graph of continuous operations: Market features → a neural block that predicts the signal Signal → a target position, subject to size and direction constraints Position → step-by-step PnL with an explicit slippage and fee model Cumulative PnL → the Sharpe ratio as a differentiable scalar loss function The key technical question is how to make positioning and costs differentiable, since real…

What are the key details on Sharpe +1.73 and +1.15 after fees?

The prototype was tested on two consecutive held-out quarters, periods the model saw neither during training nor during hyperparameter tuning. Sharpe was +1.73 in the first quarter and +1.15 in the second, after accounting for real fees. Both values are above one, the accepted baseline for algorithmic strategies. The code, data and full experimental protocol are publicly available. Anyone with access to comparable market data can reproduce the results.

ZK
Zhemal Khamidun — CPO at Alpina Digital, product manager of AlpinaGPT. Building AI products since 2019. Hamidun News is a pet project that grew into a production aggregator with 6,000+ readers.
✦ Private AI Builders Community · Vibe Club

Ship AI Faster with Founders, Engineers & Weekly Architecture Reviews

Inside Vibe Club (hamidun.com/club) — weekly live masterminds with Zhemal Khamidun, Tech Radar, full LMS access, and 370+ production Claude Code skills.

Join Vibe Club →Explore Hamidun Academy
What do you think?
Loading comments…