Skip to content

Model Dai2011LongOnlyDemo

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

Dai2011LongOnlyDemo — execution tutorial

All model results · Pinned source · Javadoc

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 39114006111
UTC publication 2026-10-18 09:11 UTC
Source commit 0097e73c040bdaaddac570e2fe694d9836b676ee
Data mode original main defaults
Exit code 0
Elapsed seconds 24.45
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:06:55,793 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
09:06:55,793 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
09:06:55,793 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [jar:file:/home/runner/work/algoquant-examples/algoquant-examples/target/lib/algoquant-dist-3.3.0-SNAPSHOT.jar!/logback.xml]
09:06:55,832 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@546a03af - URL [jar:file:/home/runner/work/algoquant-examples/algoquant-examples/target/lib/algoquant-dist-3.3.0-SNAPSHOT.jar!/logback.xml] is not of type file
09:06:56,227 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
09:06:56,229 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
09:06:56,246 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
09:06:56,258 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
09:06:56,337 |-INFO in ch.qos.logback.core.joran.action.TimestampAction - Using current interpretation time, i.e. now, as time reference.
09:06:56,339 |-INFO in ch.qos.logback.core.joran.action.TimestampAction - Adding property to the context with key="bySecond" and value="2026.10.18,09.06.56" to the LOCAL scope
09:06:56,339 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
09:06:56,343 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FILE1]
09:06:56,357 |-INFO in ch.qos.logback.core.rolling.FixedWindowRollingPolicy@721e0f4f - Will use zip compression
09:06:56,357 |-WARN in ch.qos.logback.core.rolling.FixedWindowRollingPolicy@721e0f4f - Large window sizes are not allowed.
09:06:56,357 |-WARN in ch.qos.logback.core.rolling.FixedWindowRollingPolicy@721e0f4f - MaxIndex reduced to 21
09:06:56,361 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
09:06:56,362 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE1] - Active log file name: log/algoquant.2026.10.18,09.06.56.log
09:06:56,362 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE1] - File property is set to [log/algoquant.2026.10.18,09.06.56.log]
09:06:56,364 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
09:06:56,364 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
09:06:56,364 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FILE1] to Logger[ROOT]
09:06:56,364 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
09:06:56,365 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@28864e92 - Registering current configuration as safe fallback point

09:06:56.572 [main] INFO  t.n.algoquant.util.config.AQConfig,194 - looking up configuration file: config.default.xml
09:06:56.576 [main] INFO  t.n.algoquant.util.config.AQConfig,194 - looking up configuration file: config/config.default.xml
09:06:56.577 [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:06:57.971 [main] INFO  t.n.algoquant.util.config.AQConfig,148 - 09:06:55,793 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
09:06:55,793 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
09:06:55,793 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [jar:file:/home/runner/work/algoquant-examples/algoquant-examples/target/lib/algoquant-dist-3.3.0-SNAPSHOT.jar!/logback.xml]
... excerpt shortened; complete stdout is in the release archive ...
09:06:56,337 |-INFO in ch.qos.logback.core.joran.action.TimestampAction - Using current interpretation time, i.e. now, as time reference.
09:06:56,339 |-INFO in ch.qos.logback.core.joran.action.TimestampAction - Adding property to the context with key="bySecond" and value="2026.10.18,09.06.56" to the LOCAL scope
09:06:56,339 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
09:06:56,343 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FILE1]
09:06:56,357 |-INFO in ch.qos.logback.core.rolling.FixedWindowRollingPolicy@721e0f4f - Will use zip compression
09:06:56,357 |-WARN in ch.qos.logback.core.rolling.FixedWindowRollingPolicy@721e0f4f - Large window sizes are not allowed.
09:06:56,357 |-WARN in ch.qos.logback.core.rolling.FixedWindowRollingPolicy@721e0f4f - MaxIndex reduced to 21
09:06:56,361 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
09:06:56,362 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE1] - Active log file name: log/algoquant.2026.10.18,09.06.56.log
09:06:56,362 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE1] - File property is set to [log/algoquant.2026.10.18,09.06.56.log]
09:06:56,364 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
09:06:56,364 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
09:06:56,364 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FILE1] to Logger[ROOT]
09:06:56,364 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
09:06:56,365 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@28864e92 - Registering current configuration as safe fallback point


09:06:57.971 [main] INFO  t.n.algoquant.util.config.AQConfig,95 - current directory: /home/runner/work/algoquant-examples/algoquant-examples/target/model-results/Dai2011LongOnlyDemo/work
09:06:57.972 [main] INFO  t.n.algoquant.util.config.AQConfig,169 - current config:
09:06:57.985 [main] INFO  t.n.algoquant.util.config.AQConfig,11 - nm.license: /home/runner/work/algoquant-examples/algoquant-examples/license/nm.lic
09:06:57.985 [main] INFO  t.n.algoquant.util.config.AQConfig,11 - DATA_FOLDER: ./test-data
09:06:57.986 [main] INFO  t.n.algoquant.util.config.AQConfig,11 - DATA_GAINCAPITAL: ${DATA_FOLDER}/processed/gaincapital/extracted-from-raw-arrange-by-dates
09:06:57.986 [main] INFO  t.n.algoquant.util.config.AQConfig,11 - DATA_BLOOMBERG: ${DATA_FOLDER}/processed/bloomberg
09:06:57.986 [main] INFO  t.n.algoquant.util.config.AQConfig,11 - DATA_YAHOO: ${DATA_FOLDER}/yahoo
09:06:57.987 [main] INFO  t.n.algoquant.util.config.AQConfig,11 - DATA_SGX: ${DATA_FOLDER}/raw/sgx
09:06:57.987 [main] INFO  t.n.algoquant.util.config.AQConfig,11 - DATA_HOLIDAYS: ./log/holidays
09:06:57.987 [main] INFO  t.n.algoquant.util.config.AQConfig,11 - DATA_COMPUSTAT_HK: ${DATA_FOLDER}/[database configuration redacted]/hk
09:06:57.988 [main] INFO  t.n.algoquant.util.config.AQConfig,11 - PDF_OUTPUT_FOLDER: ./log/
09:06:57.988 [main] INFO  t.n.algoquant.util.config.AQConfig,11 - PDF_PLOT_WIDTH: 800
09:06:57.988 [main] INFO  t.n.algoquant.util.config.AQConfig,11 - PDF_PLOT_HEIGHT: 600
09:07:00.134 [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:07:00.134 [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:07:01.527 [main] INFO  t.n.a.d.h.y.YahooEODCsvZipFileWriter,30 - writing csv.zip file ./log/Yahoo/^GSPC.csv.zip
09:07:01.588 [main] INFO  t.n.a.d.h.y.YahooEODCsvZipFileWriter,81 - finished writing ./log/Yahoo/^GSPC.csv.zip
09:07:06.155 [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:07:08.051 [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:07:09.720 [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:07:11.339 [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:07:13.020 [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:07:14.713 [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:07:16.843 [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:07:17.016 [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

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

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