This project predicts the daily GLD price using market features.
It includes:
- A model training script
- A FastAPI backend for predictions
- A Streamlit web app for user input and results
The model learns from historical data and predicts GLD price from these inputs:
- SPX
- USO
- SLV
- EUR/USD
src/train_model.pytrains the model and saves filessrc/gold_model.pycontains shared ML logic (load data, train, save, load, predict)src/api.pyprovides REST API endpointssrc/app.pyprovides Streamlit UIdata/gld_price_data.csvis the datasetartifacts/stores generated model and metrics
- Run training once.
- Training creates model and metrics files in
artifacts/. - Start FastAPI backend (model is loaded there).
- Streamlit sends user input to FastAPI
/predict. - Streamlit shows predicted GLD price from API response.
When training finishes, these files are created:
artifacts/gold_price_model.joblib(trained model)artifacts/metrics.json(R2, MAE, RMSE)
Use your virtual environment and install dependencies:
pip install -r requirements.txtTrain model:
python src/train_model.pyRun FastAPI server:
python -m uvicorn src.api:app --reloadRun Streamlit app:
streamlit run app.pyOptional (if backend is not local):
$env:BACKEND_URL="http://127.0.0.1:8000"Base URL after running API:
http://127.0.0.1:8000
Health route:
GET /
Prediction route:
POST /predict
Example request body:
{
"spx": 1447.16,
"uso": 78.47,
"slv": 15.18,
"eurUsd": 1.471692
}Example response:
{
"predicted_gld_price": 84.98
}- If Streamlit cannot predict, ensure FastAPI is running and
BACKEND_URLis correct. - This project is for learning and experimentation.
- It is not financial advice.
Clone from GitHub:
git clone https://github.com/saimtec/Gold-Price-Prediction.git
cd Gold-Price-PredictionInstall dependencies:
pip install -r requirements.txt