2

I have daily closing values of an index and I want to create dummy variables for a specific number of days before and after the last day of each month.

Say 4 days before and 4 days after. Total 9 days. I have 23 years of data.

The thing is that the months are not of equal length (obviously) and the data is exclusive of all weekends (making the unequal length even more "unequal").

How do I create dummy variables for the data in an effective way without having to manually go through over 6000 observations and pin point dates that are 4 days before and 4 days after the last day of the month?

%------------------------

I have managed to create a table with dates and returns from 1991 to 2014 excluding weekends. First column years, second months, third day and, fourth returns:

enter image description here

Now I want to create dummy variables for X number of days before the last business day of the month and X number of days after the last day of the month. Say 9 days. So dummies D-9, D-8... T, D+1, D+2... D+9. T=last day of the month. Total of 19 dummies. The rest of the days will have a separate dummy, ROM. I then use these as regressors on the returns.

enter image description here

My expected result will be coefficients for all dummies that describe the returns on each chosen day of the month (19 days around the turn-of-the-month) and the rest of the month (ROM). It should look something like this:

enter image description here

@Daniel

Complete data for my indices is found here

user3934760
  • 95
  • 2
  • 10

1 Answers1

1
%shorter period for demonstration purposes
startday = datenum(2015,1,1);
endday = datenum(2015,3,1);
%just make sure our calendar contains enough data so every interesting day is included
startday=startday-27;
endday=endday+27;
alldays=startday:endday;
alldaysvec=datevec(alldays);
%logical vector which is true for mon-friday. Might be updated to reflect holidays as well
workday=weekday(alldays)<=6&weekday(alldays)>=2;
%create a calendar with only the bussines days in it:
wdays=alldaysvec(workday,:);
%identify days where month is changed
closing_days=find(diff(wdays(:,2))~=0);
%closing days
wdays(closing_days,:)
%days three bussines days after the closing days
wdays(closing_days+3,:)
Daniel
  • 36,610
  • 3
  • 36
  • 69