Skip to content

quenstance/2025_Portfolio_Optimization_Forecasting

Repository files navigation

Portfolio Optimization & Forecasting in Python

Overview

This repository contains the code for a quantitative finance project that constructs and analyzes an optimal multi-asset investment portfolio. Using 15 years of historical data for the S&P 500, Tesla, Gold, and the SGD/USD exchange rate, this project applies Modern Portfolio Theory to maximize risk-adjusted returns. It provides a deep dive into risk assessment using VaR/CVaR, volatility modeling with GARCH, and return forecasting via Prophet.

How to Use

Follow these steps to set up and run the project locally.

  1. Prerequisites Ensure you have Python 3.8+ and pip installed on your system.

  2. Clone the Repository

  3. Part 1: Data Preparation Run the data preparation script to download the latest financial data from Yahoo Finance. This will create the daily_adjusted_prices.csv file needed for the analysis. python get_prices_adjclose_or_close.py

  4. Part 2: Run Analysis The entire analysis is contained within the Jupyter Notebook (portfolio_sql.ipynb). Launch Jupyter and execute the cells in order to reproduce the findings.

Methodology

The project employs a multi-step quantitative methodology to move from raw data to a fully analyzed and forecasted portfolio. It begins with data extraction from Yahoo Finance using the yfinance library, followed by ETL into a MySQL database and exploratory data analysis. The core of the project is portfolio optimization using a Monte Carlo simulation to identify the Maximum Sharpe Ratio allocation. It provides a deep dive into risk assessment using VaR/CVaR, volatility modeling with GARCH, and return forecasting via Prophet.

For a detailed mathematical and technical breakdown, please see TECHNICAL.md.

Key Findings

  • The optimal portfolio consists of 38.8% GLD, 37.9% SPX, and 23.3% TSLA.

  • It achieves an annualized Sharpe Ratio of 0.9783 and a Sortino Ratio of 1.3764.

  • The portfolio is exposed to significant tail risk, with a historical max drawdown of -30.07%.

  • The GARCH model indicates that volatility is highly persistent, meaning risky periods are prolonged.


Last Update: SEP-2025

Disclaimer This project was developed using technologies and methods prevalent at the time. Users are advised to review and update the code for compatibility with current Python versions and package dependencies.

  • The analysis is based on historical data; future performance may vary significantly.
  • The Prophet forecasting model is not optimized for highly volatile financial data and should be interpreted with caution.
  • Asset correlations are dynamic and may not hold true in future market conditions.

Last Update: SEP-2025

Disclaimer:

This project was developed using technologies and methods prevalent at the time. Users are advised to review and update the code for compatibility with current Python versions and package dependencies.

Author


Quenstance Lau

About

Using Python's yfinance library, this project analyzes 15 years of data for the S&P 500, Tesla, and Gold, managed via SQL. It applies Modern Portfolio Theory to construct an optimal portfolio, featuring in-depth risk assessment with VaR/CVaR, GARCH volatility modeling, and Prophet forecasting.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors