addBusinessCalendar
Add business calendar awareness to timetables
Description
                sets additional options specified by one or more name-value arguments, using any of
                the input arguments in the previous syntax. For example, TT = addBusinessCalendar(___,Name=Value)TT =
                    addBusinessCalendar(TT,Holidays=H) replaces the default holidays
                stored in Data_NYSE_Closures.mat with the list of holidays
                    H.
Examples
This example shows how to add a business calendar when you calculate period-over-period (PoP) rolling differences for 5 years of simulated daily prices. For each date in timetable TT, the difference represents the PoP difference of the corresponding price compared to the price one period earlier. 
Use holidays to indicate the holidays in holidays.m for the simulation period. 
H = holidays(datetime(2014,1,1),datetime(2018,12,31));
Simulate daily prices for three assets.
t = (datetime(2014,1,1):caldays:datetime(2018,12,31))';
rng(200,"twister")
Price = 100 + 0.1*(0:numel(t) - 1)'.*cumsum(randn(numel(t),1)/100); 
Price = round(Price*100)/100;       
Price2 = round(Price*94)/100; 
Price3 = round(Price*88)/100;
TT    = timetable(Price,Price2,Price3,RowTimes=t);
head(TT,15)       Time        Price     Price2    Price3
    ___________    ______    ______    ______
    01-Jan-2014       100       94        88 
    02-Jan-2014       100       94        88 
    03-Jan-2014       100       94        88 
    04-Jan-2014       100       94        88 
    05-Jan-2014    100.01    94.01     88.01 
    06-Jan-2014    100.01    94.01     88.01 
    07-Jan-2014    100.02    94.02     88.02 
    08-Jan-2014    100.02    94.02     88.02 
    09-Jan-2014    100.04    94.04     88.04 
    10-Jan-2014    100.06    94.06     88.05 
    11-Jan-2014    100.08    94.08     88.07 
    12-Jan-2014    100.11     94.1      88.1 
    13-Jan-2014    100.11     94.1      88.1 
    14-Jan-2014    100.12    94.11     88.11 
    15-Jan-2014    100.12    94.11     88.11 
 Use addBusinessCalendar to indicate the holidays for the simulation period in the timetable TT.
TT = addBusinessCalendar(TT,Holidays=H);
Use rollingreturns with the 'Method' name-value pair argument set to "difference" to compute the differences, that is, the period-over-period changes. 
deltas = rollingreturns(TT,Period=calweeks(1),Method="difference");
head(deltas,15)       Time        Price_Difference_1w    Price2_Difference_1w    Price3_Difference_1w
    ___________    ___________________    ____________________    ____________________
    01-Jan-2014            NaN                     NaN                     NaN        
    02-Jan-2014            NaN                     NaN                     NaN        
    03-Jan-2014            NaN                     NaN                     NaN        
    04-Jan-2014            NaN                     NaN                     NaN        
    05-Jan-2014            NaN                     NaN                     NaN        
    06-Jan-2014            NaN                     NaN                     NaN        
    07-Jan-2014            NaN                     NaN                     NaN        
    08-Jan-2014            NaN                     NaN                     NaN        
    09-Jan-2014           0.04                    0.04                    0.04        
    10-Jan-2014           0.06                    0.06                    0.05        
    11-Jan-2014           0.08                    0.08                    0.07        
    12-Jan-2014           0.11                     0.1                     0.1        
    13-Jan-2014            0.1                    0.09                    0.09        
    14-Jan-2014            0.1                    0.09                    0.09        
    15-Jan-2014            0.1                    0.09                    0.09        
Input Arguments
Input timetable to update with business calendar awareness, specified as a
                            timetable.
Data Types: timetable
Name-Value Arguments
Specify optional pairs of arguments as
      Name1=Value1,...,NameN=ValueN, where Name is
      the argument name and Value is the corresponding value.
      Name-value arguments must appear after other arguments, but the order of the
      pairs does not matter.
    
      Before R2021a, use commas to separate each name and value, and enclose 
      Name in quotes.
    
Example: TT = addBusinessCalendar(TT,Holidays=H) replaces the
                default holidays stored in Data_NYSE_Closures.mat with the list
                of holidays H
Alternate holidays and market closure dates, specified as a datetime
                            vector. The dates in Holidays must be whole dates
                            without HH:MM:SS components. No business is conducted
                            on the dates in Holidays.
By default, Holidays is the New York Stock
                            Exchange (NYSE) holidays and market closure dates. For more details,
                            load the default holidays in Data_NYSE_Closures.mat
                            and inspect the NYSE variable, or, if you have a
                                Financial Toolbox™ license, see holidays and isbusday.
Tip
If you have a Financial Toolbox license, you can generate alternate holiday schedules
                                by using the createholidays
                                function and  performing this procedure:
Generate a new
holidaysfunction usingcreateholidays.Call the new
holidaysfunction to get the list of holidays.Specify the alternate holidays to
addBusinessCalendarby using theHolidaysname-value argument.
Data Types: datetime
Alternate weekend days on which no business is conducted, specified as a length 7 logical vector or a string vector.
For a logical vector, true (1)
                            entries indicate a weekend day and false
                                (0) entries indicate a weekday, where entries
                            correspond to Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and
                            Saturday.
Example: Weekends=[1 0 0 0 0 1 1] specifies that
                            business is not conducted on Fridays through Sundays.
For a string vector, entries explicitly list the weekend days.
Example: Weekends=["Friday" "Saturday"
                            "Sunday"]
Tip
If business is conducted seven days per week, set
                                    Weekends to [0 0 0 0 0 0
                                    0].
Data Types: logical
Output Arguments
Updated timetable TT with added business calendar
                        awareness by the custom property BusinessCalendar,
                        returned as a timetable.
The custom property BusinessCalendar contains a data
                        structure that contains a field IsBusinessDay that stores
                        a callable function (F). The function
                            F accepts a datetime matrix (D)
                        and returns a logical indicator matrix (I) of the same
                        size: I = F(D). true
                            (1) elements of I indicate that
                        the corresponding element of D occurs on a business day;
                            false (0) elements of
                            I indicate otherwise.
Access the callable function F by using F =
                            TT.Properties.CustomProperties.BusinessCalendar.IsBusinessDay.
Version History
Introduced in R2020b
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
 - Canada (English)
 - United States (English)
 
Europe
- Belgium (English)
 - Denmark (English)
 - Deutschland (Deutsch)
 - España (Español)
 - Finland (English)
 - France (Français)
 - Ireland (English)
 - Italia (Italiano)
 - Luxembourg (English)
 
- Netherlands (English)
 - Norway (English)
 - Österreich (Deutsch)
 - Portugal (English)
 - Sweden (English)
 - Switzerland
 - United Kingdom (English)