This school project implements a basic quantitative analysis of historical commodity prices and constructs a multi-asset strategy optimization. The code demonstrates data acquisition, technical indicator computation, visualization, and a simple strategy backtest using randomly generated portfolio weights.
- Aim: Analyze historical price data for major commodities and build a random-weighted strategy index to maximize portfolio value over the past 10 years.
- Instruments Covered:
- Crude Oil (
CL=F) - Gold (
GC=F) - Silver (
SI=F) - Copper (
HG=F) - Wheat (
ZW=F)
- Crude Oil (
- Techniques Demonstrated: Data retrieval, price visualization, moving averages, Bollinger Bands, Relative Strength Index (RSI), random portfolio construction, and strategy index optimization.
- Data Acquisition:
Download 10 years of daily adjusted close prices for chosen commodities using the Yahoo Finance API (yfinance). - Visualization and Analysis:
- Plot raw historical price data.
- Compute and plot 50-day simple moving averages (SMA).
- Calculate and visualize Bollinger Bands.
- Compute and display the RSI (Relative Strength Index) for trend analysis.
- Strategy Simulation:
- Generate 100 random combinations of asset weights (using Dirichlet distribution).
- Compute the performance index of strategies rebalancing daily by these weights.
- Select and display the best-performing strategy and its weights.
- Python Libraries:
yfinance,pandas,matplotlib,numpy,dateutil - Technical Indicators: SMA, RSI, Bollinger Bands
- Portfolio Construction: Daily rebalancing, random portfolio simulation, index tracking
- Visualization: Matplotlib-based, with clear legends and axis labels