Skip to content

Model CSI300SimulationDemo

github-actions[bot] edited this page Oct 19, 2026 · 9 revisions

CSI300 simulation tutorial

This tutorial demonstrates AlgoQuant's historical-universe and simulation APIs. Its outputs illustrate the workflow and do not establish investment performance.

Index sources and verified coverage

The demo uses EastmoneyEODWebDownloader by default. Select SinaEODWebDownloader with -Dcsi300.indexSource=sina. Both are Java HTTPS clients provided by the matching AlgoQuant library change. There is no Yahoo index dependency, Python process, cookie or API token in this path.

Before implementation, live requests returned 1,944 CSI300 sessions from 2010-01-04 through 2017-12-29 from each provider, with identical date sets and at most 0.005 index-point close difference. The 2008–2017 Eastmoney response contained 2,434 observations for pre-simulation calibration. Evidence: https://github.com/nmltd/algoquant/actions/runs/39127258230 . The library diagnostic workflow additionally checks the actual Java HTTP clients.

The original demo dates remain 2010-01-01 to 2017-01-01 (exclusive). The separate coverage check includes all of calendar 2017. The demo downloads calibration history starting one year and two weeks before the simulation and validates range endpoints before running any strategy.

Constituent membership and adjusted-price ZIPs still come from test-data/china/constituent_index_300.csv and test-data/china/20070104-20171027/adjust_prices/. Provider symbols are mapped from the canonical 000300.SS; the index remains the first product, as required by IndexAwareOptimizer. The report benchmark uses these same CSI300 levels. Risk-free rate is explicitly assumed zero. Index close is a price-index level, not a total-return series.

Run

mvn -Dexec.mainClass=tech.nmfin.algoquant.demo.model.portfoliooptimization.csi300.CSI300SimulationDemo compile exec:java

# Alternative index source:
mvn -Dexec.mainClass=tech.nmfin.algoquant.demo.model.portfoliooptimization.csi300.CSI300SimulationDemo \
  -Dcsi300.indexSource=sina compile exec:java

Override local constituent paths with -Dcsi300.constituents=/data/membership.csv and -Dcsi300.prices=/data/adjust_prices. The default performs two simulations: buy-and-hold index and monthly equal-weight constituents. Opt into the original 990 optimizer simulations with -Dcsi300.fullGrid=true. The grid runs sequentially to bound memory and preserve ordering. Reports and a PNG are saved under log/; add -Dcsi300.showCharts=true to open a window.

The two-argument Java constructor accepts a caller-supplied SequentialCacheFactory<ListedProduct, StockEOD> to replay a saved authentic index response or use another feed for reproducible tests.

Dependency

This tutorial uses tech.nmfin:algoquant-dist:3.3.2. The Sina/Eastmoney downloaders and shared disk cache are introduced in AlgoQuant 3.3.2 and are not present in 3.3.1. The 3.3.2 library and this examples update are released and merged. See the library release notes and docs/eod-examples-compatibility.md in the library repository for validation results and known demo limitations.

Reusing index downloads

The demo wraps either EastmoneyEODWebDownloader or SinaEODWebDownloader in the shared DiskCachedEODFactory. Completed index histories are stored in ./cache/china-index/eastmoney-unadjusted or ./cache/china-index/sina-unadjusted and reused across runs for the same or contained date range. Override the root with -Dcsi300.indexCache=/path/to/cache. Wider requests fetch a new history; invalid cache files trigger a download. Empty/failed responses and unfinished current-day histories are not saved. Delete the provider cache directory when you want to pick up historical vendor revisions. The raw *WebDownloader classes remain network-only, just like Yahoo's web downloader; Yahoo's disk-first behavior is in its cache factory.

Verified execution and limitations

Both default baselines completed with CSV ZIP/PNG exports. Some unavailable constituent histories were skipped, and CSI300 correlation calculations were assigned NaN. This is completed with warnings, not a clean numerical result. See Compatibility-3.3.2 for source/artifact provenance and all entry-point outcomes.

Archived tutorial/execution record from before the 3.3.2 update

CSI300SimulationDemo — AlgoQuant usage tutorial

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

Paper introduction

Harry Markowitz, Portfolio Selection (1952) explains diversification as a portfolio problem: an asset's risk cannot be judged independently of how its returns move with the other holdings. Expected portfolio return is a weighted mean; portfolio variance depends on the full covariance matrix.

The efficient set contains portfolios for which expected return cannot be improved without accepting more variance, or variance reduced without giving up expected return. An investor selects a tradeoff according to preferences and constraints. Holding many positively correlated assets need not provide much diversification.

The framework assumes the relevant return means and covariances are supplied. In practice, estimates can be unstable and constraints can materially change the answer. A solved optimization is therefore a set of weights under assumptions, not evidence of future outperformance. The original article was reviewed. Rolling calibration, rebalance schedules, costs and the dataset used here belong to the demo, not to the static 1952 formulation.

How this demo connects to the idea

Reuses rolling portfolio optimization with configured CSI 300 constituents and adjusted prices. A constituent list needs time-consistent membership, and a price history needs coverage for calibration as well as trading. These dataset choices are separate from the underlying optimization theory.

What this example teaches

Using this example. Configures CSI 300 constituents and local adjusted-price files for a portfolio simulation. The constituent CSV and price directory are independent inputs and must cover compatible dates. Paths in main are examples to adapt to your own dataset.

Model and publication. Related theory and the scope of this example are distinguished below.

Implementation in this tutorial. Reuses rolling portfolio optimization with configured CSI 300 constituents and adjusted prices. A constituent list needs time-consistent membership, and a price history needs coverage for calibration as well as trading. These dataset choices are separate from the underlying optimization theory.

Verified execution record

Item Value
Status blocked-data
Run 39123124885
UTC publication 2026-10-18 11:43 UTC
Source commit 2d86d836104a85863ff1e4772e06d6bb1d9b70ac
Data mode original main defaults
Exit code 1
Elapsed seconds 8.92
Time limit seconds 1800
Maximum Java heap 6g
AlgoQuant source commit 877ff85379aedc34331fcf2696ce4e8bf33ba11f
NM Dev source commit 04c12d1640fb700f52a2f7dc5cadf560040490e6
Combined runtime SHA-256 e0f4eb8ce5100d125b2a015be824b937fcb35b87d1364c60f5c1b9249a0d17ed

The official CSI300 benchmark has no observations for the requested period. Supply its real historical price archive; constituents alone cannot reproduce the index.

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.portfoliooptimization.csi300.CSI300SimulationDemo

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

This is an incomplete or blocked run. Output below is diagnostic or partial, not a verified strategy result.

11:27:58.138 [main] INFO  t.n.a.d.h.c.ChinaIndexConstituentsHistoryReader - reading constituents from ./test-data/china/constituent_index_300.csv...
11:28:00.066 [main] INFO  tech.nmfin.algoquant.util.config.AQConfig - looking up configuration file: config.default.xml
11:28:00.067 [main] INFO  tech.nmfin.algoquant.util.config.AQConfig - looking up configuration file: config/config.default.xml
11:28:00.067 [main] INFO  tech.nmfin.algoquant.util.config.AQConfig - loading config file: file:/home/runner/work/algoquant/algoquant/target/model-results/CSI300SimulationDemo/work/config/config.default.xml


11:28:00.646 [main] INFO  tech.nmfin.algoquant.util.config.AQConfig - current directory: /home/runner/work/algoquant/algoquant/target/model-results/CSI300SimulationDemo/work
11:28:00.646 [main] INFO  tech.nmfin.algoquant.util.config.AQConfig - current config:
11:28:00.667 [main] INFO  tech.nmfin.algoquant.util.config.AQConfig - logback.configurationFile: /home/runner/work/algoquant/algoquant/config/model-demo-logback.xml
11:28:00.668 [main] INFO  tech.nmfin.algoquant.util.config.AQConfig - nm.license: /home/runner/work/algoquant/algoquant/license/nm.lic
11:28:00.668 [main] INFO  tech.nmfin.algoquant.util.config.AQConfig - DATA_FOLDER: ./test-data
11:28:00.669 [main] INFO  tech.nmfin.algoquant.util.config.AQConfig - DATA_GAINCAPITAL: ${DATA_FOLDER}/processed/gaincapital/extracted-from-raw-arrange-by-dates
11:28:00.669 [main] INFO  tech.nmfin.algoquant.util.config.AQConfig - DATA_BLOOMBERG: ${DATA_FOLDER}/processed/bloomberg
11:28:00.669 [main] INFO  tech.nmfin.algoquant.util.config.AQConfig - DATA_YAHOO: ${DATA_FOLDER}/yahoo
11:28:00.671 [main] INFO  tech.nmfin.algoquant.util.config.AQConfig - DATA_SGX: ${DATA_FOLDER}/raw/sgx
11:28:00.671 [main] INFO  tech.nmfin.algoquant.util.config.AQConfig - DATA_HOLIDAYS: ./log/holidays
11:28:00.672 [main] INFO  tech.nmfin.algoquant.util.config.AQConfig - DATA_COMPUSTAT_HK: ${DATA_FOLDER}/compustat/hk
11:28:00.672 [main] INFO  tech.nmfin.algoquant.util.config.AQConfig - PDF_OUTPUT_FOLDER: ./log/
11:28:00.672 [main] INFO  tech.nmfin.algoquant.util.config.AQConfig - PDF_PLOT_WIDTH: 800
11:28:00.672 [main] INFO  tech.nmfin.algoquant.util.config.AQConfig - PDF_PLOT_HEIGHT: 600
11:28:02.470 [main] INFO  t.n.a.d.h.yahoo.YahooEODCacheFactory - failed to load from file, reason: no data read from file; load from web
11:28:02.470 [main] INFO  t.n.a.d.h.yahoo.YahooEODCacheFactory - reading Yahoo! data for 000300.SS from the Internet from 2005-01-01T00:00 to 2017-01-01T15:00
11:28:02.528 [main] INFO  t.n.a.d.h.yahoo.YahooEODCsvZipFileWriter - writing csv.zip file ./test-data/china/20070104-20171027/adjust_prices/000300.SS.csv.zip
11:28:02.529 [main] INFO  t.n.a.d.h.yahoo.YahooEODCsvZipFileWriter - finished writing ./test-data/china/20070104-20171027/adjust_prices/000300.SS.csv.zip
java.lang.IllegalStateException: Required CSI300 index history is unavailable for [2010-01-01T00:00,2017-01-01T00:00); supply a valid 000300.SS price archive before running the index comparison
	at tech.nmfin.algoquant.data.historicaldata.china.zqf.stock.csi300.CSI300DataProvider.getCache(kkb:6)
	at tech.nmfin.algoquant.demo.model.portfoliooptimization.csi300.CSI300SimulationDemo.run(CSI300SimulationDemo.java:112)
	at tech.nmfin.algoquant.demo.model.portfoliooptimization.csi300.CSI300SimulationDemo.main(CSI300SimulationDemo.java:86)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at ModelDemoRunner.main(ModelDemoRunner.java:38)
Caused by: java.lang.IllegalStateException: Historical Yahoo price data are unavailable for 000300.SS @ SS in [2005-01-01T00:00,2017-01-01T00:00)
	at tech.nmfin.algoquant.model.strategy.rebalance.YahooCacheProvider.f(zj:6)
	at tech.nmfin.algoquant.model.strategy.rebalance.YahooCacheProvider.getCache(zj:69)
	at tech.nmfin.algoquant.data.historicaldata.china.zqf.stock.csi300.CSI300DataProvider.getCache(kkb:166)
	... 7 more

Diagnostic and prerequisites

DEMO_RUNNER_FAILURE java.lang.IllegalStateException
java.lang.IllegalStateException: Required CSI300 index history is unavailable for [2010-01-01T00:00,2017-01-01T00:00); supply a valid 000300.SS price archive before running the index comparison
Caused by: java.lang.IllegalStateException: Historical Yahoo price data are unavailable for 000300.SS @ SS in [2005-01-01T00:00,2017-01-01T00:00)

Downloadable evidence

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

Export Bytes
files/derived-charts/charts.json 3

Interpreting the result

Use the first relevant exception and the source configuration to resolve the prerequisite or code issue, then rerun. A missing dataset requires the correct original schema and period; substituting synthetic values would be a different experiment. A timeout establishes only that this bounded attempt did not finish.

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

Clone this wiki locally