This thesis investigates the application of the Random Forest Regressor to predict out-of-sample close prices of Gold (XAU/USD) across 9 distinct timeframes, ranging from 30-second intervals to monthly aggregations. The model is trained on log returns—defined as the natural logarithm of successive price ratios—rather than raw price levels, ensuring that the target variable is stationary and that the model is not required to extrapolate beyond its training range. Using institutional-grade historical data from the Dukas copy data feed spanning 2020 to 2026, I construct an identical autoregressive framework (5 lagged log returns) and apply a 100-tree Random Forest ensemble with an 80/20 chronological train-test split at each frequency. Predicted log returns are then converted back to price levels through exponential reconstruction. The empirical results demonstrate strong price-level performance across all timeframes, with the highest R² observed at the 5-Minute timeframe (0.9999) and the List at the Monthly timeframe (0.8491). The daily timeframe achieved an R² of 0.9896 with a MAPE of 1.07%. Notably, the R² on log returns themselves is slightly negative across all timeframes (approximately −0.05), reflecting the near-unpredictability of financial returns consistent with weak-form market efficiency. Feature importance analysis consistently identifies Lag 1 as the dominant predictor across all frequencies, exhibiting a classical autoregressive decay. These findings contribute to the growing literature on machine learning applications in commodity forecasting and offer practical guidance for quantitative practitioners regarding target variable selection and model evaluation.

Questa tesi indaga l'applicazione del Random Forest Regressor per prevedere i prezzi di chiusura fuori campione dell'oro (XAU/USD) su 9 diversi intervalli temporali, che vanno da intervalli di 30 secondi fino ad aggregazioni mensili. Il modello è addestrato sui rendimenti logaritmici—definiti come il logaritmo naturale dei rapporti di prezzo successivi—piuttosto che sui livelli di prezzo grezzi, garantendo che la variabile target sia stazionaria e che il modello non debba estrapolare oltre il suo range di addestramento. Utilizzando dati storici di livello istituzionale dal feed Dukas copy che coprono il periodo 2020-2026, costruisco un framework autoregressivo identico (5 rendimenti logaritmici ritardati) e applico un ensemble Random Forest con 100 alberi con uno split cronologico 80/20 tra addestramento e test a ciascuna frequenza. I rendimenti logaritmici previsti vengono poi riconvertiti in livelli di prezzo tramite ricostruzione esponenziale. I risultati empirici mostrano una forte performance a livello di prezzo su tutti gli intervalli temporali, con il valore di R² più alto osservato nell'intervallo dei 5 minuti (0.9999) e il Elencato sul timeframe mensile (0,8491). Il timeframe giornaliero ha raggiunto un R² di 0,9896 con un MAPE dell'1,07%. È interessante notare che l'R² sui rendimenti logaritmici è leggermente negativo in tutti i timeframe (circa -0,05), riflettendo l'imprevedibilità quasi completa dei rendimenti finanziari, coerente con l'efficienza dei mercati in forma debole. L'analisi dell'importanza delle caratteristiche identifica costantemente Lag 1 come il principale predittore in tutte le frequenze, mostrando un classico decadimento autoregressivo. Questi risultati contribuiscono alla letteratura crescente sulle applicazioni del machine learning nelle previsioni delle materie prime e offrono indicazioni pratiche per i professionisti quantitativi riguardo la selezione delle variabili target e la valutazione dei modelli.

PREDICTING GOLD PRICES USING RANDOM FOREST MACHINE LEARNING

DOSA, YACOB YASIN
2025/2026

Abstract

This thesis investigates the application of the Random Forest Regressor to predict out-of-sample close prices of Gold (XAU/USD) across 9 distinct timeframes, ranging from 30-second intervals to monthly aggregations. The model is trained on log returns—defined as the natural logarithm of successive price ratios—rather than raw price levels, ensuring that the target variable is stationary and that the model is not required to extrapolate beyond its training range. Using institutional-grade historical data from the Dukas copy data feed spanning 2020 to 2026, I construct an identical autoregressive framework (5 lagged log returns) and apply a 100-tree Random Forest ensemble with an 80/20 chronological train-test split at each frequency. Predicted log returns are then converted back to price levels through exponential reconstruction. The empirical results demonstrate strong price-level performance across all timeframes, with the highest R² observed at the 5-Minute timeframe (0.9999) and the List at the Monthly timeframe (0.8491). The daily timeframe achieved an R² of 0.9896 with a MAPE of 1.07%. Notably, the R² on log returns themselves is slightly negative across all timeframes (approximately −0.05), reflecting the near-unpredictability of financial returns consistent with weak-form market efficiency. Feature importance analysis consistently identifies Lag 1 as the dominant predictor across all frequencies, exhibiting a classical autoregressive decay. These findings contribute to the growing literature on machine learning applications in commodity forecasting and offer practical guidance for quantitative practitioners regarding target variable selection and model evaluation.
2025
2026-07-17
PREDICTING GOLD PRICES USING RANDOM FOREST MACHINE LEARNING
Questa tesi indaga l'applicazione del Random Forest Regressor per prevedere i prezzi di chiusura fuori campione dell'oro (XAU/USD) su 9 diversi intervalli temporali, che vanno da intervalli di 30 secondi fino ad aggregazioni mensili. Il modello è addestrato sui rendimenti logaritmici—definiti come il logaritmo naturale dei rapporti di prezzo successivi—piuttosto che sui livelli di prezzo grezzi, garantendo che la variabile target sia stazionaria e che il modello non debba estrapolare oltre il suo range di addestramento. Utilizzando dati storici di livello istituzionale dal feed Dukas copy che coprono il periodo 2020-2026, costruisco un framework autoregressivo identico (5 rendimenti logaritmici ritardati) e applico un ensemble Random Forest con 100 alberi con uno split cronologico 80/20 tra addestramento e test a ciascuna frequenza. I rendimenti logaritmici previsti vengono poi riconvertiti in livelli di prezzo tramite ricostruzione esponenziale. I risultati empirici mostrano una forte performance a livello di prezzo su tutti gli intervalli temporali, con il valore di R² più alto osservato nell'intervallo dei 5 minuti (0.9999) e il Elencato sul timeframe mensile (0,8491). Il timeframe giornaliero ha raggiunto un R² di 0,9896 con un MAPE dell'1,07%. È interessante notare che l'R² sui rendimenti logaritmici è leggermente negativo in tutti i timeframe (circa -0,05), riflettendo l'imprevedibilità quasi completa dei rendimenti finanziari, coerente con l'efficienza dei mercati in forma debole. L'analisi dell'importanza delle caratteristiche identifica costantemente Lag 1 come il principale predittore in tutte le frequenze, mostrando un classico decadimento autoregressivo. Questi risultati contribuiscono alla letteratura crescente sulle applicazioni del machine learning nelle previsioni delle materie prime e offrono indicazioni pratiche per i professionisti quantitativi riguardo la selezione delle variabili target e la valutazione dei modelli.
File in questo prodotto:
File Dimensione Formato  
Final Project - edited.pdf

accesso aperto

Descrizione: This thesis applies a Random Forest Regressor to forecast out‑of‑sample Gold (XAU/USD) close prices across nine timeframes using lagged log‑return features.
Dimensione 1.89 MB
Formato Adobe PDF
1.89 MB Adobe PDF Visualizza/Apri

I documenti in UNITESI sono protetti da copyright e tutti i diritti sono riservati, salvo diversa indicazione.

Utilizza questo identificativo per citare o creare un link a questo documento: https://hdl.handle.net/20.500.12075/27394