# Bootstrap CI for a Bootstrapped sample

31 Ansichten (letzte 30 Tage)
Ricardo am 2 Feb. 2024
Beantwortet: Shivansh am 22 Feb. 2024
I have a time series of stock returns (Tx1) with T=3000 and want to calculate confidence intervals in a two-step process, following this procedure:
"To derive the confidence intervals, we implement a bootstrap as proposed in Efron (1979) using the N = 5000 annual returns from the common block-bootstrap in the first step. Within this second-step bootstrap, we again create NB = 5000 bootstrap resamples, each consisting of 500 annual returns. "
The methodology involves a two-step bootstrap process: first, using a common block-bootstrap with N=5000 annual returns (TxN), and then within this, creating NB=2000 bootstrap resamples, each consisting of 500 annual returns.
For the first-step. I managed to get the block-bootstraped returns. However, for the second steps I have questions.
I found an insightful answer on MATLAB Central (link provided) that demonstrates bootstrapping CI. In the low-level code, I successfully modified the sample size of the bootstrap by changing NB2_size to 500
nBoot2 = 2000; %number of bootstraps
In the low-level code, I can modifie the sample size of the boostrap
bootMeans = nan(1,nBoot2);
for i = 1:nBoot2
bootMeans(i) = mean(data(randi(numel(data),NB2_size)));
end
Now, when using the bootci function, I'm unsure how to adjust the sample size. The existing code uses nBoot2 = 2000 for the number of bootstraps and calculates a 90% confidence interval with alpha=.1 and 'type','per'.
[bci,bmeans] = bootci(nBoot2,{@mean,data},'alpha',.1,'type','per'); %90 confidence interval
% Compute bootstrap sample mean
bmu = mean(bmeans);
How can I adapt the bootci function to adapt the sample size for the inner bootstrap (nBoot2) to a specific data size (NB2_size) and ensuring the correct calculation of confidence intervals?"
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Shivansh am 22 Feb. 2024
Hi Ricardo,
It seems like you want to adapt the sample size for the inner bootstrap to "NB2_size". To adapt the "bootci" function, you can create a custom sampling function that generates bootstrap samples of the desired size and then pass the function to "bootci".
You can do it by first defining a custom sampling function that takes the data and the desired sample size as inputs and outputs the mean of the bootstrap sample and then using this custom function with the "bootci" function to compute the confidence intervals.
Here is a sample MATLAB code for the above approach
data = rand(1,3000);
% Define the number of bootstrap samples for the outer and inner bootstraps
nBoot1 = 5000; % Number of bootstrap samples in the first step
nBoot2 = 2000; % Number of bootstrap samples in the second step (inner bootstrap)
% Define the sample size for the inner bootstrap
NB2_size = 500;
% Compute the 90% confidence interval using the custom bootstrap function
% Pass a function handle to the custom sampling function along with the extra parameter NB2_size
[bci, bmeans] = bootci(nBoot2, {@customBootstrapSample, data, NB2_size}, 'alpha', 0.1, 'type', 'per');
% Compute the bootstrap sample mean
bmu = mean(bmeans);
% Display the results
disp('Bootstrap Confidence Interval:');
Bootstrap Confidence Interval:
disp(bci);
0.4764 0.5232
disp('Bootstrap Sample Mean:');
Bootstrap Sample Mean:
disp(bmu);
0.4997
% Custom sampling function for the inner bootstrap
function bootSampleMean = customBootstrapSample(data, sampleSize)
% Generate a bootstrap sample of the specified size
bootSample = data(randi(numel(data), sampleSize, 1));
% Calculate the mean of the bootstrap sample
bootSampleMean = mean(bootSample);
end
You can replace the data with your original data and adjust the code accordingly. The "customBootstrapSample" function takes "data" and "sampleSize" and returns the mean of a bootstrap sample with "sampleSize" elements. The "bootci" function is then called with a function handle to "customBootstrapSample", and "NB2_size" is passed as an additional argument.
I hope it helps!
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Resampling Techniques finden Sie in Help Center und File Exchange

R2023b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by