%% Load daily spot volume.
alldates=[];
allvol=[];

% Define base path for volume data
volume_path = '..\_data\volume\';

%% 2008

data=readtable([volume_path 'trdvol08.xls'],'Sheet','January');
dates=data.Var1(4:end);
vol=data.Var21(4:end);
allvol=[allvol;vol];
alldates=[alldates;dates];

data=readtable([volume_path 'trdvol08.xls'],'Sheet','February');
dates=data.Var1(4:end);
vol=data.Var21(4:end);
allvol=[allvol;vol];
alldates=[alldates;dates];

data=readtable([volume_path 'trdvol08.xls'],'Sheet','March');
dates=data.Var1(4:end);
vol=data.Var21(4:end);
allvol=[allvol;vol];
alldates=[alldates;dates];

data=readtable([volume_path 'trdvol08.xls'],'Sheet','April');
dates=data.Var1(4:end);
vol=data.Var21(4:end);
allvol=[allvol;vol];
alldates=[alldates;dates];

data=readtable([volume_path 'trdvol08.xls'],'Sheet','May');
dates=data.Var1(4:end);
vol=data.Var21(4:end);
allvol=[allvol;vol];
alldates=[alldates;dates];

data=readtable([volume_path 'trdvol08.xls'],'Sheet','June');
dates=data.Var1(4:end);
vol=data.Var21(4:end);
allvol=[allvol;vol];
alldates=[alldates;dates];

data=readtable([volume_path 'trdvol08.xls'],'Sheet','July');
dates=data.Var1(4:end);
vol=data.Var21(4:end);
allvol=[allvol;vol];
alldates=[alldates;dates];

data=readtable([volume_path 'trdvol08.xls'],'Sheet','August');
dates=data.Var1(4:end);
vol=data.Var21(4:end);
allvol=[allvol;vol];
alldates=[alldates;dates];

data=readtable([volume_path 'trdvol08.xls'],'Sheet','September');
dates=data.Var1(4:end);
vol=data.Var21(4:end);
allvol=[allvol;vol];
alldates=[alldates;dates];

data=readtable([volume_path 'trdvol08.xls'],'Sheet','October');
dates=data.Var1(4:end);
vol=data.Var21(4:end);
allvol=[allvol;vol];
alldates=[alldates;dates];

data=readtable([volume_path 'trdvol08.xls'],'Sheet','November');
dates=data.Var1(4:end);
vol=data.Var21(4:end);
allvol=[allvol;vol];
alldates=[alldates;dates];

data=readtable([volume_path 'trdvol08.xls'],'Sheet','December');
dates=data.Var1(4:end);
vol=data.Var21(4:end);
allvol=[allvol;vol];
alldates=[alldates;dates];

%% 2009
%data=readtable([volume_path 'trdvol09.xls'],'Sheet','יומי');
[data,raw]=xlsread([volume_path 'trdvol09.xls'],'יומי');
dates=raw(11:end,1);
dates=datetime(dates);
vol=data(5:end,1);
[~,idx]=sortrows(dates);
dates=dates(idx);
vol=vol(idx);

allvol=[allvol;vol];
alldates=[alldates;dates];

%% 2010

[data,raw]=xlsread([volume_path 'trdvol10.xls'],'יומי');
dates=raw(7:end,1);
dates=datetime(dates);
vol=data(1:end,1);
[~,idx]=sortrows(dates);
dates=dates(idx);
vol=vol(idx);

allvol=[allvol;vol];
alldates=[alldates;dates];


%% 2011

[data,raw]=xlsread([volume_path 'trdvol11.xls'],'יומי');
dates=raw(7:end,1);
dates=datetime(dates);
vol=data(1:end,1);
[~,idx]=sortrows(dates);
dates=dates(idx);
vol=vol(idx);

allvol=[allvol;vol];
alldates=[alldates;dates];

%% 2012

[data,raw]=xlsread([volume_path 'trdvol12.xls'],'יומי');
dates=raw(7:end,1);
dates=datetime(dates,"Format",'dd/MM/yy');
vol=data(1:end,1);
[~,idx]=sortrows(dates);
dates=dates(idx);
vol=vol(idx);

allvol=[allvol;vol];
alldates=[alldates;dates];

%% 2013

[data,raw]=xlsread([volume_path 'trdvol13.xls'],'יומי');
dates=raw(7:end,1);
dates=datetime(dates);
vol=data(1:end,1);
[~,idx]=sortrows(dates);
dates=dates(idx);
vol=vol(idx);

allvol=[allvol;vol];
alldates=[alldates;dates];

%% 2014

[data,raw]=xlsread([volume_path 'trdvol14.xls'],'יומי');
dates=raw(7:end,1);
dates=datetime(dates);
vol=data(1:end,1);
[~,idx]=sortrows(dates);
dates=dates(idx);
vol=vol(idx);

allvol=[allvol;vol];
alldates=[alldates;dates];

%% 2015

[data,raw]=xlsread([volume_path 'trdvol15.xls'],'יומי');
dates=raw(7:end,1);
dates=datetime(dates);
vol=data(1:end,1);
[~,idx]=sortrows(dates);
dates=dates(idx);
vol=vol(idx);

allvol=[allvol;vol];
alldates=[alldates;dates];

%% 2016

[data,raw]=xlsread([volume_path 'trdvol16.xls'],'יומי');
dates=raw(7:end,1);
dates=datetime(dates);
vol=data(1:end,1);
[~,idx]=sortrows(dates);
dates=dates(idx);
vol=vol(idx);

allvol=[allvol;vol];
alldates=[alldates;dates];

%% 2017

[data,raw]=xlsread([volume_path 'trdvol17.xlsx'],'יומי_1');
dates=raw(7:end,1);
dates=datetime(dates);
vol=data(1:end,1);
[~,idx]=sortrows(dates);
dates=dates(idx);
vol=vol(idx);

allvol=[allvol;vol];
alldates=[alldates;dates];

%% 2018

[data,raw]=xlsread([volume_path 'trdvol18.xlsx'],'יומי_1');
dates=raw(7:end,1);
dates=datetime(dates);
vol=data(1:end,1);
[~,idx]=sortrows(dates);
dates=dates(idx);
vol=vol(idx);

allvol=[allvol;vol];
alldates=[alldates;dates];

%% 2019

[data,raw]=xlsread([volume_path 'trdvol19.xlsx'],'יומי_1');
dates=raw(7:end,1);
dates=datetime(dates);
vol=data(1:end,1);
[~,idx]=sortrows(dates);
dates=dates(idx);
vol=vol(idx);

allvol=[allvol;vol];
alldates=[alldates;dates];
spotvol=allvol;
spotdates=alldates;

%% Eliminate sunday and sat.
idx=weekday(spotdates);
spotdates=spotdates(idx>1);
spotvol=spotvol(idx>1);

idx=weekday(spotdates);
spotdates=spotdates(idx<7);
spotvol=spotvol(idx<7);

spotvol=spotvol(idx); %% looks like we have some repetitions
[spotdates,idx]=unique(spotdates);

save('spotvol','spotvol');
save('spotdates','spotdates');


allvol=[allvol;vol];
alldates=[alldates;dates];