Bootstrap sampling depending on portfolio
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I have this problem with coding something in Matlab, I hope someone knows how to solve this.
SUMMARY: The problem is that I have several different financial portfolios (1070 portfolios), and I need to run a regression per portfolio. Then with the residuals from the first regression, I want to bootstrap those residuals (Get around 1000 bootstrapped residual samples) but PER EACH INDIVIDUAL portfolio. This is because I can not mix residuals from different portfolios.
IN DETAIL: I have one vector that tells me the portfolio number, this is a random number but unique to that particular portfolio. I then have the portfolio returns gathered in one long vector, (14k observations), so what I need to do is some sort of "rolling window" OLS regression and ONLY regress the data corresponding to an individual portfolio, extract the constant and betas and save these, and then do this for all different portfolios.
I would get a matrix consisting of constants and betas, and then each row corresponds to a specific portfolio.
The portfolios have different amount of datapoints, so that one portfolio might have 60 observations whilst another might have 150 observations. So it is not possible to just split it up into separate portfolios just by a fixed interval.
For the bootstrapped residuals I would need to, as mentioned above, draw with replacement from the residuals from portfolios and not the whole sample. I need these bootstrapped samples for further data manipulation, but ones I have the 1000 bootstrap samples the rest is just normal addition and subtraction operations...
Does anyone know how to do this? In Stata, for the regression part, you just use the "by()" option, but for bootstrapping it is not that easy...
I am very thankful for any help!
Best regards, Philip
0 commentaires
Réponses (1)
Richard Willey
le 8 Juin 2011
Hi Philip
I attached a couple different examples of residual bootstraps using MATLAB
The following reference provides some good background information
%%Generate a data set and perform your initial regression
clear all
clc
X = linspace(1, 1000, 1000)';
Y = 3*X + 5 + randn(1000,1);
X = [ones(length(X),1), X];
[b,bint,r,rint,stats] = regress(Y,X);
%%Parametric residual bootstrap
% This method assumes that your residuals are normally distributed and
% homoskedastic. A parametric residual bootstrap is more accurate and
% converges faster than a nonparametric residual bootstrap.
% Use a one sided kstest to verify that the residuals are normally
% distributed.
kstest(r)
% Create a probability distribution object that models the residuals
foo = fitdist(r, 'normal')
% Create an array to store your new datasets
Nboot = 500;
My_Data = zeros(length(X), Nboot);
% Create your data sets
YHat = X*b;
for i = 1:Nboot
boot_noise = random(foo, 1000,1);
My_Data(:,i) = YHat + boot_noise;
end
% Use your data to do something interesting
Nonparametric residual bootstrap
% This method assumes that your errors are homoskedastic, however, there is
% no assume that they are normally distributed.
% This method also uses the bootstrp function from Statistics Toolbox and
% assumes that we're using the bootstrp to estimate standard errors
standard_errors = std(bootstrp(1000,@(bootr)regress(YHat+bootr, X),r))
0 commentaires
Voir également
Catégories
En savoir plus sur Portfolio Optimization and Asset Allocation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!