-
Notifications
You must be signed in to change notification settings - Fork 0
/
tststatboots.m
66 lines (64 loc) · 2.18 KB
/
tststatboots.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
% Test statistic generator based on stationary bootstrap of Potilis and
% Romano (1994)
%
% Script developed by Arman Hassanniakalager for the 3rd chapter of PhD,
% Created on 04 Jul 2017 11:45 BST,
% Last modified 06 Jul 2017 18:07 BST.
% ****************************************
%% Input arguments:
% -dataset: the models time series
% -bench: the Benchmark model
% -typ: test statistic type 'student' for STUDENTIZED or anything else
% for GENERAL
% -Bsize: number of Bootstrap replications
% -Bwindow: average numbr of block lengeth in the bootstrap replications
%% Output arguments:
% -tststat: test statistic of the hyposethes
% -tststatB: Bootstrap test statistic of the hyposethes
function [tststat,tststatB]=tststatboots(dataset,bench,typ,Bsize,Bwindow)
%% Input arguments
if nargin<3
error('Please call the function with models and benchmark properly')
elseif nargin==3
Bsize=1000; % Bootstrap replications
Bwindow=10; % Bootstrap length
elseif nargin==4
Bwindow=10; % Bootstrap length
end
if strcmpi(typ,'student')
isStudentized = true;
disp('Test statistic type is STUDENTIZED');
else
isStudentized = false;
disp('Test statistic type is GENERAL');
end
%% switch function between STUDENTIZED and GENERAL test statistic
whichstd=@(x,y) y*std(x)+(1-y)*ones(1,size(x,2));
%% Bootstrap indices
indices=stationary_bootstrap((1:size(dataset,1))',Bsize,Bwindow);
%%
modelscount=size(dataset,2);
tststatB=nan(Bsize,modelscount);
tststat=nan(1,modelscount);
tic;
disp('Bootstrap generation initiated');
for i=1:modelscount
if mod(i,ceil(modelscount./20)) == 0
disp([num2str(round(100*(i/modelscount))) '% completed'])
toc;
end
candmodel=dataset(:,i);
zeroind=find(cumsum(candmodel)==0,1,'last');
if zeroind<=size(dataset,1)-Bwindow
tststat(i)=mean(candmodel-bench)/whichstd(candmodel,isStudentized);
for b=1:Bsize
bsdata=candmodel(indices(:,b));
benchB=bench(indices(:,b));
tststatB(b,i)=mean(bsdata-benchB)/whichstd(bsdata,isStudentized);
end
else
tststat(i)=nan;
tststatB(:,i)=nan;
end
end
end