Repository navigation
Model PortfolioOptimizationAlgorithmDemo
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
Tze Leung Lai, Haipeng Xing and Zehao Chen, Mean–variance portfolio optimization when means and covariances are unknown (2011) addresses a practical weakness of plug-in mean–variance optimization: historical estimates are uncertain, yet a naive optimizer treats them as known.
The paper formulates allocation using predictive return uncertainty and develops a nonparametric empirical Bayes (NPEB) approach with resampling. Conceptually, the investor should account for estimation risk when evaluating an allocation, rather than optimize once using a single estimated mean and covariance matrix. The method is compared with alternative allocation procedures in numerical and empirical examples.
Its conclusions depend on the statistical modeling and resampling design. The Java API retains Lai2010, but the cited journal paper is from 2011. Resampler selection, shrinkage, bootstrap count, risk preference and rebalancing are explicit demo choices, not interchangeable settings guaranteed to reproduce the article's tables. Sections 3–4 of the original text were reviewed.
Builds a composable Lai2010OptimizationAlgorithm with a long-only/shrunk-mean optimizer, Ledoit–Wolf moments and a resampler, then uses getOptimalWeights and a TopN transformation. The selected components and post-processing define an adaptation, not a paper replication.
Shows how to compute the asset weights using a portfolio optimization algorithm.
Using this example. Calls getOptimalWeights on a returns matrix, then applies TopNOptimizationAlgorithm and associates the vector with products using PortfolioWeights. Rows are observations and columns are products. The zero initial vector and null optional arguments shown here belong to this optimizer configuration; check the concrete algorithm contract before reusing them.
Model and publication. Related theory and the scope of this example are distinguished below.
Implementation in this tutorial. Builds a composable Lai2010OptimizationAlgorithm with a long-only/shrunk-mean optimizer, Ledoit–Wolf moments and a resampler, then uses getOptimalWeights and a TopN transformation. The selected components and post-processing define an adaptation, not a paper replication.
| 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 | 53.71 |
| 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.portfoliooptimization.PortfolioOptimizationAlgorithmDemoThe 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.
optimal eta = 0.000000
{0(USD)=1.0, 1(USD)=0.0, 2(USD)=0.0, 3(USD)=0.0, 4(USD)=0.0, 5(USD)=0.0, 6(USD)=0.0, 7(USD)=0.0, 8(USD)=0.0, 9(USD)=0.0}
full w: [1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000]
w: [1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000]
w_size: 10
w_mean: mean: 0.100000; N: 10
sum: 1.0
Input asset-column indices; weights are fractions, not monetary P/L. Printed precision is retained.
Derived from stdout.log using the precision available in that file. Download plotted data. Undefined or malformed cells are omitted, never replaced by zero.

Download PortfolioOptimizationAlgorithmDemo.zip contains stdout, stderr, the execution record, checksums and any exported CSV/chart files.
| Export | Bytes |
|---|---|
files/derived-charts/charts.json |
497 |
files/derived-charts/derived-01.csv |
258 |
files/derived-charts/derived-01.png |
50807 |
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.