Skip to content

Model MeanReversionPortfolioDemo

github-actions[bot] edited this page Oct 18, 2026 · 8 revisions

MeanReversionPortfolioDemo — quantitative model tutorial

All quantitative model results · Pinned source · Javadoc

Strategy introduction

This example illustrates a mean-reversion or grid-style trading policy assembled in code. No single original publication has been established for the exact rule, so this page explains the strategy without inventing a paper citation.

The broad idea is to change inventory as price moves through configured levels, or as a spread deviates from a reference. Reversals can allow purchases and sales at different levels, while a persistent trend can accumulate exposure or losses. A rule that repeatedly realizes small gains can still carry substantial open-position risk.

The result depends on grid spacing, reference updates, position limits, data frequency, fills and costs. Mean reversion is an assumption to examine, not a property created by the grid itself. Read the implementation below for the exact configuration, and inspect both account value and outstanding inventory when interpreting a simulation.

How this demo connects to the idea

This composition combines components with different grid sizes. Read their individual scales before comparing the aggregate P/L with a single component. These are library-specific spread/grid trading policies. A basket converts product prices into a spread; the configured mean-reversion model maps its level or deviation into a desired state, and MeanReversionStrategy translates that state into product orders. Grid distance, periodic/ranged update behavior and scale are distinct controls. The folder name does not mean that option implied volatility is being traded. Mean reversion is an assumption to check, not a property guaranteed by this policy.

What this example teaches

Demonstrates how to create a MeanReversionPortfolio with different grid sizes.

Using this example. Combines mean-reversion components with different grid sizes on local GainCapital data. Follow each basket and scale into the combined portfolio; adding components changes total exposure and does not automatically normalize the allocation.

Model and publication. No single original research publication is claimed for this library/example policy.

Implementation in this tutorial. This composition combines components with different grid sizes. Read their individual scales before comparing the aggregate P/L with a single component. These are library-specific spread/grid trading policies. A basket converts product prices into a spread; the configured mean-reversion model maps its level or deviation into a desired state, and MeanReversionStrategy translates that state into product orders. Grid distance, periodic/ranged update behavior and scale are distinct controls. The folder name does not mean that option implied volatility is being traded. Mean reversion is an assumption to check, not a property guaranteed by this policy.

Verified execution record

Item Value
Status completed
Run 39114360151
UTC publication 2026-10-18 09:18 UTC
Source commit 355aa9242fc2a247b256aecc8406cbb409aa5ff3
Data mode original main defaults
Exit code 0
Elapsed seconds 2.29
Time limit seconds 180
Maximum Java heap 1200m

The original main returned successfully. Read the output and model assumptions before interpreting it.

Reproduce the calculation

Follow the repository setup for JDK 8, Maven credentials and an external NM license. From the repository root:

mvn -U -Dmaven.test.skip=true clean package
mvn exec:java -Dexec.mainClass=tech.nmfin.algoquant.demo.model.volarb.MeanReversionPortfolioDemo

The automated run uses scripts/ModelDemoRunner.java to initialize the external license before the unchanged main, save JFreeChart windows as PNGs, and exit after main returns. It uses an isolated working directory with the repository datasets/configuration linked in. Running directly may leave desktop windows open.

Observed output


09:12:41.996 [main] INFO  t.n.a.d.m.v.MeanReversionPortfolioDemo,150 - executions: 
#	Time	Side	Symbol	Quantity	Price
1	2010-08-02T02:43:30	SELL	NZD/CHF	1.0	0.7603
2	2010-08-02T03:21:46	SELL	NZD/CHF	2.0	0.7628
3	2010-08-02T03:21:46	SELL	NZD/CHF	1.0	0.7628
4	2010-08-02T03:38:30	SELL	NZD/CHF	1.0	0.7653
5	2010-08-02T03:56:06	SELL	NZD/CHF	1.0	0.7678
6	2010-08-02T03:56:06	SELL	NZD/CHF	2.0	0.7678
7	2010-08-02T05:21:38	BUY	NZD/CHF	1.0	0.7657
8	2010-08-02T09:13:54	BUY	NZD/CHF	1.0	0.7633
9	2010-08-02T09:13:54	BUY	NZD/CHF	2.0	0.7633
10	2010-08-02T10:48:49	BUY	NZD/CHF	1.0	0.7607
09:12:41.999 [main] INFO  t.n.a.d.m.v.MeanReversionPortfolioDemo,152 - Performance Report:
Product	Execution Count	Profit Loss	Information Ratio For Trades	Omega For Trades
NZD/CHF	10.0	0.022220000042580068	-0.022375793092938384	-0.056602527547561135
Total	10.0	0.022220000042580068	-0.022375793092938384	-0.056602527547561135

Charts from this run

Chart 1

Downloadable evidence

Download MeanReversionPortfolioDemo.zip contains stdout, stderr, the execution record, checksums and any exported CSV/chart files.

Export Bytes
files/charts/chart-01.png 108326

Interpreting the result

Read the reported units: optimizer weights, model-fit coefficients, forecast correlations and simulated P/L are different outputs. Synthetic runs demonstrate the API rather than historical market returns. Inspect undefined values and open positions instead of replacing them with zero. Chart exports visualize exactly this run.

For model assumptions, original publications and adaptation limits, use the literature guide.

Clone this wiki locally