为每月的 MATLAB 创建虚拟变量

Create dummy variables for turn-of-the-month MATLAB

我有一个指数的每日收盘值,我想为每个月最后一天前后的特定天数创建虚拟变量。

说前 4 天和后 4 天。总共9天。我有23年的数据。

问题是月份的长度不等(很明显)并且数据不包括所有周末(使得不等长度更加"unequal")。

如何以有效的方式为数据创建虚拟变量,而无需手动检查超过 6000 个观察值并确定每月最后一天之前 4 天和之后 4 天的日期?

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

我已经成功地创建了一个 table 日期和 returns 从 1991 年到 2014 年不包括周末。第一列年份,第二个月,第三天和第四 returns:

现在我想为该月最后一个工作日之前的 X 天数和该月最后一天之后的 X 天数创建虚拟变量。说9天。所以假人 D-9、D-8...T、D+1、D+2...D+9。 T = 该月的最后一天。共有 19 个假人。剩下的日子会有单独的dummy,ROM。然后我将这些用作 returns.

上的回归变量

我的预期结果将是所有虚拟变量的系数,这些变量描述了每个月选定的日期(月末前后的 19 天)和本月剩余时间(ROM ).它应该看起来像这样:

@丹尼尔

Complete data for my indices is found here

%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,:)