%% There are six maturities and 28 pairs
cd([ini.dirs.results.raw '/Figure E.1']);
%% ATMV: here ask is first: ask,bid,last,mid
[atmv,raw]=xlsread([ini.dirs.raw 'option liquidity/atmv.xlsx'],'atmv');
atmvdates=datenum(raw(3:end,1),'dd/mm/yyyy');
idx=find(atmvdates==datenum('01/01/2013','dd/mm/yyyy'));
idx1=find(atmvdates==datenum('31/12/2020','dd/mm/yyyy'));

atmvspread=atmv(idx:idx1,1:4:end)-atmv(idx:idx1,2:4:end);
atmvmidpoint=(atmv(idx:idx1,1:4:end)-atmv(idx:idx1,2:4:end))./atmv(idx:idx1,3:4:end);

%% midpoint
oneweek=nanmean(atmvmidpoint(:,1:28),1);
onemonth=nanmean(atmvmidpoint(:,29:29+27),1);
threemonth=nanmean(atmvmidpoint(:,57:57+27),1);
sixmonth=nanmean(atmvmidpoint(:,85:85+27),1);
ninemonth=nanmean(atmvmidpoint(:,113:113+27),1);
twelvemonth=nanmean(atmvmidpoint(:,141:141+27),1);
ilsoneweek=oneweek(2);ilsonemonth=onemonth(2);ilsthreemonth=threemonth(2);ilssixmonth=sixmonth(2);ilsninemonth=ninemonth(2);ilstwelvemonth=twelvemonth(2);
total=[oneweek';onemonth';threemonth';sixmonth';ninemonth';twelvemonth'];
x=[ones(28,1);2*ones(28,1);3*ones(28,1);4*ones(28,1);5*ones(28,1);6*ones(28,1)];

boxplot(total,x,'Labels',{'1 W','1 M','3 M','6 M','9 M','12 M'}); hold on;plot(1,ilsoneweek,'o','color','black');hold on;plot(2,ilsonemonth,'o','color','black');hold on;plot(3,ilsthreemonth,'o','color','black');hold on;plot(4,ilssixmonth,'o','color','black');
hold on;plot(5,ilsninemonth,'o','color','black');plot(6,ilstwelvemonth,'o','color','black');
legend('1 W ILS BAS','1 M ILS BAS','3 M ILS BAS','6 M ILS BAS','9 M ILS BAS','12 M ILS BAS')
ylabel({'ATMV BAS'})
set(gca,'fontsize',22);
set(gca,'fontsize',22);
set(gcf, 'Position', get(0, 'Screensize')); %% full screen figure
saveas(gcf,'Figure E.1.pdf')
close(gcf);

%% spread
oneweek=nanmean(atmvspread(:,1:28),1);
onemonth=nanmean(atmvspread(:,29:29+27),1);
threemonth=nanmean(atmvspread(:,57:57+27),1);
sixmonth=nanmean(atmvspread(:,85:85+27),1);
ninemonth=nanmean(atmvspread(:,113:113+27),1);
twelvemonth=nanmean(atmvspread(:,141:141+27),1);


%% RR: here ask is first: ask,bid,last
cd([ini.dirs.results.raw '/Figure E.2']);
[rr10,raw]=xlsread([ini.dirs.raw 'option liquidity/rr.xlsx'],'10');
[rr25]=xlsread([ini.dirs.raw 'option liquidity/rr.xlsx'],'25');
rrdates=datenum(raw(3:end,1),'dd/mm/yyyy');
idx=find(rrdates==datenum('01/01/2013','dd/mm/yyyy'));
idx1=find(rrdates==datenum('31/12/2020','dd/mm/yyyy'));

rr10spread=rr10(idx:idx1,1:3:end)-rr10(idx:idx1,2:3:end);
rr25spread=rr25(idx:idx1,1:3:end)-rr25(idx:idx1,2:3:end);

rr10midpoint=(rr10(idx:idx1,1:3:end)-rr10(idx:idx1,2:3:end))./atmv(idx:idx1,3:4:end);
rr25midpoint=(rr25(idx:idx1,1:3:end)-rr25(idx:idx1,2:3:end))./atmv(idx:idx1,3:4:end);

%% midpoint
oneweek=nanmean(0.5*rr10midpoint(:,1:28)+0.5*rr25midpoint(:,1:28),1);
onemonth=nanmean(0.5*rr10midpoint(:,29:29+27)+0.5*rr25midpoint(:,29:29+27),1);
threemonth=nanmean(0.5*rr10midpoint(:,57:57+27)+0.5*rr25midpoint(:,57:57+27),1);
sixmonth=nanmean(0.5*rr10midpoint(:,85:85+27)+0.5*rr25midpoint(:,85:85+27),1);
ninemonth=nanmean(0.5*rr10midpoint(:,113:113+27)+0.5*rr25midpoint(:,113:113+27),1);
twelvemonth=nanmean(0.5*rr10midpoint(:,141:141+27)+0.5*rr25midpoint(:,141:141+27),1);

ilsoneweek=oneweek(2);ilsonemonth=onemonth(2);ilsthreemonth=threemonth(2);ilssixmonth=sixmonth(2);ilsninemonth=ninemonth(2);ilstwelvemonth=twelvemonth(2);
total=[oneweek';onemonth';threemonth';sixmonth';ninemonth';twelvemonth'];
x=[ones(28,1);2*ones(28,1);3*ones(28,1);4*ones(28,1);5*ones(28,1);6*ones(28,1)];

boxplot(total,x,'Labels',{'1 W','1 M','3 M','6 M','9 M','12 M'}); hold on;plot(1,ilsoneweek,'o','color','black');hold on;plot(2,ilsonemonth,'o','color','black');hold on;plot(3,ilsthreemonth,'o','color','black');hold on;plot(4,ilssixmonth,'o','color','black');
hold on;plot(5,ilsninemonth,'o','color','black');plot(6,ilstwelvemonth,'o','color','black');
legend('1 W ILS BAS','1 M ILS BAS','3 M ILS BAS','6 M ILS BAS','9 M ILS BAS','12 M ILS BAS')
ylabel({'RR BAS'})
set(gca,'fontsize',22);
set(gcf, 'Position', get(0, 'Screensize')); %% full screen figure
saveas(gcf,'Figure E.2.pdf')
close(gcf);
%% spread
oneweek=nanmean(0.5*rr10spread(:,1:28)+0.5*rr25spread(:,1:28),1);
onemonth=nanmean(0.5*rr10spread(:,29:29+27)+0.5*rr25spread(:,29:29+27),1);
threemonth=nanmean(0.5*rr10spread(:,57:57+27)+0.5*rr25spread(:,57:57+27),1);
sixmonth=nanmean(0.5*rr10spread(:,85:85+27)+0.5*rr25spread(:,85:85+27),1);
ninemonth=nanmean(0.5*rr10spread(:,113:113+27)+0.5*rr25spread(:,113:113+27),1);
twelvemonth=nanmean(0.5*rr10spread(:,141:141+27)+0.5*rr25spread(:,141:141+27),1);

%% BF here bid is first. bid,ask,mid,last
cd([ini.dirs.results.raw '/Figure E.3']);
[bf10,raw]=xlsread([ini.dirs.raw 'option liquidity/bf.xlsx'],'10');
[bf25]=xlsread([ini.dirs.raw 'option liquidity/bf.xlsx'],'25');
bfdates=datenum(raw(3:end,1),'dd/mm/yyyy');
idx=find(bfdates==datenum('01/01/2013','dd/mm/yyyy'));
idx1=find(bfdates==datenum('31/12/2020','dd/mm/yyyy'));

bf10spread=bf10(idx:idx1,2:4:end)-bf10(idx:idx1,1:4:end);
bf25spread=bf25(idx:idx1,2:4:end)-bf25(idx:idx1,1:4:end);

bf10midpoint=(bf10(idx:idx1,2:4:end)-bf10(idx:idx1,1:4:end))./atmv(idx:idx1,3:4:end);
bf25midpoint=(bf25(idx:idx1,2:4:end)-bf25(idx:idx1,1:4:end))./atmv(idx:idx1,3:4:end);

%% midpoint
oneweek=nanmean(0.5*bf10midpoint(:,1:28)+0.5*bf25midpoint(:,1:28),1);
onemonth=nanmean(0.5*bf10midpoint(:,29:29+27)+0.5*bf25midpoint(:,29:29+27),1);
threemonth=nanmean(0.5*bf10midpoint(:,57:57+27)+0.5*bf25midpoint(:,57:57+27),1);
sixmonth=nanmean(0.5*bf10midpoint(:,85:85+27)+0.5*bf25midpoint(:,85:85+27),1);
ninemonth=nanmean(0.5*bf10midpoint(:,113:113+27)+0.5*bf25midpoint(:,113:113+27),1);
twelvemonth=nanmean(0.5*bf10midpoint(:,141:141+27)+0.5*bf25midpoint(:,141:141+27),1);

ilsoneweek=oneweek(2);ilsonemonth=onemonth(2);ilsthreemonth=threemonth(2);ilssixmonth=sixmonth(2);ilsninemonth=ninemonth(2);ilstwelvemonth=twelvemonth(2);
total=[oneweek';onemonth';threemonth';sixmonth';ninemonth';twelvemonth'];
x=[ones(28,1);2*ones(28,1);3*ones(28,1);4*ones(28,1);5*ones(28,1);6*ones(28,1)];

boxplot(total,x,'Labels',{'1 W','1 M','3 M','6 M','9 M','12 M'}); hold on;plot(1,ilsoneweek,'o','color','black');hold on;plot(2,ilsonemonth,'o','color','black');hold on;plot(3,ilsthreemonth,'o','color','black');hold on;plot(4,ilssixmonth,'o','color','black');
hold on;plot(5,ilsninemonth,'o','color','black');plot(6,ilstwelvemonth,'o','color','black');
legend('1 W ILS BAS','1 M ILS BAS','3 M ILS BAS','6 M ILS BAS','9 M ILS BAS','12 M ILS BAS')
ylabel({'BF BAS'})
set(gca,'fontsize',22);
set(gcf, 'Position', get(0, 'Screensize')); %% full screen figure
saveas(gcf,'Figure E.3.pdf')
close(gcf);
%% spread
oneweek=nanmean(0.5*bf10spread(:,1:28)+0.5*bf25spread(:,1:28),1);
onemonth=nanmean(0.5*bf10spread(:,29:29+27)+0.5*bf25spread(:,29:29+27),1);
threemonth=nanmean(0.5*bf10spread(:,57:57+27)+0.5*bf25spread(:,57:57+27),1);
sixmonth=nanmean(0.5*bf10spread(:,85:85+27)+0.5*bf25spread(:,85:85+27),1);
ninemonth=nanmean(0.5*bf10spread(:,113:113+27)+0.5*bf25spread(:,113:113+27),1);
twelvemonth=nanmean(0.5*bf10spread(:,141:141+27)+0.5*bf25spread(:,141:141+27),1);