Skip to content

Model Dai2011LongOnlyDemo

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

Dai2011LongOnlyDemo — quantitative model reference

Wiki home · Quantitative model references · Execution records

This quantitative model reference is provided for study, further research and application within the AlgoQuant framework. Read the research idea and implementation choices separately from the execution record.

Tutorials and quantitative model references · Pinned source · Javadoc

Paper introduction

Min Dai, Qing Zhang and Qiji Jim Zhu, Trend Following Trading under a Regime Switching Model (2010) studies when buying into a rising market and selling into a falling market can be optimal under an explicit price model and transaction costs. The journal publication is from 2010, although the Java package retains dai2011.

The market switches between hidden bull and bear regimes. The trader observes prices, not the regime itself, and updates a probability of being in the favorable state using a filtering model. Optimal-stopping arguments characterize buy and sell decisions in terms of that information and the cost of trading. Trend following here therefore has a probabilistic economic interpretation rather than being an arbitrary chart signal.

Optimality is conditional on the assumed regime dynamics, calibrated parameters and cost model; it is not a promise about future market returns. The demo's resampling, calibration windows and position-management choices are additional implementation decisions. The model, filtering and trading-cost sections of the original journal article were reviewed.

How this demo connects to the idea

Dai2011LongOnly adapts the idea with a three-year burn-in, yearly recalibration, a 21-observation regime-identification window, threshold 0.10 and rho=0. These are example calibration choices, not the paper’s complete experiment. Read its additional sizing and stop logic before comparing results. Initial cash is 1,000,000; report measures mix SIMPLE information-ratio returns with ABSOLUTE Omega inputs, so their scales differ.

What this example teaches

Demonstrates the Dai's optimal trend following trading strategy.

Using this example. Constructs Dai2011LongOnly, supplies Yahoo order books and initial capital, then runs the simulator and reads its PerformanceReport. The plotter opens a desktop chart. Inspect the model parameters and trade sizing independently of the initial cash balance.

Model and publication. The paper models bull/bear drift as an unobserved Markov state. A filtered bull probability drives entry and exit boundaries for a transaction-cost-aware stopping problem. The package’s 2011 label differs from the linked 2010 journal publication.

Implementation in this tutorial. Dai2011LongOnly adapts the idea with a three-year burn-in, yearly recalibration, a 21-observation regime-identification window, threshold 0.10 and rho=0. These are example calibration choices, not the paper’s complete experiment. Read its additional sizing and stop logic before comparing results. Initial cash is 1,000,000; report measures mix SIMPLE information-ratio returns with ABSOLUTE Omega inputs, so their scales differ.

Verified execution record

Item Value
Status completed
Run 39114360151
UTC publication 2026-10-18 11:43 UTC
Source commit 355aa9242fc2a247b256aecc8406cbb409aa5ff3
Data mode original main defaults
Exit code 0
Elapsed seconds 25.78
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.dai2011.Dai2011LongOnlyDemo

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:32.363 [main] INFO  t.n.algoquant.util.config.AQConfig,194 - looking up configuration file: config.default.xml
09:12:32.366 [main] INFO  t.n.algoquant.util.config.AQConfig,194 - looking up configuration file: config/config.default.xml
09:12:32.366 [main] INFO  t.n.algoquant.util.config.AQConfig,209 - loading config file: file:/home/runner/work/algoquant-examples/algoquant-examples/target/model-results/Dai2011LongOnlyDemo/work/config/config.default.xml


09:12:32.619 [main] INFO  t.n.algoquant.util.config.AQConfig,95 - current directory: /home/runner/work/algoquant-examples/algoquant-examples/target/model-results/Dai2011LongOnlyDemo/work
09:12:32.619 [main] INFO  t.n.algoquant.util.config.AQConfig,169 - current config:
09:12:32.627 [main] INFO  t.n.algoquant.util.config.AQConfig,11 - nm.license: /home/runner/work/algoquant-examples/algoquant-examples/license/nm.lic
09:12:32.627 [main] INFO  t.n.algoquant.util.config.AQConfig,11 - DATA_FOLDER: ./test-data
09:12:32.627 [main] INFO  t.n.algoquant.util.config.AQConfig,11 - DATA_GAINCAPITAL: ${DATA_FOLDER}/processed/gaincapital/extracted-from-raw-arrange-by-dates
09:12:32.628 [main] INFO  t.n.algoquant.util.config.AQConfig,11 - DATA_BLOOMBERG: ${DATA_FOLDER}/processed/bloomberg
09:12:32.628 [main] INFO  t.n.algoquant.util.config.AQConfig,11 - DATA_YAHOO: ${DATA_FOLDER}/yahoo
09:12:32.628 [main] INFO  t.n.algoquant.util.config.AQConfig,11 - DATA_SGX: ${DATA_FOLDER}/raw/sgx
09:12:32.628 [main] INFO  t.n.algoquant.util.config.AQConfig,11 - DATA_HOLIDAYS: ./log/holidays
09:12:32.628 [main] INFO  t.n.algoquant.util.config.AQConfig,11 - DATA_COMPUSTAT_HK: ${DATA_FOLDER}/[database configuration redacted]/hk
09:12:32.629 [main] INFO  t.n.algoquant.util.config.AQConfig,11 - PDF_OUTPUT_FOLDER: ./log/
09:12:32.629 [main] INFO  t.n.algoquant.util.config.AQConfig,11 - PDF_PLOT_WIDTH: 800
09:12:32.629 [main] INFO  t.n.algoquant.util.config.AQConfig,11 - PDF_PLOT_HEIGHT: 600
09:12:34.905 [main] INFO  t.n.a.d.h.yahoo.YahooEODCacheFactory,237 - failed to load from file, reason: no data read from file; load from web
09:12:34.905 [main] INFO  t.n.a.d.h.yahoo.YahooEODCacheFactory,196 - reading Yahoo! data for ^GSPC from the Internet from 2006-01-01T00:00 to 2015-12-31T16:00
09:12:35.054 [main] INFO  t.n.a.d.h.y.YahooEODCsvZipFileWriter,30 - writing csv.zip file ./log/Yahoo/^GSPC.csv.zip
09:12:35.123 [main] INFO  t.n.a.d.h.y.YahooEODCsvZipFileWriter,81 - finished writing ./log/Yahoo/^GSPC.csv.zip
09:12:39.844 [main] INFO  t.n.a.m.t.d.strategy.Dai2011LongOnly,32 - calibration at 2009-01-02T16:00, from 2006-01-03T16:00 to 2009-01-02T16:00
Dai 2011 HMM: 
in uptrend state: drift = 2.201207, lambda1 = 3.046598
in downtrend state: drift = -2.111269, lambda2 = 3.373191
volatility = 0.267244,
thresholds: pb = 0.7120764999999623, ps = 0.2858466250000147
09:12:41.606 [main] INFO  t.n.a.m.t.d.strategy.Dai2011LongOnly,32 - calibration at 2010-01-04T16:00, from 2006-01-05T16:00 to 2010-01-04T16:00
Dai 2011 HMM: 
in uptrend state: drift = 1.958070, lambda1 = 3.152999
in downtrend state: drift = -1.989819, lambda2 = 3.758588
volatility = 0.266189,
thresholds: pb = 0.7186683749999191, ps = 0.3041197500000117
09:12:43.627 [main] INFO  t.n.a.m.t.d.strategy.Dai2011LongOnly,32 - calibration at 2011-01-05T16:00, from 2007-01-08T16:00 to 2011-01-05T16:00
Dai 2011 HMM: 
in uptrend state: drift = 1.799042, lambda1 = 3.384687
in downtrend state: drift = -1.981272, lambda2 = 4.235415
volatility = 0.271387,
thresholds: pb = 0.7306304999999428, ps = 0.32441762500001553
09:12:45.556 [main] INFO  t.n.a.m.t.d.strategy.Dai2011LongOnly,32 - calibration at 2012-01-06T16:00, from 2008-01-07T16:00 to 2012-01-06T16:00
Dai 2011 HMM: 
in uptrend state: drift = 1.814628, lambda1 = 3.700861
in downtrend state: drift = -2.028698, lambda2 = 4.660857
volatility = 0.280502,
thresholds: pb = 0.7316213750000512, ps = 0.3311736250000415
09:12:47.758 [main] INFO  t.n.a.m.t.d.strategy.Dai2011LongOnly,32 - calibration at 2013-01-07T16:00, from 2009-01-08T16:00 to 2013-01-07T16:00
Dai 2011 HMM: 
in uptrend state: drift = 1.323844, lambda1 = 3.006532
in downtrend state: drift = -1.632394, lambda2 = 4.505211
volatility = 0.245422,
thresholds: pb = 0.7514530000000841, ps = 0.3484462499999876
09:12:50.042 [main] INFO  t.n.a.m.t.d.strategy.Dai2011LongOnly,32 - calibration at 2014-01-08T16:00, from 2010-01-11T16:00 to 2014-01-08T16:00
Dai 2011 HMM: 
in uptrend state: drift = 0.937670, lambda1 = 2.226854
in downtrend state: drift = -1.362828, lambda2 = 4.266281
volatility = 0.207933,
thresholds: pb = 0.7843048749999921, ps = 0.37449099999997665
09:12:52.144 [main] INFO  t.n.a.m.t.d.strategy.Dai2011LongOnly,32 - calibration at 2015-01-09T16:00, from 2011-01-10T16:00 to 2015-01-09T16:00
Dai 2011 HMM: 
in uptrend state: drift = 0.733946, lambda1 = 1.688971
in downtrend state: drift = -1.239282, lambda2 = 4.167398
volatility = 0.182110,
thresholds: pb = 0.8121413749999447, ps = 0.39562325000002224
09:12:52.338 [main] INFO  t.n.a.d.m.d.Dai2011LongOnlyDemo,157 - Performance Report:
Product	Profit Loss	Max Drawdown Percentage	Information Ratio For Periods	Omega For Periods
^GSPC	535054.9818115234	0.1346872184414231	0.6691663952340973	3.114359497832033
Total	535054.9818115234	0.1346872184414231	0.7065118708444367	3.5202119523387583

Charts from this run

Chart 1

Reported performance statistics

Products and aggregate shown exactly as reported; P/L is monetary, not percent. Currency conventions belong to the demo.

Derived from stdout.log using the precision available in that file. Download plotted data. Undefined or malformed cells are omitted, never replaced by zero.

Chart 2

Downloadable evidence

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

Export Bytes
files/charts/chart-01.png 198300
files/derived-charts/charts.json 521
files/derived-charts/derived-01.csv 399
files/derived-charts/derived-01.png 87386

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