Predicting the price of gold is a key interest for investors, economists, and financial analysts. While no model is a perfect crystal ball, we can use powerful time-series forecasting tools to analyze historical trends and project future possibilities.
In this tutorial, we'll use Prophet, a fast and reliable forecasting library developed by Meta (formerly Facebook). It's particularly good at handling data with strong seasonal patterns and trends. 📈
We will walk through the full process in a Jupyter Notebook, covering two different goals:
- Outcome 1: Loading data, training a model, and displaying an interactive forecast chart directly within your notebook for analysis.
- Outcome 2: Running the same forecast but exporting the results to a standalone HTML file and an Excel sheet, perfect for sharing with others.
Prerequisites: Installing the Libraries
Before we start, you'll need to install the necessary Python libraries. Open a new cell in your Jupyter Notebook and run the following command. The ! tells Jupyter to run this as a shell command.
!pip install pandas prophet plotly xlsxwriterHere's what each library does:
- pandas: The most popular library for data loading, manipulation, and analysis.
- prophet: Meta's time-series forecasting library.
- plotly: Used for creating rich, interactive charts.
- xlsxwriter: A library for writing files in the Microsoft Excel
.xlsxformat.
Download the Dataset
This tutorial requires a CSV file with historical gold price data. You can download this dataset here.
📊 Download Gold Price Dataset
Click the button below to Download Excel Sheet. Download this file and practice.
Download FileThe Core Code: Loading Data and Training the Model
Both of our scripts share the same foundation: loading the data, preparing it, and training the Prophet model. Let's break down these initial functions which are common to both approaches.
1. Displaying the Forecast Interactively
For displaying The Gold Rate forecast interactively in Jupyter Notebook You just need to copy past Code Given below in Jupyter Notebook and then Run
After running this code, the interactive visualization will appear Like below image.
2. Exporting to HTML and Excel
To export the gold rate interactive forecast visualization to HTML and Excel files using Jupyter Notebook, simply copy and paste the code given below into your Jupyter Notebook and then run it.
After running this code, the interactive visualization HTML and Excel files will be saved in the folder where Python is installed.
📹 Video Tutorial
Conclusion
You've successfully built a 10-year gold price forecast using Prophet! More importantly, you now have two distinct methods for handling the output: one for quick, personal analysis (fig.show()) and another for creating professional, shareable reports (fig.write_html() and .to_excel()).
Disclaimer: Remember, all financial forecasts are models based on historical trends. They are not guarantees of future performance, do not account for sudden market shocks or geopolitical events, and are provided for educational purposes only.

