This repository contains the code used for the Bachelor's Thesis titled "Forecasting SPOT Price in the Spanish Electricity Market using Neural Networks" by Nicolás Vega Muñoz. The thesis was submitted to the Escuela Técnica Superior de Ingenieros Informáticos at the Universidad Politécnica de Madrid in June 2024. The full thesis is available here.
The primary objective of this work is to develop a model capable of predicting the SPOT price (price per MWh) in the Spanish electricity market for each hour of the following day. This model aims to optimize market offers by providing accurate price forecasts, which are crucial for making informed decisions in a highly volatile energy market.
Note: The dataset used in this project is not published due to a confidentiality agreement.
The methodology applied in this work includes the following steps:
Data was acquired from public sources by doing some Web Scrapping and using the ESIOS API.
The variables used are:
Gas price (€)
European Union Allowances (EUA) price: CO2 emissions allowances. (€)
Demand (MwH)
Resiudal demand (MwH)
Solar production (MwH)
Eolic production (MwH)
And were obtained from:
MIBGAS: Gas price and forecast
Sendeco2: Historical CO2 prices
ICE: CO2 price and forecast
In this section, we present the various models employed to forecast electricity prices in the wholesale market. We explored both classical and deep learning approaches to identify the most accurate and robust model for our predictions.
Seasonal Autoregressive Integrated Moving Average (SARIMA) and its extension with exogenous variables (SARIMAX) were among the classical models we tested. These models are well-suited for capturing seasonality and trends in time series data. We trained a SARIMAX model with the configuration SARIMAX(1,1,4)(1,0,0)[24], which provided a good fit to our data with a mean absolute error (MAE) of 7.13 on the validation set. However, the model exhibited limitations in capturing complex patterns beyond repetitive seasonal components.
LSTM networks, a type of recurrent neural network (RNN), are effective for sequential data due to their ability to retain information over long periods. We implemented several LSTM architectures, starting with a basic model and progressing to more complex configurations with multiple LSTM layers and dense layers. The most effective LSTM model included dropout and regularization, achieving a promising MAE of 4.63 over a 7-day prediction horizon.
We also experimented with 1D Convolutional Neural Networks (CNNs) to capture local patterns in the time series data. Starting with a simple model comprising a single convolutional layer with 16 filters followed by max pooling, we gradually increased the complexity. The best CNN model demonstrated decent performance, with a MAE of 4.98, indicating its potential for capturing significant features in the time series data.
To leverage the power of attention mechanisms, we employed Temporal Fusion Transformers (TFT). This state-of-the-art model excels in handling temporal dynamics and multi-horizon forecasting. Our TFT model achieved the lowest MAE of 1.1, making it the most accurate model among those evaluated. The TFT model's interpretability also provided valuable insights into the contributing factors of the forecasts, aiding strategic decision-making.
The following table summarizes the performance of the four models evaluated:
Model | MAE |
---|---|
Temporal Fusion Transformer | 1.26 |
LSTM | 4.63 |
CNN + LSTM | 4.98 |
ARIMA | 10.8 |
The study found that the Temporal Fusion Transformer (TFT) provided the most accurate predictions with a Mean Absolute Error (MAE) of 1.26. The implementation of this model is intended to improve prediction accuracy and optimize energy offer management, helping companies to bid more competitively and efficiently.
The study found that state-of-the-art models, particularly the Temporal Fusion Transformers (TFT), provided the most accurate predictions with a Mean Absolute Error (MAE) of 1.26. The implementation of this model is intended to improve prediction accuracy and optimize energy offer management, helping companies to bid more competitively and efficiently.
)
The Temporal Fusion Transformer (TFT) model includes several mechanisms for enhancing interpretability, making it easier to understand the factors driving the SPOT price predictions. These mechanisms are crucial for strategic decision-making in the energy market.
Variable Selection Networks:
Interpretable Multi-Head Attention:
Static Covariate Encoders:
Temporal Fusion Decoder:
Key insights from the TFT model include the identification of the most relevant variables influencing the SPOT price predictions:
Below are visual representations of the attention mechanism and the importance of various decoder variables, which provide deeper insights into the interpretability of the TFT model:
Understanding Key Drivers:
Enhanced Decision-Making:
Transparency and Trust:
old/
: Old, unused files.src
: Main folder where EDA, modelling and experiments are implemented.src/models/
: Contains the implementation of the ARIMA, LSTM and CNN models evaluated in this study.plots/
: Contains plots generated in the project. Contains both the results of the best TFT models and its interpretability plots.README.md
: This README file.tfg_etsiinf_NicolasVega
: Complete thesis.requirements.txt
: Necessary libraries to execute code.git clone https://github.com/MrGG14/Electricity-Price-Forecast-TFT
pip install -r requirements.txt
This work was supervised by Bojan Mihaljevic at the Department of Artificial Intelligence, Escuela Técnica Superior de Ingenieros Informáticos, Universidad Politécnica de Madrid.
There are no models linked
There are no datasets linked
There are no datasets linked
There are no models linked