Repository navigation
Model BootstrapSimulationDemo
Wiki home · Tutorials · Execution records
These examples are tutorials that teach how to use AlgoQuant. Their numerical results are incidental and irrelevant to their teaching purpose. Use them to learn API calls, simulation setup, data flow and reporting. The technical examples use synthetic quick-mode data. Read a result here as an illustration of a library call, not as investment evidence.
Tutorials and quantitative model references · Pinned source · Javadoc
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.
The main uses Dai2011LongShort and reconstructed paths obtained from sampled log returns. Each scenario has its own market cache, simulator and report. PattonPolitisWhite2009 estimates a block length for dependent resampling; neither a resampled path nor a bootstrap P/L quantile is a new historical observation or a reproduction of the paper’s market test.
Demonstrates the bootstrap simulation of the Dai's trend following strategy.
Using this example. Resamples log returns for the Dai trend-following strategy, reconstructs price paths and runs a fresh strategy on each path. The output file under log/demo contains scenario reports. Sampled paths are hypothetical and the chosen block lengths and randomization affect the distribution.
Model and publication. Filtered regime probabilities and trading boundaries are the conceptual basis of the Dai strategy. The bootstrap performed here is a separate experiment layered over that strategy.
Implementation in this tutorial. The main uses Dai2011LongShort and reconstructed paths obtained from sampled log returns. Each scenario has its own market cache, simulator and report. PattonPolitisWhite2009 estimates a block length for dependent resampling; neither a resampled path nor a bootstrap P/L quantile is a new historical observation or a reproduction of the paper’s market test.
| 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 | 54.29 |
| Time limit seconds | 180 |
| Maximum Java heap | 1200m |
The original main returned successfully. Read the output and model assumptions before interpreting it.
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.BootstrapSimulationDemoThe 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.
09:12:34.428 [main] INFO t.n.algoquant.util.config.AQConfig,194 - looking up configuration file: config.default.xml
09:12:34.430 [main] INFO t.n.algoquant.util.config.AQConfig,194 - looking up configuration file: config/config.default.xml
09:12:34.430 [main] INFO t.n.algoquant.util.config.AQConfig,209 - loading config file: file:/home/runner/work/algoquant-examples/algoquant-examples/target/model-results/BootstrapSimulationDemo/work/config/config.default.xml
09:12:34.750 [main] INFO t.n.algoquant.util.config.AQConfig,95 - current directory: /home/runner/work/algoquant-examples/algoquant-examples/target/model-results/BootstrapSimulationDemo/work
09:12:34.750 [main] INFO t.n.algoquant.util.config.AQConfig,169 - current config:
09:12:34.758 [main] INFO t.n.algoquant.util.config.AQConfig,11 - nm.license: /home/runner/work/algoquant-examples/algoquant-examples/license/nm.lic
09:12:34.758 [main] INFO t.n.algoquant.util.config.AQConfig,11 - DATA_FOLDER: ./test-data
09:12:34.758 [main] INFO t.n.algoquant.util.config.AQConfig,11 - DATA_GAINCAPITAL: ${DATA_FOLDER}/processed/gaincapital/extracted-from-raw-arrange-by-dates
09:12:34.759 [main] INFO t.n.algoquant.util.config.AQConfig,11 - DATA_BLOOMBERG: ${DATA_FOLDER}/processed/bloomberg
09:12:34.759 [main] INFO t.n.algoquant.util.config.AQConfig,11 - DATA_YAHOO: ${DATA_FOLDER}/yahoo
09:12:34.759 [main] INFO t.n.algoquant.util.config.AQConfig,11 - DATA_SGX: ${DATA_FOLDER}/raw/sgx
09:12:34.759 [main] INFO t.n.algoquant.util.config.AQConfig,11 - DATA_HOLIDAYS: ./log/holidays
09:12:34.760 [main] INFO t.n.algoquant.util.config.AQConfig,11 - DATA_COMPUSTAT_HK: ${DATA_FOLDER}/[database configuration redacted]/hk
09:12:34.760 [main] INFO t.n.algoquant.util.config.AQConfig,11 - PDF_OUTPUT_FOLDER: ./log/
09:12:34.760 [main] INFO t.n.algoquant.util.config.AQConfig,11 - PDF_PLOT_WIDTH: 800
09:12:34.760 [main] INFO t.n.algoquant.util.config.AQConfig,11 - PDF_PLOT_HEIGHT: 600
09:12:36.537 [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:36.537 [main] INFO t.n.a.d.h.yahoo.YahooEODCacheFactory,196 - reading Yahoo! data for ^GSPC from the Internet from 2003-01-01T00:00 to 2013-01-01T16:00
09:12:36.703 [main] INFO t.n.a.d.h.y.YahooEODCsvZipFileWriter,30 - writing csv.zip file ./log/Yahoo/^GSPC.csv.zip
09:12:36.738 [main] INFO t.n.a.d.h.y.YahooEODCsvZipFileWriter,81 - finished writing ./log/Yahoo/^GSPC.csv.zip
09:12:37.245 [Dai2011-1-thread-3] INFO t.n.a.m.t.d.s.Dai2011LongShort,173 - calibrated from 2003-01-01T00:00 to 2006-01-03T16:00...
09:12:37.245 [Dai2011-1-thread-2] INFO t.n.a.m.t.d.s.Dai2011LongShort,173 - calibrated from 2003-01-01T00:00 to 2006-01-03T16:00...
09:12:37.245 [Dai2011-1-thread-1] INFO t.n.a.m.t.d.s.Dai2011LongShort,173 - calibrated from 2003-01-01T00:00 to 2006-01-03T16:00...
09:12:37.246 [Dai2011-1-thread-2] INFO t.n.a.m.t.d.s.Dai2011LongShort,188 - Dai 2011 HMM:
in uptrend state: drift = 0.634242, lambda1 = 1.950883
in downtrend state: drift = -0.678929, lambda2 = 2.729302
volatility = 0.164180
... excerpt shortened; complete stdout is in the release archive ...
in uptrend state: drift = 1.052581, lambda1 = 2.068845
in downtrend state: drift = -0.970024, lambda2 = 2.404271
volatility = 0.193359
09:12:58.212 [Dai2011-1-thread-1] INFO t.n.a.m.t.d.s.Dai2011LongShort,173 - calibrated from 2011-01-12T16:00 to 2012-01-13T16:00...
09:12:58.212 [Dai2011-1-thread-1] INFO t.n.a.m.t.d.s.Dai2011LongShort,188 - Dai 2011 HMM:
in uptrend state: drift = 1.004781, lambda1 = 2.288714
in downtrend state: drift = -1.139393, lambda2 = 2.997349
volatility = 0.198494
09:13:01.082 [Dai2011-1-thread-2] INFO t.n.a.m.t.d.s.Dai2011LongShort,173 - calibrated from 2003-01-01T00:00 to 2006-01-03T16:00...
09:13:01.083 [Dai2011-1-thread-2] INFO t.n.a.m.t.d.s.Dai2011LongShort,188 - Dai 2011 HMM:
in uptrend state: drift = 1.483143, lambda1 = 3.261950
in downtrend state: drift = -1.545926, lambda2 = 4.147174
volatility = 0.249488
09:13:01.526 [Dai2011-1-thread-1] INFO t.n.a.m.t.d.s.Dai2011LongShort,173 - calibrated from 2003-01-01T00:00 to 2006-01-03T16:00...
09:13:01.527 [Dai2011-1-thread-1] INFO t.n.a.m.t.d.s.Dai2011LongShort,188 - Dai 2011 HMM:
in uptrend state: drift = 1.083041, lambda1 = 3.365913
in downtrend state: drift = -1.259677, lambda2 = 3.671515
volatility = 0.229293
09:13:04.446 [Dai2011-1-thread-2] INFO t.n.a.m.t.d.s.Dai2011LongShort,173 - calibrated from 2006-01-03T16:00 to 2007-01-04T16:00...
09:13:04.447 [Dai2011-1-thread-2] INFO t.n.a.m.t.d.s.Dai2011LongShort,188 - Dai 2011 HMM:
in uptrend state: drift = 1.366321, lambda1 = 2.931513
in downtrend state: drift = -1.532892, lambda2 = 4.134735
volatility = 0.241443
09:13:04.691 [Dai2011-1-thread-1] INFO t.n.a.m.t.d.s.Dai2011LongShort,173 - calibrated from 2006-01-03T16:00 to 2007-01-04T16:00...
09:13:04.693 [Dai2011-1-thread-1] INFO t.n.a.m.t.d.s.Dai2011LongShort,188 - Dai 2011 HMM:
in uptrend state: drift = 1.175909, lambda1 = 3.170385
in downtrend state: drift = -1.277035, lambda2 = 3.750092
volatility = 0.231849
09:13:06.954 [Dai2011-1-thread-2] INFO t.n.a.m.t.d.s.Dai2011LongShort,173 - calibrated from 2007-01-04T16:00 to 2008-01-07T16:00...
09:13:06.954 [Dai2011-1-thread-2] INFO t.n.a.m.t.d.s.Dai2011LongShort,188 - Dai 2011 HMM:
in uptrend state: drift = 1.233788, lambda1 = 2.772577
in downtrend state: drift = -1.455052, lambda2 = 3.879331
volatility = 0.232503
09:13:07.539 [Dai2011-1-thread-1] INFO t.n.a.m.t.d.s.Dai2011LongShort,173 - calibrated from 2007-01-04T16:00 to 2008-01-07T16:00...
09:13:07.539 [Dai2011-1-thread-1] INFO t.n.a.m.t.d.s.Dai2011LongShort,188 - Dai 2011 HMM:
in uptrend state: drift = 1.194484, lambda1 = 3.078510
in downtrend state: drift = -1.233235, lambda2 = 3.589510
volatility = 0.229969
09:13:09.945 [Dai2011-1-thread-2] INFO t.n.a.m.t.d.s.Dai2011LongShort,173 - calibrated from 2008-01-07T16:00 to 2009-01-08T16:00...
09:13:09.946 [Dai2011-1-thread-2] INFO t.n.a.m.t.d.s.Dai2011LongShort,188 - Dai 2011 HMM:
in uptrend state: drift = 1.111678, lambda1 = 2.638364
in downtrend state: drift = -1.356782, lambda2 = 3.648523
volatility = 0.223161
09:13:10.466 [Dai2011-1-thread-1] INFO t.n.a.m.t.d.s.Dai2011LongShort,173 - calibrated from 2008-01-07T16:00 to 2009-01-08T16:00...
09:13:10.466 [Dai2011-1-thread-1] INFO t.n.a.m.t.d.s.Dai2011LongShort,188 - Dai 2011 HMM:
in uptrend state: drift = 1.367243, lambda1 = 2.963815
in downtrend state: drift = -1.302359, lambda2 = 3.531271
volatility = 0.232914
09:13:12.898 [Dai2011-1-thread-2] INFO t.n.a.m.t.d.s.Dai2011LongShort,173 - calibrated from 2009-01-08T16:00 to 2010-01-11T16:00...
09:13:12.898 [Dai2011-1-thread-2] INFO t.n.a.m.t.d.s.Dai2011LongShort,188 - Dai 2011 HMM:
in uptrend state: drift = 1.029321, lambda1 = 2.430371
in downtrend state: drift = -1.292244, lambda2 = 3.536153
volatility = 0.214030
09:13:13.393 [Dai2011-1-thread-1] INFO t.n.a.m.t.d.s.Dai2011LongShort,173 - calibrated from 2009-01-08T16:00 to 2010-01-11T16:00...
09:13:13.394 [Dai2011-1-thread-1] INFO t.n.a.m.t.d.s.Dai2011LongShort,188 - Dai 2011 HMM:
in uptrend state: drift = 1.397346, lambda1 = 2.899273
in downtrend state: drift = -1.328132, lambda2 = 3.497445
volatility = 0.237103
09:13:15.812 [Dai2011-1-thread-2] INFO t.n.a.m.t.d.s.Dai2011LongShort,173 - calibrated from 2010-01-11T16:00 to 2011-01-12T16:00...
09:13:15.813 [Dai2011-1-thread-2] INFO t.n.a.m.t.d.s.Dai2011LongShort,188 - Dai 2011 HMM:
in uptrend state: drift = 0.967943, lambda1 = 2.387142
in downtrend state: drift = -1.161430, lambda2 = 3.286992
volatility = 0.207033
09:13:16.372 [Dai2011-1-thread-1] INFO t.n.a.m.t.d.s.Dai2011LongShort,173 - calibrated from 2010-01-11T16:00 to 2011-01-12T16:00...
09:13:16.373 [Dai2011-1-thread-1] INFO t.n.a.m.t.d.s.Dai2011LongShort,188 - Dai 2011 HMM:
in uptrend state: drift = 1.341990, lambda1 = 2.736148
in downtrend state: drift = -1.319498, lambda2 = 3.466585
volatility = 0.234805
09:13:18.681 [Dai2011-1-thread-2] INFO t.n.a.m.t.d.s.Dai2011LongShort,173 - calibrated from 2011-01-12T16:00 to 2012-01-13T16:00...
09:13:18.681 [Dai2011-1-thread-2] INFO t.n.a.m.t.d.s.Dai2011LongShort,188 - Dai 2011 HMM:
in uptrend state: drift = 0.959626, lambda1 = 2.250008
in downtrend state: drift = -1.150134, lambda2 = 3.213921
volatility = 0.203067
09:13:18.934 [Dai2011-1-thread-1] INFO t.n.a.m.t.d.s.Dai2011LongShort,173 - calibrated from 2011-01-12T16:00 to 2012-01-13T16:00...
09:13:18.934 [Dai2011-1-thread-1] INFO t.n.a.m.t.d.s.Dai2011LongShort,188 - Dai 2011 HMM:
in uptrend state: drift = 1.289867, lambda1 = 2.598825
in downtrend state: drift = -1.360169, lambda2 = 3.517220
volatility = 0.232834
09:13:24.221 [main] INFO t.n.a.d.m.d.BootstrapSimulationDemo,246 - saving reports to /home/runner/work/algoquant-examples/algoquant-examples/target/model-results/BootstrapSimulationDemo/work/./log/demo/trendfollowing_reports.txt...
09:13:24.227 [main] INFO t.n.a.d.m.d.BootstrapSimulationDemo,263 - saving reports done.
Totals in printed report order; these are separate runs/configurations, not dates.
Derived from files/log/demo/trendfollowing_reports.txt using the precision available in that file. Download plotted data. Undefined or malformed cells are omitted, never replaced by zero.

Download BootstrapSimulationDemo.zip contains stdout, stderr, the execution record, checksums and any exported CSV/chart files.
| Export | Bytes |
|---|---|
files/log/demo/trendfollowing_reports.txt |
1116 |
files/derived-charts/charts.json |
514 |
files/derived-charts/derived-01.csv |
805 |
files/derived-charts/derived-01.png |
81931 |
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.