We introduce a novel approach by applying a hybrid machine learning framework to the area of Forex market forecasting. Focusing on four major currency pairs—EUR/USD, GBP/USD, USD/JPY, and USD/CHF—from 2013 to 2023, our approach combines supervised learning algorithms with unsupervised HDBSCAN clustering. The framework employs a unique method of deriving targets from clustering results, using moving averages. Additionally, it encompasses a diverse range of supervised models, from statistical to deep learning, from memory-less to memory-based, widening its applicability. The clustering is specifically conducted on an expansive dataset of 48 currency pairs to generate new features for the supervised models. Our evaluation employs multi-faceted metrics such as classification accuracy, financial returns, and risk-adjusted performance. Notably, the results reveal significant improvements in predictive accuracy, particularly with the GRU model, while providing nuanced insights into the complexities of financial performance metrics. These findings underscore the importance of a more advanced approach to Forex trading that takes into account both risk management and market volatility.
Arrese Rodriguez, J. (2023). A Hybrid Methodology for Forex Forecasting. MSc in Artificial Intelligence dissertation, The University of Bath.
The experiments in this study were conducted on a MacBook Pro with an M1 chip. The technical specifications of the system are as follows:
- Processor: Apple M1 chip with 10-core CPU and 16-core GPU
- Memory: 16 GB Unified Memory
- Storage: 512 GB SSD
- Operating System: macOS Ventura 13.4
- Python Version: 3.9
- Package Manager: Pip
papermill==2.4.0
pandas==2.0.2
matplotlib==3.7.1
scikit-learn==1.2.2
tensorflow==2.13.0
tensorflow-macos==2.13.0
tensorflow-metal==1.0.0
plotly==5.15.0
tsfresh==0.20.1
hdbscan==0.8.29
ipykernel==6.23.3
To set up the project, follow these steps from the project's root directory (e.g. path/to/forex_forecasting):
-
Create and Activate Virtual Environment
python -m venv venv-forex-forecasting source venv-forex-forecasting/bin/activate # macOS and Linux .\venv-forex-forecasting\Scripts\Activate # Windows
-
Install Dependencies
pip install -r requirements.txt # Windows and Linux pip install -r requirements-macos.txt # macOS
-
Update Configuration File
- Open the
src/config.pyfile in a text editor. - Locate the
PROJECT_ROOT_DIRvariable. - Replace its value with the absolute path to the project root directory:
PROJECT_ROOT_DIR = 'path/to/forex_forecasting'
- Open the
-
Set Script Permissions
find scripts -type f -name "*.sh" -exec chmod +x {} \;
-
Create a New Kernel
python -m ipykernel install --user --name=venv-forex-forecasting
There are two primary ways to execute the project, each with its own set of advantages. Regardless of the chosen method,
the results will be saved in the reports folder.
Before initiating either method, it is advisable to clean the reports and processed folders if they contain data from previous runs.
scripts/clean.shRecommended
This method automatically runs Jupyter notebooks in a sequential manner via a script. It is the recommended choice because notebooks offer rich contextual information, such as training summaries and visualisations.
Available Commands:
# Standalone
scripts/notebooks/run_notebooks_standalone.sh
# Hybrid MA5
scripts/notebooks/run_notebooks_hybrid_MA5.sh
# Hybrid MA10
scripts/notebooks/run_notebooks_hybrid_MA10.sh
# Run All
scripts/notebooks/run_all_notebooks.shThis alternative runs code directly through pipelines, also triggered by a script. While it is more streamlined, it lacks the informative context provided by notebooks.
Available Commands:
# Standalone
scripts/pipelines/run_pipelines_standalone.sh
# Hybrid MA5
scripts/pipelines/run_pipelines_hybrid_MA5.sh
# Hybrid MA10
scripts/pipelines/run_pipelines_hybrid_MA10.sh
# Run All
scripts/pipelines/run_all_pipelines.sh