Skip to content

Model MarkowitzBigDemo

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

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

Benchmarks the optimizer on generated high-dimensional inputs. Its asset count exercises numerical scaling; no historical strategy is simulated, and runtime or feasibility says nothing about out-of-sample returns.

What this example teaches

This demo shows the performance/speed of running our implementation of Markowitz algorithm on a large pool of assets, e.g., N = 10000.

Using this example. Benchmarks Markowitz optimization on a large generated asset universe. Increase the asset count only after checking memory and solver runtime; this demonstrates numerical scaling, not historical investment performance.

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

Implementation in this tutorial. Benchmarks the optimizer on generated high-dimensional inputs. Its asset count exercises numerical scaling; no historical strategy is simulated, and runtime or feasibility says nothing about out-of-sample returns.

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 39.14
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.MarkowitzBigDemo

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:30.460 [main] INFO  t.n.a.d.m.p.MarkowitzBigDemo,91 - elapsed = 29314ms; Markowitz model weights: [0.002053, 0.001897, 0.000499, 0.002768, 0.000000, 0.000063, 0.000000, 0.000010, 0.000000, 0.001796, 0.001775, 0.002254, 0.000360, 0.000964, 0.000536, 0.000000, 0.002950, 0.000040, 0.000414, 0.000000, 0.000280, 0.002675, 0.002040, 0.000030, 0.000000, 0.001555, 0.000000, 0.000723, 0.002574, 0.000000, 0.000511, 0.000047, 0.000402, 0.000642, 0.001237, 0.000922, 0.000000, 0.000000, 0.000000, 0.001072, 0.002744, 0.000000, 0.000908, 0.000000, 0.000746, 0.000000, 0.003683, 0.000000, 0.000092, 0.002107, 0.000000, 0.000468, 0.002050, 0.000392, 0.001366, 0.000000, 0.002414, 0.001718, 0.000000, 0.000021, 0.000000, 0.000000, 0.001972, 0.000000, 0.001206, 0.001506, 0.000000, 0.000000, 0.001122, 0.000000, 0.000000, 0.002058, 0.000644, 0.000027, 0.000000, 0.000840, 0.001128, 0.001340, 0.000678, 0.000000, 0.000875, 0.001594, 0.000000, 0.000502, 0.000847, 0.000806, 0.000000, 0.000994, 0.001857, 0.000000, 0.001057, 0.002393, 0.001564, 0.000000, 0.000000, 0.001127, 0.000928, 0.000747, 0.000000, 0.002165, 0.002171, 0.000070, 0.001831, 0.001665, 0.004175, 0.002221, 0.000000, 0.002566, 0.001117, 0.001226, 0.000263, 0.003308, 0.000320, 0.002346, 0.000000, 0.000000, 0.000272, 0.000000, 0.001877, 0.000000, 0.000483, 0.001559, 0.002033, 0.000453, 0.000387, 0.000504, 0.000523, 0.000000, 0.002044, 0.000000, 0.000000, 0.001323, 0.000000, 0.000356, 0.002690, 0.002023, 0.000000, 0.002003, 0.000116, 0.000342, 0.000000, 0.000956, 0.000532, 0.001241, 0.001661, 0.000000, 0.000000, 0.001914, 0.001490, 0.000217, 0.002865, 0.000256, 0.002709, 0.000000, 0.001171, 0.000966, 0.002572, 0.000025, 0.002407, 0.000000, 0.000000, 0.000795, 0.002916, 0.000663, 0.001384, 0.001393, 0.000000, 0.000000, 0.000000, 0.002561, 0.000000, 0.001642, 0.000000, 0.001813, 0.002485, 0.000000, 0.000425, 0.000000, 0.000982, 0.000919, 0.000939, 0.000000, 0.000836, 0.000296, 0.000000, 0.001307, 0.000036, 0.000000, 0.000000, 0.001591, 0.002144, 0.002590, 0.001636, 0.000000, 0.000572, 0.003153, 0.000000, 0.000929, 0.000978, 0.001714, 0.000000, 0.002442, 0.002058, 0.001880, 0.000786, 0.001131, 0.001734, 0.001037, 0.000463, 0.000000, 0.000122, 0.000853, 0.000000, 0.000139, 0.001459, 0.001180, 0.000285, 0.002104, 0.001580, 0.000000, 0.000569, 0.001089, 0.000000, 0.000964, 0.003838, 0.001291, 0.001611, 0.000344, 0.001671, 0.000900, 0.000000, 0.001681, 0.000000, 0.000800, 0.000326, 0.000000, 0.000000, 0.003260, 0.000499, 0.000250, 0.000461, 0.000000, 0.000333, 0.000710, 0.000000, 0.000615, 0.001330, 0.001665, 0.000929, 0.000000, 0.001514, 0.000000, 0.000235, 0.001026, 0.001236, 0.000000, 0.002894, 0.001073, 0.000393, 0.001323, 0.001440, 0.000000, 0.000857, 0.000000, 0.000000, 0.002708, 0.002694, 0.001343, 0.000878, 0.001391, 0.000252, 0.000108, 0.002247, 0.001104, 0.002008, 0.000532, 0.000458, 0.001964, 0.000531, 0.000000, 0.000056, 0.002484, 0.001096, 0.000522, 0.000582, 0.000271, 0.000000, 0.000000, 0.000557, 0.000470, 0.000157, 0.002133, 0.000840, 0.000000, 0.000865, 0.000418, 0.002837, 0.000000, 0.000055, 0.000879, 0.000000, 0.001166, 0.002190, 0.001018, 0.001859, 0.000000, 0.000672, 0.000000, 0.000441, 0.001690, 0.000499, 0.002297, 0.002360, 0.001110, 0.003413, 0.000106, 0.001844, 0.000078, 0.000857, 0.000000, 0.002922, 0.000000, 0.000262, 0.000477, 0.002877, 0.000000, 0.000739, 0.002382, 0.003398, 0.000772, 0.001664, 0.000000, 0.002178, 0.003451, 0.004008, 0.000000, 0.000416, 0.000635, 0.001434, 0.001977, 0.000941, 0.000000, 0.000000, 0.001665, 0.000000, 0.001703, 0.000558, 0.000603, 0.000000, 0.002511, 0.000040, 0.000000, 0.002893, 0.000266, 0.000883, 0.001157, 0.002200, 0.000000, 0.000000, -0.000000, 0.000851, 0.003754, 0.000322, 0.002408, 0.001315, 0.001199, 0.002047, 0.000921, 0.002760, 0.000720, 0.001838, 0.000239, 0.000000, 0.001183, 0.000000, 0.000000, 0.001580, 0.000000, 0.001396, 0.001298, 0.001171, 0.001221, 0.001490, 0.001658, -0.000000, 0.001340, 0.001761, 0.000000, 0.001112, 0.000250, 0.000000, 0.001379, 0.000000, 0.000696, 0.000641, 0.002017, 0.000000, 0.001030, 0.001924, 0.000000, 0.000658, 0.002030, 0.000000, 0.000538, 0.000528, 0.001914, 0.001201, -0.000000, 0.000000, 0.000063, 0.000171, 0.000398, 0.001013, 0.001175, 0.001018, 0.000000, 0.003183, 0.000000, 0.000559, 0.001726, 0.000327, 0.003295, 0.002529, 0.000000, 0.003005, 0.000000, 0.001625, 0.000870, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000726, 0.001652, 0.002437, 0.000000, 0.000849, 0.001941, 0.000561, 0.000000, 0.001232, 0.000674, 0.000000, 0.001570, 0.000000, 0.002946, 0.001340, 0.000053, 0.002728, 0.001628, 0.000000, 0.000000, 0.000846, 0.000000, 0.000374, 0.001675, 0.002519, 0.001051, 0.000000, 0.000802, 0.000040, 0.002056, 0.000000, 0.001390, 0.002027, 0.002090, 0.000000, 0.001507, 0.001377, 0.001382, 0.000000, 0.000906, 0.003008, 0.001830, 0.000775, 0.002060, 0.001297, 0.000000, 0.001706, 0.001460, 0.003053, 0.001732, 0.001617, 0.000000, 0.003332, 0.002735, 0.000364, 0.000000, 0.001786, 0.000735, 0.001517, 0.000548, 0.001225, 0.000048, 0.000000, 0.001137, 0.002701, 0.002443, 0.000000, 0.000000, 0.000288, 0.001305, 0.000963, 0.000000, 0.000163, 0.000000, 0.000000, 0.001879, 0.000000, 0.000000, 0.001513, -0.000000, 0.002102, 0.000000, 0.000000, 0.000495, 0.000000, 0.003209, 0.002274, 0.001210, 0.000000, 0.002403, 0.001744, 0.000000, 0.000637, 0.000944, 0.000000, 0.000000, 0.001215, 0.001869, 0.000698, 0.003384, 0.000243, 0.000785, 0.002028, 0.000000, 0.000000, 0.000677, 0.001765, 0.000119, 0.001811, 0.000712, 0.002072, 0.001128, 0.000226, 0.001167, 0.000117, 0.000000, 0.000000, 0.000200, 0.000066, 0.002376, 0.001133, 0.002073, 0.001766, 0.001200, 0.001742, 0.001209, 0.004200, 0.000730, 0.000000, 0.001293, 0.001223, 0.000158, 0.000000, 0.000524, 0.001609, 0.000197, 0.001096, 0.000745, 0.001393, 0.000339, 0.000127, 0.000000, 0.000921, 0.000000, 0.001462, 0.000000, 0.000384, 0.000000, 0.001194, 0.000717, 0.000171, 0.001453, 0.001710, 0.002432, 0.000471, 0.001429, 0.001106, 0.002296, 0.000837, 0.001272, 0.000442, 0.000000, 0.000000, 0.000000, 0.000000, 0.000234, 0.000325, 0.001661, 0.000006, 0.001242, 0.000361, 0.001447, 0.000000, 0.000000, 0.000000, 0.000000, 0.001405, 0.000000, 0.000221, 0.001487, 0.003589, 0.000000, 0.004006, 0.000000, 0.001249, 0.001647, 0.001447, 0.003116, 0.000000, 0.000213, 0.000000, 0.000000, 0.000000, 0.001984, 0.003163, 0.001161, 0.002618, 0.000000, 0.001043, 0.000000, 0.000000, 0.000860, 0.001999, 0.000507, 0.001916, 0.000902, 0.000000, 0.000185, 0.003527, 0.003377, 0.000488, 0.003115, 0.002362, 0.001267, 0.000000, 0.000589, 0.004149, 0.002336, 0.001284, 0.001612, 0.000863, 0.000000, 0.001044, 0.000000, 0.000364, 0.000000, 0.002809, 0.001232, 0.002188, 0.000000, 0.000000, 0.000000, 0.000944, 0.000000, 0.001337, 0.001555, 0.000770, 0.000734, 0.001978, 0.000692, 0.001635, 0.000212, 0.001937, 0.001257, 0.001971, 0.000160, 0.002427, 0.000000, 0.000000, 0.001636, 0.001872, 0.001892, 0.000000, 0.000324, 0.000552, 0.000000, 0.001571, 0.001460, 0.002712, 0.001132, 0.000000, 0.000579, 0.001501, 0.002957, 0.003578, 0.001335, 0.001403, 0.000500, 0.000000, 0.000000, 0.000000, 0.000252, 0.000000, 0.002303, 0.000000, 0.001665, 0.001244, 0.000007, 0.002281, 0.000000, 0.000000, 0.001342, 0.001937, 0.000000, 0.000879, 0.000875, 0.001164, 0.000066, 0.002758, 0.000000, 0.000383, 0.000274, 0.000133, 0.001001, 0.002980, 0.002340, 0.000000, 0.000274, 0.000000, 0.000000, 0.002848, 0.002130, 0.000400, 0.001794, 0.000000, 0.000734, 0.000305, 0.000174, 0.001044, 0.002116, 0.001298, 0.002218, 0.001459, 0.002938, 0.001702, 0.001139, 0.000656, 0.000000, 0.001580, 0.003554, 0.000389, 0.000681, 0.000100, 0.000663, 0.000000, 0.003816, 0.000234, 0.000573, 0.002226, 0.001472, 0.000000, 0.000553, 0.003304, 0.000000, 0.002634, 0.000578, 0.001213, 0.000000, 0.000803, 0.000368, 0.001793, 0.000043, 0.001509, 0.001801, 0.000000, 0.000178, 0.000926, 0.000718, 0.001153, 0.001107, 0.002473, 0.000317, 0.000898, 0.002716, 0.000000, 0.002498, 0.000000, 0.001345, 0.000000, 0.001466, 0.001445, 0.000336, 0.000000, 0.002910, 0.001824, 0.003361, 0.000000, 0.000097, 0.001479, 0.001479, 0.000712, 0.001285, 0.000000, 0.002254, 0.000000, 0.000000, 0.001890, 0.000005, 0.000636, 0.003396, 0.001355, 0.000859, 0.000000, 0.000000, 0.001055, 0.001055, 0.000199, 0.000871, 0.002657, 0.000705, 0.000000, 0.000983, 0.000000, 0.001293, 0.000179, 0.000686, 0.000404, 0.001026, 0.001713, 0.002786, 0.001191, 0.000000, 0.003032, 0.000000, 0.001930, 0.000000, 0.002418, 0.002383, 0.001508, 0.002885, 0.001816, 0.004355, 0.002609, 0.001519, 0.002541, 0.001739, 0.000000, 0.000000, 0.001545, 0.000841, 0.000198, 0.000000, 0.001183, 0.001707, 0.001337, 0.000000, 0.001212, 0.000000, 0.001820, 0.000928, 0.000218, 0.000531, 0.000000, 0.000386, 0.000364, 0.001464, 0.000000, 0.000000, 0.001442, 0.000000, 0.002074, 0.002089, 0.000257, 0.002885, 0.002827, 0.001515, 0.001896, 0.000692, 0.001299, 0.000000, 0.000542, 0.000000, 0.001526, 0.000000, 0.002661, 0.003236, 0.001573, 0.001811, 0.000993, 0.001141, 0.000771, 0.001482, 0.002076, 0.000112, 0.000641, 0.001720, 0.001194, 0.001849, 0.002242, 0.000000, 0.000153, 0.000000, 0.000680, 0.000744, 0.002131, 0.000581, 0.000441, 0.000828, 0.000519, 0.000996, 0.002068, 0.001745, 0.001930, 0.000000, 0.000000, 0.001016, 0.000000, 0.003204, 0.002263, 0.000000, 0.000197, 0.001314, 0.002431, 0.000363, 0.001823, 0.000000, 0.000480, 0.000615, 0.000438, 0.000000, 0.000643, 0.000836, 0.000000, 0.000212, 0.000753, 0.000499, 0.001968, 0.000000, 0.000000, 0.000000, 0.002907, 0.000896, 0.000000, 0.000116, 0.002766, 0.002526, 0.001836, 0.000000, 0.000000, 0.002067, 0.000058, 0.002755, 0.000000, 0.001144, 0.002254, 0.004734, 0.000000, 0.000939, 0.000000, 0.001263, 0.001746, 0.000353, 0.001093, 0.000000, 0.000642, 0.000359, 0.000350, 0.000000, 0.000000, 0.000068, 0.003591, 0.000939, 0.001297, 0.000000, 0.000000, 0.000301, 0.000000, 0.000818, 0.000318, 0.001877, 0.002308, 0.001006, 0.001151, 0.000059, 0.001668, 0.003987, 0.000071, 0.000019, 0.002564, 0.000157, 0.000473, 0.004155, 0.003210, 0.000918, 0.001936, 0.000459, 0.000000] 

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 MarkowitzBigDemo.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 36469
files/derived-charts/derived-01.png 174838

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