Page 1 of 1

### Stationary Bootstrap with variable block size

Posted: Fri Aug 23, 2013 6:35 am
Hi everyone,

I would like to conduct the so called stationary bootstrap in a Single-Index model. The stationary bootstrap is a method which goes back to Politis/Romano (1994). It is applicable if overlapping data are to be analyzed. The process of stationary bootstrapping is not trivial and needs a bit of explanation. The most important aspect though is the variable block length. The length of a block is determined by a geometric distribution with probability p. I have only seen the option to set the block size in the procedure of a series to a fixed length. Is there any way to manipulate the block size in a way that allows for variable length?

Thanks in advance for help and suggestions.

### Re: Stationary Bootstrap with variable block size

Posted: Fri Aug 23, 2013 7:48 am
There is nothing built in to do it, but it should not be particularly difficult to program yourself, I think.

### Re: Stationary Bootstrap with variable block size

Posted: Fri Aug 23, 2013 8:37 am
Hi Gareth,

I would like to actually start programming the stationary bootstrap, and so maybe you could move this whole question to the programming section of the forum, where it will probably fit better than here.

I will write again, once I have an idea for programming the procedure.

### Re: Stationary Bootstrap with variable block size

Posted: Fri Aug 23, 2013 10:10 am
Here's my very quick pass at it. I haven't robustly checked that it a) works, or b) matches the theory correctly.

Code: Select all

`create d5 1990 2000series x=@trendseries xrs!p = 0.5smpl 1991 @lastcall PolitisRomano(x, xrs, !p)subroutine local PolitisRomano(series in, series out, scalar !prob)   !n = @obssmpl      vector(!n) temp  'vector that will hold the resampled values      %first = @otods(1) 'date of first observation in current sample   !first = @dtoo(%first) 'observation number of first observation in current sample      !getnew = 1    'do we draw a new one, or do we get the next value?  First time through we definitely get a new one.   !ob = 1  'declaration      'do the draws   for !i=1 to !n      if !getnew or !ob = !n then   'if we're getting a new value, then !ob is equal to a random integer         !ob = @floor(@rnd*!n)      else          !ob = !ob + 1      endif      %date = @otod(!ob+!first-1)      !val = @elem(in, %date)      temp(!i) = !val      !getnew = @rnd>!prob   next      'convert vector to series   mtos(temp, out)endsub`

### Re: Stationary Bootstrap with variable block size

Posted: Sat Aug 24, 2013 6:46 am
Hi Gareth,

Thanks for your answer. I couldn't completely follow your code, that's why I wrote my own. But it does include some of your ideas, so thanks for that. Let me know what you think.

Code: Select all

`create d5 1950 2000series returns=@nrnd   'Input series 1series returns_res      'Output series 1, data from input series 1 will be resampled into this seriessmpl 1951 1999!NoObs=@obssmpl%first = @otods(1) 'date of first observation in current sample!first = @dtoo(%first) 'observation number of first observation in current sample!p=!NoObs^(-1/3) 'Probability for geometric distribution, can be altered, but is at optimum size at p=n^(-1/3)'Necessary work to prepare for resampling procedure   call WriteBlocks 'Creates a vector of Blocks of variable length   call WriteStarts 'Creates a vector of variable starting points. These starting points define from where return data will be extracted.   call WriteStartsResample 'Creates a vector of starting points where the resampled data will get stored at'Resampling procedure      call StationaryBootstrap 'Executes procedure of stationary bootstrap   'Start of subroutine section ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------subroutine WriteBlocks()'Writes a vector of simulated BlockLengths. The size of the vector is determined by the number of Blocks for which the sum of their respective BlockLenghts reaches the number of observations.      vector (!NoObs) Blocks 'Assigns a size for the vector, which will later be trimmed.   !i=0 'Declaration      while @sum(Blocks)<!NoObs 'Do while until sum of BlockLengths exceeds number of observations         call GeometricCounter 'Simulates one specific BlockLength         !i=!i+1         Blocks(!i)=!BlockLength 'Writes simulated BlockLength into vector Blocks         wend      Blocks(!i)=Blocks(!i)-(@sum(Blocks)-!NoObs) 'Reduces the last BlockLength to a length that will allow the sum of BlockLengths in vector Block to be exactly equal the number of observations.   vector(!i)Blocks 'Trims off all zeros following the last entry of a BlockLength in the vector Blocksendsubsubroutine GeometricCounter()'Simulates one single BlockLength. The BlockLength is determined by the number of trials, until for the first time a random (0-1) number drops below the value p.          !intCounter=1         while @rnd>!p      !intCounter=!intCounter+1   wend      !BlockLength=!intCounter   endsubsubroutine WriteStarts()' Writes random number of StartingPoints into vector called StartingPoints      'Determine number of necessary starting points; is equal to number of Blocks      !NoParam=@obs(Blocks)   'Create vector with length of that number and call it StartingPoints      vector(!NoParam) StartingPoints      ' Write starting points into vector            for !i=1 to !NoParam            call StartPoint 'Simulates one specific StartingPoint            StartingPoints(!i)=!StartPoint 'Writes StartingPoint into vector StartingPoints at position !i      nextendsubsubroutine StartPoint()'Defines StartingPoint by drawing an integer number between 1 and number of observations      !StartPoint=@floor(@runif(!first,!first+!NoObs))   endsubsubroutine WriteStartsResample()'Defines the Starting Points for the new series containing the resamples in dependence of BlockLengths      'Create vector to store starting points in      vector(!NoParam) StartingPointsResample   'Write starting points into vector, first starting point is 1   '      for !i=!first+1 to !first-1+!NoParam'         StartingPointsResample(1)=!first'         StartingPointsResample(!i-!first+1)=StartingPointsResample(!i-!first)+Blocks(!i-!first)'   next      for !i=2 to !NoParam         StartingPointsResample(1)=!first         StartingPointsResample(!i)=StartingPointsResample(!i-1)+Blocks(!i-1)      nextendsubsubroutine StationaryBootstrap()'Executes the procedure of the stationary bootstrap method.'Line1: Procedure needs to be executed as many times as there are parameters, i.e. = no. of blocks = no. of starting points 'Line2: Loops until length of a block is reached'Line3: If row index of input series does not exceed the maximum row index of entire sample, then Line4, else Line5'Line4: Writes resamples into outputseries'Line5: Will be executed only, if row index of input series exceeds the maximum row index of entire sample. If so, the resampling will continue at first observation in sample of input series (wrapping the tail to the head)            for !i=1 to !NoParam 'Line1         for !j=0 to blocks(!i)-1 'Line2            if returns(startingpoints(!i)+!j)<=!first+!NoObs-1 then 'Line3               returns_res(startingpointsresample(!i)+!j)=returns(startingpoints(!i)+!j)'Line4            else               returns_res(startingpointsresample(!i)+!j)=returns(startingpoints(!i)+!j-!NoObs)'Line5            endif         next      next      endsub`

### Re: Stationary Bootstrap with variable block size

Posted: Tue Jul 21, 2015 4:50 pm
Hi Eviews Gareth
Trust all is well. I Believe I understand how you have set up your code, but I have a few questions.

Code: Select all

`!getnew = @rnd>!prob`
-'generates a binary outcome, which then feeds into the top of the loop.

Apart from when !getnew or !ob =the number of observations(!n), when does

Code: Select all

`if !getnew or !ob = !n`
occur if !getnew can only be a 1 or 0 after each iteration?

Wouldn't this imply the !ob=!ob+1 (block bootstrap) would be the outcome the majority of the time?

Fred

### Re: Stationary Bootstrap with variable block size

Posted: Tue Jul 21, 2015 9:03 pm

!ob=!n is only to protect against running off the end of the sample, so we can ignore that condition.

Then we're just saying we draw a new number only if !getnew=1 (i.e. if @rnd>!prob).

### Re: Stationary Bootstrap with variable block size

Posted: Wed Jul 22, 2015 12:56 am
Hi Gareth