MATLAB routine for bootstrapping statistic hypothesis for calendar effects instock returns

Page 1

MATLAB routine for bootstrapping statistic hypothesis for calendar effects in stock returns Eleftherios Giovanis Abstract This paper presents a programming routine in MATLAB software for applications in calendar effects or anomalies in stock returns. The calendar effects which are tested is the turn-of-the-month, the day-of-the-Week, the month-of-the-Year and the semimonth effect. Keywords: calendar effects/anomalies, MATLAB, stock returns Introduction We find useful to provide the specific routine as it’s not perfect and can be modified in order to be improved, but also we provide it for application for further study and research as also for applications in other scientific fields , not only in finance and economics, but anywhere which the specific routine might has application. This script file has been used in the paper study of Giovanis (2009) and we don’t present the results and the methodology here, but only the MATLAB file. Also this methodology has its disadvantages because it’s based on probability and statistic theory and not in intelligent systems. Guide We provide a brief guide for using the script file. First we should mention that is not a function, but it’s a script file. Copy the following routine and open a new file in MATLAB and paste in the Editor window. You can save the file as you like. In the same folder you saved the script file you should also save the data files in order to call them when you run the function. The data file is constituted by two separate vectors in any calendar anomaly you examine. The first vector, which I called X, always stores the stock returns. The difference is on the second vector. For the day of the week effect the second column is a dummy variable taking values of 1, 2, 3, 4 and 5. 1 for Monday, 2 for Tuesday, 3 for Wednesday, 4 for Thursday and 5 for Friday. You can create this dummy very easy in Excel and with function “weekday”, just you need the date series you download the data. Also this dummy can be created also very easy in SPSS software. For the turn of the month and the semi month effect the second column is constituted by number of 1 to 31, which are the days of the month, for example 1 is 1st of the month and so on. The last effect, which is the month of the year effect you have in the second vector always a dummy variable of values of 1,2,3….12, which each one represents the month of the year. For example value 1 for January, 2 for February and so on up to 12 for December. I called the second vector as date_day. You can change the names but you need to make the necessary modifications in the whole script. The first option is which calendar effect you want to examine the second option is turn= 1 or 2, which means that 1 for turn of the month (TOM) effect and 2 for NTOM effect. The third option is day=1,2…5, which is 1 for Monday, 2 for Tuesday and so on. The fourth option is month=1 ,2,…12 which represent the month of the year, as

1 Electronic copy available at: http://ssrn.com/abstract=1522942


we mentioned above. The last option is fort for values 1 and 2 which means that value 1 represents the first fortnight and value 2 represents the second fortnight. The functions has been tested in MATLAB 7.6 R2008a as also in MATLAB 6.5 2002 edition. In the old edition you will encounter a problem that

??? Undefined function or variable 'nanvar'. Because it’s missed by MATLAB, so you have to find this function ('nanvar') in the newer editions and added in MATLAB toolbox.

The functions use 10,000 replications and the process is very fast, based on stock returns, so you can increase the number of replications or even to decrease it. For other more complicate time series data the process might be slower, depending on the nature of the data. Furthermore in this routine we apply simple bootstrap, while it ca be modified by setting up a double bootstrap or wild bootstrap.

References Giovanis, E. (2009), Calendar Effects in Fifty-five Stock Market Indices, Global Journal of Finance and Management, 1(2), pp.75-98.

2 Electronic copy available at: http://ssrn.com/abstract=1522942


MATLAB script file

load file.mat

% You can specify any name you like for example stock.mat

% Set up the calendar effects Calendar_effect=1 % 1 for the turn_of_the_month effect, 2 for the % day_of_the_Week effect, 3 for the month_of_the_Year effect %and 4 for the semi_month effect. n=length(X);

% Set up the dates for each calendar effect turn=1 % 1 for turn_of_the_month effect (TOM) and 2 for no % turn_of_the_month effect (NTOM) day=1

month=1 fort=1

% 1 for Monday, 2 for Tuesday, 3 for Wednesday, 4 for Thursday % and 5 for Friday % 1 for January, 2 for February..... and 12 for December % 1 for first fortnight and 2 for second fortnight % of the month

if Calendar_effect==1 if turn==1 TOM=find(date_day==1 | date_day==2 | date_day==3 | date_day==30 date_day==31) sample1=X(TOM) All_TOM =find(date_day>=4& date_day<=29) sample2 = X(All_TOM) elseif turn==2 NTOM= find(date_day>=4& date_day<=29) sample1=X(NTOM) TOM=find(date_day==1 | date_day==2 | date_day==3 | date_day==30 date_day==31) sample2 = X(TOM) end

elseif Calendar_effect==2 if day==1 MON=find(date_day==1) sample1=X(MON) All_days= find(date_day==2 | date_day==3 | date_day==4 | date_day==5) sample2 = X(All_days) elseif day==2

3

|

|


TUE=find(date_day==2) sample1=X(TUE) All_days= find(date_day==1 | date_day==3 | date_day==4 | date_day==5) sample2 = X(All_days) elseif day==3 WED=find(date_day==3) sample1=X(WED) All_days= find(date_day==1 | date_day==2 | date_day==4 | date_day==5) sample2 = X(All_days) elseif day==4 THU=find(date_day==4) sample1=X(THU) All_days= find(date_day==1 | date_day==2 | date_day==3 | date_day==5) sample2 = X(All_days) elseif day==5 FRI=find(date_day==5) sample1=X(FRI) All_days= find(date_day==1 | date_day==2 | date_day==3 | date_day==4) sample2 = X(All_days) end

elseif Calendar_effect==3 if month==1 JAN=find(date_day==1) sample1=X(JAN) All_JAN =find(date_day==2|date_day==3|date_day==4|date_day==5|date_day==6.... |date_day==7|date_day==8|date_day==9|date_day==10|date_day==11|date_day==12) sample2 = X(All_JAN) elseif month==2 FEB=find(date_day==2) sample1=X(FEB) All_FEB =find(date_day==1|date_day==3|date_day==4|date_day==5|date_day==6.... |date_day==7|date_day==8|date_day==9|date_day==10|date_day==11|date_day==12) sample2 = X(All_FEB)

elseif month==3 MAR=find(date_day==3) sample1=X(MAR) All_MAR =find(date_day==1|date_day==2|date_day==4|date_day==5|date_day==6.... |date_day==7|date_day==8|date_day==9|date_day==10|date_day==11|date_day==12) sample2 = X(All_MAR)

4


elseif month==4 APR=find(date_day==4) sample1=X(APR) All_APR =find(date_day==1|date_day==2|date_day==3|date_day==5|date_day==6.... |date_day==7|date_day==8|date_day==9|date_day==10|date_day==11|date_day==12) sample2 = X(All_APR) elseif month==5 MAY=find(date_day==5) sample1=X(MAY) All_MAY =find(date_day==1|date_day==2|date_day==3|date_day==4|date_day==6.... |date_day==7|date_day==8|date_day==9|date_day==10|date_day==11|date_day==12) sample2 = X(All_MAY) elseif month==6 JUNE=find(date_day==6) sample1=X(JUNE) All_JUNE =find(date_day==1|date_day==2|date_day==3|date_day==4|date_day==5.... |date_day==7|date_day==8|date_day==9|date_day==10|date_day==11|date_day==12) sample2 = X(All_JUNE) elseif month==7 JULY=find(date_day==7) sample1=X(JULY) All_JULY =find(date_day==1|date_day==2|date_day==3|date_day==4|date_day==5.... |date_day==6|date_day==8|date_day==9|date_day==10|date_day==11|date_day==12) sample2 = X(All_JULY) elseif month==8 AUG=find(date_day==8) sample1=X(AUG) All_AUG =find(date_day==1|date_day==2|date_day==3|date_day==4|date_day==5.... |date_day==6|date_day==7|date_day==9|date_day==10|date_day==11|date_day==12) sample2 = X(All_AUG) elseif month==9 SEP=find(date_day==9) sample1=X(SEP) All_SEP =find(date_day==1|date_day==2|date_day==3|date_day==4|date_day==5.... |date_day==6|date_day==7|date_day==8|date_day==10|date_day==11|date_day==12) sample2 = X(All_SEP) elseif month==10 OCT=find(date_day==10) sample1=X(OCT) All_OCT =find(date_day==1|date_day==2|date_day==3|date_day==4|date_day==5....

5


|date_day==6|date_day==7|date_day==8|date_day==9|date_day==11|date_day==12) sample2 = X(All_OCT) elseif month==11 NOV=find(date_day==11) sample1=X(NOV) All_NOV =find(date_day==1|date_day==2|date_day==3|date_day==4|date_day==5.... |date_day==6|date_day==7|date_day==8|date_day==9|date_day==10|date_day==12) sample2 = X(All_NOV) elseif month==12 DEC=find(date_day==12) sample1=X(DEC) All_DEC =find(date_day==1|date_day==2|date_day==3|date_day==4|date_day==5.... |date_day==6|date_day==7|date_day==8|date_day==9|date_day==10|date_day==11) sample2 = X(All_DEC) end elseif Calendar_effect==4 if fort==1 FIRST_FORT=find(date_day>=1 & date_day<=15) sample1=X(FIRST_FORT) SECOND_FORT=find(date_day>=16 & date_day<=31) sample2 = X(SECOND_FORT) elseif fort==1 SECOND_FORT=find(date_day>=16 & date_day<=31) sample1 = X(SECOND_FORT) FIRST_FORT=find(date_day>=1 & date_day<=15) sample2=X(FIRST_FORT) end end difference = nanmean(sample1) - nanmean(sample2); s2sample1 = nanvar(sample1) s2sample2 = nanvar(sample2) nsample1=size(sample1) nsample2=size(sample2) dfe = nsample1 + nsample2 - 2; sPooled = sqrt(((nsample1-1) .* s2sample1 + (nsample2-1) .* s2sample2) ./ dfe); se = sPooled .* sqrt(1./nsample1 + 1./nsample2); tratio = difference ./ se; tratio=tratio(1,1) bootsample1=bootstrp(10000,@nanmean, sample1); bootsample2=bootstrp(10000,@nanmean, sample2); meanbootsample1=mean(bootsample1) meanbootsample2=mean(bootsample2) meansample1=nanmean(sample1) meansample2=nanmean(sample2)

6


difr1=(bootsample1-bootsample2) difr2=(meansample1-meansample2) bootdifference = difr1-difr2; bootse=std((bootsample1-bootsample2)-(meanbootsample1-meanbootsample2)) boottratio = bootdifference ./ bootse; y1 = quantile(boottratio(:,1),.05); y2= quantile(boottratio(:,1),.95); low=quantile(bootsample1,.05) high=quantile(bootsample1,.95) y=[y1 y2] if tratio<y2 h1 =0 else tratio>y2 h1=1 end if tratio>y1 h2 =0 else tratio<y1 h2=1 end

7


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.