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.