Skip to content

LucasSt04/Commodity-Trading-Risk-Analysis

Repository files navigation

Commodity Portfolio Optimization

This project builds a quantitative commodity portfolio allocation pipeline from raw price data to final portfolio weights.
It combines data import, risk analysis, time-series forecasting, and Black-Litterman portfolio construction in a single workflow.


1. Data import and price updates

1.1 Strategy for import and update price data (prices.py)

The prices.py script is designed to automatically build and maintain a daily commodity price dataset using Yahoo Finance.

Initial run

  • If no existing dataset is found, the script downloads approximately five years of historical daily close prices for all listed assets.
  • The data are stored locally in a prices.parquet file.

Incremental updates

  • If a dataset already exists, the script identifies the last available trading date.
  • It then downloads only the missing daily close prices, starting from the day following the last recorded date.
  • New observations are appended to the existing dataset, avoiding duplicates.

Daily close convention

  • To ensure data consistency, the script updates prices only up to the previous trading day (T-1).
  • This avoids the inclusion of partial or intraday data for the current day, which may be incomplete depending on market closing times.

Error handling

  • Assets with unavailable or missing data are automatically skipped and reported via warning messages.
  • The update process continues without interruption for all remaining assets.

This approach ensures a robust, reproducible, and continuously updated dataset suitable for quantitative analysis and portfolio construction.


2. Project objectives

The goal is to construct a diversified long-only commodity portfolio by combining:

  • historical risk analysis
  • ARIMA forecasts for short-term return views
  • GARCH forecasts for conditional volatility
  • Black-Litterman allocation to combine market priors and model-driven views

The project is designed to produce both:

  • clean Excel reports
  • interpretable portfolio outputs for analysis and presentation

3. Main features

3.1 Risk reporting

The project computes descriptive and portfolio risk metrics such as:

  • return series
  • volatility and rolling volatility
  • drawdown
  • correlation matrix
  • Sharpe ratio
  • summary tables by asset

3.2 Time-series modelling

Two families of models are used:

  • ARIMA to estimate one-step-ahead expected returns
  • GARCH(1,1) to estimate one-step-ahead conditional volatility

These forecasts are transformed into portfolio views and risk inputs.

3.3 Portfolio construction (Black-Litterman)

The portfolio is built using a Black-Litterman framework, where:

  • the prior comes from a reference portfolio (market-like or equal weight)
  • ARIMA forecasts provide the views
  • confidence levels determine the uncertainty of each view
  • the covariance matrix blends Ledoit-Wolf shrinkage and GARCH-based conditional covariance

The final optimization is performed under:

  • long-only constraints
  • weights summing to 100%

4. Project structure

.
├── MASTER_FINAL.csv
├── prices.py
├── Portfolio.py
├── ts_models.py
├── run_models.py
├── run_portfolio.py
├── risk_report.py
├── outputs/
│   ├── models/
│   └── portfolio/
└── README.md

About

Commodity trading strategies and associated risk analysis - Jupyter Notebook

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages