Skip to content

Model CovarianceComparisonDemo

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

CovarianceComparisonDemo — 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

Related papers introduction

Olivier Ledoit and Michael Wolf, A well-conditioned estimator for large-dimensional covariance matrices (2004) addresses noisy sample covariance estimates, especially when the number of assets is large relative to the observations. Shrinkage combines sample information with a more structured target to reduce estimation error and improve conditioning.

Their later Nonlinear shrinkage estimation of large-dimensional covariance matrices (2012) adjusts sample eigenvalues nonlinearly rather than applying one common linear shrinkage rule. These are covariance-estimation methods; a better matrix estimate does not, on its own, specify a trading strategy.

This page provides conceptual background from the original publication abstracts. The demo compares sample covariance with the library's LedoitWolf2004 and LedoitWolf2016 implementations. The latter class name alone does not establish which version or numerical procedure exactly matches either reference. Read the invoked API and convergence diagnostics; this run's eigensolver failure prevents a completed comparison.

How this demo connects to the idea

This example compares estimators; it does not define a stand-alone trading model. Covariance summarizes joint variability of returns, so data frequency, demeaning, sample size and asset ordering affect the optimizer input. Inspect each estimator invoked before interpreting a numerical difference.

What this example teaches

Using this example. Compares covariance calculations for the data assembled in main. Keep the observations-by- assets orientation consistent across estimators; covariance estimates are inputs to portfolio optimization, not strategy performance measures.

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

Implementation in this tutorial. This example compares estimators; it does not define a stand-alone trading model. Covariance summarizes joint variability of returns, so data frequency, demeaning, sample size and asset ordering affect the optimizer input. Inspect each estimator invoked before interpreting a numerical difference.

Verified execution record

Item Value
Status completed
Run 39122217560
UTC publication 2026-10-18 11:43 UTC
Source commit f497645628296f441e1e254127a7547d15106bbc
Data mode original main defaults
Exit code 0
Elapsed seconds 86.22
Time limit seconds 1800
Maximum Java heap 6g
AlgoQuant source commit aba178deb0e78dc72184546a1e0934c3abce74a1
NM Dev source commit 04c12d1640fb700f52a2f7dc5cadf560040490e6
Combined runtime SHA-256 c1199a1c204cc4ffdf937b756bceacaf30bb64f35a844770490fea268742379b

The original main returned successfully without a detected calculation error. Read its 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.CovarianceComparisonDemo

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

11:15:33.078 [main] INFO  t.n.a.d.m.p.CovarianceComparisonDemo - distances/errors: [4344.572725874731, 3494.637219698951, 9505.99514955521]
11:15:33.840 [main] INFO  t.n.a.d.m.p.CovarianceComparisonDemo - distances/errors: [2.216045026456306, 1.5564757234024658, 1.6035821224860627]
11:15:34.263 [main] INFO  t.n.a.d.m.p.CovarianceComparisonDemo - distances/errors: [301973.32603712543, 268269.08395571995, 259258.5429748724]
11:15:40.553 [main] INFO  t.n.a.d.m.p.CovarianceComparisonDemo - distances/errors: [1.1559490934510606, 0.9048256434251443, 1.0905858677559623]
11:15:59.987 [main] INFO  t.n.a.d.m.p.CovarianceComparisonDemo - distances/errors: [8448.809640229512, 6257.929002102012, 5885.665645629329]
11:16:18.493 [main] INFO  t.n.a.d.m.p.CovarianceComparisonDemo - distances/errors: [7.718796892460403, 5.123240367830349, 5.156138884041344]
11:16:25.991 [main] INFO  t.n.a.d.m.p.CovarianceComparisonDemo - distances/errors: [747255.8533433342, 660042.2385080961, 658581.9898547676]
11:16:50.197 [main] INFO  t.n.a.d.m.p.CovarianceComparisonDemo - distances/errors: [8.811407541288565, 6.809286873694928, 7.016132103979931]

Charts from this run

Covariance eigenvalue estimation errors — part 1

Euclidean distance between covariance eigenvalue vectors. Scenario order follows main; dimensions, distributions and scales differ. These errors are not investment returns and do not establish a universal estimator ranking.

Derived from stdout.log using the precision available in that file. Download plotted data. Undefined or malformed cells are omitted, never replaced by zero.

Chart 1

Covariance eigenvalue estimation errors — part 2

Euclidean distance between covariance eigenvalue vectors. Scenario order follows main; dimensions, distributions and scales differ. These errors are not investment returns and do not establish a universal estimator ranking.

Derived from stdout.log using the precision available in that file. Download plotted data. Undefined or malformed cells are omitted, never replaced by zero.

Chart 2

Downloadable evidence

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

Export Bytes
files/derived-charts/charts.json 1289
files/derived-charts/derived-01.csv 902
files/derived-charts/derived-01.png 168404
files/derived-charts/derived-02.csv 316
files/derived-charts/derived-02.png 79693

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