Skip to content

Model SOCPMarkowitzComparisonDemo

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

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

Compares QP and SOCP representations under the configured constraints and data. Equality of mathematical formulations does not imply bit-identical numerical solutions; inspect the existing correlated-input TODO and solver tolerances.

What this example teaches

We compare the results from a QP solver (Markowitz) and from an SOCP solver. They should give more or less the same results given only QP constraints, subject to numerical differences.

The portfolio optimization problem is:

max rw-qw'Sigmaw s.t. sum(w)=1, w_i=1 for i in the black list.

We assume that the last index of w is in the black list.

Using this example. Compares quadratic and second-order-cone formulations using the same inputs and constraints. Numerical solver tolerances can produce different weights; inspect the existing TODO about correlated inputs rather than assuming universal agreement.

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

Implementation in this tutorial. Compares QP and SOCP representations under the configured constraints and data. Equality of mathematical formulations does not imply bit-identical numerical solutions; inspect the existing correlated-input TODO and solver tolerances.

Verified execution record

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 1.23
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.SOCPMarkowitzComparisonDemo

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


09:13:15.084 [main] INFO  t.n.a.d.m.p.SOCPMarkowitzComparisonDemo,107 - x1: [0.331978, 0.336715, 0.187407, 0.143901, 0.000000] 
09:13:15.092 [main] INFO  t.n.a.d.m.p.SOCPMarkowitzComparisonDemo,108 - x2: [0.341506, 0.345905, 0.181232, 0.131357, -0.000000] 
09:13:15.092 [main] INFO  t.n.a.d.m.p.SOCPMarkowitzComparisonDemo,109 - obj1 -0.0474881053881621 vs. obj2 -0.04741091251200159

Charts from this run

Optimizer allocation vectors

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.

Chart 1

Downloadable evidence

Download SOCPMarkowitzComparisonDemo.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 167
files/derived-charts/derived-01.png 47587

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