Project Advanced Mathematics · VUB 2026-2027 · Koen Hanegreefs

Can maths build a better thematic portfolio?

I invest in semiconductors, defense and quantum computing. I used linear algebra and optimisation in Python to find the "best" mix of ten assets, and then checked whether that mix would really have worked.

The ten assets drawn as a chip floorplan: Semiconductors (SMH, NVDA, ASML), Quantum (IONQ, RGTI, QBTS), Core (URTH, IEF, GLD) and Defense (ITA). Semiconductors SMH · NVDA · ASML Quantum IONQ RGTI QBTS Core URTH · IEF · GLD Defense ITA
10 × 222
assets × weekly returns, Aug 2022 to Nov 2026
1.49
Sharpe ratio of the optimal portfolio in hindsight (equal weights: 1.00)
2.14 → 0.70
Sharpe ratio promised in training vs delivered out of sample
0.75
out-of-sample Sharpe ratio of simply holding the world ETF

Step 1 · The question

Position sizes by feel, or by formula?

My portfolio is built around themes I believe in. What I never had was a rule for how much to put in each one. Modern portfolio theory (Harry Markowitz, 1952) says the answer is a mathematical optimisation problem: choose the weights that give the lowest risk for the return you want.

Research question. Does mean-variance optimisation give a better risk-adjusted portfolio of my thematic assets than simply giving every asset the same weight, and does the advantage survive on data the optimiser has never seen?

"Risk-adjusted" is measured with the Sharpe ratio: the return above the risk-free rate, per unit of volatility.

Sharpe = (μp − rf) / σp μp = average yearly return of the portfolio, σp = its yearly volatility (standard deviation), rf = 4 % risk-free rate

Step 2 · The data

Ten assets, four themes, 223 weeks

I downloaded weekly closing prices from the historical data service of Interactive Brokers on 16 November 2026. The sample runs from the week ending 12 August 2022, the first week in which all ten assets trade, to 13 November 2026. Prices are in US dollar and adjusted for stock splits; dividends and bond coupons are not included.

Four themes, ten assets

Core

URTH · IEF · GLD

World equities, US Treasuries and gold: the ballast of the portfolio.

Volatility 7.0 to 17.7 %

Semiconductors

SMH · NVDA · ASML

The whole chip industry in one ETF, the leading AI chip designer and the only maker of EUV lithography machines.

Volatility 34.0 to 46.5 %

Defense

ITA

US aerospace and defense companies in one ETF.

Volatility 20.2 %

Quantum

IONQ · RGTI · QBTS

Three young quantum computing companies, each betting on a different hardware approach.

Volatility 97.5 to 184.2 %

Bars show the range of annual volatility within each theme, on one scale from 0 to 190 %.

From prices I compute simple weekly returns, and I annualise by multiplying the mean by 52 and the standard deviation by √52.

rt = Pt / Pt−1 − 1 Pt = closing price at the end of week t
Risk and return per asset over the full sample (annualised, price returns)
AssetThemeMean returnVolatilitySharpeCompound growthWorst drawdown
URTH · MSCI World ETFCore13.7 %14.8 %0.6613.5 %−14.9 %
IEF · US Treasury bondsCore−3.1 %7.0 %−1.00−3.2 %−13.1 %
GLD · GoldCore19.2 %17.7 %0.8619.2 %−26.5 %
SMH · Semiconductor ETFSemiconductors38.1 %34.0 %1.0038.1 %−34.1 %
NVDA · NVIDIASemiconductors61.5 %46.5 %1.2466.0 %−37.1 %
ASML · ASML HoldingSemiconductors30.6 %40.7 %0.6525.0 %−44.2 %
ITA · Defense ETFDefense18.2 %20.2 %0.7017.5 %−20.1 %
IONQ · IonQQuantum79.5 %97.5 %0.7743.3 %−65.0 %
RGTI · Rigetti ComputingQuantum99.9 %139.2 %0.6917.5 %−91.8 %
QBTS · D-Wave QuantumQuantum112.1 %184.2 %0.59−2.9 %−95.5 %

One line in this table already taught me something. D-Wave has the highest average weekly return of all ten assets (112 % a year), yet an investor who held it for the whole period lost 2.9 % a year. Extreme volatility destroys compound growth: after a loss of 50 % you need a gain of 100 % to get back to where you started.

Step 3 · Analysis 1

How much diversification do my themes really give?

Diversification only works when assets do not move together. I measured this with the correlation matrix of the weekly returns: a 10 × 10 table in which every number lies between −1 (always opposite) and +1 (always together).

Heatmap of the correlation matrix of weekly returns for the ten assets. Correlations among the world ETF, semiconductors and defense are between 0.5 and 0.8; bonds and gold are close to zero with everything.
Figure 1. Correlation of weekly returns. The average correlation between two different assets is 0.31.

The world ETF, the three semiconductor positions and defense form one red block: their correlations are between 0.34 and 0.81. The three quantum stocks form a second block (0.46 to 0.68). Only the bond ETF and gold are close to zero with everything else.

Eigenvalues: how many independent risks are there?

To summarise 45 correlations in a few numbers I computed the eigenvalues and eigenvectors of the correlation matrix (this is called principal component analysis). Each eigenvector is a combination of assets that moves independently of the others; its eigenvalue tells how much of the total variation it explains.

C v = λ v C = correlation matrix, v = eigenvector (a "risk factor"), λ = eigenvalue. The ten eigenvalues add up to 10, so λ / 10 is the share of variance explained.
Left: bar chart of the share of variance explained by each of the ten principal components, 42, 16 and 12 percent for the first three. Right: loadings of the ten assets on the first two components.
Figure 2. Left: share of the total variance explained by each eigenvector. Right: the weights of the assets in the first two eigenvectors.

Interpretation. The first eigenvector explains 42 % of everything. All ten assets have a positive weight in it, so it is the general "market" direction: when it falls, my whole portfolio falls. The second (16 %) separates the quantum stocks from the rest, and the third (12 %) is bonds and gold. Together three factors explain 70 % of the variation of ten assets. Ten positions in my themes are, in terms of risk, closer to three.

Step 3 · Analysis 2

The optimal portfolio in hindsight

A portfolio is a vector of weights w that add up to 1. With the vector of mean returns μ and the covariance matrix Σ of the ten assets, its return and risk are:

μp = wTμ     σp2 = wTΣ w the return is a weighted average; the variance is a quadratic form that includes every pair of covariances

Markowitz optimisation looks for the weights with the smallest variance for a chosen return:

minimise wTΣ w   subject to   wTμ = m,   wT1 = 1   (and w ≥ 0 if short selling is not allowed)

Without the condition w ≥ 0 this can be solved exactly with Lagrange multipliers; the solution only needs two linear systems (Σx = 1 and Σx = μ). With the condition, which is my real situation, I let Python solve it numerically (SLSQP algorithm in SciPy). Repeating this for many target returns m draws the efficient frontier. As a sanity check I also generated 20 000 random portfolios (Monte Carlo).

Scatter plot of risk against expected return with 20 000 random portfolios, the long-only efficient frontier, the frontier with short selling, the capital market line, and markers for the equal-weight, minimum-variance and maximum-Sharpe portfolios.
Figure 3. Every blue dot is a random portfolio. The black curve is the efficient frontier: no portfolio without short selling lies above it. The green line starts at the risk-free rate and touches the frontier at the maximum-Sharpe portfolio.
Three portfolios on the full sample (Aug 2022 to Nov 2026)
PortfolioExpected returnVolatilitySharpeMain weights
Equal weight47.0 %43.0 %1.0010 % in each asset
Minimum variance−0.1 %6.7 %−0.61IEF 85 %, URTH 9 %, GLD 3 %, ITA 3 %
Maximum Sharpe35.4 %21.0 %1.49GLD 56 %, NVDA 31 %, ITA 9 %, RGTI 3 %, IONQ 2 %
Grouped bar chart of the weights of the ten assets in the equal-weight, minimum-variance and maximum-Sharpe portfolios.
Figure 4. Weights of the three portfolios. The optimiser gives most assets a weight of zero.

Interpretation. In hindsight the optimiser clearly beats equal weights: the Sharpe ratio rises from 1.00 to 1.49, with half the volatility (21 % instead of 43 %). None of the 20 000 random portfolios reaches 1.49 (the best one has 1.43), which confirms that the solver found the true optimum. But look at what it buys: more than half in gold, a third in NVIDIA and nothing in the world ETF, the semiconductor ETF or ASML. It simply loads up on whatever had the best past numbers. The minimum-variance portfolio shows the opposite problem: it is 85 % bonds, the calmest asset, and it earned nothing.

Step 3 · Analysis 3

The honest test: does it work on unseen data?

Analysis 2 cheats: it uses returns that an investor could not know in advance. So I split the data in two. I computed the weights using only the training period (Aug 2022 to 27 Dec 2024, 124 weeks) and then measured what those fixed weights did in the test period (3 Jan 2025 to 13 Nov 2026, 98 weeks).

Left: line chart of the value of 100 invested at the end of December 2024 in four strategies; equal weight ends at 151, maximum Sharpe at 141, MSCI World only at 130 and minimum variance at 107. Right: bar chart comparing the Sharpe ratio in the training period with the Sharpe ratio in the test period for each strategy.
Figure 5. Left: growth of 100 in the test period. Right: the Sharpe ratio each strategy had in the training period (grey) against what it delivered afterwards (colour).
Out-of-sample results, 3 Jan 2025 to 13 Nov 2026 (weights fixed on 27 Dec 2024, rebalanced weekly)
StrategySharpe promisedSharpe deliveredReturn p.a.VolatilityValue of 100Worst drawdown
Equal weight1.240.6429.3 %39.2 %151−30.0 %
Minimum variance−0.57−0.093.5 %5.8 %107−10.6 %
Maximum Sharpe2.140.7021.4 %24.9 %141−22.0 %
MSCI World only0.590.7514.9 %14.4 %130−14.9 %

Interpretation. The maximum-Sharpe portfolio promised 2.14 and delivered 0.70, one third of the promise. Its Sharpe ratio was still slightly above that of equal weights (0.70 against 0.64) because it took much less risk, but the boring world ETF had the best risk-adjusted result of all (0.75).

Why? The optimiser's two inputs behaved very differently. Risk was predictable: the maximum-Sharpe portfolio was expected to have 22.9 % volatility and had 24.9 %. Return was not: NVIDIA averaged +96 % a year in the training period and +18 % a year in the test period. The optimiser trusted the +96 % and put a third of the portfolio there. Small errors in μ are magnified into large errors in the weights; this is known as estimation error.

Step 5 · Conclusion

What I take away for my own portfolio

Answer. Yes in hindsight, hardly in practice. Optimisation improved the Sharpe ratio from 1.00 to 1.49 on past data, but on unseen data the advantage shrank to 0.70 against 0.64, and a single world ETF did better than both.

Limitations

What this project cannot tell

Reproduce it

All data, code and figures are in the public repository: github.com/Fomural/thematic-portfolio-optimisation. Running python run_all.py rebuilds every number and figure on this page. The figures are also available as PDF in the figures/ folder.