Professional Documents
Culture Documents
Sarima Model For Forecasting Currency Exchange Rates
Sarima Model For Forecasting Currency Exchange Rates
S T AT I S T I C S T I M E S E RI E S T I M E S E RI E S F O RE C A S T I NG
Introduction
Forecasting currency exchange rates is the practice of anticipating future changes in the value of one
currency about another. Currency forecasting may assist people, corporations, and financial organizations
make educated financial decisions. One of the forecasting techniques that can be used is SARIMA.
SARIMA is an excellent time series forecasting technique for estimating time series data with seasonal
patterns. It works by modeling the link between past and current values of a time series and recognizing
patterns in the data. SARIMA utilizes a variety of auto-regression (AR) and moving average (MA) models, as
well as differencing, to capture trends and seasonality in data. “seasonality” refers to data variations that
occur regularly and predictably throughout a specified period, such as daily, weekly, or annual cycles. We
can be better informed about changes in currency values by anticipating exchange rates. Now, let’s make
the forecasting through the steps in the article.
Learning Objectives
1. To help individuals, businesses, and financial institutions anticipate market trends by identifying
patterns and trends in historical data.
2. To reduce risk by identifying potential risks associated with currency fluctuations.
3. To optimize currency conversions by identifying the best time to convert currencies.
4. Improve decision-making by providing businesses and individuals with information about the future
direction of currency exchange rates.
Based on these objectives, we will use SARIMA to develop a model to estimate currency exchange rates by
aggregating seasonal data patterns to make more accurate predictions of future values.
Table of contents
Introduction
Learning Objectives
Step 1: Import Library
Step 2: Read the Data
Step 3: Conversion Rate Analysis
Step 4: Build a SARIMA Model and Make a Forecasting
Conclusion
Frequently Asked Questions
Step 1: Import Library
!pip install pmdarima from pmdarima.arima import auto_arima from statsmodels.tsa.statespace.sarimax import
We must install the ‘pmdarima’ library to use the auto_arima function. This function fits an ARIMA model
with time series data and automatically determines the appropriate model parameters based on the data
provided.
We need historical data about exchange rates between two currencies to forecast exchange rates. Thus,
we can download historical data containing weekly exchange rates between INR and USD at yahoo finance
web. And we can utilize a period of December 1, 2003, to June 15, 2023. Fortunately, I’ve made it public on
GitHub.
pd.read_csv(alamat) print(data.sample(11))
Data Overview
Let’s check whether the dataset includes any missing values before proceeding further. It is essential to
verify.
print(data.isna().sum())
Missing Value
Several missing values in the dataset have been identified. As a result, we must eliminate them.
data = data.dropna()
Examine descriptive statistics to acquire a better understanding of the data set and the factors that
underpin it. We may get essential insights into data set characteristics, spot potential outliers, grasp data
distribution elements, and establish the framework for future exploratory data analysis and modeling
efforts. Let’s look at the descriptive statistics for this data collection.
print(data.describe())
The dataset contains the value of INR for 1 USD for a given time. Below are all the features in the data:
1. The date represents the specific day of the exchange rate data.
2. Open refers to the exchange rate at the start of a specific trading period, such as the opening price for
the day or the week.
3. High represents the highest exchange rate observed during a specific trading period.
4. Low represents the lowest exchange rate observed during a specific trading period.
5. Close shows the currency rate at the end of a certain trading period.
. Adjusted Closing considers any business activities that may impact the Closing Price, such as stock
splits or dividends.
7. Volume refers to the number of USD-INR currency pairs traded during a specific period.
Let’s analyze the conversion rates between the two currencies over the years. By examining historical
trends, we can gain valuable insights into exchange rate dynamics and potentially uncover important
patterns or events that affect these exchange rates. To visualize this analysis, we will use a line chart to
illustrate the trend of the USD-INR conversion rate over time.
figure = px.line(data, x="Date", y="Close", title='Conversion Rate over the years (USD/INR)') figure.show()
Let’s add year and month fields to the data so we can enable deeper temporal analysis.
data["Date"] = pd.to_datetime(data["Date"], format = '%Y-%m-%d') data['Year'] = data['Date'].dt.year
Let’s examine the compounded yearly increase of the INR-USD exchange rate to discover times of
economic strength or weakness, important events impacting currency rates, or long-term patterns in INR-
USD conversion rates.
Now let’s break it down again by looking at the combined monthly conversion rate growth between INR and
USD.
x.iloc[0] * 100) # Group data by Month and calculate average growth grouped_data =
The graph illustrates that the USD value has consistently decreased in January and March. This
observation shows that the INR tends to strengthen against the USD during these months, reducing the
conversion rate. Meanwhile, in the second quarter, the USD boosted against the INR every year. The USD
value against INR peaked in August but fell in September, rose annually in the fourth quarter, and fell again
in December.
We must perform a seasonal decomposition of the USD – INR exchange rate data. This method separates
the different data components: trends, seasonality, and residual or random fluctuations.
Seasonal Decomposition
We can see that there is a seasonal pattern to this data. So, we use SARIMA as the most appropriate
algorithm for this data. Before using SARIMA, we need to find the p, d, and q values first. We can use the
‘pmdarima’ library to find those values automatically.
p,d,q value
The parameter seasonal=True determines that the time series shows a seasonal pattern. Meanwhile, the
parameter m=52 shows the seasonal periodicity of weekly data. And 2, 1, 0 is the p, d, q value.
We are ready to train our model using SARIMA to estimate currency exchange rates.
model.fit() print(fitted.summary())
We now predict future currency exchange rates from the fitted ARIMA model.
Prediction Values
fig = go.Figure() # Add training data line plot fig.add_trace(go.Scatter( x=data.index, y=data['Close'],
mode='lines', name='Training Data', line=dict(color='blue') )) # Add predictions line plot
Conclusion
This article starts by checking if there are missing values in the dataset and analyzing the data with
descriptive statistics. Then explore the conversion rate between the two currencies aggregated annually
and monthly before forecasting the currency exchange rate using the SARIMA. We have discussed the
following:
The SARIMA model is a statistical model that captures seasonal trends in the past values of the data to
predict future discounts.
The SARIMA model can forecast currency exchange rates for various currencies.
The SARIMA model helps make informed decisions related to currency trading, financial planning, or
international business operations.
The accuracy of the model depends on several factors, including the data quality and the currency
market’s stability.
This article provides a comprehensive guide to currency exchange rate forecasting with SARIMA using
Python.
A. Forecasting currency exchange rates is predicting changes in the value of one currency compared to
another at a particular time. Generally influenced by various factors, including economic figures, political
events, market mood, and technical analysis.
A. SARIMA (Seasonal Autoregressive Integrated Moving Average) is a statistical technique used for
forecasting time series data, a series of observations recorded at regular intervals over time. SARIMA
models are a combination of autoregressive (AR) models, moving average (MA) models, and
differencing.
A. ARIMA and SARIMA are statistical models that forecast time series data. They are both based on the
autoregressive integrated moving average (ARIMA) model, but SARIMA includes a seasonality element.
Q5. What are the risks associated with using the SARIMA model?
A. 1. Overfitting happens when a model fits the data too closely and does not generalize well to new data.
SARIMA models are susceptible to overfitting.
2. Complexity: SARIMA models can be challenging to comprehend and apply.
3. Computational cost: Training and forecasting SARIMA models can be
computationally expensive.
The media shown in this ar ticle is not owned by Analytics Vidhya and is used at the Author’s discretion.
Ata Amrullah