Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ˆ Gold Price Prediction

Predicting Gold (GLD) ETF Prices Using Machine Learning

Python Scikit-Learn Pandas NumPy License

Open In Colab


๐Ÿ“– Overview

This project builds a Random Forest Regression model to predict the price of the SPDR Gold Shares (GLD) ETF using historical financial market data. The model leverages correlated financial instruments โ€” including the S&P 500 index, crude oil (USO), silver (SLV), and the EUR/USD exchange rate โ€” as predictive features to estimate gold price movements.

The complete analysis pipeline โ€” from data loading and exploratory analysis through model training and evaluation โ€” is implemented in a single, reproducible Jupyter Notebook designed for Google Colab.


โœจ Key Features

  • ๐Ÿ“Š Exploratory Data Analysis โ€” Statistical summaries, null-value checks, distribution plots, and correlation heatmaps to deeply understand the dataset before modeling.
  • ๐Ÿค– Random Forest Regressor โ€” Ensemble learning model with 100 decision trees for robust, high-accuracy price predictions.
  • ๐Ÿ“ˆ Visual Model Evaluation โ€” Side-by-side comparison of actual vs. predicted gold prices using line plots for intuitive performance assessment.
  • ๐Ÿ“ Quantitative Metrics โ€” Model accuracy measured using R-squared error and Mean Absolute Error (MAE).
  • โ˜๏ธ Cloud-Ready โ€” Pre-configured for seamless execution on Google Colab with zero local setup required.

๐Ÿ—‚๏ธ Project Structure

Gold_Price_Prediction-main/
โ”‚
โ”œโ”€โ”€ Gold_Price_Prediction.ipynb   # Main Jupyter Notebook (full pipeline)
โ”œโ”€โ”€ gold_price_data.csv           # Dataset (2,290 trading days)
โ”œโ”€โ”€ Gold Price Prediction.docx    # Project documentation
โ”œโ”€โ”€ README.md                     # This file
โ””โ”€โ”€ LICENSE                       # MIT License

๐Ÿ“‹ Dataset

The dataset contains 2,290 daily observations spanning from January 2, 2008 to May 16, 2018, with no missing values.

Column Description Type
Date Trading date Object
SPX S&P 500 Index closing price Float64
GLD SPDR Gold Shares ETF price (Target) Float64
USO United States Oil Fund price Float64
SLV iShares Silver Trust price Float64
EUR/USD EUR to USD exchange rate Float64

Key Statistics

Metric SPX GLD USO SLV EUR/USD
Mean 1,654.32 122.73 31.84 20.08 1.2837
Std 519.11 23.28 19.52 7.09 0.1315
Min 676.53 70.00 7.96 8.85 1.0390
Max 2,872.87 184.59 117.48 47.26 1.5988

๐Ÿ”ฌ Methodology

1. Data Collection & Processing

  • Load the CSV dataset into a Pandas DataFrame.
  • Inspect for missing values, data types, and basic statistical measures.

2. Exploratory Data Analysis

  • Distribution Analysis โ€” Visualize the GLD price distribution using Seaborn's displot.
  • Correlation Analysis โ€” Compute and visualize feature correlations using a heatmap to identify relationships between financial instruments.

3. Feature Engineering

  • Features (X): SPX, USO, SLV, EUR/USD
  • Target (Y): GLD
  • Drop the Date column (non-numeric) and the target variable from the feature set.

4. Train-Test Split

  • 80/20 split with random_state=2 for reproducibility.
  • Training set: 1,832 samples
  • Test set: 458 samples

5. Model Training

  • Algorithm: RandomForestRegressor from Scikit-learn
  • Hyperparameters: n_estimators=100 (100 decision trees in the ensemble)

6. Model Evaluation

  • Predictions generated on the held-out test set.
  • Performance assessed using:
    • R-squared (Rยฒ) โ€” Measures the proportion of variance explained by the model.
    • Mean Absolute Error (MAE) โ€” Average absolute difference between predicted and actual values.
  • Visualization: Actual vs. predicted prices plotted for visual comparison.

๐Ÿ› ๏ธ Technology Stack

Category Libraries
Data Manipulation NumPy, Pandas
Visualization Matplotlib, Seaborn
Machine Learning Scikit-learn (RandomForestRegressor, metrics)
Environment Jupyter Notebook, Google Colab

๐Ÿš€ Getting Started

Option 1: Google Colab (Recommended)

The quickest way to run this project โ€” no local installation needed:

  1. Click the "Open in Colab" badge at the top of this README.
  2. Upload gold_price_data.csv to the Colab runtime when prompted (or modify the path).
  3. Run all cells sequentially (Runtime โ†’ Run all).

Option 2: Run Locally

Prerequisites

  • Python 3.9 or higher
  • pip (Python package manager)

Steps

# 1. Clone the repository
git clone https://github.com/MYoussef885/Gold_Price_Prediction.git
cd Gold_Price_Prediction

# 2. Create and activate a virtual environment
python -m venv venv

# Windows
venv\Scripts\activate

# macOS / Linux
source venv/bin/activate

# 3. Install dependencies
pip install numpy pandas matplotlib seaborn scikit-learn jupyter

# 4. Launch Jupyter Notebook
jupyter notebook Gold_Price_Prediction.ipynb

๐Ÿ“ˆ Results

The Random Forest Regressor demonstrates strong predictive performance on the test set:

  • โœ… High Rยฒ score โ€” The model explains a significant proportion of variance in gold prices.
  • โœ… Low MAE โ€” Predicted values closely track actual GLD prices.
  • โœ… Visual alignment โ€” The actual vs. predicted price plot shows tight correspondence, particularly for mid-range gold prices.

Note: The model performs best when market conditions follow historical patterns observed in the 2008โ€“2018 training period. Performance may vary for out-of-distribution data.


๐Ÿ”ฎ Future Improvements

  • Add time-series features (moving averages, RSI, MACD)
  • Experiment with additional models (XGBoost, LSTM, Gradient Boosting)
  • Implement hyperparameter tuning via GridSearchCV or RandomizedSearchCV
  • Incorporate additional macroeconomic indicators (interest rates, inflation)
  • Build an interactive dashboard for real-time predictions
  • Extend the dataset to include more recent trading data

๐Ÿค Contributing

Contributions, issues, and feature requests are welcome! Feel free to:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“ License

This project is licensed under the MIT License โ€” see the LICENSE file for details.


๐Ÿ™ Acknowledgements

  • MYoussef885 โ€” Original project author
  • Siddhardhan โ€” Project mentor and tutorial guidance
  • The open-source community behind NumPy, Pandas, Scikit-learn, Matplotlib, and Seaborn

Built with โค๏ธ for data science and financial analysis

About

Machine Learning project that predicts SPDR Gold Shares (GLD) ETF prices using a Random Forest Regression model. The model analyzes historical market data and correlated financial indicators such as the S&P 500, crude oil, silver, and EUR/USD exchange rates to forecast gold price movements.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages