【问题标题】:Create dummy variables for turn-of-the-month MATLAB为月末 MATLAB 创建虚拟变量
【发布时间】:2015-06-09 11:20:30
【问题描述】:

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

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

问题是月份不等长(显然),并且数据不包括所有周末(使得不等长更加“不等”)。

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

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

我设法创建了一个表格,其中包含 1991 年至 2014 年不包括周末的日期和回报。第一列年份、第二个月、第三天和第四列:

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

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

@丹尼尔

Complete data for my indices is found here

【问题讨论】:

  • 举个例子——一些数据,你期望的结果让问题更容易理解
  • 更新详情@Daniel

标签: matlab dummy-data


【解决方案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,:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-27
    • 2021-11-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-23
    • 2018-04-06
    • 2020-01-31
    • 1970-01-01
    相关资源
    最近更新 更多