How to find the first business date of the week in MATLAB?

We can use fbusdate to get the first business day of the month:

 Date = fbusdate(Year, Month); 

However, how do we get the first working day of the week?

As an example, during the week that I publish, Monday 09/07/2017 was a holiday in the USA:

 isbusday(736942) % = 0 

How to determine that the first working day this week will be the next day 736943 ?

+5
source share
3 answers

I decided. Here is a function based on @ m7913d's answer:

 function Busday = fbusdateweek(date) % Return the first business day after Sunday % 'date' is a datenum input dperiod = date-6:date; sundays = weekday(dperiod)==1; sunday = find(sundays==1,1,'first'); datesunday = dperiod(sunday); % --> Busday = busdate(datesunday); end 
+1
source

I don't know the built-in function that returns the first business day of the week, but you can get it by requesting the next business day after Sunday:

 busdate(736941); % 736941 = Sunday 09/03/2017 
+4
source

Your desired fbusdateweek function can be executed on one line, using only the weekday function to get the first Sunday of the week then busdate to get the next business day after that:

 dn = 736942; % Date number for any day in a week Date = busdate(dn-weekday(dn)+1); 


Note. busdate uses the holidays function by default to get all holidays and special days without a trend for the New York Stock Exchange. If necessary, you can use an alternative set of holidays for busdate as follows:

 holidayArray = ...; % Some set of date numbers, vectors, or datetimes Date = busdate(dn-weekday(dn)+1, 1, holidayArray); 

This way you can define a set of localized holidays.

+4
source

Source: https://habr.com/ru/post/1271613/


All Articles