{"id":4521,"date":"2024-01-09T20:44:18","date_gmt":"2024-01-09T20:44:18","guid":{"rendered":"https:\/\/eodhd.com\/financial-academy\/?p=4521"},"modified":"2025-02-05T11:18:10","modified_gmt":"2025-02-05T11:18:10","slug":"forecast-economic-variables-with-arima","status":"publish","type":"post","link":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima","title":{"rendered":"Forecast Economic Variables with ARIMA"},"content":{"rendered":"\n<p>Time series analysis is a fundamental component of statistical studies and forecasting in various fields such as economics, finance, environmental science, and many more. In this comprehensive guide, we will delve into an example of time series analysis and show how to forecast economic variables with ARIMA model. In this case, we will use the <em>Unemployment Rate<\/em> in the United States and provide detailed insights and statistical formalization of each step in the process.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a class=\"maxbutton-1 maxbutton maxbutton-subscribe-to-api external-css btn\" href=\"https:\/\/eodhd.com\/register\"><span class='mb-text'>Register &amp; Get Data<\/span><\/a><\/p>\n\n\n\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-data-collection-and-preprocessing\"><strong>Data Collection and Preprocessing<\/strong><\/h2>\n\n\n\n<p>The journey begins with data collection, which is done through the <a href=\"https:\/\/github.com\/EodHistoricalData\/EODHD-APIs-Python-Financial-Library\/tree\/main\" target=\"_blank\" rel=\"noreferrer noopener\">Official EODHD APIs library<\/a>. This is a important steps to step that enables the connection to an external data source to retrieve the data. For this case study, we retrieve US unemployment data from 1960. The snippet:<\/p>\n\n\n\n<p class=\"bordered_paragraph\">1. Use the \u201c<strong>demo<\/strong>\u201d API key to test our data from a limited set of tickers without registering: <a href=\"https:\/\/eodhistoricaldata.com\/financial-summary\/AAPL.US\" target=\"_blank\" rel=\"noreferrer noopener\">AAPL.US<\/a> | <a href=\"https:\/\/eodhistoricaldata.com\/financial-summary\/TSLA.US\" target=\"_blank\" rel=\"noreferrer noopener\">TSLA.US <\/a>| <a href=\"https:\/\/eodhistoricaldata.com\/financial-summary\/VTI.US\" target=\"_blank\" rel=\"noreferrer noopener\">VTI.US<\/a> | <a href=\"https:\/\/eodhistoricaldata.com\/financial-summary\/AMZN.US\" target=\"_blank\" rel=\"noreferrer noopener\">AMZN.US<\/a> | <a href=\"https:\/\/eodhistoricaldata.com\/financial-summary\/BTC-USD.CC\" target=\"_blank\" rel=\"noreferrer noopener\">BTC-USD<\/a> | <a href=\"https:\/\/eodhistoricaldata.com\/financial-summary\/EURUSD.FOREX\" target=\"_blank\" rel=\"noreferrer noopener\">EUR-USD<\/a><br><a href=\"https:\/\/eodhistoricaldata.com\/financial-summary\/AAPL.US\" target=\"_blank\" rel=\"noreferrer noopener\">Real-Time Data<\/a> and all of the APIs (except Bulk) are included without API calls limitations with these tickers and the demo key.<br>2. Register to get your free API key (limited to 20 API calls per day) with access to: <a href=\"https:\/\/eodhistoricaldata.com\/financial-apis\/api-for-historical-data-and-volumes\/\" target=\"_blank\" rel=\"noreferrer noopener\">End-Of-Day Historical Data<\/a> with only the past year for any ticker, and the <a href=\"https:\/\/eodhistoricaldata.com\/financial-apis\/api-for-historical-data-and-volumes\/\" target=\"_blank\" rel=\"noreferrer noopener\">List of tickers per Exchange<\/a>.<br>3. To unlock your API key, we recommend to choose the subscription plan which covers your needs.<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-c6e206c9585f65602a32715a5e196caf\"><code lang=\"python\" class=\"language-python\">from utils.config import apikey\napi = APIClient(apikey)\n\n# Fetch and preprocess data\nunemployment_data = pd.DataFrame(api.get_macro_indicators_data(\"USA\", \"unemployment_total_percent\"))[[\"Date\", \"Value\"]]\nunemployment_data = unemployment_data.set_index(\"Date\").sort_index()\nunemployment_data.index = pd.to_datetime(unemployment_data.index)\nunemployment_data = unemployment_data.asfreq(freq='A')\nunemployment_data.head()<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p>illustrates how data is fetched and transformed into a Pandas DataFrame for ease of manipulation.<\/p>\n\n\n\n<p>Next, the data undergoes preprocessing. Timestamps are standardized, and the series is structured with an annual frequency. This structuring is vital for ensuring consistency in time intervals, a strict requirement in ARIMA models.<\/p>\n\n\n\n<p>Also we split our data into a estimation and prediction sample. In our case, 90% of the data will be used to estimated the model coefficients while and the remaining 10% to check to quality of our forecast.<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-d6e82c16f41d657abf54a5429c105ffc\"><code lang=\"python\" class=\"language-python\"># Splitting the time series data\nsplit_percentage = 0.9\nsplit_index = int(len(unemployment_data) * split_percentage)\ntraining_data = unemployment_data[:split_index]\ntest_data = unemployment_data[split_index:]<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p>Finally we plot the whole time series for better visualization<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"854\" height=\"525\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2024\/01\/plot2.png\" alt=\"\" class=\"wp-image-4543\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-stationarity\"><strong>Stationarity<\/strong><\/h2>\n\n\n\n<p>A stationary process in time series analysis refers to a stochastic process whose statistical properties do not change over time. This implies that the process generates a series of data points where its mean, variance, and autocorrelation structure remain constant over time, irrespective of the period at which they are measured. This characteristic is essential because many statistical methods and models for time series analysis are based on the assumption of stationarity. Stationarity makes the series easier to analyze and predict, as the properties of the series do not change over time.<\/p>\n\n\n\n<p>In practical terms, a stationary process can be visualized as a time series plot where the series fluctuates around a constant mean level, and the amplitude of the fluctuations does not increase or decrease over time. This consistency over time allows for the application of various time series forecasting methods, such as ARIMA (Auto-Regressive Integrated Moving Average) models, which assume that the series is stationary or has been transformed into a stationary series. In economics, individual time series are usually integrated processes, but sometimes the spread between two variables can be stationary and in this case we can say the prices are <em>cointegrated.<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-augmented-dickey-fuller-adf\"><strong>Augmented Dickey-Fuller (ADF)<\/strong><\/h2>\n\n\n\n<p>Generally, time series analysis commences with the Augmented Dickey-Fuller (ADF) test, which is a formal statistical test to check for stationarity. Here&#8217;s a short formalization of the test:<\/p>\n\n\n\n<p align=\"center\"><img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%5CDelta+Y_t+%3D+%5Calpha+%2B+%5Cbeta+t+%2B+%5Cgamma+Y_%7Bt-1%7D+%2B+%5Cdelta_1+%5CDelta+Y_%7Bt-1%7D+%2B+%5Cdelta_2+%5CDelta+Y_%7Bt-2%7D+%2B+%5Ccdots+%2B+%5Cdelta_p+%5CDelta+Y_%7Bt-p%7D+%2B+%5Cvarepsilon_t+&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"&#92;Delta Y_t = &#92;alpha + &#92;beta t + &#92;gamma Y_{t-1} + &#92;delta_1 &#92;Delta Y_{t-1} + &#92;delta_2 &#92;Delta Y_{t-2} + &#92;cdots + &#92;delta_p &#92;Delta Y_{t-p} + &#92;varepsilon_t \" class=\"latex\" \/><\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container\">\n<ul class=\"wp-block-list\">\n<li><img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%5CDelta+Y_t++&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"&#92;Delta Y_t  \" class=\"latex\" \/> is the difference of the time series at time t <\/li>\n\n\n\n<li><img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%5Calpha++&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"&#92;alpha  \" class=\"latex\" \/> is a constant (intercept).<\/li>\n\n\n\n<li><img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%5Cbeta+t++&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"&#92;beta t  \" class=\"latex\" \/> represents a deterministic time trend.<\/li>\n\n\n\n<li><img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%5Cgamma+++&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"&#92;gamma   \" class=\"latex\" \/> is the coefficient on the lagged level of the time series.<\/li>\n\n\n\n<li><img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%5Cdelta_1%2C+%5Cdelta_2%2C+%5Ccdots%2C+%5Cdelta_p+&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"&#92;delta_1, &#92;delta_2, &#92;cdots, &#92;delta_p \" class=\"latex\" \/> are the coefficients of the lagged differences of the series.<\/li>\n\n\n\n<li><img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%5Cvarepsilon_t+++&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"&#92;varepsilon_t   \" class=\"latex\" \/>  is the error term.<\/li>\n<\/ul>\n\n\n\n<p>The null hypothesis H0 states that there is a unit root, implying the time series is non-stationary. Mathematically, this means <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%5Cgamma+%3D+0&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"&#92;gamma = 0\" class=\"latex\" \/>. The alternative hypothesis H1 is that the time series is stationary, which implies  <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%5Cgamma+%3C+0&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"&#92;gamma &lt; 0\" class=\"latex\" \/>. The decision whether to reject the null hypothesis is based on the p-value associated with the test statistic. If the p-value is less than a chosen significance level (commonly 0.05), the null hypothesis is rejected, indicating the series is stationary.<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-cf997bf88ff4922acc2313b6ce638ad6\"><code lang=\"python\" class=\"language-python\"># Function to perform the Augmented Dickey-Fuller test\ndef adf_test(time_series):\n    result = adfuller(time_series)\n    print('ADF Statistic: %f' % result[0])\n    print('p-value: %f' % result[1])\n    print('Critical Values:')\n    for key, value in result[4].items():\n        print('\\t%s: %.3f' % (key, value))\n    if result[1] &gt; 0.05:\n        print(\"Series is non-stationary\")\n    else:\n        print(\"Series is stationary\")\n\n# Perform ADF test on the training data\nadf_test(training_data['Value'])<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        <\/div><\/div>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"183\" height=\"149\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2024\/01\/stationarity.png\" alt=\"\" class=\"wp-image-4535\"\/><\/figure>\n<\/div>\n\n\n<p>Once we have tested the stationarity of the process, we can move to the model fitting.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-arima-models\"><strong>ARIMA Models<\/strong><\/h2>\n\n\n\n<p>ARIMA (AutoRegressive Integrated Moving Average) is a widely used statistical method in time series forecasting. It combines autoregressive features (AR), integration (I \u2013 used for making the series stationary), and moving average (MA) components. The model is generally denoted as ARIMA(p, d, q), where:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>p (AR part)<\/strong>: This represents the &#8216;autoregressive&#8217; aspect of the model. It is the number of lag observations included in the model. Essentially, it is the degree to which current values of the series are dependent on its previous values.<\/li>\n\n\n\n<li><strong>d (I part)<\/strong>: The &#8216;integrated&#8217; part, d, denotes the number of times the data needs differencing to make the time series stationary.<\/li>\n\n\n\n<li><strong>q (MA part)<\/strong>: The &#8216;moving average&#8217; aspect. It is the size of the moving average window, indicating the number of lagged forecast errors that should go into the ARIMA model.<\/li>\n<\/ul>\n\n\n\n<p>Formally, an ARIMA(p, d, q) model can be described as:<\/p>\n\n\n\n<p align=\"center\"><img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=ARIMA%28p%2C+d%2C+q%29+%3A+%281+-+%5Csum_%7Bi%3D1%7D%5E%7Bp%7D+%5Cphi_i+L%5Ei%29%281+-+L%29%5Ed+X_t+%3D+%281+%2B+%5Csum_%7Bi%3D1%7D%5E%7Bq%7D+%5Ctheta_i+L%5Ei%29+&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"ARIMA(p, d, q) : (1 - &#92;sum_{i=1}^{p} &#92;phi_i L^i)(1 - L)^d X_t = (1 + &#92;sum_{i=1}^{q} &#92;theta_i L^i) \" class=\"latex\" \/><\/p>\n\n\n\n<p>Here, L  is the lag operator, <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%5Cphi_i&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"&#92;phi_i\" class=\"latex\" \/> are the parameters of the autoregressive part, <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%5Ctheta_i&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"&#92;theta_i\" class=\"latex\" \/> are the parameters of the moving average part, and <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=%5Ctheta_i&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"&#92;theta_i\" class=\"latex\" \/> is white noise.<\/p>\n\n\n\n<p>The<em> auto_arima <\/em>function from the <em>pmdarima <\/em>library automates the process of selecting the best set of parameters (p, d, q) by iterating over multiple combinations and evaluating their performance.<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-0871f5fd0a03874cb85875adbddfea6a\"><code lang=\"python\" class=\"language-python\"># Building and fitting the ARIMA model\nmodel_autoARIMA = auto_arima(training_data, start_p=0, start_q=0,\n                             test='adf', max_p=2, max_q=2, m=1,\n                             d=None, seasonal=False, start_P=0, \n                             D=0, trace=True,\n                             error_action='ignore',  \n                             suppress_warnings=True, \n                             stepwise=True)\n\nprint(model_autoARIMA.summary())\nmodel_autoARIMA.plot_diagnostics(figsize=(15,8))\nplt.show()<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"806\" height=\"532\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2024\/01\/output-arima.png\" alt=\"\" class=\"wp-image-4537\" style=\"width:757px;height:auto\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1038\" height=\"568\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2024\/01\/result-arima.png\" alt=\"\" class=\"wp-image-4538\" style=\"width:897px;height:auto\"\/><\/figure>\n\n\n\n<p>Looking at the results of the <em>auto_arima<\/em> function, it is evident how the combination <em>I<\/em>=1 and <em>Q<\/em>=1 is the one that best fits the current data. For this reason, we will now estimate the models parameters and derive forecasts using those arguments in the <em>statsmodels.tsa.arima.model.ARIMA<\/em> function.<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-5618fd11a835faf5fe45f3ae02b4a313\"><code lang=\"python\" class=\"language-python\"># Fitting the ARIMA model\nmodel = ARIMA(training_data, order=(0,1,1))  \nfitted_model = model.fit()  \nprint(fitted_model.summary())<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<p>The final stage involves forecasting the unemployment rates using the fitted ARIMA model. The forecast is then compared against the actual data in the test set, using metrics like the Mean Squared Error (MSE) and Root Mean Squared Error (RMSE) to assess accuracy. The results are visually represented through plots showing the estimation data and forecasted values.<\/p>\n\n\n\n            <div class=\"code__wrapper\">\n                <div class=\"code__content\">\n                    \n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-8f340e2af924d50eb9d52f355ed8446a\"><code lang=\"python\" class=\"language-python\"># Forecasting\nforecast_steps = len(test_data)\nforecast_results = fitted_model.get_forecast(steps=forecast_steps)\nforecast_series = pd.Series(forecast_results.predicted_mean, index=test_data.index)\n\n# Evaluating the forecast\nmse = mean_squared_error(test_data, forecast_series)\nrmse = mse**0.5\n\n# Plotting the forecast results\nplt.figure(figsize=(14,7))\nplt.plot(training_data, label='Training Data')\nplt.plot(test_data, label='Actual Data', color='orange')\nplt.plot(forecast_series, label='Forecasted Data', color='green')\nplt.fill_between(test_data.index, \n                 forecast_results.conf_int().iloc[:, 0], \n                 forecast_results.conf_int().iloc[:, 1], \n                 color='k', alpha=.15)\nplt.title('ARIMA Model Forecast Evaluation')\nplt.xlabel('Year')\nplt.ylabel('Unemployment Rate (%)')\nplt.legend()\nplt.show()<\/code><\/pre>\n\n                <\/div>\n                <div class=\"code__btns\">\n                    <button class=\"code__copy\" class=\"copy\" title=\"Copy url\">\n                        <svg class=\"code__copy__icon\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                            <use xlink:href=\"\/img\/icons\/copy.svg#copy\"><\/use>\n                        <\/svg>\n                        <img decoding=\"async\" class=\"code__copy__approve\" alt=\"\" src=\"\/img\/approve_ico.svg\" loading=\"eager\">\n                    <\/button>\n                <\/div>\n            <\/div>\n        \n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1046\" height=\"550\" src=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2024\/01\/plot1.png\" alt=\"\" class=\"wp-image-4539\" style=\"width:893px;height:auto\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2>\n\n\n\n<p>In this article, we introduced the concept of stationarity and showed a simple application of ARIMA model to forecast economic variables with ARIMA model.  This comprehensive approach from data gathering, preprocessing, model building, to forecasting and evaluation exemplifies the intricate process of time series analysis using ARIMA models. It underscores the critical importance of understanding both the data and the underlying statistical methods for effective forecasting, particularly in areas as significant as economic indicators like unemployment rates.<\/p>\n\n\n\n<p class=\"has-text-align-center\"><a class=\"maxbutton-1 maxbutton maxbutton-subscribe-to-api external-css btn\" href=\"https:\/\/eodhd.com\/register\"><span class='mb-text'>Register &amp; Get Data<\/span><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Time series analysis is a fundamental component of statistical studies and forecasting in various fields such as economics, finance, environmental science, and many more. In this comprehensive guide, we will delve into an example of time series analysis and show how to forecast economic variables with ARIMA model. In this case, we will use the [&hellip;]<\/p>\n","protected":false},"author":22,"featured_media":4538,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[43,62],"tags":[],"coding-language":[30],"ready-to-go-solution":[56],"qualification":[31],"financial-apis-category":[36],"financial-apis-manuals":[39],"class_list":["post-4521","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-how-to-get-stocks-data-examples","category-stocks-price-prediction-examples","coding-language-python","ready-to-go-solution-eodhd-python-financial-library","qualification-experienced","financial-apis-category-stock-market-prices","financial-apis-manuals-end-of-day","has_thumb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.9 (Yoast SEO v26.7) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Forecast Economic Variables with ARIMA | EODHD APIs Academy<\/title>\n<meta name=\"description\" content=\"In this comprehensive guide, we will delve into an example of time series analysis and how to forecast economic variables with ARIMA model.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Forecast Economic Variables with ARIMA\" \/>\n<meta property=\"og:description\" content=\"In this comprehensive guide, we will delve into an example of time series analysis and how to forecast economic variables with ARIMA model.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima\" \/>\n<meta property=\"og:site_name\" content=\"Financial Academy\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/eodhistoricaldata\" \/>\n<meta property=\"article:published_time\" content=\"2024-01-09T20:44:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-05T11:18:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2024\/01\/result-arima.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1038\" \/>\n\t<meta property=\"og:image:height\" content=\"568\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Gianluca Baglini\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@EOD_data\" \/>\n<meta name=\"twitter:site\" content=\"@EOD_data\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Gianluca Baglini\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima#article\",\"isPartOf\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima\"},\"author\":{\"name\":\"Gianluca Baglini\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/6c95b0cef2acc2fbaebccff191d7027f\"},\"headline\":\"Forecast Economic Variables with ARIMA\",\"datePublished\":\"2024-01-09T20:44:18+00:00\",\"dateModified\":\"2025-02-05T11:18:10+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima\"},\"wordCount\":1169,\"publisher\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2024\/01\/result-arima.png\",\"articleSection\":[\"How to Get Stocks Data Examples\",\"Stocks Price Predictions Examples\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima\",\"name\":\"Forecast Economic Variables with ARIMA | EODHD APIs Academy\",\"isPartOf\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima#primaryimage\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima#primaryimage\"},\"thumbnailUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2024\/01\/result-arima.png\",\"datePublished\":\"2024-01-09T20:44:18+00:00\",\"dateModified\":\"2025-02-05T11:18:10+00:00\",\"description\":\"In this comprehensive guide, we will delve into an example of time series analysis and how to forecast economic variables with ARIMA model.\",\"breadcrumb\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima#primaryimage\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2024\/01\/result-arima.png\",\"contentUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2024\/01\/result-arima.png\",\"width\":1038,\"height\":568,\"caption\":\"arima-diagnostics\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/eodhd.com\/financial-academy\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Forecast Economic Variables with ARIMA\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#website\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/\",\"name\":\"Financial APIs Academy | EODHD\",\"description\":\"Financial Stock Market Academy\",\"publisher\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/eodhd.com\/financial-academy\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#organization\",\"name\":\"EODHD (EOD Historical Data)\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png\",\"contentUrl\":\"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png\",\"width\":159,\"height\":82,\"caption\":\"EODHD (EOD Historical Data)\"},\"image\":{\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/eodhistoricaldata\",\"https:\/\/x.com\/EOD_data\",\"https:\/\/www.reddit.com\/r\/EODHistoricalData\/\",\"https:\/\/eod-historical-data.medium.com\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/6c95b0cef2acc2fbaebccff191d7027f\",\"name\":\"Gianluca Baglini\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2a3c6038fdaa1636ec4863020f9191a4991c58f0935313853fd01a4b88bfbee9?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2a3c6038fdaa1636ec4863020f9191a4991c58f0935313853fd01a4b88bfbee9?s=96&d=mm&r=g\",\"caption\":\"Gianluca Baglini\"},\"description\":\"Financial &amp; Risk Analyst, Data Scientist, Python Developer, Owner of BagliniFinance blog\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/gianluca-baglini\/\"],\"url\":\"https:\/\/eodhd.com\/financial-academy\/author\/gianlucabaglini\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Forecast Economic Variables with ARIMA | EODHD APIs Academy","description":"In this comprehensive guide, we will delve into an example of time series analysis and how to forecast economic variables with ARIMA model.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima","og_locale":"en_US","og_type":"article","og_title":"Forecast Economic Variables with ARIMA","og_description":"In this comprehensive guide, we will delve into an example of time series analysis and how to forecast economic variables with ARIMA model.","og_url":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima","og_site_name":"Financial Academy","article_publisher":"https:\/\/www.facebook.com\/eodhistoricaldata","article_published_time":"2024-01-09T20:44:18+00:00","article_modified_time":"2025-02-05T11:18:10+00:00","og_image":[{"width":1038,"height":568,"url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2024\/01\/result-arima.png","type":"image\/png"}],"author":"Gianluca Baglini","twitter_card":"summary_large_image","twitter_creator":"@EOD_data","twitter_site":"@EOD_data","twitter_misc":{"Written by":"Gianluca Baglini","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima#article","isPartOf":{"@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima"},"author":{"name":"Gianluca Baglini","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/6c95b0cef2acc2fbaebccff191d7027f"},"headline":"Forecast Economic Variables with ARIMA","datePublished":"2024-01-09T20:44:18+00:00","dateModified":"2025-02-05T11:18:10+00:00","mainEntityOfPage":{"@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima"},"wordCount":1169,"publisher":{"@id":"https:\/\/eodhd.com\/financial-academy\/#organization"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima#primaryimage"},"thumbnailUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2024\/01\/result-arima.png","articleSection":["How to Get Stocks Data Examples","Stocks Price Predictions Examples"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima","url":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima","name":"Forecast Economic Variables with ARIMA | EODHD APIs Academy","isPartOf":{"@id":"https:\/\/eodhd.com\/financial-academy\/#website"},"primaryImageOfPage":{"@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima#primaryimage"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima#primaryimage"},"thumbnailUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2024\/01\/result-arima.png","datePublished":"2024-01-09T20:44:18+00:00","dateModified":"2025-02-05T11:18:10+00:00","description":"In this comprehensive guide, we will delve into an example of time series analysis and how to forecast economic variables with ARIMA model.","breadcrumb":{"@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima#primaryimage","url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2024\/01\/result-arima.png","contentUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2024\/01\/result-arima.png","width":1038,"height":568,"caption":"arima-diagnostics"},{"@type":"BreadcrumbList","@id":"https:\/\/eodhd.com\/financial-academy\/stocks-price-prediction-examples\/forecast-economic-variables-with-arima#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/eodhd.com\/financial-academy\/"},{"@type":"ListItem","position":2,"name":"Forecast Economic Variables with ARIMA"}]},{"@type":"WebSite","@id":"https:\/\/eodhd.com\/financial-academy\/#website","url":"https:\/\/eodhd.com\/financial-academy\/","name":"Financial APIs Academy | EODHD","description":"Financial Stock Market Academy","publisher":{"@id":"https:\/\/eodhd.com\/financial-academy\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/eodhd.com\/financial-academy\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/eodhd.com\/financial-academy\/#organization","name":"EODHD (EOD Historical Data)","url":"https:\/\/eodhd.com\/financial-academy\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/","url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png","contentUrl":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2023\/12\/EODHD-Logo.png","width":159,"height":82,"caption":"EODHD (EOD Historical Data)"},"image":{"@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/eodhistoricaldata","https:\/\/x.com\/EOD_data","https:\/\/www.reddit.com\/r\/EODHistoricalData\/","https:\/\/eod-historical-data.medium.com\/"]},{"@type":"Person","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/6c95b0cef2acc2fbaebccff191d7027f","name":"Gianluca Baglini","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/eodhd.com\/financial-academy\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2a3c6038fdaa1636ec4863020f9191a4991c58f0935313853fd01a4b88bfbee9?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2a3c6038fdaa1636ec4863020f9191a4991c58f0935313853fd01a4b88bfbee9?s=96&d=mm&r=g","caption":"Gianluca Baglini"},"description":"Financial &amp; Risk Analyst, Data Scientist, Python Developer, Owner of BagliniFinance blog","sameAs":["https:\/\/www.linkedin.com\/in\/gianluca-baglini\/"],"url":"https:\/\/eodhd.com\/financial-academy\/author\/gianlucabaglini"}]}},"jetpack_featured_media_url":"https:\/\/eodhd.com\/financial-academy\/wp-content\/uploads\/2024\/01\/result-arima.png","jetpack_shortlink":"https:\/\/wp.me\/pdOdVT-1aV","jetpack_sharing_enabled":true,"acf":[],"_links":{"self":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/4521","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/comments?post=4521"}],"version-history":[{"count":16,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/4521\/revisions"}],"predecessor-version":[{"id":6221,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/posts\/4521\/revisions\/6221"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/media\/4538"}],"wp:attachment":[{"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/media?parent=4521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/categories?post=4521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/tags?post=4521"},{"taxonomy":"coding-language","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/coding-language?post=4521"},{"taxonomy":"ready-to-go-solution","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/ready-to-go-solution?post=4521"},{"taxonomy":"qualification","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/qualification?post=4521"},{"taxonomy":"financial-apis-category","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/financial-apis-category?post=4521"},{"taxonomy":"financial-apis-manuals","embeddable":true,"href":"https:\/\/eodhd.com\/financial-academy\/wp-json\/wp\/v2\/financial-apis-manuals?post=4521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}