Let us now look at two built-in Python libraries. When it comes to financial data management,
two of the most frequently used Python packages/libraries are Pandas and Numpy.
A function can be easily called only after we import the library.
This is why the command for importing libraries is always put at the beginning of a script.
To employ the pandas library, we import it on the notebook.
This line means that Jupyter is told to import the pandas library and assigns it a short name, pd
, for ease of reference. 📚
One of the first steps of every statistical analysis is importing the dataset to be analyzed into the software. Depending on the format of the data, there are different ways of accomplishing this task. This study conducts a comprehensive analysis of monthly USD/TRY and EUR/TRY exchange rates from Q1 2012 to October 2024. Data, acquired from the Turkish Central Bank’s EVDS database, consists of separate buying and selling rates, later averaged into a 'basket' rate for consistency. 🌐
Initially, the analysis focuses on USD/TRY before moving to EUR/TRY in parallel, applying various time series methods to capture both trend and seasonality. The primary methodological framework includes Moving Averages and Smoothing Techniques, such as centered moving averages, simple exponential smoothing, and the Holt-Winters model. These techniques smooth the data, helping reveal trend and seasonal components effectively.
Stationarity of the series is then assessed through the Augmented Dickey-Fuller (ADF) test, which identifies whether transformations, like differencing or logarithmic adjustments, are needed to stabilize mean and variance over time. Once stationarity is confirmed, Model Selection and Forecasting proceeds using both additive and multiplicative decompositions to select a model aligned with the data’s structure. ✨
Further, advanced forecasting models, including Holt's linear (two-parameter) and seasonal (three-parameter) adjustments, as well as exponential trend modeling, are applied. For series with substantial trend and seasonal components, Box-Jenkins ARMA modeling will enhance forecast precision. Autocorrelation Analysis through autocorrelation and partial autocorrelation functions (normalized via Bartlett’s correction) assesses whether trend components need to be removed. The theoretical basis for these methods rests on stochastic process principles, where a real-valued time series in probability space forms a stochastic process, a sequence of random variables evolving over time. Detailed mathematical formulations supporting each step will follow in later sections. 🧮
Trend Component Analysis distinguishes between linear and nonlinear growth or decline over the long term, as expressed by the trend function. Seasonal Components are addressed by observing recurring patterns in monthly exchange rates. Additionally, Cyclical Components, characterized by longer-term fluctuations influenced by economic policies, are examined.
import pandas
as pd
import numpy
as np
import statsmodels.api
as sm
foreign_dataset['t'] = range(1, len(foreign_dataset) + 1) foreign_dataset['log_usd_sepet'] = np.log(foreign_dataset['usd_sepet'])
X = foreign_dataset[['t']] X = sm.add_constant(X) y = foreign_dataset['log_usd_sepet']
model = sm.OLS(y, X).fit() print(model.summary())
foreign_dataset['usd_sepet_pred'] = np.exp(model.predict(X)) print(foreign_dataset[['t', 'usd_sepet', 'usd_sepet_pred']].head())
Observed: Last observed value = 34.20 USD/TRY Predicted: Last estimated value = 33.93 USD/TRY