%% Date: 24/10/2025
%% See Tables excel.

% Panel A

%% Specification 1: Intervention on 8 day change in usd/ils
load ccys;
load ccydates;

%% ccys+ccysdates:  eur/usd, usd/ils, NEER, 3m forward

dCCYS=[repmat(NaN,1,3);log(ccys(2:end,:)./ccys(1:end-1,:) )]*100; %% change in pct.
dCCYS(:,3)=-dCCYS(:,3); %% because the NEER is the other way around here.
ccystartdate = find(ccydates >= datenum('01/01/2013','dd/mm/yyyy'), 1, 'first');
ccyenddate = find(ccydates <= datenum('31/12/2019','dd/mm/yyyy'), 1, 'last');

%% 3m forward
load newforwards;
dforwards=[repmat(NaN,1,5);100*log(newforwards(2:end,:)./newforwards(1:end-1,:))]; %% in %

%% volume - This starts from 02/01/2013
volume=[fspotvol,swapvol,otcvol]; %% in $ Millions.
volstartdate = find(voldates >= datenum('02/01/2013','dd/mm/yyyy'), 1, 'first');
volenddate = find(voldates <= datenum('31/12/2019','dd/mm/yyyy'), 1, 'last');

%% Flows
%% With flows, NaN = zero
foreign_total( isnan(foreign_total) )= 0; real_sector( isnan(real_sector) )= 0; finance_sector( isnan(finance_sector) )= 0; inst( isnan(inst) )= 0;
flows=[foreign_total,real_sector,finance_sector,inst];
flowsstartdate = find(flowsdates >= datenum('01/01/2013','dd/mm/yyyy'), 1, 'first');
flowsenddate = find(flowsdates <= datenum('31/12/2019','dd/mm/yyyy'), 1, 'last');

%% CDS
load cdsdates; load cds;
cdsstartdate = find(cdsdates >= datenum('01/01/2013','dd/mm/yyyy'), 1, 'first');
cdsenddate = find(cdsdates <= datenum('31/12/2019','dd/mm/yyyy'), 1, 'last');

%% 3M CCB: 
load newbasis

%% VIX
load vix; load vixdates
vixstartdate = find(vixdates >= datenum('01/01/2013','dd/mm/yyyy'), 1, 'first');
vixenddate = find(vixdates <= datenum('31/12/2019','dd/mm/yyyy'), 1, 'last');

% Telbor minus libor 1 m and 1 y
load telbor; load uslibor; load interestdates;
interest=[telbor(:,2)-uslibor(:,2),telbor(:,6)-uslibor(:,6)]; %% in pct points
intereststartdate = find(interestdates >= datenum('01/01/2013','dd/mm/yyyy'), 1, 'first');
interestenddate = find(interestdates <= datenum('31/12/2019','dd/mm/yyyy'), 1, 'last');
newbasis=fillmissing(newbasis,'previous');

PanelA=[nanmean(dCCYS(ccystartdate:ccyenddate,1)),nanmedian(dCCYS(ccystartdate:ccyenddate,1)),nanstd(dCCYS(ccystartdate:ccyenddate,1)),min(dCCYS(ccystartdate:ccyenddate,1)),max(dCCYS(ccystartdate:ccyenddate,1)),corr(dCCYS(ccystartdate+1:ccyenddate,1),dCCYS(ccystartdate:ccyenddate-1,1),'rows','complete'), sum( ~isnan(dCCYS(ccystartdate:ccyenddate,1)));
        nanmean(dCCYS(ccystartdate:ccyenddate,2)),nanmedian(dCCYS(ccystartdate:ccyenddate,2)),nanstd(dCCYS(ccystartdate:ccyenddate,2)),min(dCCYS(ccystartdate:ccyenddate,2)),max(dCCYS(ccystartdate:ccyenddate,2)),corr(dCCYS(ccystartdate+1:ccyenddate,2),dCCYS(ccystartdate:ccyenddate-1,2),'rows','complete'), sum( ~isnan(dCCYS(ccystartdate:ccyenddate,2)));    
        nanmean(dCCYS(ccystartdate:ccyenddate,3)),nanmedian(dCCYS(ccystartdate:ccyenddate,3)),nanstd(dCCYS(ccystartdate:ccyenddate,3)),min(dCCYS(ccystartdate:ccyenddate,3)),max(dCCYS(ccystartdate:ccyenddate,3)),corr(dCCYS(ccystartdate+1:ccyenddate,3),dCCYS(ccystartdate:ccyenddate-1,3),'rows','complete'), sum( ~isnan(dCCYS(ccystartdate:ccyenddate,3)));   
        nanmean(dforwards(ccystartdate:ccyenddate,3)),nanmedian(dforwards(ccystartdate:ccyenddate,3)),nanstd(dforwards(ccystartdate:ccyenddate,3)),min(dforwards(ccystartdate:ccyenddate,3)),max(dforwards(ccystartdate:ccyenddate,3)),corr(dforwards(ccystartdate+1:ccyenddate,3),dforwards(ccystartdate:ccyenddate-1,3),'rows','complete'), sum( ~isnan(dforwards(ccystartdate:ccyenddate,3)));
        nanmean(newbasis(ccystartdate:ccyenddate,2)),nanmedian(newbasis(ccystartdate:ccyenddate,2)),nanstd((newbasis(ccystartdate:ccyenddate,2))),min(newbasis(ccystartdate:ccyenddate,2)),max(newbasis(ccystartdate:ccyenddate,2)),corr(newbasis(ccystartdate+1:ccyenddate,2),newbasis(ccystartdate:ccyenddate-1,2),'rows','complete'), sum( ~isnan(newbasis(ccystartdate:ccyenddate,2)));   
        nanmean(volume(volstartdate:volenddate,1)),nanmedian(volume(volstartdate:volenddate,1)),nanstd(volume(volstartdate:volenddate,1)),min(volume(volstartdate:volenddate,1)),max(volume(volstartdate:volenddate,1)),corr(volume(volstartdate+1:volenddate,1),volume(volstartdate:volenddate-1,1),'rows','complete'), sum( ~isnan(volume(volstartdate:volenddate,1)));
        nanmean(volume(volstartdate:volenddate,2)),nanmedian(volume(volstartdate:volenddate,2)),nanstd(volume(volstartdate:volenddate,2)),min(volume(volstartdate:volenddate,2)),max(volume(volstartdate:volenddate,2)),corr(volume(volstartdate+1:volenddate,2),volume(volstartdate:volenddate-1,2),'rows','complete'), sum( ~isnan(volume(volstartdate:volenddate,2)));  
        nanmean(volume(volstartdate:volenddate,3)),nanmedian(volume(volstartdate:volenddate,3)),nanstd(volume(volstartdate:volenddate,3)),min(volume(volstartdate:volenddate,3)),max(volume(volstartdate:volenddate,3)),corr(volume(volstartdate+1:volenddate,3),volume(volstartdate:volenddate-1,3),'rows','complete'), sum( ~isnan(volume(volstartdate:volenddate,3)));  
        nanmean(flows(flowsstartdate:flowsenddate,1)),nanmedian(flows(flowsstartdate:flowsenddate,1)),nanstd(flows(flowsstartdate:flowsenddate,1)),min(flows(flowsstartdate:flowsenddate,1)),max(flows(flowsstartdate:flowsenddate,1)),corr(flows(flowsstartdate+1:flowsenddate,1),flows(flowsstartdate:flowsenddate-1,1),'rows','complete'), sum( ~isnan(flows(flowsstartdate:flowsenddate,1)));
        nanmean(flows(flowsstartdate:flowsenddate,2)),nanmedian(flows(flowsstartdate:flowsenddate,2)),nanstd(flows(flowsstartdate:flowsenddate,2)),min(flows(flowsstartdate:flowsenddate,2)),max(flows(flowsstartdate:flowsenddate,2)),corr(flows(flowsstartdate+1:flowsenddate,2),flows(flowsstartdate:flowsenddate-1,2),'rows','complete'), sum( ~isnan(flows(flowsstartdate:flowsenddate,2)));  
        nanmean(flows(flowsstartdate:flowsenddate,3)),nanmedian(flows(flowsstartdate:flowsenddate,3)),nanstd(flows(flowsstartdate:flowsenddate,3)),min(flows(flowsstartdate:flowsenddate,3)),max(flows(flowsstartdate:flowsenddate,3)),corr(flows(flowsstartdate+1:flowsenddate,3),flows(flowsstartdate:flowsenddate-1,3),'rows','complete'), sum( ~isnan(flows(flowsstartdate:flowsenddate,3)));  
        nanmean(flows(flowsstartdate:flowsenddate,4)),nanmedian(flows(flowsstartdate:flowsenddate,4)),nanstd(flows(flowsstartdate:flowsenddate,4)),min(flows(flowsstartdate:flowsenddate,4)),max(flows(flowsstartdate:flowsenddate,4)),corr(flows(flowsstartdate+1:flowsenddate,4),flows(flowsstartdate:flowsenddate-1,4),'rows','complete'), sum( ~isnan(flows(flowsstartdate:flowsenddate,4)));
        nanmean(cds(cdsstartdate:cdsenddate,1))/100,nanmedian(cds(cdsstartdate:cdsenddate,1))/100,nanstd(cds(cdsstartdate:cdsenddate,1))/100,min(cds(cdsstartdate:cdsenddate,1))/100,max(cds(cdsstartdate:cdsenddate,1))/100,corr(cds(cdsstartdate+1:cdsenddate,1),cds(cdsstartdate:cdsenddate-1,1),'rows','complete'), sum( ~isnan(cds(cdsstartdate:cdsenddate,1)));
        nanmean(telbor(intereststartdate:interestenddate,1)),nanmedian(telbor(intereststartdate:interestenddate,1)),nanstd(telbor(intereststartdate:interestenddate,1)),min(telbor(intereststartdate:interestenddate,1)),max(telbor(intereststartdate:interestenddate,1)),corr(telbor(intereststartdate+1:interestenddate,1),telbor(intereststartdate:interestenddate-1,1),'rows','complete'), sum( ~isnan(telbor(intereststartdate:interestenddate,1)));
        nanmean(uslibor(intereststartdate:interestenddate,1)),nanmedian(uslibor(intereststartdate:interestenddate,1)),nanstd(uslibor(intereststartdate:interestenddate,1)),min(uslibor(intereststartdate:interestenddate,1)),max(uslibor(intereststartdate:interestenddate,1)),corr(uslibor(intereststartdate+1:interestenddate,1),uslibor(intereststartdate:interestenddate-1,1),'rows','complete'), sum( ~isnan(uslibor(intereststartdate:interestenddate,1)))  
        nanmean(vix(vixstartdate:vixenddate)),nanmedian(vix(vixstartdate:vixenddate)),nanstd(vix(vixstartdate:vixenddate)),min(vix(vixstartdate:vixenddate)),max(vix(vixstartdate:vixenddate)),corr(vix(vixstartdate+1:vixenddate),vix(vixstartdate:vixenddate-1),'rows','complete'), sum( ~isnan(vix(vixstartdate:vixenddate)))  
      
];

%% RR+BF+ATMV
optionstartdate=find(optionsdates==datenum('01/01/2013','dd/mm/yyyy' ) ) ;
optionenddate=find(optionsdates==datenum('31/12/2019','dd/mm/yyyy' ) ) ;

PanelB=[nanmean(usdilsrr10(optionstartdate:optionenddate,1)),nanmedian(usdilsrr10(optionstartdate:optionenddate,1)),nanstd(usdilsrr10(optionstartdate:optionenddate,1)),min(usdilsrr10(optionstartdate:optionenddate,1)),max(usdilsrr10(optionstartdate:optionenddate,1)),corr(usdilsrr10(optionstartdate+1:optionenddate,1),usdilsrr10(optionstartdate:optionenddate-1,1),'rows','complete'), sum( ~isnan(usdilsrr10(optionstartdate:optionenddate,1)));
        nanmean(usdilsrr10(optionstartdate:optionenddate,2)),nanmedian(usdilsrr10(optionstartdate:optionenddate,2)),nanstd(usdilsrr10(optionstartdate:optionenddate,2)),min(usdilsrr10(optionstartdate:optionenddate,2)),max(usdilsrr10(optionstartdate:optionenddate,2)),corr(usdilsrr10(optionstartdate+1:optionenddate,2),usdilsrr10(optionstartdate:optionenddate-1,2),'rows','complete'), sum( ~isnan(usdilsrr10(optionstartdate:optionenddate,2)));  
        nanmean(usdilsrr10(optionstartdate:optionenddate,3)),nanmedian(usdilsrr10(optionstartdate:optionenddate,3)),nanstd(usdilsrr10(optionstartdate:optionenddate,3)),min(usdilsrr10(optionstartdate:optionenddate,3)),max(usdilsrr10(optionstartdate:optionenddate,3)),corr(usdilsrr10(optionstartdate+1:optionenddate,3),usdilsrr10(optionstartdate:optionenddate-1,3),'rows','complete'), sum( ~isnan(usdilsrr10(optionstartdate:optionenddate,3)));  
        nanmean(usdilsrr10(optionstartdate:optionenddate,4)),nanmedian(usdilsrr10(optionstartdate:optionenddate,4)),nanstd(usdilsrr10(optionstartdate:optionenddate,4)),min(usdilsrr10(optionstartdate:optionenddate,4)),max(usdilsrr10(optionstartdate:optionenddate,4)),corr(usdilsrr10(optionstartdate+1:optionenddate,4),usdilsrr10(optionstartdate:optionenddate-1,4),'rows','complete'), sum( ~isnan(usdilsrr10(optionstartdate:optionenddate,4)));
        nanmean(usdilsrr10(optionstartdate:optionenddate,5)),nanmedian(usdilsrr10(optionstartdate:optionenddate,5)),nanstd(usdilsrr10(optionstartdate:optionenddate,5)),min(usdilsrr10(optionstartdate:optionenddate,5)),max(usdilsrr10(optionstartdate:optionenddate,5)),corr(usdilsrr10(optionstartdate+1:optionenddate,5),usdilsrr10(optionstartdate:optionenddate-1,5),'rows','complete'), sum( ~isnan(usdilsrr10(optionstartdate:optionenddate,5)));  
        nanmean(usdilsrr10(optionstartdate:optionenddate,6)),nanmedian(usdilsrr10(optionstartdate:optionenddate,6)),nanstd(usdilsrr10(optionstartdate:optionenddate,6)),min(usdilsrr10(optionstartdate:optionenddate,6)),max(usdilsrr10(optionstartdate:optionenddate,6)),corr(usdilsrr10(optionstartdate+1:optionenddate,6),usdilsrr10(optionstartdate:optionenddate-1,6),'rows','complete'), sum( ~isnan(usdilsrr10(optionstartdate:optionenddate,6)));  
        nanmean(usdilsrr25(optionstartdate:optionenddate,1)),nanmedian(usdilsrr25(optionstartdate:optionenddate,1)),nanstd(usdilsrr25(optionstartdate:optionenddate,1)),min(usdilsrr25(optionstartdate:optionenddate,1)),max(usdilsrr25(optionstartdate:optionenddate,1)),corr(usdilsrr25(optionstartdate+1:optionenddate,1),usdilsrr25(optionstartdate:optionenddate-1,1),'rows','complete'), sum( ~isnan(usdilsrr25(optionstartdate:optionenddate,1)));
        nanmean(usdilsrr25(optionstartdate:optionenddate,2)),nanmedian(usdilsrr25(optionstartdate:optionenddate,2)),nanstd(usdilsrr25(optionstartdate:optionenddate,2)),min(usdilsrr25(optionstartdate:optionenddate,2)),max(usdilsrr25(optionstartdate:optionenddate,2)),corr(usdilsrr25(optionstartdate+1:optionenddate,2),usdilsrr25(optionstartdate:optionenddate-1,2),'rows','complete'), sum( ~isnan(usdilsrr25(optionstartdate:optionenddate,2)));  
        nanmean(usdilsrr25(optionstartdate:optionenddate,3)),nanmedian(usdilsrr25(optionstartdate:optionenddate,3)),nanstd(usdilsrr25(optionstartdate:optionenddate,3)),min(usdilsrr25(optionstartdate:optionenddate,3)),max(usdilsrr25(optionstartdate:optionenddate,3)),corr(usdilsrr25(optionstartdate+1:optionenddate,3),usdilsrr25(optionstartdate:optionenddate-1,3),'rows','complete'), sum( ~isnan(usdilsrr25(optionstartdate:optionenddate,3)));  
        nanmean(usdilsrr25(optionstartdate:optionenddate,4)),nanmedian(usdilsrr25(optionstartdate:optionenddate,4)),nanstd(usdilsrr25(optionstartdate:optionenddate,4)),min(usdilsrr25(optionstartdate:optionenddate,4)),max(usdilsrr25(optionstartdate:optionenddate,4)),corr(usdilsrr25(optionstartdate+1:optionenddate,4),usdilsrr25(optionstartdate:optionenddate-1,4),'rows','complete'), sum( ~isnan(usdilsrr25(optionstartdate:optionenddate,4)));
        nanmean(usdilsrr25(optionstartdate:optionenddate,5)),nanmedian(usdilsrr25(optionstartdate:optionenddate,5)),nanstd(usdilsrr25(optionstartdate:optionenddate,5)),min(usdilsrr25(optionstartdate:optionenddate,5)),max(usdilsrr25(optionstartdate:optionenddate,5)),corr(usdilsrr25(optionstartdate+1:optionenddate,5),usdilsrr25(optionstartdate:optionenddate-1,5),'rows','complete'), sum( ~isnan(usdilsrr25(optionstartdate:optionenddate,5)));  
        nanmean(usdilsrr25(optionstartdate:optionenddate,6)),nanmedian(usdilsrr25(optionstartdate:optionenddate,6)),nanstd(usdilsrr25(optionstartdate:optionenddate,6)),min(usdilsrr25(optionstartdate:optionenddate,6)),max(usdilsrr25(optionstartdate:optionenddate,6)),corr(usdilsrr25(optionstartdate+1:optionenddate,6),usdilsrr25(optionstartdate:optionenddate-1,6),'rows','complete'), sum( ~isnan(usdilsrr25(optionstartdate:optionenddate,6)));  
        nanmean(usdilsbf10(optionstartdate:optionenddate,1)),nanmedian(usdilsbf10(optionstartdate:optionenddate,1)),nanstd(usdilsbf10(optionstartdate:optionenddate,1)),min(usdilsbf10(optionstartdate:optionenddate,1)),max(usdilsbf10(optionstartdate:optionenddate,1)),corr(usdilsbf10(optionstartdate+1:optionenddate,1),usdilsbf10(optionstartdate:optionenddate-1,1),'rows','complete'), sum( ~isnan(usdilsbf10(optionstartdate:optionenddate,1)));
        nanmean(usdilsbf10(optionstartdate:optionenddate,2)),nanmedian(usdilsbf10(optionstartdate:optionenddate,2)),nanstd(usdilsbf10(optionstartdate:optionenddate,2)),min(usdilsbf10(optionstartdate:optionenddate,2)),max(usdilsbf10(optionstartdate:optionenddate,2)),corr(usdilsbf10(optionstartdate+1:optionenddate,2),usdilsbf10(optionstartdate:optionenddate-1,2),'rows','complete'), sum( ~isnan(usdilsbf10(optionstartdate:optionenddate,2)));  
        nanmean(usdilsbf10(optionstartdate:optionenddate,3)),nanmedian(usdilsbf10(optionstartdate:optionenddate,3)),nanstd(usdilsbf10(optionstartdate:optionenddate,3)),min(usdilsbf10(optionstartdate:optionenddate,3)),max(usdilsbf10(optionstartdate:optionenddate,3)),corr(usdilsbf10(optionstartdate+1:optionenddate,3),usdilsbf10(optionstartdate:optionenddate-1,3),'rows','complete'), sum( ~isnan(usdilsbf10(optionstartdate:optionenddate,3)));  
        nanmean(usdilsbf10(optionstartdate:optionenddate,4)),nanmedian(usdilsbf10(optionstartdate:optionenddate,4)),nanstd(usdilsbf10(optionstartdate:optionenddate,4)),min(usdilsbf10(optionstartdate:optionenddate,4)),max(usdilsbf10(optionstartdate:optionenddate,4)),corr(usdilsbf10(optionstartdate+1:optionenddate,4),usdilsbf10(optionstartdate:optionenddate-1,4),'rows','complete'), sum( ~isnan(usdilsbf10(optionstartdate:optionenddate,4)));
        nanmean(usdilsbf10(optionstartdate:optionenddate,5)),nanmedian(usdilsbf10(optionstartdate:optionenddate,5)),nanstd(usdilsbf10(optionstartdate:optionenddate,5)),min(usdilsbf10(optionstartdate:optionenddate,5)),max(usdilsbf10(optionstartdate:optionenddate,5)),corr(usdilsbf10(optionstartdate+1:optionenddate,5),usdilsbf10(optionstartdate:optionenddate-1,5),'rows','complete'), sum( ~isnan(usdilsbf10(optionstartdate:optionenddate,5)));  
        nanmean(usdilsbf10(optionstartdate:optionenddate,6)),nanmedian(usdilsbf10(optionstartdate:optionenddate,6)),nanstd(usdilsbf10(optionstartdate:optionenddate,6)),min(usdilsbf10(optionstartdate:optionenddate,6)),max(usdilsbf10(optionstartdate:optionenddate,6)),corr(usdilsbf10(optionstartdate+1:optionenddate,6),usdilsbf10(optionstartdate:optionenddate-1,6),'rows','complete'), sum( ~isnan(usdilsbf10(optionstartdate:optionenddate,6)));  
        nanmean(usdilsbf25(optionstartdate:optionenddate,1)),nanmedian(usdilsbf25(optionstartdate:optionenddate,1)),nanstd(usdilsbf25(optionstartdate:optionenddate,1)),min(usdilsbf25(optionstartdate:optionenddate,1)),max(usdilsbf25(optionstartdate:optionenddate,1)),corr(usdilsbf25(optionstartdate+1:optionenddate,1),usdilsbf25(optionstartdate:optionenddate-1,1),'rows','complete'), sum( ~isnan(usdilsbf25(optionstartdate:optionenddate,1)));
        nanmean(usdilsbf25(optionstartdate:optionenddate,2)),nanmedian(usdilsbf25(optionstartdate:optionenddate,2)),nanstd(usdilsbf25(optionstartdate:optionenddate,2)),min(usdilsbf25(optionstartdate:optionenddate,2)),max(usdilsbf25(optionstartdate:optionenddate,2)),corr(usdilsbf25(optionstartdate+1:optionenddate,2),usdilsbf25(optionstartdate:optionenddate-1,2),'rows','complete'), sum( ~isnan(usdilsbf25(optionstartdate:optionenddate,2)));  
        nanmean(usdilsbf25(optionstartdate:optionenddate,3)),nanmedian(usdilsbf25(optionstartdate:optionenddate,3)),nanstd(usdilsbf25(optionstartdate:optionenddate,3)),min(usdilsbf25(optionstartdate:optionenddate,3)),max(usdilsbf25(optionstartdate:optionenddate,3)),corr(usdilsbf25(optionstartdate+1:optionenddate,3),usdilsbf25(optionstartdate:optionenddate-1,3),'rows','complete'), sum( ~isnan(usdilsbf25(optionstartdate:optionenddate,3)));  
        nanmean(usdilsbf25(optionstartdate:optionenddate,4)),nanmedian(usdilsbf25(optionstartdate:optionenddate,4)),nanstd(usdilsbf25(optionstartdate:optionenddate,4)),min(usdilsbf25(optionstartdate:optionenddate,4)),max(usdilsbf25(optionstartdate:optionenddate,4)),corr(usdilsbf25(optionstartdate+1:optionenddate,4),usdilsbf25(optionstartdate:optionenddate-1,4),'rows','complete'), sum( ~isnan(usdilsbf25(optionstartdate:optionenddate,4)));
        nanmean(usdilsbf25(optionstartdate:optionenddate,5)),nanmedian(usdilsbf25(optionstartdate:optionenddate,5)),nanstd(usdilsbf25(optionstartdate:optionenddate,5)),min(usdilsbf25(optionstartdate:optionenddate,5)),max(usdilsbf25(optionstartdate:optionenddate,5)),corr(usdilsbf25(optionstartdate+1:optionenddate,5),usdilsbf25(optionstartdate:optionenddate-1,5),'rows','complete'), sum( ~isnan(usdilsbf25(optionstartdate:optionenddate,5)));  
        nanmean(usdilsbf25(optionstartdate:optionenddate,6)),nanmedian(usdilsbf25(optionstartdate:optionenddate,6)),nanstd(usdilsbf25(optionstartdate:optionenddate,6)),min(usdilsbf25(optionstartdate:optionenddate,6)),max(usdilsbf25(optionstartdate:optionenddate,6)),corr(usdilsbf25(optionstartdate+1:optionenddate,6),usdilsbf25(optionstartdate:optionenddate-1,6),'rows','complete'), sum( ~isnan(usdilsbf25(optionstartdate:optionenddate,6)));  
        nanmean(usdilsatmv(optionstartdate:optionenddate,1)),nanmedian(usdilsatmv(optionstartdate:optionenddate,1)),nanstd(usdilsatmv(optionstartdate:optionenddate,1)),min(usdilsatmv(optionstartdate:optionenddate,1)),max(usdilsatmv(optionstartdate:optionenddate,1)),corr(usdilsatmv(optionstartdate+1:optionenddate,1),usdilsatmv(optionstartdate:optionenddate-1,1),'rows','complete'), sum( ~isnan(usdilsatmv(optionstartdate:optionenddate,1)));
        nanmean(usdilsatmv(optionstartdate:optionenddate,2)),nanmedian(usdilsatmv(optionstartdate:optionenddate,2)),nanstd(usdilsatmv(optionstartdate:optionenddate,2)),min(usdilsatmv(optionstartdate:optionenddate,2)),max(usdilsatmv(optionstartdate:optionenddate,2)),corr(usdilsatmv(optionstartdate+1:optionenddate,2),usdilsatmv(optionstartdate:optionenddate-1,2),'rows','complete'), sum( ~isnan(usdilsatmv(optionstartdate:optionenddate,2)));  
        nanmean(usdilsatmv(optionstartdate:optionenddate,3)),nanmedian(usdilsatmv(optionstartdate:optionenddate,3)),nanstd(usdilsatmv(optionstartdate:optionenddate,3)),min(usdilsatmv(optionstartdate:optionenddate,3)),max(usdilsatmv(optionstartdate:optionenddate,3)),corr(usdilsatmv(optionstartdate+1:optionenddate,3),usdilsatmv(optionstartdate:optionenddate-1,3),'rows','complete'), sum( ~isnan(usdilsatmv(optionstartdate:optionenddate,3)));  
        nanmean(usdilsatmv(optionstartdate:optionenddate,4)),nanmedian(usdilsatmv(optionstartdate:optionenddate,4)),nanstd(usdilsatmv(optionstartdate:optionenddate,4)),min(usdilsatmv(optionstartdate:optionenddate,4)),max(usdilsatmv(optionstartdate:optionenddate,4)),corr(usdilsatmv(optionstartdate+1:optionenddate,4),usdilsatmv(optionstartdate:optionenddate-1,4),'rows','complete'), sum( ~isnan(usdilsatmv(optionstartdate:optionenddate,4)));
        nanmean(usdilsatmv(optionstartdate:optionenddate,5)),nanmedian(usdilsatmv(optionstartdate:optionenddate,5)),nanstd(usdilsatmv(optionstartdate:optionenddate,5)),min(usdilsatmv(optionstartdate:optionenddate,5)),max(usdilsatmv(optionstartdate:optionenddate,5)),corr(usdilsatmv(optionstartdate+1:optionenddate,5),usdilsatmv(optionstartdate:optionenddate-1,5),'rows','complete'), sum( ~isnan(usdilsatmv(optionstartdate:optionenddate,5)));  
        nanmean(usdilsatmv(optionstartdate:optionenddate,6)),nanmedian(usdilsatmv(optionstartdate:optionenddate,6)),nanstd(usdilsatmv(optionstartdate:optionenddate,6)),min(usdilsatmv(optionstartdate:optionenddate,6)),max(usdilsatmv(optionstartdate:optionenddate,6)),corr(usdilsatmv(optionstartdate+1:optionenddate,6),usdilsatmv(optionstartdate:optionenddate-1,6),'rows','complete'), sum( ~isnan(usdilsatmv(optionstartdate:optionenddate,6)))
];

%% Panel C


%% Monthly intervention

[num,~,raw]=xlsread([ini.dirs.raw '\Monthly intervention\monthly_data_matlab.xlsx']);
monthly_intervention=num(:,1);NERmonthly=num(:,4);usdilsmonthly=num(:,5);
monthly_intervention_dates=datenum(raw(2:end,1),'dd/mm/yyyy');

int_startdate=find(monthly_intervention_dates==datenum('01/01/2013','dd/mm/yyyy' ) ) ;
int_enddate=find(monthly_intervention_dates==datenum('31/12/2019','dd/mm/yyyy' ) ) ;

%% Panel D
monthly_intervention(monthly_intervention==0)=NaN;
PanelC=[nanmean(monthly_intervention(int_startdate:int_enddate,1)),nanmedian(monthly_intervention(int_startdate:int_enddate,1)),nanstd(monthly_intervention(int_startdate:int_enddate,1)),min(monthly_intervention(int_startdate:int_enddate,1)),max(monthly_intervention(int_startdate:int_enddate,1)), sum( ~isnan(monthly_intervention(int_startdate:int_enddate,1)))];

%% Some more indicators
load 'intervention'; load 'interventiondates';

%% calculate average length of intervention
%% first we want to make sure we start from 2013
T=find(interventiondates==datenum('01/01/2013','dd/mm/yyyy'));
idx1=find(interventiondates==datenum('31/12/2019','dd/mm/yyyy'));
count=0;
totalrun=[];
N=idx1-T+1;
for i=T:idx1
    if ~isnan(intervention(i) )
        count=count+1;
        if i==N 
        totalrun=[totalrun;count];
        end
    else
       totalrun=[totalrun;count];
        count=0;
    end
end

totalrun(totalrun==0)=NaN;
avg_spell=nanmean(totalrun);

%% Calendar weekly spells. We run on each week seperatley from Monday to Monday, tuesday to tuesday etc..
T=find(interventiondates==datenum('01/01/2013'));
for j=1:5 %% 5 days of the week
     k=1;
    for i=T-1+j:5:idx1-5
      weeklyint(k,j)=nansum(intervention(i:i+5)>0);
      k=k+1;
    end
end


weeklyint(weeklyint==0)=NaN;
weeklyavg=nanmean(nanmean(weeklyint,1));

%% gdp

gdp=readtable([ini.dirs.raw 'gdp stats\gdpnew.xlsx']);
idx=find(datenum(gdp.date)==datenum('31/12/2019','dd/mm/yyyy'));
gdpratio=nanmean( 100*(gdp.int(1:idx)./gdp.gdpus(1:idx)) ); %% us gdp

%% spot volume
%% spot volume
load voldates;
load fspotvol.mat;

% Use idx_end instead of idx to avoid variable name conflict
idx_end = length(interventiondates); % or whatever your original idx value should be

intdates = interventiondates(T:idx_end);
intdata = intervention(T:idx_end);

% Use intersect instead of ismember to get properly aligned arrays
[common_dates, vol_idx, int_idx] = intersect(voldates, intdates);

% Calculate volratio
if isempty(common_dates)
    warning('No common dates found');
    volratio = NaN;
else
    volratio = nanmean(intdata(int_idx) ./ fspotvol(vol_idx)) * 100;
    disp(['volratio: ', num2str(volratio)]);
end

% Create tabres
tabres = [gdpratio; volratio; avg_spell; weeklyavg];
disp('tabres:');
disp(tabres);