Publishedpaper Bayesian 4
Publishedpaper Bayesian 4
Publishedpaper Bayesian 4
net/publication/343054057
CITATIONS READS
6 3,580
2 authors:
All content following this page was uploaded by Khushnoor Khan on 19 July 2020.
The current study focused on modeling times series using Bayesian Structural Time Series tech-
nique (BSTS) on a univariate data-set. Real-life secondary data from stock prices for flying cement
covering a period of one year was used for analysis. Statistical results were based on simulation
procedures using Kalman filter and Monte Carlo Markov Chain (MCMC). Though the current study
involved stock prices data, the same approach can be applied to complex engineering process
involving lead times. Results from the current study were compared with classical Autoregressive
Integrated Moving Average (ARIMA) technique. For working out the Bayesian posterior sampling
distributions BSTS package run with R software was used. Four BSTS models were used on a
real data set to demonstrate the working of BSTS technique. The predictive accuracy for competing
models was assessed using Forecasts plots and Mean Absolute Percent Error (MAPE). An easy-
to-follow approach was adopted so that both academicians and practitioners can easily replicate
the mechanism. Findings from the study revealed that, for short-term forecasting, both ARIMA and
BSTS are equally good but for long term forecasting, BSTS with local level is the most plausible
option.
Keywords: Bayesian, Time Series, Structural, ARIMA, State-Space, Prior, Posterior.
linear, on a real data set at the same time on a single data The ARIMA (p1 d1 q) models are based upon choice of
set. Hence, current study will be the first study to study optimum values of p and q. ARIMA (p1 d1 q) models are
the effect of four BSTS models, apart from ARIMA tech-
useful in modeling mean of a process given that the vari-
nique, in forecasting stock returns of a real data set.
ance is constant.
Present study will focus on the application of four mod-
Abbasi et al. [17] dealt with ARIMA analysis of the
els of BSTS on stock prices of flying cement and it also
data under study and Almarashi et al. [18] studied in detail
compares the results will classical ARIMA model. Easy-
the GARCH modelling of the data. Reference [17] used
to-follow approach involving less mathematical hassle is
secondary data stock prices data from Ref. [19] with time
demonstrated so that the practitioners can easily apply the
starting from 1st January 2016 to 30th January 2017. For
model in diversified fields of study.
model estimation and for model validation, the data set
was split into two parts for performing the proposed mod-
1.1. Format of the Paper els (from 1st January 2016–31st December 2016 known
The format of the current study is as follows: Section 2 as the in-sample) and for cross validation (from 1st Jan-
introduces the competing techniques for forecasting— uary 2017–20th January 2017 known as out-of-sample).
ARIMA and Structural time series and Bayesian frame- Predicted values and the value of MAPE for the ARIMA
work on structural time series coupled with relevant (1,2,1) model on the secondary data from Ref. [18] exhib-
equations to be used to derive the results in the present ited in Table I.
context. Also, the criteria for comparison of competing ARIMA is a theoretical approach to forecasting time
models is explained in the same section: Section 3 pro- series i.e., there are no a priori expectations (lack of the-
duces and explains the results obtained through the use oretical underpinnings) in the case of ARIMA modelling.
of appropriate statistical tools: Section 4 deals with two The value of MAPE points to the fact that ARIMA (1,2,1)
different ways by which to compare the outcome of the predicts the well but the model is unable to theorize the
competing models and Section 5 concludes the present time series itself. All one can know is that the ARIMA
study. model fits well using a combination of AR, lagged and
MA terms.
2. METHODS Figure 1 displays the Forecasted values along with orig-
2.1. ARIMA inal data the light grey area depicts the 95% confidence
The procedure, for fitting ARIMA approach, developed by interval and slightly dark grey area is the 80% confidence
Mokilane et al. [1], on a stationed data, is summarized as
follows: Table I. Cross validation of ARIMA model for one-month.
• Constructing correlograms and working out the p and
MM/DD/YY Original Ln (Original) Predicted Ln (Predicted)
q terms-PACF will indicate AR (p) terms and ACF will
show MA (q) terms. 01/02/17 15.00 2.71 15.05 2.71
• Fitting the model with terms worked out in step 1. 01/03/17 15.26 2.72 15.10 2.71
• Finding the residual and performing diagnostic tests. If 01/04/17 14.95 2.70 15.32 2.73
01/05/17 14.50 2.67 15.10 2.72
the residuals are IID (independently and identically dis- 01/06/17 14.35 2.66 14.66 2.68
tributed), then the fitted model will be considered suitable. 01/09/17 14.44 2.67 14.46 2.67
Otherwise the same process with other AR and MA terms 01/10/17 14.40 2.67 14.50 2.67
should be repeated. 01/11/17 14.40 2.67 14.49 2.67
• Application of the model for forecasting purposes and 01/12/17 14.33 2.66 14.48 2.67
01/13/17 14.14 2.65 14.42 2.67
comparing different forecasting models using some infor-
01/16/17 14.45 2.67 14.24 2.66
mation criteria—AIC, SBC, BICC. 01/17/17 14.20 2.65 14.47 2.67
01/18/17 14.25 2.66 14.31 2.66
The ARIMA (p, d, q) models are useful in modelling a
01/19/17 14.54 2.68 14.31 2.66
short-memory process and is specified as follows: 01/20/17 14.30 2.66 14.56 2.68
MAPE 1.214%
4B p 541 − B5d 4Yt − xt/ 5 = 4B q 5t (1)
made of. For instance, one may study the classical decom- 2.4.5. Semi-Local Linear Trend Model
position where a time series is the addition or multiplica- Though the local linear trend and semi-local linear trend is
tion of four components namely-trend, season, cycle and somewhat similar, the latter is more useful for long-term
regression [22] depending on the pattern as exhibited in forecasting. It assumes that the level component moves
the time series plot. according to a random walk, but the slope component
moves according to an AR(1) process centered on a poten-
2.4.2. Local Level Model tially nonzero value D. The equation for the level is:
Local level model is the simplest Structural times series
t+1 = t + t + t t ∼N 401 2 5 (11)
model. Local level assumes the trend is a random walk:
2
The equation for the slope is:
yt = t + t t ∼N 401 5 (4)
t+1 = t + t t ∼N 401 2 5 (5) t+1 = D + 4t D5 + t t ∼N 401 2 5 (12)
yt = t + t + 2 2.6. Data/Analysis
t t ∼N 401 5 (9)
For the proposed BSTS technique, secondary data consist-
1
ing of 260 days of stock prices for Flying Cement col-
t ∼N 401 2 5
X
yt+1 = I 1t1 i + t (10)
i=2
lected by Ref. [17] is used. For extracting empirical results
R package (BSTS) written and developed by Ref. [9] is
and the remaining elements are shifted down one. When employed. As a first step model fitting for Flying cement
t is any other day then t+1 =. If the local, trend stock returns data by using local, local linear, seasonal
and seasonal components are used simultaneously, then (monthly) and Semi-local linear trend will be carried out.
there are four parameters i.e., four error variance terms In the second step, posterior distributions of our model
(↓ ↑ 21 ↓ ↑ 21 ↓ ↑ 2). time series will be generated and will be displayed through
ARIMA 2.52–2.89 2
Local level 2.51–2.86 1
Local linear level 2.32–3.20 4
Monthly seasonal level 2.25–3.25 5
Semi-local linear level 2.51–2.90 3
3. RESULTS
The data for the study behaved as displayed in Figure 2.
The upper panel shows the original times series for the
stock returns [log (stock prices)] varying from 1.0 to 2.8.
The lower panel of Figure 2 displays the monthly season-
ality this aspect was in fact overlooked by the previous
authors while using ARIMA model. We begin with sim-
ple BSTS model like local level and gradually increased
the complexity by incrementing local linear trend monthly
seasonal trend and Semi-local linear trend.
Fig. 3. Showing expectation of posteriors and forecasts along with original data for local level model.
Fig. 4. Expectation of posteriors and forecasts along with original data for local linear model.
By looking at the plots shown in Figures 3–6, it seems 3.2. Comparison Among Competing
like all four models fitted the data well and seemed little Models (Diagnostics)
difficult to differentiate among the competing models. In Original stock returns are shown in the lower panel
order to overcome this difficulty, the predictive accuracy and cumulative absolute errors are in the upper panel
for the competing models is evaluated using (a) a com- of Figure 7. The last points of the lines in the top
bined graph of four models using cumulative predictive panel indicate the proportion of the mean absolute pre-
errors (b) computing and comparing the MAPE of com- diction error for the competing models. Here again it
peting models. was witnessed that Local Level and Semi-local Linear
Fig. 5. Expectation of posteriors and forecasts along with original data for monthly seasonal model.
Fig. 6. Expectation of posteriors and forecasts along with original data for semi-local linear model.
16. Peters, G.P., Weber, C.L., Guan, D. and Hubacek, K., 2007. China’s 19. Flying Cement Limited Stock Prices Data,
growing CO2 emissions a race between increasing consumption and (https://pkfinance.info/kse/stock/FLYNG).
efficiency gains. Environmental Science & Technology, 41, pp.5939– 20. Joao, T.J., 2009. Structural time series models and the Kalman filter:
5944. A concise review. FEUNL Working Paper Series. Universidade Nova
17. Abbasi, U., Almarashi, A.M., Khan, K. and Hanif, S., 2017. Fore- de Lisboa, Faculdade de Economia.
casting cement stock prices using ARIMA model: A case study of 21. Kalman, R., 1960. A new approach to linear filtering and prediction
flying cement. Science International, 29(5), pp.1039–1043. problems. Journal of Basic Engineering, 82, pp.94–135.
18. Almarashi, A.M., Abbasi, U., Saman, H., Alzahrani, M.R. and 22. Steven, L.S., 2017. Fitting Bayesian Structural Time Series
Khushnoor, K., 2018. Modeling volatility in stock prices using with the BSTS R package. (http://www.unofficialgoogledatascience.
ARCH/GARCH. Science International, 30(1), pp.89–94. com/2017/07/fitting-bayesian-structural-time-series.html).