Hi everyone,
I would like to conduct the so called stationary bootstrap in a SingleIndex 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.
Stationary Bootstrap with variable block size
Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

 Posts: 50
 Joined: Sat Oct 20, 2012 7:30 am

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12291
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Stationary Bootstrap with variable block size
There is nothing built in to do it, but it should not be particularly difficult to program yourself, I think.
Follow us on Twitter @IHSEViews

 Posts: 50
 Joined: Sat Oct 20, 2012 7:30 am
Re: Stationary Bootstrap with variable block size
Hi Gareth,
Thanks for your answer. That's what I thought as well.
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.
Thanks for your answer. That's what I thought as well.
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.

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12291
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Stationary Bootstrap with variable block size
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 2000
series x=@trend
series xrs
!p = 0.5
smpl 1991 @last
call 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+!first1)
!val = @elem(in, %date)
temp(!i) = !val
!getnew = @rnd>!prob
next
'convert vector to series
mtos(temp, out)
endsub
Follow us on Twitter @IHSEViews

 Posts: 50
 Joined: Sat Oct 20, 2012 7:30 am
Re: Stationary Bootstrap with variable block size
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.
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 2000
series returns=@nrnd 'Input series 1
series returns_res 'Output series 1, data from input series 1 will be resampled into this series
smpl 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 Blocks
endsub
subroutine GeometricCounter()
'Simulates one single BlockLength. The BlockLength is determined by the number of trials, until for the first time a random (01) number drops below the value p.
!intCounter=1
while @rnd>!p
!intCounter=!intCounter+1
wend
!BlockLength=!intCounter
endsub
subroutine 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
next
endsub
subroutine StartPoint()
'Defines StartingPoint by drawing an integer number between 1 and number of observations
!StartPoint=@floor(@runif(!first,!first+!NoObs))
endsub
subroutine 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 !first1+!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(!i1)+Blocks(!i1)
next
endsub
subroutine 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+!NoObs1 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
Hi Eviews Gareth
Trust all is well. I Believe I understand how you have set up your code, but I have a few questions.
'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 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?
Thanks in advance
Fred
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
Apart from when !getnew or !ob =the number of observations(!n), when does
Code: Select all
if !getnew or !ob = !n
Wouldn't this imply the !ob=!ob+1 (block bootstrap) would be the outcome the majority of the time?
Thanks in advance
Fred

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12291
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Stationary Bootstrap with variable block size
Not entirely sure I follow your question.
!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).
!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).
Follow us on Twitter @IHSEViews
Re: Stationary Bootstrap with variable block size
Hi Gareth
Thanks for the prompt reply.
OK this makes sense the code reads !getnew OR !ob=!n
Would "if !getnew=1 or !ob=!n" make sense, i.e qualifying that !getnow would need to equal 1?
Thanks
Fred
Thanks for the prompt reply.
OK this makes sense the code reads !getnew OR !ob=!n
Would "if !getnew=1 or !ob=!n" make sense, i.e qualifying that !getnow would need to equal 1?
Thanks
Fred

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12291
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Stationary Bootstrap with variable block size
That would do the same thing, yes
Follow us on Twitter @IHSEViews
Who is online
Users browsing this forum: Majestic12 [Bot] and 2 guests