I am struggling to write fast code to compute a function of the following vector:
Currently I code it using for loop, which is very slow:
rho <- 0.9
E_D <- numeric(100)
E_D[1] <- 1
for (t in 2:100){
summm <- sum(cumsum(0.9^(0:(t-2)))^2)
E_D[t] <- t+exp(summm)
}
summm is the element of the vector I analytically defined in the picture above. E_D is a vector, which is some function of that vector. If I set maximum t to 5000, then the code above runs for more than 1 sec on my machine, which is too slow for my purposes.
I tried data.table solution, but it can not accommodate intermediate vector output within a cell:
tempdt <- data.table(prd=2:100 ,summm=0)
tempdt[, summm:=sum(cumsum(rho^(0:(prd-2)))^2)]
Warning message:
In 0:(prd - 2) : numerical expression has 99 elements: only the first used
How to make the code above faster? Please do not tell me that I have to do it in Matlab...
EDIT: To clarify, I need to compute the following vector:

