Re: garchmvbootstrap.rpf
Posted: Fri Jan 23, 2026 9:02 am
A Forum for RATS Software and Econometrics Discussions
https://estima.com/forum/
As an exampleTomDoan wrote: ↑Fri Jan 23, 2026 11:29 am In viewtopic.php?p=19882#p19882, I describe a valid test for PoF in overlapping samples. If you aren't satisfied with the Wald test based on QMLE asymptotics, you can block bootstrap the exceedance data and get a bootstrapped distribution for the alphahat. (You don't have to do anything fancy to estimate alphahat since the point estimate is just the fraction of exceedances in each bootstrapped replication).
I can block bootstrap trigger within a loop, ndraws times, and calculate the means. That's straightforward.
Yes, the mean across bootstrap samples is approximately the same as the mean of the data.
I've plotted alphahatDist.
I don't know how to proceed?TomDoan wrote: ↑Sat Jan 24, 2026 11:06 am So you want to count the percentage of times the bootstrapped sample has an alphahat that is on the other side of alpha. (A two-sided test is not easy to construct in this situation). The closest example is bootsimple.rpf (which actually does generate a two-sided test, but that's when doing a sample mean, which symmetrizes more easily than a binomial).
Code: Select all
procedure acAlphaBlockBoot trigger start end
type series trigger
type integer start end
local integer startl endl
local integer draw N
local real alphahatStar
local series alphahatDist
local series boottrigger
local series[integer] bootentries
option real alpha 0.01
option integer horizon 1
option integer ndraws 10000
* Sample range
inquire(reglist) startl<<start endl<<end
# trigger
* Compute observed violation rate
sstats(mean) startl endl trigger>>%%alphahatObs
compute N = %nobs
* Create series to store bootstrap results
set alphahatDist 1 ndraws = 0.0
* Bootstrap loop
do draw = 1, ndraws
* Generate bootstrap block indices from the actual data range
BOOT(block=horizon) bootentries startl endl startl endl
* Resample the ACTUAL trigger series using those indices
set boottrigger startl endl = trigger(bootentries(t))
* Compute violation rate for this bootstrap sample
sstats(mean) startl endl boottrigger>>alphahatStar
compute alphahatDist(draw) = alphahatStar
end do draw
* Compute bootstrap statistics
stats(fractiles) alphahatDist 1 ndraws
compute %%bootmean = %mean
compute %%bootse = sqrt(%variance)
* --- Plot density function for alphabootdist ---
density(smoothing=2.0) alphahatDist 1 ndraws galphaboot falphaboot
* 10 horizons, 10 colours
compute col = %if(horizon==1,2,$
%if(horizon==2,4,$
%if(horizon==3,5,$
%if(horizon==4,6,$
%if(horizon==5,7,$
%if(horizon==6,8,$
%if(horizon==7,9,$
%if(horizon==8,10,$
%if(horizon==9,11,12)))))))))
spgraph(hea="",vfi=1,hfi=1)
scatter(key=upright,head="A non-parametric empirical approximation to the sampling distribution",$
hgrid=||%%bootmean||,style=line) 1
# galphaboot falphaboot 1 ndraws col
spgraph(done)
* --- Output Results ---
disp "=================================================="
disp " Alpha Block Bootstrap Unconditional Coverage Test"
disp "=================================================="
disp "Horizon (horizon): " horizon
disp "Sample size (N): " N
disp "Target alpha: " alpha
disp "Observed alphahat: " %%alphahatObs
disp "Bootstrap mean: " %%bootmean
disp "Bootstrap SE: " %%bootse
disp "=================================================="
end procedure
[1]TomDoan wrote: ↑Sat Jan 24, 2026 1:33 pm Compute the percentage of draws that are on the wrong side of the hypothesized alpha.
sstats(mean) 1 ndraws (alphahatDist>alpha)>>pctover (alphadataDist<alpha)>>pctunder
whichever of pctover and pctunder is appropriate. See the first example in the description of SSTATS.
Code: Select all
procedure acAlphahatBlockBoot trigger start end
type series trigger
type integer start end
local integer startl endl
local real k_real
local integer k_obs N
local series alphahatDist
local integer draw
local series[integer] bootentries
local series boottrigger
local real alphahatStar bootmean bootse pctunder pctover p_value_boot
local integer col galphahatboot
local series falphahatboot
option real alpha 0.01
option integer horizon 1
option integer ndraws 10000
* --- Sample range ---
inquire(reglist) startl<<start endl<<end
# trigger
* --- Calculate observed statistics ---
sstats startl endl trigger>>k_real
compute k_obs = fix(k_real)
* --- Compute observed violation rate ---
sstats(mean) startl endl trigger>>alphahatObs
compute N = %nobs
* --- Create series to store bootstrap results ---
set alphahatDist 1 ndraws = 0.0
* --- Bootstrap loop ---
do draw = 1, ndraws
* Generate bootstrap block indices from the actual data range
BOOT(block=horizon) bootentries startl endl startl endl
* Resample the ACTUAL trigger series using those indices
set boottrigger startl endl = trigger(bootentries(t))
* Compute violation rate for this bootstrap sample
sstats(mean) startl endl boottrigger>>alphahatStar
compute alphahatDist(draw) = alphahatStar
end do draw
* --- Compute bootstrap statistics ---
stats(fractiles) alphahatDist 1 ndraws
compute bootmean = %mean
compute bootse = sqrt(%variance)
* --- Calculate p-value ---
sstats(mean) 1 ndraws (alphahatDist>alpha)>>pctover (alphahatDist<alpha)>>pctunder
compute p_value_boot = 2.0 * %min(pctover,pctunder)
compute p_value_boot = %min(p_value_boot,1.0)
compute %%palphahat_boot = p_value_boot
* --- Plot density function for alphahatDist ---
density(smoothing=2.0) alphahatDist 1 ndraws galphahatboot falphahatboot
* 10 horizons, 10 colours
compute col = %if(horizon==1,2,$
%if(horizon==2,4,$
%if(horizon==3,5,$
%if(horizon==4,6,$
%if(horizon==5,7,$
%if(horizon==6,8,$
%if(horizon==7,9,$
%if(horizon==8,10,$
%if(horizon==9,11,12)))))))))
spgraph(hea="",vfi=1,hfi=1)
scatter(key=upright,head="A non-parametric empirical approximation to the sampling distribution\\of alphahat with serial dependence",$
footer="horizon="+%strval(horizon,"#")+", "+$
"Observed alphahat:"+%strval(alphahatObs,".####")+", "+$
"Target alpha (fixed,regardless of N):"+%strval(alpha,".##")+", "+$
"Bootstrap mean:"+%strval(bootmean,".####")+", "+$
"p-value (bootstrap):"+%strval(%%palphahat_boot,".####"),$
hgrid=||alpha,bootmean||,style=line) 1
# galphahatboot falphahatboot 1 ndraws col
spgraph(done)
* --- Output Results ---
display "====================================================="
display " Alphahat Block Bootstrap Unconditional Coverage Test"
display "====================================================="
display "Horizon (horizon): " horizon
display "Sample size (N): " N
display "Expected exceedances E[K]=N*alpha: " N*alpha
display "Observed exceedances (k): " k_obs
display "Target alpha (fixed,regardless of N): " alpha
display "Observed alphahat: " alphahatObs
display "Bootstrap mean: " bootmean
display "Bootstrap SE: " bootse
display "pctover: " pctover
display "pctunder: " pctunder
display "p-value (bootstrap): " %%palphahat_boot
display "=================================================="
end procedure