

%%% Script data JAE

data=xlsread('oploss_unicredit_JAE.xlsx');
[~,header]=xlsread('oploss_unicredit_JAE.xlsx',1,'A1:AD1');
data2=data;

%%% Applying the thresholding procedure: quantile of level p for a given
%%% ET.

p=0.75; % define the confidence level of the quantile used as a threshold

for cat=1:7
    dd=data(data(:,3+cat)==1,:);
    t(cat)=quantile(dd(:,1),p);
    data2(data(:,3+cat)==1,1)=data2(data(:,3+cat)==1,1)-t(cat); % compute the exceedance with the appropriate threshold
end

ind=[];
for cat=1:7
    ind=[ind;find((data(:,3+cat)==1 & data(:,1)>t(cat))==1)]; % keep only the losses larger than the threshold, i.e. with a positive exceedance
end
ind=sort(ind);

%%% Final data

new_data=data2(ind,:);

%%% Regressors for sigma
xs=new_data(:,[4:9 11:end]);

%%% Regressors for gamma
xg=new_data(:,[4:9 11:end]);

%%% Exceedances
y=new_data(:,1);

%%% standardize the covariates

%xs=(xs-repmat(mean(xs),length(xs),1))./repmat(std(xs),length(xs),1);
%xg=(xg-repmat(mean(xg),length(xg),1))./repmat(std(xg),length(xg),1);
