Skip to content

itsvalls/Gold-Price-Analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

📊 Gold Price Statistical Analysis in R

This repository contains R code for analyzing the statistical relationships between gold prices and various economic indicators, including the USD Index (DXY), crude oil, S&P 500, RSI, and moving averages. The analysis includes hypothesis testing, correlation studies, seasonal trends, and Monte Carlo simulations.


📁 Dataset

File Required: Gold final PS.csv

Expected Columns:

  • time: Date (YYYY-MM-DD)
  • close: Gold price
  • dxy_close: US Dollar Index
  • light_crude_oil_close: Crude Oil price
  • sp500_close: S&P 500 Index
  • gold_RSI: Relative Strength Index
  • gold_SMA_10, gold_SMA_50, gold_SMA_200: Simple Moving Averages

📦 Requirements

Install required R packages:

install.packages(c("ggplot2", "BSDA", "zoo", "dplyr", "lubridate", "tidyr"))

▶️ How to Run

  1. Clone the repository:

    git clone https://github.com/yourusername/gold-price-analysis.git
    cd gold-price-analysis
  2. Open and run the R script:

    • gold_analysis.R — contains all analyses
  3. Load data by modifying the path in the script:

    data <- read.csv("path/to/Gold final PS.csv")

🧪 Analyses Performed

📈 Correlation Analysis

  • Pearson correlations between gold and:
    • DXY
    • Crude Oil
    • S&P 500
    • RSI

🔬 Hypothesis Testing

  • Z-tests on gold prices based on:
    • High vs. low DXY
    • Crude oil price ranges
    • RSI overbought/oversold
    • SMA crossover conditions

📊 Rolling Statistics

  • 30-day rolling mean
  • 30-day rolling volatility
  • Plotting key historical periods (e.g., 2008)

📅 Seasonality & ANOVA

  • Monthly average returns
  • One-way ANOVA to detect significant seasonal patterns
  • Tukey’s HSD post-hoc test

🔄 Monte Carlo Simulation

  • Simulates future gold prices using daily return volatility
  • 1-year projection with 1,000 trials

📌 Key Outputs

  • Line plots with moving averages
  • Correlation matrix
  • RSI return analysis
  • Monthly return seasonality plot
  • Monte Carlo simulation fan chart

📂 File Structure

├── Gold final PS.csv       # Input data file
├── gold_analysis.R         # Main R script
├── README.md               # This README
└── /outputs                # (Optional) Generated plots and results

📝 Interpretation Highlights

  • DXY vs Gold: Negative correlation — supports safe-haven narrative.
  • Oil vs Gold: Positive in inflationary conditions.
  • RSI Returns: Statistically significant overbought/oversold behavior.
  • Seasonality: November–January tend to outperform (ANOVA confirmed).
  • Forecasting: Simulated price bands provide risk-based outlook.

📜 License

This project is licensed under the MIT License.


🙋‍♂️ Contributing

Contributions are welcome! Please open issues or submit pull requests.

About

This project explores the behavior of gold prices using statistical methods such as Monte Carlo simulations, Chi-Square tests, ANOVA, and Z-tests.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages