# [R-SIG-Finance] help (regarding block bootstrap)

Brian G. Peterson brian at braverock.com
Tue Mar 17 13:25:30 CET 2009

```Yana Roth wrote:
> Hello,
> I am trying to do block reasampling to rearrange my data and not succeed to do random permutation and assugnement.
> I would like to divide original time series to subsamples and then to rearange this subsamples randomly.
>
> Function tsboot works only if I need to check statistic, I am interested in just rearranging the data while keeping its structure.
>
> The problem is defined as follows.
> 1. I define llentgh of block , b.
> 2.Divide an original time series by b and receive k=n/b subsamles.
> 3. I need to generate random vector of integers from 1 to k
> 4 Let Z*(j) be for j=1....k be the j th row of a matrix with num of rows equal to number of blocks and number of columns equal to number of simulations.
> 5. Assigne to each Z*(j) the blocks according to generated random vector(each column of matrix is a different order of permutations)
For future reference, please provide reproducible code as per the posting guidelines.  It makes it easier for others to help you.  Also, please use a desciptive subject, as we all get a quite a lot of mail.

Your procedure appears incorrect.

Your steps 3-5 look like a homework assignment, so I'm going to ignore those and focus on the block bootstrap, which has some applicability to other members of this list in financial time series analysis.

I suspect that you simply misunderstood the "statistic" parameter of tsboot().  I expect that you do indeed intend to use the bootstrapped data to calculate one or more statstics, this is what the statistic parameter is for.

Block bootstrapping works by randomly sampling blocks of length l from your original series.  The tsboot function also applies one or more statistics to the bootstrapped data, and uses the multiple samples to calculate the bias and standard error for those statistics, providing you with a sensitivity analysis for those statistics on your data.

Using the data series "acme" included with R, you would do something like:

library(boot)
library(PerformanceAnalytics)
data(acme)

#calculate the sensitivity of standard deviation on the data:
tsboot(tseries=acme[,2],statistic=sd,R=1000,l=12,sim="fixed",endcorr=FALSE,n.sim=1000)
# use blocks of length 12 (one year) to
# create 1000 bootstrapped time series
# each of length 1000 observations

#Returns:
#Bootstrap Statistics :
#      original       bias    std. error
#t1* 0.05362889 0.0001614213 0.001925484

# calculate sensitivity of VaR:
tsboot(tseries=acme[,2],statistic=VaR.CornishFisher,R=1000,sim="fixed",l=12,endcorr=FALSE,n.sim=1000)

#Returns:
#Bootstrap Statistics :
#    original      bias    std. error
#t1* 0.227064 0.009412978 0.007284343

Normally, this is what you want.  The random bootstrapped series itself is not useful to you, except to calculate a statistic or statistics of interest, and understand their sensitivity.  If you want the bootstrapped series returned, you can modify the code of the tsboot function to do what you want.

If you want to apply your steps 3-5 to the bootstrapped data, see the documentation of tsboot() for an example of defining a function to use as the statistic parameter.

Regards,

- Brian

--
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock

```