Home > other >  Discounting Old Time Series Values, Exponential Smoothing
Discounting Old Time Series Values, Exponential Smoothing

Time:03-09

I would like to build a time series from another time series, discounting older values. That is, the most recent value is included in the sum normally, and the previous value is discounted with delta^t. Then a new value is added, which is again normally included in the new time series, the older values are then discounted with delta^t and delta^(t-k). The whole thing should look like this:

Data: df<- c(0.4387738, 0.05203873, 0.3238407, 0.1117364)

> test[[1]][["se_ne"]][[1]] 
[1] 0.4387738
> 
> test[[2]][["se_ne"]][[2]]   0.4^(2-1)*test[[2]][["se_ne"]][[2-1]] 
[1] 0.2275482
> 
> test[[3]][["se_ne"]][[3]]   0.4^(3-2)*test[[3]][["se_ne"]][[3-1]]   0.4^(3-1)*test[[3]][["se_ne"]][[3-2]] 
[1] 0.41486

But the dataset has over 700 observations, is there a smarter solution than calculating everything by hand?

Thanks for the feedback!

CodePudding user response:

Perhaps this SO answer might help you:

Exponential smoothing method

If it does not, then a good next step would be to explain the differences between that post and your question.

CodePudding user response:

Thanks for your answer! I tried something like this, but unfortunately I still have not the right answer.

#Calculate DSE
test <- lapply(seq(1,nrow(pred_ne)), function(x) 
 data = pred_ne[1:x , ])

#test[[1]][["se_ne"]][[1]]

#test[[2]][["se_ne"]][[2]]   0.4^(2-1)*test[[2]][["se_ne"]][[2-1]]

#test[[3]][["se_ne"]][[3]]   0.4^(3-2)*test[[3]][["se_ne"]][[3-1]]   0.4^(3-1)*test[[3]][["se_ne"]][[3-2]] 

#test[[4]][["se_ne"]][[4]]   0.4^(4-3)*test[[4]][["se_ne"]][[4-1]]   0.4^(4-2)*test[[4]][["se_ne"]][[4-2]]   0.4^(4-1)*test[[4]][["se_ne"]][[4-3]] 


#pred_ne$se_ne[[1]]

datalist = list()

for (i in 2:length(test)) {
  dat <- sapply(1:5, function(k) sum(0.4^(k-(1 1))*pred_ne$se_ne[[k]]))
  datalist[[i]] <- dat # add it to your list
}

I think one solution would be to sum k to K previous periods so that the k periods before are increasingly discounted. Would the sum of k to K then be a solution?

CodePudding user response:

I tried something again, but I still don't get it. Maybe someone has some ideas?

test <- lapply(seq(1,nrow(pred_ne)), function(x) 
 data = pred_ne[1:x , ])

0.4^(1-1)*test[[1]][["se_ne"]][[1]]

0.4^(2-2)*test[[2]][["se_ne"]][[2]]   0.4^(2-1)*test[[2]][["se_ne"]][[2-1]]

0.4^(3-3)*test[[3]][["se_ne"]][[3]]   0.4^(3-2)*test[[3]][["se_ne"]][[3-1]]   0.4^(3-1)*test[[3]][["se_ne"]][[3-2]] 

0.4^(4-4)*test[[4]][["se_ne"]][[4]]   0.4^(4-3)*test[[4]][["se_ne"]][[4-1]]   0.4^(4-2)*test[[4]][["se_ne"]][[4-2]]   0.4^(4-1)*test[[4]][["se_ne"]][[4-3]] 


datalist = list()
delta = 0.4


list = list()

for (t in 1:length(test)) {
  for (k in 1:nrow(test[[t]])) {
   sum(delta^(k)*(test[[t]][["se_ne"]][[t]]))
  
  }
}
  • Related