2026-03-16 13:16:16 +00:00

2.6 KiB

ECB FX Trend Analyzer & Pair Ranker

Overview

This R script automates the extraction and statistical analysis of daily foreign exchange rates from the European Central Bank (ECB). Designed for trend-following or long/short strategy research, it identifies the top FX pairs exhibiting the strongest, most predictable linear trends over a customizable rolling window.

Instead of relying on standard return/volatility metrics, it ranks pairs using a custom Signal-to-Noise Ratio derived from linear regression, isolating pairs that move cleanly in one direction with minimal chop.


Key Features

  • Automated Data Ingestion: Securely downloads, unzips, and cleans the latest historical daily exchange rate dataset directly from the ECB repository.
  • Dynamic Cross-Pair Generation: Automatically calculates non-EUR cross-pairs (e.g., USD/JPY, GBP/JPY) on the fly based on any user-defined list of target currencies.
  • Custom Timeframes: Allows users to easily slice the dataset to analyze specific lookback periods (e.g., the last 720 days).
  • Statistical Ranking Methodology: * Runs a simple linear regression for each currency pair (Exchange Rate ~ Time).
    • Extracts the slope (Beta) to measure the strength and direction of the trend.
    • Extracts the Residual Standard Error (RSE) to measure the volatility or "noise" around that trendline.
    • Ranks all pairs by |Beta| / RSE, surfacing the top 3 pairs with the smoothest, most predictable trajectories regardless of whether they are trending up or down.

Prerequisites

  • R (Version 3.0 or higher): The script relies entirely on base R functions. No external libraries (like dplyr or quantmod) are required.
  • Internet Connection: Required for the script to automatically fetch the latest dataset directly from the ECB servers.

How to Use

1. Open the Script Open the .R file in your preferred environment (RStudio, VS Code, or the standard R GUI).

2. Configure Your Parameters At the very top of the script, locate the CONFIGURATION section to customize your analysis:

  • target_currencies: An array of the currency tickers you want to analyze. The script will automatically generate all possible cross-pairs from this list. (Note: All original columns are priced with a EUR base by default).
  • n_days_to_analyze: An integer representing your lookback window in days (e.g., 720 for roughly two years). Set this to NULL to analyze the entire historical dataset dating back to 1999.
# Example Configuration
target_currencies <- c("USD", "JPY", "GBP")
n_days_to_analyze <- 720