{ "cells": [ { "cell_type": "markdown", "id": "y4ofn86ksre", "metadata": {}, "source": [ "# Mean-Variance Efficient Frontier\n", "\n", "This notebook builds a mean-variance efficient frontier from historical ETF\n", "prices. We use **James-Stein** shrinkage for expected returns and the\n", "**Oracle Approximating Shrinkage (OAS)** estimator for the covariance matrix,\n", "then extract the tangency and minimum-risk portfolios." ] }, { "cell_type": "code", "execution_count": 1, "id": "b4hu24g5uc", "metadata": { "execution": { "iopub.execute_input": "2026-03-30T19:38:36.927722Z", "iopub.status.busy": "2026-03-30T19:38:36.927400Z", "iopub.status.idle": "2026-03-30T19:38:37.574882Z", "shell.execute_reply": "2026-03-30T19:38:37.574623Z" } }, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "from pyvallocation import (\n", " PortfolioWrapper,\n", " estimate_moments,\n", ")" ] }, { "cell_type": "markdown", "id": "18s6iikq281", "metadata": {}, "source": [ "## Load ETF price data\n", "\n", "The bundled CSV contains daily prices for DBC, GLD, SPY, and TLT." ] }, { "cell_type": "code", "execution_count": 2, "id": "mgklispye8d", "metadata": { "execution": { "iopub.execute_input": "2026-03-30T19:38:37.576312Z", "iopub.status.busy": "2026-03-30T19:38:37.576211Z", "iopub.status.idle": "2026-03-30T19:38:37.587274Z", "shell.execute_reply": "2026-03-30T19:38:37.587061Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Assets : ['DBC', 'GLD', 'SPY', 'TLT']\n", "Periods: 4855\n" ] }, { "data": { "text/html": [ "
| \n", " | DBC | \n", "GLD | \n", "SPY | \n", "TLT | \n", "
|---|---|---|---|---|
| Date | \n", "\n", " | \n", " | \n", " | \n", " |
| 2025-05-19 | \n", "-0.001416 | \n", "0.012881 | \n", "0.001094 | \n", "-0.002897 | \n", "
| 2025-05-20 | \n", "0.012760 | \n", "0.018622 | \n", "-0.003362 | \n", "-0.007205 | \n", "
| 2025-05-21 | \n", "-0.001400 | \n", "0.007379 | \n", "-0.016851 | \n", "-0.017090 | \n", "
| 2025-05-22 | \n", "-0.005140 | \n", "-0.008861 | \n", "0.000395 | \n", "0.005240 | \n", "
| 2025-05-23 | \n", "0.005636 | \n", "0.021906 | \n", "-0.006826 | \n", "0.001659 | \n", "