futuretest <- function(prices,a.head,port1,data.length){
set.seed(111)
data <- apply(prices,2,PriceToReturn)
library(boot)
if( is.vector(data) == FALSE && dim(data)[1]> data.length){
data.tmp <- data[(dim(data)[1]-data.length):dim(data)[1],]
data <- data.tmp
}
#Run tsboot on any series using the selected block size
R <- 200 # scenario
l <- 20 # block size
#n.sim <- 52*5 # length of scenario path
n.sim <- a.head
# perform block bootstrapping
bootstrap <- tsboot(data,mean,R=R,l=l, n.sim=n.sim,sim="fixed")
ba <- boot.array(bootstrap)
#Use index from bootstrap output to reconstruct multivariate time series
port.scen <- array(0, dim=c(R,n.sim))
for(i in 1:R){
port.scen[i,] <- cumprod(apply(unlist(port1)*data[ba[i,],names(port1)],1,sum)+1)
}
#apply(unlist(port1) * data[ba[i,],names(port1)],1,sum)
quantiles <- cbind(c(0,0,0,0,0),apply(port.scen,2,quantile,probs=c(.05,0.25,0.5,0.75,0.95))-1)*100
# out <- list()
# out[[1]] <- quantiles
# out[[2]] <- port.scen
return(quantiles)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.