database,postgresql,function,timestamp,volatility

The key word IMMUTABLE is never added automatically by pgAdmin or Postgres. Who ever created or replaced the function did that. The correct function volatility (read the manual) setting for the given function is VOLATILE, not STABLE - or it wouldn't make sense to use clock_timestamp() which is VOLATILE as...

You can avoid this loop with some matrix algebra. Let's assume the raw data is a vector (a_1, a_2, a_3, ..., a_n) and we want to create the EWMA variance (x_1, x_2, x_3, ..., x_n) according to your definition. Let d be the decay factor. If i understood your code...

You can efficiently calculate it by sum(x*x)-x*x #dummy data x <- rnorm(1000) #vectorized f1 <- function(x) sum(x*x)-x*x #for loop f2 <- function(x){ n <- length(x) rv <- rep(NA, n) s <- x*x for(i in 1:n) {rv[i]=sum(s[-i])} rv } rbenchmark::benchmark(f1(x), f2(x))[1:3] test replications elapsed 1 f1(x) 100 0.0 2 f2(x) 100...

matlab,for-loop,return,time-series,volatility

I think you are a bit confused about how matrix indexing works in Matlab. If understood correctly, you have a variable TR_t with which you want to store the value for time t. You then try to do the following: TR_t = TR_{t-1} * exp(R_t); I will try to explain...