# Modelling promotions for demand forecasting

I am trying to develop a model to predict future demand for a product. Now, there are always some promotional events that affect the sales. I am trying to solve this problem using dummy variables. Here's how:

Supposing that the firm runs 7 promotional events on a particular product. So, I construct 7 dummy variables, that are boolean. For supposing that a for a particular week, promotion 3 was running. So, my training data-point becomes [0,0,1,0,0,0,0] and the corresponding sales. I construct a linear regression model for promotions in this way.

Now, here is my problem. When we model seasonality using this method, we construct a base linear model, after deseasonalising the data, and then use the two models to predict the final output. In case of promotions, how do I 'depromotionalise' the data?

Any tips in solving the problem are appreciated. Thanks!

To create dummy variables for days promotion holidays, you might find this example useful.

If you are sure you do not have an out-of-stock problem anytime in the history you could use an autoregressive model to predict future sales (demand) for any product that has historical data. Depending on your data you could choose a model. Following code is an example which combines four different models by giving different weight to different models. This type of models capture seasonality and trends of your data. For more details about the models please check Rob Hyndman's forecast package documentation.

choose_model<-function(x,h,reg,new_reg,end_train,start_test){
library(forecast)
library(tidyverse)

#train data

x_train <- window(x, end = end_train )

x_test <- window(x, start = start_test)

#train and test for regressors

reg_train <- window(reg, end = end_train )

reg_test <- window(reg, start = start_test)

h1=length(x_test)

#model1

stlf(x_train , method="arima",s.window= nrow(x_train),xreg = reg_train, newxreg = reg_test, h=h1)-> fc_stlf_xreg

#model2
auto.arima(x_train, stepwise = FALSE, approximation = FALSE,xreg=reg_train)%>%forecast(h=h1,xreg=reg_test) -> fc_arima_xreg

#model3
set.seed(12345)#for nnetar model
nnetar(x_train, MaxNWts=nrow(x), xreg=reg_train)%>%forecast(h=h1, xreg=reg_test) -> fc_nnetar_xreg

#model4
stlf(x_train , method= "ets",s.window= 12, h=h1)-> fc_stlf_ets

#Combination

mod1 <- lm(x_test ~ 0 + fc_stlf_xreg$mean + fc_arima_xreg$mean + fc_nnetar_xreg$mean + fc_stlf_ets$mean)
mod2 <- lm(x_test/I(sum(coef(mod1))) ~ 0 + fc_stlf_xreg$mean + fc_arima_xreg$mean + fc_nnetar_xreg$mean + fc_stlf_ets$mean)

#model1

stlf(x, method="arima",s.window= 12,xreg=reg, newxreg=new_reg, h=h)-> fc_stlf

#model2
auto.arima(x, stepwise = FALSE, approximation = FALSE,xreg=reg)%>%forecast(h=h,xreg=new_reg) -> fc_arima

#model3
set.seed(12345)#for nnetar model
nnetar(x, MaxNWts=nrow(x), xreg=reg)%>%forecast(h=h, xreg=new_reg) -> fc_nnetar

#model4
stlf(x , method= "ets",s.window= 12, h=h)-> fc_stlf_e

#Combination

Combi <- (mod2$coefficients[[1]]*fc_stlf$mean + mod2$coefficients[[2]]*fc_arima$mean +
mod2$coefficients[[3]]*fc_nnetar$mean + mod2$coefficients[[4]]*fc_stlf_e$mean)

return(Combi)
}


The usage of the function:

coose_model(x,h,reg,new_reg,c(2018,02),c(2018,3))


$x$ is a time series

$h$ is time horizon to predict

$reg$ is the historical promotions, dummy date variables, holidays...

$new_ reg$ is the promotions, dummy date variables, holidays that are that you know it is going to happen

If you know that there is out-of-stock problem then take a look to this paper.