Repository navigation
Model SOCPMarkowitzComparisonDemo
All model results · Pinned source · Javadoc
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.
| Item | Value |
|---|---|
| Status | completed |
| Run | 39114006111 |
| UTC publication | 2026-10-18 09:11 UTC |
| Source commit | 0097e73c040bdaaddac570e2fe694d9836b676ee |
| Data mode | original main defaults |
| Exit code | 0 |
| Elapsed seconds | 1.44 |
| 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.SOCPMarkowitzComparisonDemoThe 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.
09:07:45,422 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
09:07:45,422 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
09:07:45,423 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [jar:file:/home/runner/work/algoquant-examples/algoquant-examples/target/lib/algoquant-dist-3.3.0-SNAPSHOT.jar!/logback.xml]
09:07:45,458 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@16c0663d - URL [jar:file:/home/runner/work/algoquant-examples/algoquant-examples/target/lib/algoquant-dist-3.3.0-SNAPSHOT.jar!/logback.xml] is not of type file
09:07:45,554 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
09:07:45,557 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
09:07:45,580 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
09:07:45,601 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
09:07:45,693 |-INFO in ch.qos.logback.core.joran.action.TimestampAction - Using current interpretation time, i.e. now, as time reference.
09:07:45,701 |-INFO in ch.qos.logback.core.joran.action.TimestampAction - Adding property to the context with key="bySecond" and value="2026.10.18,09.07.45" to the LOCAL scope
09:07:45,701 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
09:07:45,708 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [FILE1]
09:07:45,726 |-INFO in ch.qos.logback.core.rolling.FixedWindowRollingPolicy@23223dd8 - Will use zip compression
09:07:45,726 |-WARN in ch.qos.logback.core.rolling.FixedWindowRollingPolicy@23223dd8 - Large window sizes are not allowed.
09:07:45,726 |-WARN in ch.qos.logback.core.rolling.FixedWindowRollingPolicy@23223dd8 - MaxIndex reduced to 21
09:07:45,737 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
09:07:45,738 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE1] - Active log file name: log/algoquant.2026.10.18,09.07.45.log
09:07:45,738 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[FILE1] - File property is set to [log/algoquant.2026.10.18,09.07.45.log]
09:07:45,739 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
09:07:45,739 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
09:07:45,740 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [FILE1] to Logger[ROOT]
09:07:45,740 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
09:07:45,741 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@4ec6a292 - Registering current configuration as safe fallback point
09:07:46.254 [main] INFO t.n.a.d.m.p.SOCPMarkowitzComparisonDemo,107 - x1: [0.331978, 0.336715, 0.187407, 0.143901, 0.000000]
09:07:46.259 [main] INFO t.n.a.d.m.p.SOCPMarkowitzComparisonDemo,108 - x2: [0.341506, 0.345905, 0.181232, 0.131357, -0.000000]
09:07:46.261 [main] INFO t.n.a.d.m.p.SOCPMarkowitzComparisonDemo,109 - obj1 -0.0474881053881621 vs. obj2 -0.04741091251200159
Download SOCPMarkowitzComparisonDemo.zip contains stdout, stderr, the execution record, checksums and any exported CSV/chart files.
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.