Skip to content

Model PortfolioOptimizationAlgorithmDemo

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

PortfolioOptimizationAlgorithmDemo — execution tutorial

All model results · Pinned source · Javadoc

What this example teaches

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.

Verified execution record

Item Value
Status completed
Run 39114360151
UTC publication 2026-10-18 09:18 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.

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.PortfolioOptimizationAlgorithmDemo

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


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

Downloadable evidence

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

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