USD/TRY Next 30 Days (with SARIMAX)

Orhan D.
3 min readJun 10, 2023

--

After the presidential elections on May 28th in Turkey, there is significant anticipation regarding the future of the USD/TRY exchange rate. Despite the inclusion of well-known figures like Mehmet Simsek in Erdogan’s cabinet, the market has shown an upward trend. In this article, I will outline the expected trajectory of the USD/TRY exchange rate over the next 30 days.

SARIMAX is a common time series model in machine learning. This model is particularly useful for gaining insights into future values and expectations.

Last but not least, the data should exhibit an upward trend, similar to the USD/TRY exchange rate.

  1. Import the data:

The CSV file was downloaded from Investing.com. The dataset covers the USD/TRY exchange rates for the past 90 days.In SARIMAX model the data must consist of just datetime and target variable. Because of that index_col is chosen as ‘Date’ column.

df = pd.read_csv('/kaggle/input/dolar-next-30-days/USD_TRY Historical Data.csv',
index_col = 'Date',parse_dates = True)

2.Check the Data Set:

df.head()

3.Target Variable :

Our goal is to gain insights into the daily closing price of the US Dollar in Turkish Lira. We should choose ‘Price’ as our target variable in the dataset.

df_price = df[['Price']]

4.Resampling the data:

In this data set the weekends are not included. Also in Turkey, the exchange market closed 5 A.M on Fridays. This situation can mislead our timeseries model. But to avoid this problem we must use ‘resampling’ method.

df_price = df_price.resample('B').sum()

5.Check the Trends on Targe Varible:

As seen below, our ‘Price’ variable exhibits an upward trend.

6.Building SARIMAX model:

First, we should install the SARIMAX model in our Jupyter notebook. Then, we can build our model using the following code. The ‘m’ parameter represents our forecast period, and we are aiming to forecast the next 30 days. The AutoARIMA model provides the ‘best_parameters’ for us to use in our model. At the end the model gives us the parameters as ARIMA(3,2,1)(0,1,0)[30]

!pip install pmdarima
Sarimax_model = auto_arima(df_price,
start_P=1,
start_q=1,
max_p=3,
max_q=3,
m=30,
seasonal=True,
d=None,
D=1,
trace=True,
error_action='ignore',
suppress_warnings=True,
stepwise=True)
Sarimax_model.summary()

7.Building the model:

After the model gave us the the best_parameters. We build our model.

model_price = SARIMAX(df_price,order=(3, 2, 1),
seasonal_order=(0, 1,0,30),
enforce_stationarity=False,
enforce_invertibility=False)
results_price = model_price.fit()

8.Prediction:

With prediction function, the model predicts the values for the next 30 Days. We have build 2 different prediction models to test the performance of our model. As the last graph shows that our model performs pretty good its role.

forecast_price = results_price.predict(start = len(df_price),
end=len(df_price)+30,typ='levels').rename('Arima --Dolar Price($)-- forecast')

forecast_price_test = results_price.predict(start = len(df_price)-30,
end=len(df_price),typ='levels').rename('Arima --Dolar Price ($)(TEST) -- forecast')

9.Plot the predictions:

df_price.plot(figsize=(12,8),legend=True)
forecast_price.plot(legend=True);
forecast_price_test.plot(legend=True);

10.Printing Forecast:

As you can see below, our model shows that the US dollar exchange rate will reach approximately 45 lira in the next 30 days. It should be noted, however, that the results of this model should not be considered as investment advice.

print(forecast_price)

--

--