GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - lcx0731/robust-portfolio-optimization-lab: Constraint-aware portfolio optimization with covariance shrinkage and stress tests

BranchesTags
Open more actions menu

Latest commit

 

History

2 Commits
2 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
artifacts
artifacts
 
 
src/robust_portfolio_optimization_lab
src/robust_portfolio_optimization_lab
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
pyproject.toml
pyproject.toml
 
 

Repository files navigation

Robust Portfolio Optimization Lab

A compact, reproducible quantitative research project that connects covariance estimation, constrained numerical optimization, transaction-aware rebalancing, bootstrap stability, and factor stress testing.

The experiment uses deterministic synthetic returns from a transparent three-factor model whose true covariance is known. It contains no private data and makes no claim about real investment performance.

What this demonstrates

  • Sample covariance versus Ledoit–Wolf shrinkage.
  • Long-only, fully invested global minimum-variance optimization with a 35% cap.
  • A smooth L1 turnover penalty relative to a predeclared current portfolio.
  • Evaluation against the generator's true covariance, not the matrix optimized.
  • A stronger first-factor stress applied to both variances and covariances.
  • Bootstrap weight stability and true-risk dispersion across resamples.
  • Feasibility, positive-semidefinite, hand-calculation, turnover, and stability tests.

Optimization problem

For weights w, covariance Sigma, current weights w0, and penalty lambda, the solver minimizes

w' Sigma w + lambda * sum(sqrt((w_i - w0_i)^2 + epsilon^2) - epsilon)

subject to sum(w) = 1, 0 <= w_i <= 0.35. The smoothing constant is 1e-6. The documented run sets the turnover penalty to 1e-5. The reported one-way turnover is 0.5 * sum(abs(w - w0)); it is not the smoothed quantity used by the numerical objective.

Quick start

Requires Python 3.10 or newer.

python -m venv .venv
source .venv/bin/activate
python -m pip install -e ".[dev]"
pytest
python -m robust_portfolio_optimization_lab \
  --output-dir artifacts \
  --observations 160 \
  --assets 8 \
  --bootstrap 120 \
  --seed 20260916

The command writes portfolio weights and metrics, bootstrap results, stressed risk contributions, a JSON summary, and three diagnostic charts.

Reproducible result

The checked-in artifacts use the command above. Results describe only this synthetic generator, sample size, constraints, solver settings, and seed.

Portfolio True annual volatility Stressed annual volatility One-way turnover Maximum weight
Current 13.13% 19.87% 0.00% 30.00%
Equal weight 14.84% 22.54% 27.50% 12.50%
Sample-covariance GMV 13.03% 19.49% 16.58% 35.00%
Shrinkage-covariance GMV 13.06% 19.59% 16.00% 35.00%
Turnover-aware shrinkage 13.06% 19.74% 3.82% 30.47%

In this single seeded experiment, sample-covariance GMV has marginally lower true risk than shrinkage GMV; the shrinkage benefit is instead visible in the better-conditioned estimate (condition number 10.30 versus 13.35) and slightly lower median bootstrap weight distance (0.237 versus 0.242). The turnover-aware portfolio retains the shrinkage solution's true risk to the reported precision while reducing one-way turnover from 16.00% to 3.82%. The factor stress raises annualized volatility by roughly 49.7% to 51.9% across the five portfolios.

Portfolio weights

Bootstrap stability

Risk stress

Interpretation boundaries

The true covariance is available only because this is a simulation. In real data, out-of-sample risk is unknown and nonstationary. Shrinkage can improve conditioning and stability but does not guarantee lower realized risk. Bootstrap dispersion is an estimation-sensitivity diagnostic, not a probability distribution for future returns. The factor stress is a transparent scenario, not a forecast.

This project deliberately omits expected-return estimation, leverage, shorting, taxes, market impact, liquidity, nonlinear costs, and dynamic rebalancing. SLSQP success and constraint checks establish numerical feasibility, not global economic optimality under a different objective.

Educational use only. This repository is not investment advice.

Repository layout

src/robust_portfolio_optimization_lab/
  simulation.py   # known factor covariance and stressed covariance
  estimation.py   # sample and Ledoit–Wolf estimates
  optimization.py # capped long-only SLSQP optimizer
  evaluation.py   # risk metrics, bootstrap, and stress contributions
  reporting.py    # CSV/JSON outputs and charts
  cli.py          # reproducible command-line workflow
tests/             # estimator, optimizer, risk, and stability tests
artifacts/         # checked-in outputs from the documented run

License

MIT

About

Constraint-aware portfolio optimization with covariance shrinkage and stress tests

Topics

ledoit-wolfoptimizationportfolio-optimizationpythonquantitative-financerisk-management

Resources

Readme
MIT license
Activity

Stars

3 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.