|
12 | 12 | "In this section, we compare how well the different risk models predict an out-of-sample covariance matrix, and how well the different returns models predict out-of-sample returns.\n", |
13 | 13 | "\n", |
14 | 14 | "[](https://colab.research.google.com/github/pyportfolio/pyportfolioopt/blob/master/cookbook/1-RiskReturnModels.ipynb)\n", |
15 | | - " \n", |
| 15 | + "\n", |
16 | 16 | "[](https://kaggle.com/kernels/welcome?src=https://github.com/PyPortfolio/PyPortfolioOpt/blob/main/cookbook/1-RiskReturnModels.ipynb)\n", |
17 | | - " \n", |
| 17 | + "\n", |
18 | 18 | "[](https://console.paperspace.com/github/pyportfolio/pyportfolioopt/blob/master/cookbook/1-RiskReturnModels.ipynb)\n", |
19 | | - " \n", |
| 19 | + "\n", |
20 | 20 | "[](https://studiolab.sagemaker.aws/import/github/pyportfolio/pyportfolioopt/blob/master/cookbook/1-RiskReturnModels.ipynb)\n", |
21 | 21 | "\n", |
22 | 22 | "## Risk models" |
23 | 23 | ] |
24 | 24 | }, |
25 | 25 | { |
26 | 26 | "cell_type": "code", |
27 | | - "execution_count": 1, |
28 | 27 | "metadata": { |
29 | 28 | "colab": { |
30 | 29 | "base_uri": "https://localhost:8080/" |
31 | 30 | }, |
32 | 31 | "id": "ajpb4cfuzzCd", |
33 | | - "outputId": "c075b649-0764-4b2d-cd48-65d6a85e7003" |
| 32 | + "outputId": "c075b649-0764-4b2d-cd48-65d6a85e7003", |
| 33 | + "ExecuteTime": { |
| 34 | + "end_time": "2025-11-15T07:38:12.128260Z", |
| 35 | + "start_time": "2025-11-15T07:38:11.505395Z" |
| 36 | + } |
34 | 37 | }, |
35 | | - "outputs": [], |
36 | 38 | "source": [ |
37 | 39 | "!pip install pandas numpy matplotlib PyPortfolioOpt\n", |
38 | 40 | "import os\n", |
39 | 41 | "\n", |
40 | 42 | "if not os.path.isdir(\"data\"):\n", |
41 | 43 | " os.system(\"git clone https://github.com/pyportfolio/pyportfolioopt.git\")\n", |
42 | 44 | " os.chdir(\"PyPortfolioOpt/cookbook\")" |
43 | | - ] |
| 45 | + ], |
| 46 | + "outputs": [ |
| 47 | + { |
| 48 | + "name": "stdout", |
| 49 | + "output_type": "stream", |
| 50 | + "text": [ |
| 51 | + "Requirement already satisfied: pandas in /Users/thomasschmelzer/projects/PyPortfolioOpt/.venv/lib/python3.13/site-packages (2.3.3)\r\n", |
| 52 | + "Requirement already satisfied: numpy in /Users/thomasschmelzer/projects/PyPortfolioOpt/.venv/lib/python3.13/site-packages (2.3.4)\r\n", |
| 53 | + "Requirement already satisfied: matplotlib in /Users/thomasschmelzer/projects/PyPortfolioOpt/.venv/lib/python3.13/site-packages (3.10.7)\r\n", |
| 54 | + "Requirement already satisfied: PyPortfolioOpt in /Users/thomasschmelzer/projects/PyPortfolioOpt (1.5.6)\r\n", |
| 55 | + "Requirement already satisfied: python-dateutil>=2.8.2 in /Users/thomasschmelzer/projects/PyPortfolioOpt/.venv/lib/python3.13/site-packages (from pandas) (2.9.0.post0)\r\n", |
| 56 | + "Requirement already satisfied: pytz>=2020.1 in /Users/thomasschmelzer/projects/PyPortfolioOpt/.venv/lib/python3.13/site-packages (from pandas) (2025.2)\r\n", |
| 57 | + "Requirement already satisfied: tzdata>=2022.7 in /Users/thomasschmelzer/projects/PyPortfolioOpt/.venv/lib/python3.13/site-packages (from pandas) (2025.2)\r\n", |
| 58 | + "Requirement already satisfied: contourpy>=1.0.1 in /Users/thomasschmelzer/projects/PyPortfolioOpt/.venv/lib/python3.13/site-packages (from matplotlib) (1.3.3)\r\n", |
| 59 | + "Requirement already satisfied: cycler>=0.10 in /Users/thomasschmelzer/projects/PyPortfolioOpt/.venv/lib/python3.13/site-packages (from matplotlib) (0.12.1)\r\n", |
| 60 | + "Requirement already satisfied: fonttools>=4.22.0 in /Users/thomasschmelzer/projects/PyPortfolioOpt/.venv/lib/python3.13/site-packages (from matplotlib) (4.60.1)\r\n", |
| 61 | + "Requirement already satisfied: kiwisolver>=1.3.1 in /Users/thomasschmelzer/projects/PyPortfolioOpt/.venv/lib/python3.13/site-packages (from matplotlib) (1.4.9)\r\n", |
| 62 | + "Requirement already satisfied: packaging>=20.0 in /Users/thomasschmelzer/projects/PyPortfolioOpt/.venv/lib/python3.13/site-packages (from matplotlib) (25.0)\r\n", |
| 63 | + "Requirement already satisfied: pillow>=8 in /Users/thomasschmelzer/projects/PyPortfolioOpt/.venv/lib/python3.13/site-packages (from matplotlib) (12.0.0)\r\n", |
| 64 | + "Requirement already satisfied: pyparsing>=3 in /Users/thomasschmelzer/projects/PyPortfolioOpt/.venv/lib/python3.13/site-packages (from matplotlib) (3.2.5)\r\n", |
| 65 | + "Requirement already satisfied: cvxpy>=1.1.19 in /Users/thomasschmelzer/projects/PyPortfolioOpt/.venv/lib/python3.13/site-packages (from PyPortfolioOpt) (1.7.3)\r\n", |
| 66 | + "Requirement already satisfied: scikit-learn>=0.24.1 in /Users/thomasschmelzer/projects/PyPortfolioOpt/.venv/lib/python3.13/site-packages (from PyPortfolioOpt) (1.7.2)\r\n", |
| 67 | + "Requirement already satisfied: scipy>=1.3.0 in /Users/thomasschmelzer/projects/PyPortfolioOpt/.venv/lib/python3.13/site-packages (from PyPortfolioOpt) (1.16.3)\r\n", |
| 68 | + "Requirement already satisfied: osqp>=1.0.0 in /Users/thomasschmelzer/projects/PyPortfolioOpt/.venv/lib/python3.13/site-packages (from cvxpy>=1.1.19->PyPortfolioOpt) (1.0.5)\r\n", |
| 69 | + "Requirement already satisfied: clarabel>=0.5.0 in /Users/thomasschmelzer/projects/PyPortfolioOpt/.venv/lib/python3.13/site-packages (from cvxpy>=1.1.19->PyPortfolioOpt) (0.11.1)\r\n", |
| 70 | + "Requirement already satisfied: scs>=3.2.4.post1 in /Users/thomasschmelzer/projects/PyPortfolioOpt/.venv/lib/python3.13/site-packages (from cvxpy>=1.1.19->PyPortfolioOpt) (3.2.9)\r\n", |
| 71 | + "Requirement already satisfied: six>=1.5 in /Users/thomasschmelzer/projects/PyPortfolioOpt/.venv/lib/python3.13/site-packages (from python-dateutil>=2.8.2->pandas) (1.17.0)\r\n", |
| 72 | + "Requirement already satisfied: joblib>=1.2.0 in /Users/thomasschmelzer/projects/PyPortfolioOpt/.venv/lib/python3.13/site-packages (from scikit-learn>=0.24.1->PyPortfolioOpt) (1.5.2)\r\n", |
| 73 | + "Requirement already satisfied: threadpoolctl>=3.1.0 in /Users/thomasschmelzer/projects/PyPortfolioOpt/.venv/lib/python3.13/site-packages (from scikit-learn>=0.24.1->PyPortfolioOpt) (3.6.0)\r\n", |
| 74 | + "Requirement already satisfied: cffi in /Users/thomasschmelzer/projects/PyPortfolioOpt/.venv/lib/python3.13/site-packages (from clarabel>=0.5.0->cvxpy>=1.1.19->PyPortfolioOpt) (2.0.0)\r\n", |
| 75 | + "Requirement already satisfied: jinja2 in /Users/thomasschmelzer/projects/PyPortfolioOpt/.venv/lib/python3.13/site-packages (from osqp>=1.0.0->cvxpy>=1.1.19->PyPortfolioOpt) (3.1.6)\r\n", |
| 76 | + "Requirement already satisfied: setuptools in /Users/thomasschmelzer/projects/PyPortfolioOpt/.venv/lib/python3.13/site-packages (from osqp>=1.0.0->cvxpy>=1.1.19->PyPortfolioOpt) (80.9.0)\r\n", |
| 77 | + "Requirement already satisfied: pycparser in /Users/thomasschmelzer/projects/PyPortfolioOpt/.venv/lib/python3.13/site-packages (from cffi->clarabel>=0.5.0->cvxpy>=1.1.19->PyPortfolioOpt) (2.23)\r\n", |
| 78 | + "Requirement already satisfied: MarkupSafe>=2.0 in /Users/thomasschmelzer/projects/PyPortfolioOpt/.venv/lib/python3.13/site-packages (from jinja2->osqp>=1.0.0->cvxpy>=1.1.19->PyPortfolioOpt) (3.0.3)\r\n", |
| 79 | + "\r\n", |
| 80 | + "\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m A new release of pip is available: \u001B[0m\u001B[31;49m24.3.1\u001B[0m\u001B[39;49m -> \u001B[0m\u001B[32;49m25.3\u001B[0m\r\n", |
| 81 | + "\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m To update, run: \u001B[0m\u001B[32;49mpip install --upgrade pip\u001B[0m\r\n" |
| 82 | + ] |
| 83 | + } |
| 84 | + ], |
| 85 | + "execution_count": 1 |
44 | 86 | }, |
45 | 87 | { |
46 | 88 | "cell_type": "code", |
47 | | - "execution_count": 2, |
48 | 89 | "metadata": { |
49 | 90 | "colab": { |
50 | 91 | "base_uri": "https://localhost:8080/", |
51 | 92 | "height": 35 |
52 | 93 | }, |
53 | 94 | "id": "3aAcuLOKzwIT", |
54 | | - "outputId": "456251e3-a9fd-4e83-8847-44cb43dbb422" |
55 | | - }, |
56 | | - "outputs": [ |
57 | | - { |
58 | | - "data": { |
59 | | - "text/plain": [ |
60 | | - "'1.5.6'" |
61 | | - ] |
62 | | - }, |
63 | | - "execution_count": 2, |
64 | | - "metadata": {}, |
65 | | - "output_type": "execute_result" |
| 95 | + "outputId": "456251e3-a9fd-4e83-8847-44cb43dbb422", |
| 96 | + "ExecuteTime": { |
| 97 | + "end_time": "2025-11-15T07:38:13.282190Z", |
| 98 | + "start_time": "2025-11-15T07:38:12.133749Z" |
66 | 99 | } |
67 | | - ], |
| 100 | + }, |
68 | 101 | "source": [ |
69 | 102 | "import matplotlib.pyplot as plt\n", |
70 | 103 | "import numpy as np\n", |
|
74 | 107 | "from pypfopt import expected_returns, plotting, risk_models\n", |
75 | 108 | "\n", |
76 | 109 | "pypfopt.__version__" |
77 | | - ] |
| 110 | + ], |
| 111 | + "outputs": [ |
| 112 | + { |
| 113 | + "ename": "ModuleNotFoundError", |
| 114 | + "evalue": "No module named 'skbase'", |
| 115 | + "output_type": "error", |
| 116 | + "traceback": [ |
| 117 | + "\u001B[31m---------------------------------------------------------------------------\u001B[39m", |
| 118 | + "\u001B[31mModuleNotFoundError\u001B[39m Traceback (most recent call last)", |
| 119 | + "\u001B[36mCell\u001B[39m\u001B[36m \u001B[39m\u001B[32mIn[2]\u001B[39m\u001B[32m, line 5\u001B[39m\n\u001B[32m 2\u001B[39m \u001B[38;5;28;01mimport\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mnumpy\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mas\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mnp\u001B[39;00m\n\u001B[32m 3\u001B[39m \u001B[38;5;28;01mimport\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mpandas\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mas\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mpd\u001B[39;00m\n\u001B[32m----> \u001B[39m\u001B[32m5\u001B[39m \u001B[38;5;28;01mimport\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mpypfopt\u001B[39;00m\n\u001B[32m 6\u001B[39m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mpypfopt\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m expected_returns, plotting, risk_models\n\u001B[32m 8\u001B[39m pypfopt.__version__\n", |
| 120 | + "\u001B[36mFile \u001B[39m\u001B[32m~/projects/PyPortfolioOpt/pypfopt/__init__.py:7\u001B[39m\n\u001B[32m 1\u001B[39m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01m.\u001B[39;00m\u001B[34;01mblack_litterman\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m (\n\u001B[32m 2\u001B[39m BlackLittermanModel,\n\u001B[32m 3\u001B[39m market_implied_prior_returns,\n\u001B[32m 4\u001B[39m market_implied_risk_aversion,\n\u001B[32m 5\u001B[39m )\n\u001B[32m 6\u001B[39m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01m.\u001B[39;00m\u001B[34;01mcla\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m CLA\n\u001B[32m----> \u001B[39m\u001B[32m7\u001B[39m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01m.\u001B[39;00m\u001B[34;01mdiscrete_allocation\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m DiscreteAllocation, get_latest_prices\n\u001B[32m 8\u001B[39m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01m.\u001B[39;00m\u001B[34;01mefficient_frontier\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m (\n\u001B[32m 9\u001B[39m EfficientCDaR,\n\u001B[32m 10\u001B[39m EfficientCVaR,\n\u001B[32m 11\u001B[39m EfficientFrontier,\n\u001B[32m 12\u001B[39m EfficientSemivariance,\n\u001B[32m 13\u001B[39m )\n\u001B[32m 14\u001B[39m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01m.\u001B[39;00m\u001B[34;01mhierarchical_portfolio\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m HRPOpt\n", |
| 121 | + "\u001B[36mFile \u001B[39m\u001B[32m~/projects/PyPortfolioOpt/pypfopt/discrete_allocation.py:12\u001B[39m\n\u001B[32m 10\u001B[39m \u001B[38;5;28;01mimport\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mnumpy\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mas\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mnp\u001B[39;00m\n\u001B[32m 11\u001B[39m \u001B[38;5;28;01mimport\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mpandas\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mas\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mpd\u001B[39;00m\n\u001B[32m---> \u001B[39m\u001B[32m12\u001B[39m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01mskbase\u001B[39;00m\u001B[34;01m.\u001B[39;00m\u001B[34;01mutils\u001B[39;00m\u001B[34;01m.\u001B[39;00m\u001B[34;01mdependencies\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m _check_soft_dependencies\n\u001B[32m 14\u001B[39m \u001B[38;5;28;01mfrom\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34;01m.\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;28;01mimport\u001B[39;00m exceptions\n\u001B[32m 17\u001B[39m \u001B[38;5;28;01mdef\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34mget_latest_prices\u001B[39m(prices):\n", |
| 122 | + "\u001B[31mModuleNotFoundError\u001B[39m: No module named 'skbase'" |
| 123 | + ] |
| 124 | + } |
| 125 | + ], |
| 126 | + "execution_count": 2 |
78 | 127 | }, |
79 | 128 | { |
80 | 129 | "cell_type": "code", |
|
370 | 419 | "provenance": [] |
371 | 420 | }, |
372 | 421 | "kernelspec": { |
373 | | - "display_name": "Python 3", |
374 | | - "name": "python3" |
| 422 | + "display_name": "Python 3 (ipykernel)", |
| 423 | + "name": "python3", |
| 424 | + "language": "python" |
375 | 425 | }, |
376 | 426 | "language_info": { |
377 | 427 | "codemirror_mode": { |
|
0 commit comments