This project analyzes the connectedness of commodity markets and performs portfolio optimization using both covariance and DYIC (Dynamic Connectedness Index) matrices.
- Fetches and cleans historical commodity data from Yahoo Finance using
yfinance - Computes rolling-window connectedness measures (DYIC) using VAR models
- Visualizes connectedness and portfolio performance
- Portfolio optimization using [PyPortfolioOpt] with both covariance and DYIC matrices
- Compares optimized portfolios with an equally weighted benchmark
code.ipynb: Main Jupyter notebook containing all code, analysis, and visualizationspyproject.toml: Project dependencies and configuration (uses Poetry)poetry.lock: Locked dependency versions
- Python >= 3.13
- See dependencies in pyproject.toml
-
Install dependencies
Using Poetry:poetry install
Using pip:
pip install -r requirements.txt
-
Run the notebook
Opencode.ipynbin VS Code or JupyterLab and run all cells.
numpy,pandas: Data manipulationyfinance: Downloading financial datamatplotlib,seaborn: Visualizationstatsmodels: VAR modeling and connectedness analysispyportfolioopt: Portfolio optimization
Etienne Larchet
MIT License