Skip to content

Model PortfolioOptimComparisons1Demo

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

PortfolioOptimComparisons1Demo — quantitative model tutorial

All quantitative model results · Pinned source · Javadoc

Related papers introduction

This is a comparison of different allocation ideas, rather than an implementation of one paper. Markowitz (1952), Portfolio Selection, balances expected return against covariance-based risk. Black and Litterman (1992), Global Portfolio Optimization, combines an equilibrium starting point with investor views and uncertainty about those views.

Corvalán (2005), Well Diversified Efficient Portfolios, seeks diversification among nearly equivalent risk–return allocations. Lai, Xing and Chen (2011) address uncertainty in estimated means and covariances using predictive reasoning and resampling. These approaches answer different questions, so their risk parameters and assumptions are not directly interchangeable.

The demo's common synthetic return matrix makes computed weights comparable on that input; it does not establish an out-of-sample winner. Its Black–Litterman wrapper supplies equal market weights and sample means as views, rather than eliciting independent investor forecasts. The literature guide records the review scope for each reference; the Black–Litterman scan was inspected, but detailed derivations were not independently verified.

How this demo connects to the idea

Compares multiple optimizer families on one synthetic return matrix. Black–Litterman combines equilibrium information with views. The wrapper assumes equal market weights, sample means as views and tau=1/T; this demo supplies risk aversion rather than explicit investor views. Other branches use Markowitz, Corvalán, smart-beta assumptions and Lai-style resampling. These are separate models, not interchangeable solver settings.

What this example teaches

This demo shows how to build customized portfolio optimization algorithms and call these optimizers for the same data set.

AQ has a suite of tools to do asset allocation/portfolio optimization. It comes with out-of-box ready to use tools and users can also put together different models to customize their own optimizers. This demo shows a few simple out-of-box optimizers.

The simulated returns are from beta distribution and are correlated so the regular smart beta algorithms don't exhibit usual behaviors when uncorrelated normal distributions are assumed.

Using this example. Feeds the same generated return matrix to several optimizer implementations to compare their weights. Rows are observations and columns are assets; keep this order when wrapping a result in PortfolioWeights. This is a numerical comparison without a transaction-cost or execution simulation.

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

Implementation in this tutorial. Compares multiple optimizer families on one synthetic return matrix. Black–Litterman combines equilibrium information with views. The wrapper assumes equal market weights, sample means as views and tau=1/T; this demo supplies risk aversion rather than explicit investor views. Other branches use Markowitz, Corvalán, smart-beta assumptions and Lai-style resampling. These are separate models, not interchangeable solver settings.

Verified execution record

Item Value
Status failed
Run 39114360151
UTC publication 2026-10-18 09:18 UTC
Source commit 355aa9242fc2a247b256aecc8406cbb409aa5ff3
Data mode original main defaults
Exit code 1
Elapsed seconds 0.72
Time limit seconds 180
Maximum Java heap 1200m

The demo raised an exception or did not return normally. This is not a verified numerical result.

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

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.


09:14:15.932 [main] INFO  t.n.a.d.m.p.PortfolioOptimComparisons1Demo,119 - Markowitz model weights: [0.000000, 0.091766, 0.089007, 0.250419, 0.052848, 0.158530, 0.104201, 0.182553, 0.048576, 0.022100] 
09:14:15.948 [main] INFO  t.n.a.d.m.p.PortfolioOptimComparisons1Demo,129 - BlackLitterman model weights: [0.057903, 0.086740, 0.086342, 0.126650, 0.128685, 0.108934, 0.089547, 0.142704, 0.089683, 0.082813] 
09:14:15.982 [main] INFO  t.n.a.d.m.p.PortfolioOptimComparisons1Demo,139 - Corvalan2005 model weights: [0.118030, 0.102017, 0.067548, 0.120184, 0.089430, 0.097481, 0.103445, 0.118982, 0.094115, 0.088767] 
09:14:16.012 [main] ERROR t.n.a.m.p.SOCPOptimizationAlgorithm,52 - SOCP failed to compute optimal weights: sorry, best effort fails; the problem is probably ill-defined: 
PrimalDualInteriorPointMinimizer1: null
tech.nmfin.algoquant.model.portfoliooptimization.AlgorithmFailureException: algorithm 'SOCPOptimizationAlgorithm' failed; reason: failed to compute the optimal weights: sorry, best effort fails; the problem is probably ill-defined: 
PrimalDualInteriorPointMinimizer1: null
r = {0.000778398085230571300000000000, 0.004410147057789686000000000000, 0.018936707149300600000000000000, -0.004330670173974114000000000000, 0.012076886624596390000000000000, 0.022946638507040696000000000000, -0.012933806366649574000000000000, -0.009415530050972891000000000000, 0.009718126864375684000000000000, -0.006980434396789792000000000000, }
V = {{0.186932152965119560000000000000, -0.012636269597900730000000000000, 0.031330641678227696000000000000, -0.023427038878390958000000000000, -0.084452709895808730000000000000, 0.050466377542368386000000000000, 0.074526130031545400000000000000, -0.032041489775750040000000000000, 0.095217671280920330000000000000, -0.007760553233886977000000000000, },
{-0.012636269597900730000000000000, 0.085731687179539620000000000000, 0.017226397191531720000000000000, 0.018507438224685153000000000000, 0.026181086162084522000000000000, 0.037802441798344015000000000000, -0.029577518059774675000000000000, -0.080847681067478460000000000000, -0.038958621745139030000000000000, 0.047307750753263766000000000000, },
{0.031330641678227696000000000000, 0.017226397191531720000000000000, 0.166661477284924200000000000000, 0.021923149503245712000000000000, -0.008810310246091475000000000000, -0.039995512486070424000000000000, -0.000419561740898738700000000000, -0.078962412630741540000000000000, 0.041234317138803970000000000000, 0.020073151797821705000000000000, },
{-0.023427038878390958000000000000, 0.018507438224685153000000000000, 0.021923149503245712000000000000, 0.090782244431382900000000000000, 0.041344236350423730000000000000, -0.095518357375127100000000000000, -0.022258256994236565000000000000, -0.042088643772912350000000000000, -0.034377244778978410000000000000, 0.034031150775718520000000000000, },
{-0.084452709895808730000000000000, 0.026181086162084522000000000000, -0.008810310246091475000000000000, 0.041344236350423730000000000000, 0.145912818938914750000000000000, -0.069556762029228710000000000000, -0.034403443274285400000000000000, 0.018254149845624085000000000000, -0.102024855507975560000000000000, -0.024086162129311472000000000000, },
{0.050466377542368386000000000000, 0.037802441798344015000000000000, -0.039995512486070424000000000000, -0.095518357375127100000000000000, -0.069556762029228710000000000000, 0.231142563000980020000000000000, -0.022053787959799730000000000000, -0.038031023321161615000000000000, 0.058376593430361216000000000000, 0.028752692159133574000000000000, },
{0.074526130031545400000000000000, -0.029577518059774675000000000000, -0.000419561740898738700000000000, -0.022258256994236565000000000000, -0.034403443274285400000000000000, -0.022053787959799730000000000000, 0.091075912663136750000000000000, 0.034403407720285550000000000000, 0.028452700495708347000000000000, -0.055336527053429486000000000000, },
{-0.032041489775750040000000000000, -0.080847681067478460000000000000, -0.078962412630741540000000000000, -0.042088643772912350000000000000, 0.018254149845624085000000000000, -0.038031023321161615000000000000, 0.034403407720285550000000000000, 0.168079398190702220000000000000, -0.004119042638051827000000000000, -0.074150974298550400000000000000, },
{0.095217671280920330000000000000, -0.038958621745139030000000000000, 0.041234317138803970000000000000, -0.034377244778978410000000000000, -0.102024855507975560000000000000, 0.058376593430361216000000000000, 0.028452700495708347000000000000, -0.004119042638051827000000000000, 0.115891700428624400000000000000, -0.015161801828408992000000000000, },
{-0.007760553233886977000000000000, 0.047307750753263766000000000000, 0.020073151797821705000000000000, 0.034031150775718520000000000000, -0.024086162129311472000000000000, 0.028752692159133574000000000000, -0.055336527053429486000000000000, -0.074150974298550400000000000000, -0.015161801828408992000000000000, 0.205556705833005840000000000000, },
}
lambda = 20.000000000000000000000000000000

	at tech.nmfin.algoquant.model.portfoliooptimization.SOCPOptimizationAlgorithm.s(jg:95)
	at tech.nmfin.algoquant.model.portfoliooptimization.SOCPOptimizationAlgorithm.getOptimalWeights(jg:150)
	at tech.nmfin.algoquant.demo.model.portfoliooptimization.PortfolioOptimComparisons1Demo.run(PortfolioOptimComparisons1Demo.java:146)
	at tech.nmfin.algoquant.demo.model.portfoliooptimization.PortfolioOptimComparisons1Demo.main(PortfolioOptimComparisons1Demo.java:101)
	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.Exception: sorry, best effort fails; the problem is probably ill-defined: 
PrimalDualInteriorPointMinimizer1: null
	at tech.nmfin.algoquant.model.portfoliooptimization.socp.SimpleSOCPPortfolio.getOptimalWeights(ae:44)
	at tech.nmfin.algoquant.model.portfoliooptimization.SOCPOptimizationAlgorithm.getOptimalWeights(jg:50)
	... 7 more

Diagnostic and prerequisites

DEMO_RUNNER_FAILURE tech.nmfin.algoquant.model.portfoliooptimization.AlgorithmFailureException
tech.nmfin.algoquant.model.portfoliooptimization.AlgorithmFailureException: algorithm 'SOCPOptimizationAlgorithm' failed; reason: failed to compute the optimal weights: sorry, best effort fails; the problem is probably ill-defined: 
Caused by: java.lang.Exception: sorry, best effort fails; the problem is probably ill-defined: 

Downloadable evidence

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

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