← Projects
2025 PythoncvxpyNumPyConvex OptimizationPortfolio Theory

Portfolio Optimization via Convex Programming


Overview

A project from KAIST's Convex Optimization Techniques (EE523, 2025, A0) applying equality-constrained least squares to Markowitz portfolio optimization. Given historical return data for the Magnificent 7 stocks, the goal is to find allocation weights that minimize return variance subject to a target return and budget constraint.


Problem Formulation

Following Markowitz (1953), portfolio optimization balances two competing goals: maximizing return and minimizing risk (variance of returns). With allocation weights w ∈ ℝⁿ and a per-period return matrix R ∈ ℝᵀˣⁿ, the problem is formulated as equality-constrained LS:

min  ‖Rw − ρ·1_T‖²
 w

subject to  [1_T^T · R] w = [T·ρ]
            [  1_n^T  ]       [ 1 ]

where ρ is the target average per-period return and the two constraints enforce (1) the target total return and (2) the budget constraint 1ᵀw = 1. Allocation weights can be negative, corresponding to short positions.


Closed-Form Solution via KKT

The KKT conditions yield a closed-form solution. Introducing Lagrange multipliers z ∈ ℝ², the optimal weights are obtained by solving a linear system:

[w*]   [2RᵀR    Rᵀ1_T   1_n]⁻¹   [2ρRᵀ1_T]
[ z ] = [1_Tᵀ R    0       0  ]   ·  [ T·ρ   ]
        [1_nᵀ      0       0  ]       [  1    ]

This is implemented directly in NumPy — no iterative solver needed. The annualized risk is then computed as √250 · std(Rw*), assuming 250 trading days per year.


Data & Experiment

Using closing price data for the Magnificent 7 (AAPL, AMZN, GOOGL, META, MSFT, NVDA, TSLA) from May 2020 to May 2025 via yfinance. The efficient frontier is traced across four target annualized returns: 10%, 20%, 40%, and 80%. Results are compared against the naïve equal-weight (1/n) benchmark.

Key finding: at a similar risk level (~0.30 annualized), the optimized portfolio achieves a meaningfully higher annualized return than the equal-weight rule — consistent with Markowitz's theoretical result. Higher-return targets require significantly elevated leverage (L > 1), implying short positions.


Code

github.com/Danbi-Kim-0624
Jupyter notebook — data pipeline, KKT solver, efficient frontier plot, portfolio value evolution