pandas-market-calendars 5.1.0__py3-none-any.whl → 5.1.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pandas_market_calendars/__init__.py +39 -39
 - pandas_market_calendars/calendar_registry.py +58 -57
 - pandas_market_calendars/calendar_utils.py +1151 -1151
 - pandas_market_calendars/calendars/asx.py +100 -70
 - pandas_market_calendars/calendars/bmf.py +225 -219
 - pandas_market_calendars/calendars/bse.py +433 -425
 - pandas_market_calendars/calendars/cboe.py +153 -149
 - pandas_market_calendars/calendars/cme.py +417 -405
 - pandas_market_calendars/calendars/cme_globex_agriculture.py +172 -172
 - pandas_market_calendars/calendars/cme_globex_base.py +127 -119
 - pandas_market_calendars/calendars/cme_globex_crypto.py +166 -158
 - pandas_market_calendars/calendars/cme_globex_energy_and_metals.py +224 -216
 - pandas_market_calendars/calendars/cme_globex_equities.py +131 -123
 - pandas_market_calendars/calendars/cme_globex_fixed_income.py +136 -136
 - pandas_market_calendars/calendars/cme_globex_fx.py +101 -101
 - pandas_market_calendars/calendars/eurex.py +139 -131
 - pandas_market_calendars/calendars/eurex_fixed_income.py +106 -98
 - pandas_market_calendars/calendars/hkex.py +437 -431
 - pandas_market_calendars/calendars/ice.py +89 -81
 - pandas_market_calendars/calendars/iex.py +163 -155
 - pandas_market_calendars/calendars/jpx.py +125 -117
 - pandas_market_calendars/calendars/lse.py +126 -118
 - pandas_market_calendars/calendars/mirror.py +144 -144
 - pandas_market_calendars/calendars/nyse.py +1462 -1466
 - pandas_market_calendars/calendars/ose.py +124 -118
 - pandas_market_calendars/calendars/sifma.py +391 -383
 - pandas_market_calendars/calendars/six.py +144 -136
 - pandas_market_calendars/calendars/sse.py +305 -315
 - pandas_market_calendars/calendars/tase.py +232 -224
 - pandas_market_calendars/calendars/tsx.py +193 -185
 - pandas_market_calendars/class_registry.py +115 -115
 - pandas_market_calendars/holidays/cme.py +385 -385
 - pandas_market_calendars/holidays/cme_globex.py +214 -214
 - pandas_market_calendars/holidays/cn.py +1476 -1476
 - pandas_market_calendars/holidays/jp.py +401 -401
 - pandas_market_calendars/holidays/jpx_equinox.py +506 -506
 - pandas_market_calendars/holidays/nyse.py +1536 -1536
 - pandas_market_calendars/holidays/oz.py +82 -63
 - pandas_market_calendars/holidays/sifma.py +350 -350
 - pandas_market_calendars/holidays/uk.py +186 -186
 - pandas_market_calendars/holidays/us.py +376 -376
 - pandas_market_calendars/market_calendar.py +1006 -1008
 - {pandas_market_calendars-5.1.0.dist-info → pandas_market_calendars-5.1.3.dist-info}/METADATA +5 -4
 - pandas_market_calendars-5.1.3.dist-info/RECORD +50 -0
 - {pandas_market_calendars-5.1.0.dist-info → pandas_market_calendars-5.1.3.dist-info}/WHEEL +1 -1
 - pandas_market_calendars-5.1.0.dist-info/RECORD +0 -50
 - {pandas_market_calendars-5.1.0.dist-info → pandas_market_calendars-5.1.3.dist-info}/licenses/LICENSE +0 -0
 - {pandas_market_calendars-5.1.0.dist-info → pandas_market_calendars-5.1.3.dist-info}/licenses/NOTICE +0 -0
 - {pandas_market_calendars-5.1.0.dist-info → pandas_market_calendars-5.1.3.dist-info}/top_level.txt +0 -0
 
| 
         @@ -1,1008 +1,1006 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # Fork of zipline from Quantopian. Licensed under MIT, original licence below
         
     | 
| 
       2 
     | 
    
         
            -
            #
         
     | 
| 
       3 
     | 
    
         
            -
            # Copyright 2016 Quantopian, Inc.
         
     | 
| 
       4 
     | 
    
         
            -
            #
         
     | 
| 
       5 
     | 
    
         
            -
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
       6 
     | 
    
         
            -
            # you may not use this file except in compliance with the License.
         
     | 
| 
       7 
     | 
    
         
            -
            # You may obtain a copy of the License at
         
     | 
| 
       8 
     | 
    
         
            -
            #
         
     | 
| 
       9 
     | 
    
         
            -
            #     http://www.apache.org/licenses/LICENSE-2.0
         
     | 
| 
       10 
     | 
    
         
            -
            #
         
     | 
| 
       11 
     | 
    
         
            -
            # Unless required by applicable law or agreed to in writing, software
         
     | 
| 
       12 
     | 
    
         
            -
            # distributed under the License is distributed on an "AS IS" BASIS,
         
     | 
| 
       13 
     | 
    
         
            -
            # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
         
     | 
| 
       14 
     | 
    
         
            -
            # See the License for the specific language governing permissions and
         
     | 
| 
       15 
     | 
    
         
            -
            # limitations under the License.
         
     | 
| 
       16 
     | 
    
         
            -
            import warnings
         
     | 
| 
       17 
     | 
    
         
            -
            from abc import ABCMeta, abstractmethod
         
     | 
| 
       18 
     | 
    
         
            -
            from datetime import time
         
     | 
| 
       19 
     | 
    
         
            -
            from typing import Literal, Union
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
            import pandas as pd
         
     | 
| 
       22 
     | 
    
         
            -
            from pandas.tseries.offsets import CustomBusinessDay
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
            from .class_registry import RegisteryMeta, ProtectedDict
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
            from . import calendar_utils as u
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
            MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY = range(7)
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
            WEEKMASK_ABBR = {
         
     | 
| 
       31 
     | 
    
         
            -
                MONDAY: "Mon",
         
     | 
| 
       32 
     | 
    
         
            -
                TUESDAY: "Tue",
         
     | 
| 
       33 
     | 
    
         
            -
                WEDNESDAY: "Wed",
         
     | 
| 
       34 
     | 
    
         
            -
                THURSDAY: "Thu",
         
     | 
| 
       35 
     | 
    
         
            -
                FRIDAY: "Fri",
         
     | 
| 
       36 
     | 
    
         
            -
                SATURDAY: "Sat",
         
     | 
| 
       37 
     | 
    
         
            -
                SUNDAY: "Sun",
         
     | 
| 
       38 
     | 
    
         
            -
            }
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
            class DEFAULT:
         
     | 
| 
       42 
     | 
    
         
            -
                pass
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
            class MarketCalendarMeta(ABCMeta, RegisteryMeta):
         
     | 
| 
       46 
     | 
    
         
            -
                pass
         
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
            class MarketCalendar(metaclass=MarketCalendarMeta):
         
     | 
| 
       50 
     | 
    
         
            -
                """
         
     | 
| 
       51 
     | 
    
         
            -
                An MarketCalendar represents the timing information of a single market or exchange.
         
     | 
| 
       52 
     | 
    
         
            -
                Unless otherwise noted all times are in UTC and use Pandas data structures.
         
     | 
| 
       53 
     | 
    
         
            -
                """
         
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
                regular_market_times = {
         
     | 
| 
       56 
     | 
    
         
            -
                    "market_open": ((None, time(0)),),
         
     | 
| 
       57 
     | 
    
         
            -
                    "market_close": ((None, time(23)),),
         
     | 
| 
       58 
     | 
    
         
            -
                }
         
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
                open_close_map = {
         
     | 
| 
       61 
     | 
    
         
            -
                    "market_open": True,
         
     | 
| 
       62 
     | 
    
         
            -
                    "market_close": False,
         
     | 
| 
       63 
     | 
    
         
            -
                    "break_start": False,
         
     | 
| 
       64 
     | 
    
         
            -
                    "break_end": True,
         
     | 
| 
       65 
     | 
    
         
            -
                    "pre": True,
         
     | 
| 
       66 
     | 
    
         
            -
                    "post": False,
         
     | 
| 
       67 
     | 
    
         
            -
                }
         
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
       69 
     | 
    
         
            -
                @staticmethod
         
     | 
| 
       70 
     | 
    
         
            -
                def _tdelta(t, day_offset=0):
         
     | 
| 
       71 
     | 
    
         
            -
                    try:
         
     | 
| 
       72 
     | 
    
         
            -
                        return pd.Timedelta(
         
     | 
| 
       73 
     | 
    
         
            -
                            days=day_offset, hours=t.hour, minutes=t.minute, seconds=t.second
         
     | 
| 
       74 
     | 
    
         
            -
                        )
         
     | 
| 
       75 
     | 
    
         
            -
                    except AttributeError:
         
     | 
| 
       76 
     | 
    
         
            -
                        t, day_offset = t
         
     | 
| 
       77 
     | 
    
         
            -
                        return pd.Timedelta(
         
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
                     
     | 
| 
       84 
     | 
    
         
            -
                        return  
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       87 
     | 
    
         
            -
             
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
                    """ 
     | 
| 
       91 
     | 
    
         
            -
                     
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
             
     | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
                     
     | 
| 
       98 
     | 
    
         
            -
                    : 
     | 
| 
       99 
     | 
    
         
            -
                     
     | 
| 
       100 
     | 
    
         
            -
                     
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
             
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
       105 
     | 
    
         
            -
                     
     | 
| 
       106 
     | 
    
         
            -
                     
     | 
| 
       107 
     | 
    
         
            -
             
     | 
| 
       108 
     | 
    
         
            -
                     
     | 
| 
       109 
     | 
    
         
            -
             
     | 
| 
       110 
     | 
    
         
            -
                    self. 
     | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
       112 
     | 
    
         
            -
                     
     | 
| 
       113 
     | 
    
         
            -
             
     | 
| 
       114 
     | 
    
         
            -
             
     | 
| 
       115 
     | 
    
         
            -
             
     | 
| 
       116 
     | 
    
         
            -
             
     | 
| 
       117 
     | 
    
         
            -
             
     | 
| 
       118 
     | 
    
         
            -
             
     | 
| 
       119 
     | 
    
         
            -
             
     | 
| 
       120 
     | 
    
         
            -
             
     | 
| 
       121 
     | 
    
         
            -
             
     | 
| 
       122 
     | 
    
         
            -
             
     | 
| 
       123 
     | 
    
         
            -
                 
     | 
| 
       124 
     | 
    
         
            -
             
     | 
| 
       125 
     | 
    
         
            -
             
     | 
| 
       126 
     | 
    
         
            -
             
     | 
| 
       127 
     | 
    
         
            -
                     
     | 
| 
       128 
     | 
    
         
            -
             
     | 
| 
       129 
     | 
    
         
            -
                     
     | 
| 
       130 
     | 
    
         
            -
             
     | 
| 
       131 
     | 
    
         
            -
             
     | 
| 
       132 
     | 
    
         
            -
             
     | 
| 
       133 
     | 
    
         
            -
             
     | 
| 
       134 
     | 
    
         
            -
             
     | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
       136 
     | 
    
         
            -
                     
     | 
| 
       137 
     | 
    
         
            -
             
     | 
| 
       138 
     | 
    
         
            -
                     
     | 
| 
       139 
     | 
    
         
            -
             
     | 
| 
       140 
     | 
    
         
            -
             
     | 
| 
       141 
     | 
    
         
            -
             
     | 
| 
       142 
     | 
    
         
            -
                 
     | 
| 
       143 
     | 
    
         
            -
             
     | 
| 
       144 
     | 
    
         
            -
             
     | 
| 
       145 
     | 
    
         
            -
             
     | 
| 
       146 
     | 
    
         
            -
                     
     | 
| 
       147 
     | 
    
         
            -
             
     | 
| 
       148 
     | 
    
         
            -
                     
     | 
| 
       149 
     | 
    
         
            -
             
     | 
| 
       150 
     | 
    
         
            -
             
     | 
| 
       151 
     | 
    
         
            -
             
     | 
| 
       152 
     | 
    
         
            -
             
     | 
| 
       153 
     | 
    
         
            -
             
     | 
| 
       154 
     | 
    
         
            -
             
     | 
| 
       155 
     | 
    
         
            -
             
     | 
| 
       156 
     | 
    
         
            -
             
     | 
| 
       157 
     | 
    
         
            -
             
     | 
| 
       158 
     | 
    
         
            -
                     
     | 
| 
       159 
     | 
    
         
            -
             
     | 
| 
       160 
     | 
    
         
            -
                     
     | 
| 
       161 
     | 
    
         
            -
             
     | 
| 
       162 
     | 
    
         
            -
                     
     | 
| 
       163 
     | 
    
         
            -
             
     | 
| 
       164 
     | 
    
         
            -
             
     | 
| 
       165 
     | 
    
         
            -
                         
     | 
| 
       166 
     | 
    
         
            -
             
     | 
| 
       167 
     | 
    
         
            -
             
     | 
| 
       168 
     | 
    
         
            -
             
     | 
| 
       169 
     | 
    
         
            -
             
     | 
| 
       170 
     | 
    
         
            -
             
     | 
| 
       171 
     | 
    
         
            -
                             
     | 
| 
       172 
     | 
    
         
            -
             
     | 
| 
       173 
     | 
    
         
            -
             
     | 
| 
       174 
     | 
    
         
            -
             
     | 
| 
       175 
     | 
    
         
            -
             
     | 
| 
       176 
     | 
    
         
            -
             
     | 
| 
       177 
     | 
    
         
            -
             
     | 
| 
       178 
     | 
    
         
            -
             
     | 
| 
       179 
     | 
    
         
            -
                            f" 
     | 
| 
       180 
     | 
    
         
            -
                            f"  
     | 
| 
       181 
     | 
    
         
            -
             
     | 
| 
       182 
     | 
    
         
            -
             
     | 
| 
       183 
     | 
    
         
            -
             
     | 
| 
       184 
     | 
    
         
            -
             
     | 
| 
       185 
     | 
    
         
            -
             
     | 
| 
       186 
     | 
    
         
            -
                    self. 
     | 
| 
       187 
     | 
    
         
            -
             
     | 
| 
       188 
     | 
    
         
            -
                    self. 
     | 
| 
       189 
     | 
    
         
            -
             
     | 
| 
       190 
     | 
    
         
            -
             
     | 
| 
       191 
     | 
    
         
            -
             
     | 
| 
       192 
     | 
    
         
            -
             
     | 
| 
       193 
     | 
    
         
            -
             
     | 
| 
       194 
     | 
    
         
            -
             
     | 
| 
       195 
     | 
    
         
            -
                             
     | 
| 
       196 
     | 
    
         
            -
                                times = (times,)
         
     | 
| 
       197 
     | 
    
         
            -
             
     | 
| 
       198 
     | 
    
         
            -
             
     | 
| 
       199 
     | 
    
         
            -
             
     | 
| 
       200 
     | 
    
         
            -
             
     | 
| 
       201 
     | 
    
         
            -
             
     | 
| 
       202 
     | 
    
         
            -
             
     | 
| 
       203 
     | 
    
         
            -
             
     | 
| 
       204 
     | 
    
         
            -
             
     | 
| 
       205 
     | 
    
         
            -
                            assert  
     | 
| 
       206 
     | 
    
         
            -
             
     | 
| 
       207 
     | 
    
         
            -
                             
     | 
| 
       208 
     | 
    
         
            -
             
     | 
| 
       209 
     | 
    
         
            -
             
     | 
| 
       210 
     | 
    
         
            -
             
     | 
| 
       211 
     | 
    
         
            -
             
     | 
| 
       212 
     | 
    
         
            -
             
     | 
| 
       213 
     | 
    
         
            -
             
     | 
| 
       214 
     | 
    
         
            -
             
     | 
| 
       215 
     | 
    
         
            -
             
     | 
| 
       216 
     | 
    
         
            -
             
     | 
| 
       217 
     | 
    
         
            -
             
     | 
| 
       218 
     | 
    
         
            -
             
     | 
| 
       219 
     | 
    
         
            -
             
     | 
| 
       220 
     | 
    
         
            -
             
     | 
| 
       221 
     | 
    
         
            -
                         
     | 
| 
       222 
     | 
    
         
            -
                             
     | 
| 
       223 
     | 
    
         
            -
             
     | 
| 
       224 
     | 
    
         
            -
             
     | 
| 
       225 
     | 
    
         
            -
             
     | 
| 
       226 
     | 
    
         
            -
             
     | 
| 
       227 
     | 
    
         
            -
             
     | 
| 
       228 
     | 
    
         
            -
                    self. 
     | 
| 
       229 
     | 
    
         
            -
             
     | 
| 
       230 
     | 
    
         
            -
             
     | 
| 
       231 
     | 
    
         
            -
             
     | 
| 
       232 
     | 
    
         
            -
             
     | 
| 
       233 
     | 
    
         
            -
             
     | 
| 
       234 
     | 
    
         
            -
             
     | 
| 
       235 
     | 
    
         
            -
             
     | 
| 
       236 
     | 
    
         
            -
             
     | 
| 
       237 
     | 
    
         
            -
                     
     | 
| 
       238 
     | 
    
         
            -
             
     | 
| 
       239 
     | 
    
         
            -
                    :param  
     | 
| 
       240 
     | 
    
         
            -
             
     | 
| 
       241 
     | 
    
         
            -
             
     | 
| 
       242 
     | 
    
         
            -
                         
     | 
| 
       243 
     | 
    
         
            -
                         
     | 
| 
       244 
     | 
    
         
            -
                         
     | 
| 
       245 
     | 
    
         
            -
             
     | 
| 
       246 
     | 
    
         
            -
             
     | 
| 
       247 
     | 
    
         
            -
             
     | 
| 
       248 
     | 
    
         
            -
                     
     | 
| 
       249 
     | 
    
         
            -
             
     | 
| 
       250 
     | 
    
         
            -
                     
     | 
| 
       251 
     | 
    
         
            -
             
     | 
| 
       252 
     | 
    
         
            -
             
     | 
| 
       253 
     | 
    
         
            -
             
     | 
| 
       254 
     | 
    
         
            -
             
     | 
| 
       255 
     | 
    
         
            -
             
     | 
| 
       256 
     | 
    
         
            -
             
     | 
| 
       257 
     | 
    
         
            -
                     
     | 
| 
       258 
     | 
    
         
            -
             
     | 
| 
       259 
     | 
    
         
            -
                    :param  
     | 
| 
       260 
     | 
    
         
            -
                    : 
     | 
| 
       261 
     | 
    
         
            -
                     
     | 
| 
       262 
     | 
    
         
            -
                     
     | 
| 
       263 
     | 
    
         
            -
             
     | 
| 
       264 
     | 
    
         
            -
                     
     | 
| 
       265 
     | 
    
         
            -
             
     | 
| 
       266 
     | 
    
         
            -
                    )
         
     | 
| 
       267 
     | 
    
         
            -
             
     | 
| 
       268 
     | 
    
         
            -
             
     | 
| 
       269 
     | 
    
         
            -
             
     | 
| 
       270 
     | 
    
         
            -
             
     | 
| 
       271 
     | 
    
         
            -
             
     | 
| 
       272 
     | 
    
         
            -
                     
     | 
| 
       273 
     | 
    
         
            -
             
     | 
| 
       274 
     | 
    
         
            -
                     
     | 
| 
       275 
     | 
    
         
            -
             
     | 
| 
       276 
     | 
    
         
            -
                     
     | 
| 
       277 
     | 
    
         
            -
             
     | 
| 
       278 
     | 
    
         
            -
             
     | 
| 
       279 
     | 
    
         
            -
                     
     | 
| 
       280 
     | 
    
         
            -
                         
     | 
| 
       281 
     | 
    
         
            -
             
     | 
| 
       282 
     | 
    
         
            -
             
     | 
| 
       283 
     | 
    
         
            -
             
     | 
| 
       284 
     | 
    
         
            -
             
     | 
| 
       285 
     | 
    
         
            -
             
     | 
| 
       286 
     | 
    
         
            -
             
     | 
| 
       287 
     | 
    
         
            -
             
     | 
| 
       288 
     | 
    
         
            -
             
     | 
| 
       289 
     | 
    
         
            -
             
     | 
| 
       290 
     | 
    
         
            -
             
     | 
| 
       291 
     | 
    
         
            -
             
     | 
| 
       292 
     | 
    
         
            -
             
     | 
| 
       293 
     | 
    
         
            -
             
     | 
| 
       294 
     | 
    
         
            -
             
     | 
| 
       295 
     | 
    
         
            -
             
     | 
| 
       296 
     | 
    
         
            -
             
     | 
| 
       297 
     | 
    
         
            -
             
     | 
| 
       298 
     | 
    
         
            -
             
     | 
| 
       299 
     | 
    
         
            -
             
     | 
| 
       300 
     | 
    
         
            -
             
     | 
| 
       301 
     | 
    
         
            -
             
     | 
| 
       302 
     | 
    
         
            -
             
     | 
| 
       303 
     | 
    
         
            -
                     
     | 
| 
       304 
     | 
    
         
            -
                         
     | 
| 
       305 
     | 
    
         
            -
             
     | 
| 
       306 
     | 
    
         
            -
                         
     | 
| 
       307 
     | 
    
         
            -
                             
     | 
| 
       308 
     | 
    
         
            -
                         
     | 
| 
       309 
     | 
    
         
            -
                            raise  
     | 
| 
       310 
     | 
    
         
            -
             
     | 
| 
       311 
     | 
    
         
            -
             
     | 
| 
       312 
     | 
    
         
            -
             
     | 
| 
       313 
     | 
    
         
            -
                     
     | 
| 
       314 
     | 
    
         
            -
             
     | 
| 
       315 
     | 
    
         
            -
             
     | 
| 
       316 
     | 
    
         
            -
             
     | 
| 
       317 
     | 
    
         
            -
             
     | 
| 
       318 
     | 
    
         
            -
             
     | 
| 
       319 
     | 
    
         
            -
             
     | 
| 
       320 
     | 
    
         
            -
             
     | 
| 
       321 
     | 
    
         
            -
             
     | 
| 
       322 
     | 
    
         
            -
             
     | 
| 
       323 
     | 
    
         
            -
             
     | 
| 
       324 
     | 
    
         
            -
             
     | 
| 
       325 
     | 
    
         
            -
             
     | 
| 
       326 
     | 
    
         
            -
             
     | 
| 
       327 
     | 
    
         
            -
             
     | 
| 
       328 
     | 
    
         
            -
             
     | 
| 
       329 
     | 
    
         
            -
             
     | 
| 
       330 
     | 
    
         
            -
             
     | 
| 
       331 
     | 
    
         
            -
             
     | 
| 
       332 
     | 
    
         
            -
             
     | 
| 
       333 
     | 
    
         
            -
             
     | 
| 
       334 
     | 
    
         
            -
             
     | 
| 
       335 
     | 
    
         
            -
             
     | 
| 
       336 
     | 
    
         
            -
             
     | 
| 
       337 
     | 
    
         
            -
             
     | 
| 
       338 
     | 
    
         
            -
             
     | 
| 
       339 
     | 
    
         
            -
             
     | 
| 
       340 
     | 
    
         
            -
             
     | 
| 
       341 
     | 
    
         
            -
             
     | 
| 
       342 
     | 
    
         
            -
                     
     | 
| 
       343 
     | 
    
         
            -
             
     | 
| 
       344 
     | 
    
         
            -
                     
     | 
| 
       345 
     | 
    
         
            -
             
     | 
| 
       346 
     | 
    
         
            -
             
     | 
| 
       347 
     | 
    
         
            -
             
     | 
| 
       348 
     | 
    
         
            -
             
     | 
| 
       349 
     | 
    
         
            -
             
     | 
| 
       350 
     | 
    
         
            -
             
     | 
| 
       351 
     | 
    
         
            -
                     
     | 
| 
       352 
     | 
    
         
            -
             
     | 
| 
       353 
     | 
    
         
            -
                     
     | 
| 
       354 
     | 
    
         
            -
             
     | 
| 
       355 
     | 
    
         
            -
             
     | 
| 
       356 
     | 
    
         
            -
             
     | 
| 
       357 
     | 
    
         
            -
             
     | 
| 
       358 
     | 
    
         
            -
             
     | 
| 
       359 
     | 
    
         
            -
             
     | 
| 
       360 
     | 
    
         
            -
                     
     | 
| 
       361 
     | 
    
         
            -
             
     | 
| 
       362 
     | 
    
         
            -
                     
     | 
| 
       363 
     | 
    
         
            -
             
     | 
| 
       364 
     | 
    
         
            -
             
     | 
| 
       365 
     | 
    
         
            -
             
     | 
| 
       366 
     | 
    
         
            -
             
     | 
| 
       367 
     | 
    
         
            -
             
     | 
| 
       368 
     | 
    
         
            -
             
     | 
| 
       369 
     | 
    
         
            -
                     
     | 
| 
       370 
     | 
    
         
            -
             
     | 
| 
       371 
     | 
    
         
            -
                     
     | 
| 
       372 
     | 
    
         
            -
             
     | 
| 
       373 
     | 
    
         
            -
             
     | 
| 
       374 
     | 
    
         
            -
             
     | 
| 
       375 
     | 
    
         
            -
             
     | 
| 
       376 
     | 
    
         
            -
             
     | 
| 
       377 
     | 
    
         
            -
                     
     | 
| 
       378 
     | 
    
         
            -
             
     | 
| 
       379 
     | 
    
         
            -
                     
     | 
| 
       380 
     | 
    
         
            -
             
     | 
| 
       381 
     | 
    
         
            -
             
     | 
| 
       382 
     | 
    
         
            -
             
     | 
| 
       383 
     | 
    
         
            -
             
     | 
| 
       384 
     | 
    
         
            -
             
     | 
| 
       385 
     | 
    
         
            -
                     
     | 
| 
       386 
     | 
    
         
            -
             
     | 
| 
       387 
     | 
    
         
            -
                     
     | 
| 
       388 
     | 
    
         
            -
             
     | 
| 
       389 
     | 
    
         
            -
             
     | 
| 
       390 
     | 
    
         
            -
             
     | 
| 
       391 
     | 
    
         
            -
             
     | 
| 
       392 
     | 
    
         
            -
             
     | 
| 
       393 
     | 
    
         
            -
             
     | 
| 
       394 
     | 
    
         
            -
             
     | 
| 
       395 
     | 
    
         
            -
             
     | 
| 
       396 
     | 
    
         
            -
             
     | 
| 
       397 
     | 
    
         
            -
             
     | 
| 
       398 
     | 
    
         
            -
                     
     | 
| 
       399 
     | 
    
         
            -
             
     | 
| 
       400 
     | 
    
         
            -
                     
     | 
| 
       401 
     | 
    
         
            -
             
     | 
| 
       402 
     | 
    
         
            -
             
     | 
| 
       403 
     | 
    
         
            -
             
     | 
| 
       404 
     | 
    
         
            -
             
     | 
| 
       405 
     | 
    
         
            -
             
     | 
| 
       406 
     | 
    
         
            -
                     
     | 
| 
       407 
     | 
    
         
            -
             
     | 
| 
       408 
     | 
    
         
            -
                     
     | 
| 
       409 
     | 
    
         
            -
             
     | 
| 
       410 
     | 
    
         
            -
             
     | 
| 
       411 
     | 
    
         
            -
             
     | 
| 
       412 
     | 
    
         
            -
             
     | 
| 
       413 
     | 
    
         
            -
             
     | 
| 
       414 
     | 
    
         
            -
             
     | 
| 
       415 
     | 
    
         
            -
                     
     | 
| 
       416 
     | 
    
         
            -
             
     | 
| 
       417 
     | 
    
         
            -
                     
     | 
| 
       418 
     | 
    
         
            -
             
     | 
| 
       419 
     | 
    
         
            -
             
     | 
| 
       420 
     | 
    
         
            -
             
     | 
| 
       421 
     | 
    
         
            -
             
     | 
| 
       422 
     | 
    
         
            -
             
     | 
| 
       423 
     | 
    
         
            -
                     
     | 
| 
       424 
     | 
    
         
            -
             
     | 
| 
       425 
     | 
    
         
            -
                     
     | 
| 
       426 
     | 
    
         
            -
             
     | 
| 
       427 
     | 
    
         
            -
             
     | 
| 
       428 
     | 
    
         
            -
             
     | 
| 
       429 
     | 
    
         
            -
             
     | 
| 
       430 
     | 
    
         
            -
             
     | 
| 
       431 
     | 
    
         
            -
             
     | 
| 
       432 
     | 
    
         
            -
             
     | 
| 
       433 
     | 
    
         
            -
             
     | 
| 
       434 
     | 
    
         
            -
             
     | 
| 
       435 
     | 
    
         
            -
             
     | 
| 
       436 
     | 
    
         
            -
             
     | 
| 
       437 
     | 
    
         
            -
             
     | 
| 
       438 
     | 
    
         
            -
             
     | 
| 
       439 
     | 
    
         
            -
             
     | 
| 
       440 
     | 
    
         
            -
                    """
         
     | 
| 
       441 
     | 
    
         
            -
                     
     | 
| 
       442 
     | 
    
         
            -
             
     | 
| 
       443 
     | 
    
         
            -
             
     | 
| 
       444 
     | 
    
         
            -
             
     | 
| 
       445 
     | 
    
         
            -
             
     | 
| 
       446 
     | 
    
         
            -
             
     | 
| 
       447 
     | 
    
         
            -
                    """
         
     | 
| 
       448 
     | 
    
         
            -
                     
     | 
| 
       449 
     | 
    
         
            -
             
     | 
| 
       450 
     | 
    
         
            -
             
     | 
| 
       451 
     | 
    
         
            -
             
     | 
| 
       452 
     | 
    
         
            -
             
     | 
| 
       453 
     | 
    
         
            -
             
     | 
| 
       454 
     | 
    
         
            -
                     
     | 
| 
       455 
     | 
    
         
            -
             
     | 
| 
       456 
     | 
    
         
            -
             
     | 
| 
       457 
     | 
    
         
            -
             
     | 
| 
       458 
     | 
    
         
            -
             
     | 
| 
       459 
     | 
    
         
            -
             
     | 
| 
       460 
     | 
    
         
            -
             
     | 
| 
       461 
     | 
    
         
            -
             
     | 
| 
       462 
     | 
    
         
            -
                        (" 
     | 
| 
       463 
     | 
    
         
            -
                        (" 
     | 
| 
       464 
     | 
    
         
            -
             
     | 
| 
       465 
     | 
    
         
            -
             
     | 
| 
       466 
     | 
    
         
            -
                     
     | 
| 
       467 
     | 
    
         
            -
             
     | 
| 
       468 
     | 
    
         
            -
             
     | 
| 
       469 
     | 
    
         
            -
             
     | 
| 
       470 
     | 
    
         
            -
             
     | 
| 
       471 
     | 
    
         
            -
             
     | 
| 
       472 
     | 
    
         
            -
                     
     | 
| 
       473 
     | 
    
         
            -
             
     | 
| 
       474 
     | 
    
         
            -
             
     | 
| 
       475 
     | 
    
         
            -
             
     | 
| 
       476 
     | 
    
         
            -
             
     | 
| 
       477 
     | 
    
         
            -
                     
     | 
| 
       478 
     | 
    
         
            -
                     
     | 
| 
       479 
     | 
    
         
            -
                    of  
     | 
| 
       480 
     | 
    
         
            -
             
     | 
| 
       481 
     | 
    
         
            -
                     
     | 
| 
       482 
     | 
    
         
            -
             
     | 
| 
       483 
     | 
    
         
            -
             
     | 
| 
       484 
     | 
    
         
            -
             
     | 
| 
       485 
     | 
    
         
            -
             
     | 
| 
       486 
     | 
    
         
            -
             
     | 
| 
       487 
     | 
    
         
            -
             
     | 
| 
       488 
     | 
    
         
            -
             
     | 
| 
       489 
     | 
    
         
            -
             
     | 
| 
       490 
     | 
    
         
            -
                     
     | 
| 
       491 
     | 
    
         
            -
                     
     | 
| 
       492 
     | 
    
         
            -
                     
     | 
| 
       493 
     | 
    
         
            -
                     
     | 
| 
       494 
     | 
    
         
            -
                     
     | 
| 
       495 
     | 
    
         
            -
                     
     | 
| 
       496 
     | 
    
         
            -
             
     | 
| 
       497 
     | 
    
         
            -
                     
     | 
| 
       498 
     | 
    
         
            -
                         
     | 
| 
       499 
     | 
    
         
            -
             
     | 
| 
       500 
     | 
    
         
            -
             
     | 
| 
       501 
     | 
    
         
            -
                             
     | 
| 
       502 
     | 
    
         
            -
             
     | 
| 
       503 
     | 
    
         
            -
             
     | 
| 
       504 
     | 
    
         
            -
             
     | 
| 
       505 
     | 
    
         
            -
             
     | 
| 
       506 
     | 
    
         
            -
             
     | 
| 
       507 
     | 
    
         
            -
             
     | 
| 
       508 
     | 
    
         
            -
                             
     | 
| 
       509 
     | 
    
         
            -
             
     | 
| 
       510 
     | 
    
         
            -
             
     | 
| 
       511 
     | 
    
         
            -
                        )
         
     | 
| 
       512 
     | 
    
         
            -
             
     | 
| 
       513 
     | 
    
         
            -
             
     | 
| 
       514 
     | 
    
         
            -
             
     | 
| 
       515 
     | 
    
         
            -
             
     | 
| 
       516 
     | 
    
         
            -
             
     | 
| 
       517 
     | 
    
         
            -
             
     | 
| 
       518 
     | 
    
         
            -
             
     | 
| 
       519 
     | 
    
         
            -
             
     | 
| 
       520 
     | 
    
         
            -
             
     | 
| 
       521 
     | 
    
         
            -
             
     | 
| 
       522 
     | 
    
         
            -
                    """
         
     | 
| 
       523 
     | 
    
         
            -
                     
     | 
| 
       524 
     | 
    
         
            -
             
     | 
| 
       525 
     | 
    
         
            -
                     
     | 
| 
       526 
     | 
    
         
            -
             
     | 
| 
       527 
     | 
    
         
            -
             
     | 
| 
       528 
     | 
    
         
            -
                    intr. 
     | 
| 
       529 
     | 
    
         
            -
             
     | 
| 
       530 
     | 
    
         
            -
             
     | 
| 
       531 
     | 
    
         
            -
                    intr. 
     | 
| 
       532 
     | 
    
         
            -
             
     | 
| 
       533 
     | 
    
         
            -
             
     | 
| 
       534 
     | 
    
         
            -
             
     | 
| 
       535 
     | 
    
         
            -
             
     | 
| 
       536 
     | 
    
         
            -
                     
     | 
| 
       537 
     | 
    
         
            -
             
     | 
| 
       538 
     | 
    
         
            -
                     
     | 
| 
       539 
     | 
    
         
            -
             
     | 
| 
       540 
     | 
    
         
            -
                    : 
     | 
| 
       541 
     | 
    
         
            -
             
     | 
| 
       542 
     | 
    
         
            -
                     
     | 
| 
       543 
     | 
    
         
            -
                         
     | 
| 
       544 
     | 
    
         
            -
             
     | 
| 
       545 
     | 
    
         
            -
             
     | 
| 
       546 
     | 
    
         
            -
                             
     | 
| 
       547 
     | 
    
         
            -
             
     | 
| 
       548 
     | 
    
         
            -
             
     | 
| 
       549 
     | 
    
         
            -
             
     | 
| 
       550 
     | 
    
         
            -
             
     | 
| 
       551 
     | 
    
         
            -
             
     | 
| 
       552 
     | 
    
         
            -
             
     | 
| 
       553 
     | 
    
         
            -
             
     | 
| 
       554 
     | 
    
         
            -
                     
     | 
| 
       555 
     | 
    
         
            -
             
     | 
| 
       556 
     | 
    
         
            -
                    :param  
     | 
| 
       557 
     | 
    
         
            -
                    : 
     | 
| 
       558 
     | 
    
         
            -
                     
     | 
| 
       559 
     | 
    
         
            -
                     
     | 
| 
       560 
     | 
    
         
            -
             
     | 
| 
       561 
     | 
    
         
            -
             
     | 
| 
       562 
     | 
    
         
            -
             
     | 
| 
       563 
     | 
    
         
            -
             
     | 
| 
       564 
     | 
    
         
            -
             
     | 
| 
       565 
     | 
    
         
            -
             
     | 
| 
       566 
     | 
    
         
            -
             
     | 
| 
       567 
     | 
    
         
            -
             
     | 
| 
       568 
     | 
    
         
            -
             
     | 
| 
       569 
     | 
    
         
            -
                     
     | 
| 
       570 
     | 
    
         
            -
             
     | 
| 
       571 
     | 
    
         
            -
                     
     | 
| 
       572 
     | 
    
         
            -
             
     | 
| 
       573 
     | 
    
         
            -
                     
     | 
| 
       574 
     | 
    
         
            -
             
     | 
| 
       575 
     | 
    
         
            -
                    >>>  
     | 
| 
       576 
     | 
    
         
            -
                    >>>  
     | 
| 
       577 
     | 
    
         
            -
                     
     | 
| 
       578 
     | 
    
         
            -
             
     | 
| 
       579 
     | 
    
         
            -
             
     | 
| 
       580 
     | 
    
         
            -
             
     | 
| 
       581 
     | 
    
         
            -
             
     | 
| 
       582 
     | 
    
         
            -
             
     | 
| 
       583 
     | 
    
         
            -
                    :param  
     | 
| 
       584 
     | 
    
         
            -
                    : 
     | 
| 
       585 
     | 
    
         
            -
                     
     | 
| 
       586 
     | 
    
         
            -
                     
     | 
| 
       587 
     | 
    
         
            -
                     
     | 
| 
       588 
     | 
    
         
            -
             
     | 
| 
       589 
     | 
    
         
            -
                     
     | 
| 
       590 
     | 
    
         
            -
             
     | 
| 
       591 
     | 
    
         
            -
             
     | 
| 
       592 
     | 
    
         
            -
                         
     | 
| 
       593 
     | 
    
         
            -
             
     | 
| 
       594 
     | 
    
         
            -
             
     | 
| 
       595 
     | 
    
         
            -
             
     | 
| 
       596 
     | 
    
         
            -
             
     | 
| 
       597 
     | 
    
         
            -
             
     | 
| 
       598 
     | 
    
         
            -
             
     | 
| 
       599 
     | 
    
         
            -
             
     | 
| 
       600 
     | 
    
         
            -
             
     | 
| 
       601 
     | 
    
         
            -
             
     | 
| 
       602 
     | 
    
         
            -
             
     | 
| 
       603 
     | 
    
         
            -
             
     | 
| 
       604 
     | 
    
         
            -
                         
     | 
| 
       605 
     | 
    
         
            -
                         
     | 
| 
       606 
     | 
    
         
            -
             
     | 
| 
       607 
     | 
    
         
            -
                         
     | 
| 
       608 
     | 
    
         
            -
                            return  
     | 
| 
       609 
     | 
    
         
            -
             
     | 
| 
       610 
     | 
    
         
            -
             
     | 
| 
       611 
     | 
    
         
            -
             
     | 
| 
       612 
     | 
    
         
            -
             
     | 
| 
       613 
     | 
    
         
            -
             
     | 
| 
       614 
     | 
    
         
            -
             
     | 
| 
       615 
     | 
    
         
            -
                     
     | 
| 
       616 
     | 
    
         
            -
                     
     | 
| 
       617 
     | 
    
         
            -
             
     | 
| 
       618 
     | 
    
         
            -
                    is  
     | 
| 
       619 
     | 
    
         
            -
             
     | 
| 
       620 
     | 
    
         
            -
                     
     | 
| 
       621 
     | 
    
         
            -
                     
     | 
| 
       622 
     | 
    
         
            -
             
     | 
| 
       623 
     | 
    
         
            -
             
     | 
| 
       624 
     | 
    
         
            -
             
     | 
| 
       625 
     | 
    
         
            -
             
     | 
| 
       626 
     | 
    
         
            -
                            indexes.append(self.days_at_time( 
     | 
| 
       627 
     | 
    
         
            -
             
     | 
| 
       628 
     | 
    
         
            -
             
     | 
| 
       629 
     | 
    
         
            -
             
     | 
| 
       630 
     | 
    
         
            -
                    indexes 
     | 
| 
       631 
     | 
    
         
            -
             
     | 
| 
       632 
     | 
    
         
            -
             
     | 
| 
       633 
     | 
    
         
            -
             
     | 
| 
       634 
     | 
    
         
            -
             
     | 
| 
       635 
     | 
    
         
            -
             
     | 
| 
       636 
     | 
    
         
            -
             
     | 
| 
       637 
     | 
    
         
            -
             
     | 
| 
       638 
     | 
    
         
            -
             
     | 
| 
       639 
     | 
    
         
            -
             
     | 
| 
       640 
     | 
    
         
            -
                     
     | 
| 
       641 
     | 
    
         
            -
             
     | 
| 
       642 
     | 
    
         
            -
                    :param  
     | 
| 
       643 
     | 
    
         
            -
                    :param  
     | 
| 
       644 
     | 
    
         
            -
             
     | 
| 
       645 
     | 
    
         
            -
                    : 
     | 
| 
       646 
     | 
    
         
            -
             
     | 
| 
       647 
     | 
    
         
            -
                     
     | 
| 
       648 
     | 
    
         
            -
                     
     | 
| 
       649 
     | 
    
         
            -
                     
     | 
| 
       650 
     | 
    
         
            -
                     
     | 
| 
       651 
     | 
    
         
            -
             
     | 
| 
       652 
     | 
    
         
            -
                     
     | 
| 
       653 
     | 
    
         
            -
             
     | 
| 
       654 
     | 
    
         
            -
             
     | 
| 
       655 
     | 
    
         
            -
             
     | 
| 
       656 
     | 
    
         
            -
             
     | 
| 
       657 
     | 
    
         
            -
             
     | 
| 
       658 
     | 
    
         
            -
             
     | 
| 
       659 
     | 
    
         
            -
             
     | 
| 
       660 
     | 
    
         
            -
                     
     | 
| 
       661 
     | 
    
         
            -
                     
     | 
| 
       662 
     | 
    
         
            -
                     
     | 
| 
       663 
     | 
    
         
            -
                     
     | 
| 
       664 
     | 
    
         
            -
                     
     | 
| 
       665 
     | 
    
         
            -
                     
     | 
| 
       666 
     | 
    
         
            -
                     
     | 
| 
       667 
     | 
    
         
            -
             
     | 
| 
       668 
     | 
    
         
            -
                     
     | 
| 
       669 
     | 
    
         
            -
             
     | 
| 
       670 
     | 
    
         
            -
                     
     | 
| 
       671 
     | 
    
         
            -
                     
     | 
| 
       672 
     | 
    
         
            -
                     
     | 
| 
       673 
     | 
    
         
            -
                     
     | 
| 
       674 
     | 
    
         
            -
             
     | 
| 
       675 
     | 
    
         
            -
                     
     | 
| 
       676 
     | 
    
         
            -
             
     | 
| 
       677 
     | 
    
         
            -
             
     | 
| 
       678 
     | 
    
         
            -
                     
     | 
| 
       679 
     | 
    
         
            -
             
     | 
| 
       680 
     | 
    
         
            -
                    :param  
     | 
| 
       681 
     | 
    
         
            -
                    :param  
     | 
| 
       682 
     | 
    
         
            -
                    :param  
     | 
| 
       683 
     | 
    
         
            -
                    :param  
     | 
| 
       684 
     | 
    
         
            -
             
     | 
| 
       685 
     | 
    
         
            -
             
     | 
| 
       686 
     | 
    
         
            -
                         
     | 
| 
       687 
     | 
    
         
            -
             
     | 
| 
       688 
     | 
    
         
            -
             
     | 
| 
       689 
     | 
    
         
            -
             
     | 
| 
       690 
     | 
    
         
            -
             
     | 
| 
       691 
     | 
    
         
            -
             
     | 
| 
       692 
     | 
    
         
            -
                         
     | 
| 
       693 
     | 
    
         
            -
             
     | 
| 
       694 
     | 
    
         
            -
             
     | 
| 
       695 
     | 
    
         
            -
                     
     | 
| 
       696 
     | 
    
         
            -
                     
     | 
| 
       697 
     | 
    
         
            -
             
     | 
| 
       698 
     | 
    
         
            -
             
     | 
| 
       699 
     | 
    
         
            -
             
     | 
| 
       700 
     | 
    
         
            -
             
     | 
| 
       701 
     | 
    
         
            -
                     
     | 
| 
       702 
     | 
    
         
            -
             
     | 
| 
       703 
     | 
    
         
            -
             
     | 
| 
       704 
     | 
    
         
            -
                     
     | 
| 
       705 
     | 
    
         
            -
                        market_times = self. 
     | 
| 
       706 
     | 
    
         
            -
             
     | 
| 
       707 
     | 
    
         
            -
             
     | 
| 
       708 
     | 
    
         
            -
             
     | 
| 
       709 
     | 
    
         
            -
             
     | 
| 
       710 
     | 
    
         
            -
             
     | 
| 
       711 
     | 
    
         
            -
             
     | 
| 
       712 
     | 
    
         
            -
             
     | 
| 
       713 
     | 
    
         
            -
             
     | 
| 
       714 
     | 
    
         
            -
             
     | 
| 
       715 
     | 
    
         
            -
                     
     | 
| 
       716 
     | 
    
         
            -
                     
     | 
| 
       717 
     | 
    
         
            -
                     
     | 
| 
       718 
     | 
    
         
            -
                     
     | 
| 
       719 
     | 
    
         
            -
                     
     | 
| 
       720 
     | 
    
         
            -
                     
     | 
| 
       721 
     | 
    
         
            -
             
     | 
| 
       722 
     | 
    
         
            -
                     
     | 
| 
       723 
     | 
    
         
            -
             
     | 
| 
       724 
     | 
    
         
            -
             
     | 
| 
       725 
     | 
    
         
            -
                     
     | 
| 
       726 
     | 
    
         
            -
             
     | 
| 
       727 
     | 
    
         
            -
                     
     | 
| 
       728 
     | 
    
         
            -
                     
     | 
| 
       729 
     | 
    
         
            -
             
     | 
| 
       730 
     | 
    
         
            -
                     
     | 
| 
       731 
     | 
    
         
            -
             
     | 
| 
       732 
     | 
    
         
            -
             
     | 
| 
       733 
     | 
    
         
            -
                     
     | 
| 
       734 
     | 
    
         
            -
             
     | 
| 
       735 
     | 
    
         
            -
             
     | 
| 
       736 
     | 
    
         
            -
             
     | 
| 
       737 
     | 
    
         
            -
             
     | 
| 
       738 
     | 
    
         
            -
                    :param  
     | 
| 
       739 
     | 
    
         
            -
                    :param  
     | 
| 
       740 
     | 
    
         
            -
             
     | 
| 
       741 
     | 
    
         
            -
             
     | 
| 
       742 
     | 
    
         
            -
                         
     | 
| 
       743 
     | 
    
         
            -
             
     | 
| 
       744 
     | 
    
         
            -
             
     | 
| 
       745 
     | 
    
         
            -
             
     | 
| 
       746 
     | 
    
         
            -
             
     | 
| 
       747 
     | 
    
         
            -
             
     | 
| 
       748 
     | 
    
         
            -
                         
     | 
| 
       749 
     | 
    
         
            -
             
     | 
| 
       750 
     | 
    
         
            -
             
     | 
| 
       751 
     | 
    
         
            -
             
     | 
| 
       752 
     | 
    
         
            -
                    "" 
     | 
| 
       753 
     | 
    
         
            -
             
     | 
| 
       754 
     | 
    
         
            -
             
     | 
| 
       755 
     | 
    
         
            -
             
     | 
| 
       756 
     | 
    
         
            -
             
     | 
| 
       757 
     | 
    
         
            -
             
     | 
| 
       758 
     | 
    
         
            -
                     
     | 
| 
       759 
     | 
    
         
            -
                        market_times = self. 
     | 
| 
       760 
     | 
    
         
            -
             
     | 
| 
       761 
     | 
    
         
            -
             
     | 
| 
       762 
     | 
    
         
            -
             
     | 
| 
       763 
     | 
    
         
            -
                     
     | 
| 
       764 
     | 
    
         
            -
             
     | 
| 
       765 
     | 
    
         
            -
                     
     | 
| 
       766 
     | 
    
         
            -
             
     | 
| 
       767 
     | 
    
         
            -
             
     | 
| 
       768 
     | 
    
         
            -
             
     | 
| 
       769 
     | 
    
         
            -
             
     | 
| 
       770 
     | 
    
         
            -
             
     | 
| 
       771 
     | 
    
         
            -
                            #  
     | 
| 
       772 
     | 
    
         
            -
                             
     | 
| 
       773 
     | 
    
         
            -
             
     | 
| 
       774 
     | 
    
         
            -
                             
     | 
| 
       775 
     | 
    
         
            -
             
     | 
| 
       776 
     | 
    
         
            -
             
     | 
| 
       777 
     | 
    
         
            -
                             
     | 
| 
       778 
     | 
    
         
            -
             
     | 
| 
       779 
     | 
    
         
            -
             
     | 
| 
       780 
     | 
    
         
            -
                                 
     | 
| 
       781 
     | 
    
         
            -
                                     
     | 
| 
       782 
     | 
    
         
            -
             
     | 
| 
       783 
     | 
    
         
            -
             
     | 
| 
       784 
     | 
    
         
            -
             
     | 
| 
       785 
     | 
    
         
            -
             
     | 
| 
       786 
     | 
    
         
            -
             
     | 
| 
       787 
     | 
    
         
            -
             
     | 
| 
       788 
     | 
    
         
            -
             
     | 
| 
       789 
     | 
    
         
            -
                         
     | 
| 
       790 
     | 
    
         
            -
             
     | 
| 
       791 
     | 
    
         
            -
             
     | 
| 
       792 
     | 
    
         
            -
             
     | 
| 
       793 
     | 
    
         
            -
             
     | 
| 
       794 
     | 
    
         
            -
             
     | 
| 
       795 
     | 
    
         
            -
             
     | 
| 
       796 
     | 
    
         
            -
             
     | 
| 
       797 
     | 
    
         
            -
             
     | 
| 
       798 
     | 
    
         
            -
             
     | 
| 
       799 
     | 
    
         
            -
             
     | 
| 
       800 
     | 
    
         
            -
                         
     | 
| 
       801 
     | 
    
         
            -
             
     | 
| 
       802 
     | 
    
         
            -
             
     | 
| 
       803 
     | 
    
         
            -
             
     | 
| 
       804 
     | 
    
         
            -
             
     | 
| 
       805 
     | 
    
         
            -
             
     | 
| 
       806 
     | 
    
         
            -
             
     | 
| 
       807 
     | 
    
         
            -
             
     | 
| 
       808 
     | 
    
         
            -
             
     | 
| 
       809 
     | 
    
         
            -
             
     | 
| 
       810 
     | 
    
         
            -
                         
     | 
| 
       811 
     | 
    
         
            -
             
     | 
| 
       812 
     | 
    
         
            -
             
     | 
| 
       813 
     | 
    
         
            -
             
     | 
| 
       814 
     | 
    
         
            -
             
     | 
| 
       815 
     | 
    
         
            -
             
     | 
| 
       816 
     | 
    
         
            -
             
     | 
| 
       817 
     | 
    
         
            -
             
     | 
| 
       818 
     | 
    
         
            -
             
     | 
| 
       819 
     | 
    
         
            -
             
     | 
| 
       820 
     | 
    
         
            -
                     
     | 
| 
       821 
     | 
    
         
            -
                     
     | 
| 
       822 
     | 
    
         
            -
                     
     | 
| 
       823 
     | 
    
         
            -
                     
     | 
| 
       824 
     | 
    
         
            -
                     
     | 
| 
       825 
     | 
    
         
            -
                     
     | 
| 
       826 
     | 
    
         
            -
                     
     | 
| 
       827 
     | 
    
         
            -
             
     | 
| 
       828 
     | 
    
         
            -
                     
     | 
| 
       829 
     | 
    
         
            -
             
     | 
| 
       830 
     | 
    
         
            -
             
     | 
| 
       831 
     | 
    
         
            -
                     
     | 
| 
       832 
     | 
    
         
            -
             
     | 
| 
       833 
     | 
    
         
            -
                     
     | 
| 
       834 
     | 
    
         
            -
             
     | 
| 
       835 
     | 
    
         
            -
             
     | 
| 
       836 
     | 
    
         
            -
             
     | 
| 
       837 
     | 
    
         
            -
                        : 
     | 
| 
       838 
     | 
    
         
            -
             
     | 
| 
       839 
     | 
    
         
            -
             
     | 
| 
       840 
     | 
    
         
            -
             
     | 
| 
       841 
     | 
    
         
            -
             
     | 
| 
       842 
     | 
    
         
            -
             
     | 
| 
       843 
     | 
    
         
            -
             
     | 
| 
       844 
     | 
    
         
            -
             
     | 
| 
       845 
     | 
    
         
            -
             
     | 
| 
       846 
     | 
    
         
            -
             
     | 
| 
       847 
     | 
    
         
            -
             
     | 
| 
       848 
     | 
    
         
            -
             
     | 
| 
       849 
     | 
    
         
            -
             
     | 
| 
       850 
     | 
    
         
            -
             
     | 
| 
       851 
     | 
    
         
            -
             
     | 
| 
       852 
     | 
    
         
            -
                        : 
     | 
| 
       853 
     | 
    
         
            -
             
     | 
| 
       854 
     | 
    
         
            -
             
     | 
| 
       855 
     | 
    
         
            -
             
     | 
| 
       856 
     | 
    
         
            -
             
     | 
| 
       857 
     | 
    
         
            -
                        :  
     | 
| 
       858 
     | 
    
         
            -
             
     | 
| 
       859 
     | 
    
         
            -
             
     | 
| 
       860 
     | 
    
         
            -
                        :  
     | 
| 
       861 
     | 
    
         
            -
             
     | 
| 
       862 
     | 
    
         
            -
             
     | 
| 
       863 
     | 
    
         
            -
             
     | 
| 
       864 
     | 
    
         
            -
             
     | 
| 
       865 
     | 
    
         
            -
             
     | 
| 
       866 
     | 
    
         
            -
             
     | 
| 
       867 
     | 
    
         
            -
             
     | 
| 
       868 
     | 
    
         
            -
             
     | 
| 
       869 
     | 
    
         
            -
                         
     | 
| 
       870 
     | 
    
         
            -
                         
     | 
| 
       871 
     | 
    
         
            -
                         
     | 
| 
       872 
     | 
    
         
            -
                         
     | 
| 
       873 
     | 
    
         
            -
                         
     | 
| 
       874 
     | 
    
         
            -
                         
     | 
| 
       875 
     | 
    
         
            -
             
     | 
| 
       876 
     | 
    
         
            -
             
     | 
| 
       877 
     | 
    
         
            -
             
     | 
| 
       878 
     | 
    
         
            -
             
     | 
| 
       879 
     | 
    
         
            -
             
     | 
| 
       880 
     | 
    
         
            -
                     
     | 
| 
       881 
     | 
    
         
            -
             
     | 
| 
       882 
     | 
    
         
            -
                     
     | 
| 
       883 
     | 
    
         
            -
             
     | 
| 
       884 
     | 
    
         
            -
                    :param  
     | 
| 
       885 
     | 
    
         
            -
             
     | 
| 
       886 
     | 
    
         
            -
             
     | 
| 
       887 
     | 
    
         
            -
                         
     | 
| 
       888 
     | 
    
         
            -
             
     | 
| 
       889 
     | 
    
         
            -
                         
     | 
| 
       890 
     | 
    
         
            -
                    : 
     | 
| 
       891 
     | 
    
         
            -
             
     | 
| 
       892 
     | 
    
         
            -
                     
     | 
| 
       893 
     | 
    
         
            -
                     
     | 
| 
       894 
     | 
    
         
            -
             
     | 
| 
       895 
     | 
    
         
            -
                     
     | 
| 
       896 
     | 
    
         
            -
                         
     | 
| 
       897 
     | 
    
         
            -
             
     | 
| 
       898 
     | 
    
         
            -
             
     | 
| 
       899 
     | 
    
         
            -
             
     | 
| 
       900 
     | 
    
         
            -
                    cols  
     | 
| 
       901 
     | 
    
         
            -
             
     | 
| 
       902 
     | 
    
         
            -
             
     | 
| 
       903 
     | 
    
         
            -
             
     | 
| 
       904 
     | 
    
         
            -
             
     | 
| 
       905 
     | 
    
         
            -
             
     | 
| 
       906 
     | 
    
         
            -
             
     | 
| 
       907 
     | 
    
         
            -
             
     | 
| 
       908 
     | 
    
         
            -
                     
     | 
| 
       909 
     | 
    
         
            -
                         
     | 
| 
       910 
     | 
    
         
            -
             
     | 
| 
       911 
     | 
    
         
            -
                         
     | 
| 
       912 
     | 
    
         
            -
             
     | 
| 
       913 
     | 
    
         
            -
             
     | 
| 
       914 
     | 
    
         
            -
             
     | 
| 
       915 
     | 
    
         
            -
             
     | 
| 
       916 
     | 
    
         
            -
             
     | 
| 
       917 
     | 
    
         
            -
             
     | 
| 
       918 
     | 
    
         
            -
                    day =  
     | 
| 
       919 
     | 
    
         
            -
             
     | 
| 
       920 
     | 
    
         
            -
                     
     | 
| 
       921 
     | 
    
         
            -
             
     | 
| 
       922 
     | 
    
         
            -
             
     | 
| 
       923 
     | 
    
         
            -
                        starts =  
     | 
| 
       924 
     | 
    
         
            -
                        ends =  
     | 
| 
       925 
     | 
    
         
            -
             
     | 
| 
       926 
     | 
    
         
            -
             
     | 
| 
       927 
     | 
    
         
            -
             
     | 
| 
       928 
     | 
    
         
            -
                     
     | 
| 
       929 
     | 
    
         
            -
             
     | 
| 
       930 
     | 
    
         
            -
                     
     | 
| 
       931 
     | 
    
         
            -
             
     | 
| 
       932 
     | 
    
         
            -
                     
     | 
| 
       933 
     | 
    
         
            -
                        below = day.index  
     | 
| 
       934 
     | 
    
         
            -
                     
     | 
| 
       935 
     | 
    
         
            -
             
     | 
| 
       936 
     | 
    
         
            -
             
     | 
| 
       937 
     | 
    
         
            -
             
     | 
| 
       938 
     | 
    
         
            -
                 
     | 
| 
       939 
     | 
    
         
            -
             
     | 
| 
       940 
     | 
    
         
            -
             
     | 
| 
       941 
     | 
    
         
            -
             
     | 
| 
       942 
     | 
    
         
            -
             
     | 
| 
       943 
     | 
    
         
            -
             
     | 
| 
       944 
     | 
    
         
            -
             
     | 
| 
       945 
     | 
    
         
            -
                     
     | 
| 
       946 
     | 
    
         
            -
             
     | 
| 
       947 
     | 
    
         
            -
             
     | 
| 
       948 
     | 
    
         
            -
             
     | 
| 
       949 
     | 
    
         
            -
                         
     | 
| 
       950 
     | 
    
         
            -
             
     | 
| 
       951 
     | 
    
         
            -
             
     | 
| 
       952 
     | 
    
         
            -
                    : 
     | 
| 
       953 
     | 
    
         
            -
             
     | 
| 
       954 
     | 
    
         
            -
                     
     | 
| 
       955 
     | 
    
         
            -
                     
     | 
| 
       956 
     | 
    
         
            -
             
     | 
| 
       957 
     | 
    
         
            -
             
     | 
| 
       958 
     | 
    
         
            -
             
     | 
| 
       959 
     | 
    
         
            -
             
     | 
| 
       960 
     | 
    
         
            -
             
     | 
| 
       961 
     | 
    
         
            -
                     
     | 
| 
       962 
     | 
    
         
            -
             
     | 
| 
       963 
     | 
    
         
            -
                    : 
     | 
| 
       964 
     | 
    
         
            -
                     
     | 
| 
       965 
     | 
    
         
            -
                     
     | 
| 
       966 
     | 
    
         
            -
                     
     | 
| 
       967 
     | 
    
         
            -
                    start_date  
     | 
| 
       968 
     | 
    
         
            -
             
     | 
| 
       969 
     | 
    
         
            -
             
     | 
| 
       970 
     | 
    
         
            -
             
     | 
| 
       971 
     | 
    
         
            -
             
     | 
| 
       972 
     | 
    
         
            -
                     
     | 
| 
       973 
     | 
    
         
            -
             
     | 
| 
       974 
     | 
    
         
            -
             
     | 
| 
       975 
     | 
    
         
            -
             
     | 
| 
       976 
     | 
    
         
            -
             
     | 
| 
       977 
     | 
    
         
            -
             
     | 
| 
       978 
     | 
    
         
            -
             
     | 
| 
       979 
     | 
    
         
            -
                     
     | 
| 
       980 
     | 
    
         
            -
             
     | 
| 
       981 
     | 
    
         
            -
                     
     | 
| 
       982 
     | 
    
         
            -
                     
     | 
| 
       983 
     | 
    
         
            -
             
     | 
| 
       984 
     | 
    
         
            -
             
     | 
| 
       985 
     | 
    
         
            -
             
     | 
| 
       986 
     | 
    
         
            -
             
     | 
| 
       987 
     | 
    
         
            -
             
     | 
| 
       988 
     | 
    
         
            -
                     
     | 
| 
       989 
     | 
    
         
            -
             
     | 
| 
       990 
     | 
    
         
            -
                     
     | 
| 
       991 
     | 
    
         
            -
                     
     | 
| 
       992 
     | 
    
         
            -
             
     | 
| 
       993 
     | 
    
         
            -
             
     | 
| 
       994 
     | 
    
         
            -
             
     | 
| 
       995 
     | 
    
         
            -
             
     | 
| 
       996 
     | 
    
         
            -
             
     | 
| 
       997 
     | 
    
         
            -
                         
     | 
| 
       998 
     | 
    
         
            -
                            return self. 
     | 
| 
       999 
     | 
    
         
            -
             
     | 
| 
       1000 
     | 
    
         
            -
             
     | 
| 
       1001 
     | 
    
         
            -
             
     | 
| 
       1002 
     | 
    
         
            -
             
     | 
| 
       1003 
     | 
    
         
            -
             
     | 
| 
       1004 
     | 
    
         
            -
             
     | 
| 
       1005 
     | 
    
         
            -
             
     | 
| 
       1006 
     | 
    
         
            -
             
     | 
| 
       1007 
     | 
    
         
            -
                def __delitem__(self, key):
         
     | 
| 
       1008 
     | 
    
         
            -
                    return self.remove_time(key)
         
     | 
| 
      
 1 
     | 
    
         
            +
            # Fork of zipline from Quantopian. Licensed under MIT, original licence below
         
     | 
| 
      
 2 
     | 
    
         
            +
            #
         
     | 
| 
      
 3 
     | 
    
         
            +
            # Copyright 2016 Quantopian, Inc.
         
     | 
| 
      
 4 
     | 
    
         
            +
            #
         
     | 
| 
      
 5 
     | 
    
         
            +
            # Licensed under the Apache License, Version 2.0 (the "License");
         
     | 
| 
      
 6 
     | 
    
         
            +
            # you may not use this file except in compliance with the License.
         
     | 
| 
      
 7 
     | 
    
         
            +
            # You may obtain a copy of the License at
         
     | 
| 
      
 8 
     | 
    
         
            +
            #
         
     | 
| 
      
 9 
     | 
    
         
            +
            #     http://www.apache.org/licenses/LICENSE-2.0
         
     | 
| 
      
 10 
     | 
    
         
            +
            #
         
     | 
| 
      
 11 
     | 
    
         
            +
            # Unless required by applicable law or agreed to in writing, software
         
     | 
| 
      
 12 
     | 
    
         
            +
            # distributed under the License is distributed on an "AS IS" BASIS,
         
     | 
| 
      
 13 
     | 
    
         
            +
            # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
         
     | 
| 
      
 14 
     | 
    
         
            +
            # See the License for the specific language governing permissions and
         
     | 
| 
      
 15 
     | 
    
         
            +
            # limitations under the License.
         
     | 
| 
      
 16 
     | 
    
         
            +
            import warnings
         
     | 
| 
      
 17 
     | 
    
         
            +
            from abc import ABCMeta, abstractmethod
         
     | 
| 
      
 18 
     | 
    
         
            +
            from datetime import time
         
     | 
| 
      
 19 
     | 
    
         
            +
            from typing import Literal, Union
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            import pandas as pd
         
     | 
| 
      
 22 
     | 
    
         
            +
            from pandas.tseries.offsets import CustomBusinessDay
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
            from .class_registry import RegisteryMeta, ProtectedDict
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
            from . import calendar_utils as u
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
            MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY = range(7)
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
            WEEKMASK_ABBR = {
         
     | 
| 
      
 31 
     | 
    
         
            +
                MONDAY: "Mon",
         
     | 
| 
      
 32 
     | 
    
         
            +
                TUESDAY: "Tue",
         
     | 
| 
      
 33 
     | 
    
         
            +
                WEDNESDAY: "Wed",
         
     | 
| 
      
 34 
     | 
    
         
            +
                THURSDAY: "Thu",
         
     | 
| 
      
 35 
     | 
    
         
            +
                FRIDAY: "Fri",
         
     | 
| 
      
 36 
     | 
    
         
            +
                SATURDAY: "Sat",
         
     | 
| 
      
 37 
     | 
    
         
            +
                SUNDAY: "Sun",
         
     | 
| 
      
 38 
     | 
    
         
            +
            }
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
            class DEFAULT:
         
     | 
| 
      
 42 
     | 
    
         
            +
                pass
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
            class MarketCalendarMeta(ABCMeta, RegisteryMeta):
         
     | 
| 
      
 46 
     | 
    
         
            +
                pass
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
            class MarketCalendar(metaclass=MarketCalendarMeta):
         
     | 
| 
      
 50 
     | 
    
         
            +
                """
         
     | 
| 
      
 51 
     | 
    
         
            +
                An MarketCalendar represents the timing information of a single market or exchange.
         
     | 
| 
      
 52 
     | 
    
         
            +
                Unless otherwise noted all times are in UTC and use Pandas data structures.
         
     | 
| 
      
 53 
     | 
    
         
            +
                """
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                regular_market_times = {
         
     | 
| 
      
 56 
     | 
    
         
            +
                    "market_open": ((None, time(0)),),
         
     | 
| 
      
 57 
     | 
    
         
            +
                    "market_close": ((None, time(23)),),
         
     | 
| 
      
 58 
     | 
    
         
            +
                }
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                open_close_map = {
         
     | 
| 
      
 61 
     | 
    
         
            +
                    "market_open": True,
         
     | 
| 
      
 62 
     | 
    
         
            +
                    "market_close": False,
         
     | 
| 
      
 63 
     | 
    
         
            +
                    "break_start": False,
         
     | 
| 
      
 64 
     | 
    
         
            +
                    "break_end": True,
         
     | 
| 
      
 65 
     | 
    
         
            +
                    "pre": True,
         
     | 
| 
      
 66 
     | 
    
         
            +
                    "post": False,
         
     | 
| 
      
 67 
     | 
    
         
            +
                }
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                @staticmethod
         
     | 
| 
      
 70 
     | 
    
         
            +
                def _tdelta(t, day_offset=0):
         
     | 
| 
      
 71 
     | 
    
         
            +
                    try:
         
     | 
| 
      
 72 
     | 
    
         
            +
                        return pd.Timedelta(
         
     | 
| 
      
 73 
     | 
    
         
            +
                            days=day_offset, hours=t.hour, minutes=t.minute, seconds=t.second
         
     | 
| 
      
 74 
     | 
    
         
            +
                        )
         
     | 
| 
      
 75 
     | 
    
         
            +
                    except AttributeError:
         
     | 
| 
      
 76 
     | 
    
         
            +
                        t, day_offset = t
         
     | 
| 
      
 77 
     | 
    
         
            +
                        return pd.Timedelta(days=day_offset, hours=t.hour, minutes=t.minute, seconds=t.second)
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
                @staticmethod
         
     | 
| 
      
 80 
     | 
    
         
            +
                def _off(tple):
         
     | 
| 
      
 81 
     | 
    
         
            +
                    try:
         
     | 
| 
      
 82 
     | 
    
         
            +
                        return tple[2]
         
     | 
| 
      
 83 
     | 
    
         
            +
                    except IndexError:
         
     | 
| 
      
 84 
     | 
    
         
            +
                        return 0
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
                @classmethod
         
     | 
| 
      
 87 
     | 
    
         
            +
                def calendar_names(cls):
         
     | 
| 
      
 88 
     | 
    
         
            +
                    """All Market Calendar names and aliases that can be used in "factory"
         
     | 
| 
      
 89 
     | 
    
         
            +
                    :return: list(str)
         
     | 
| 
      
 90 
     | 
    
         
            +
                    """
         
     | 
| 
      
 91 
     | 
    
         
            +
                    return [cal for cal in cls._regmeta_class_registry.keys() if cal not in ["MarketCalendar", "TradingCalendar"]]
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
                @classmethod
         
     | 
| 
      
 94 
     | 
    
         
            +
                def factory(cls, name, *args, **kwargs):  # Will be set by Meta, keeping it there for tests
         
     | 
| 
      
 95 
     | 
    
         
            +
                    """
         
     | 
| 
      
 96 
     | 
    
         
            +
                    :param name: The name of the MarketCalendar to be retrieved.
         
     | 
| 
      
 97 
     | 
    
         
            +
                    :param *args/**kwargs: passed to requested MarketCalendar.__init__
         
     | 
| 
      
 98 
     | 
    
         
            +
                    :return: MarketCalendar of the desired calendar.
         
     | 
| 
      
 99 
     | 
    
         
            +
                    """
         
     | 
| 
      
 100 
     | 
    
         
            +
                    return
         
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
      
 102 
     | 
    
         
            +
                def __init__(self, open_time=None, close_time=None):
         
     | 
| 
      
 103 
     | 
    
         
            +
                    """
         
     | 
| 
      
 104 
     | 
    
         
            +
                    :param open_time: Market open time override as datetime.time object. If None then default is used.
         
     | 
| 
      
 105 
     | 
    
         
            +
                    :param close_time: Market close time override as datetime.time object. If None then default is used.
         
     | 
| 
      
 106 
     | 
    
         
            +
                    """
         
     | 
| 
      
 107 
     | 
    
         
            +
             
     | 
| 
      
 108 
     | 
    
         
            +
                    self.regular_market_times = self.regular_market_times.copy()
         
     | 
| 
      
 109 
     | 
    
         
            +
                    self.open_close_map = self.open_close_map.copy()
         
     | 
| 
      
 110 
     | 
    
         
            +
                    self._customized_market_times = []
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
                    if open_time is not None:
         
     | 
| 
      
 113 
     | 
    
         
            +
                        self.change_time("market_open", open_time)
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
                    if close_time is not None:
         
     | 
| 
      
 116 
     | 
    
         
            +
                        self.change_time("market_close", close_time)
         
     | 
| 
      
 117 
     | 
    
         
            +
             
     | 
| 
      
 118 
     | 
    
         
            +
                    if not hasattr(self, "_market_times"):
         
     | 
| 
      
 119 
     | 
    
         
            +
                        self._prepare_regular_market_times()
         
     | 
| 
      
 120 
     | 
    
         
            +
             
     | 
| 
      
 121 
     | 
    
         
            +
                @property
         
     | 
| 
      
 122 
     | 
    
         
            +
                @abstractmethod
         
     | 
| 
      
 123 
     | 
    
         
            +
                def name(self):
         
     | 
| 
      
 124 
     | 
    
         
            +
                    """
         
     | 
| 
      
 125 
     | 
    
         
            +
                    Name of the market
         
     | 
| 
      
 126 
     | 
    
         
            +
             
     | 
| 
      
 127 
     | 
    
         
            +
                    :return: string name
         
     | 
| 
      
 128 
     | 
    
         
            +
                    """
         
     | 
| 
      
 129 
     | 
    
         
            +
                    raise NotImplementedError()
         
     | 
| 
      
 130 
     | 
    
         
            +
             
     | 
| 
      
 131 
     | 
    
         
            +
                @property
         
     | 
| 
      
 132 
     | 
    
         
            +
                def full_name(self):
         
     | 
| 
      
 133 
     | 
    
         
            +
                    """
         
     | 
| 
      
 134 
     | 
    
         
            +
                    Full name of the market
         
     | 
| 
      
 135 
     | 
    
         
            +
             
     | 
| 
      
 136 
     | 
    
         
            +
                    :return: string name
         
     | 
| 
      
 137 
     | 
    
         
            +
                    """
         
     | 
| 
      
 138 
     | 
    
         
            +
                    return self.name
         
     | 
| 
      
 139 
     | 
    
         
            +
             
     | 
| 
      
 140 
     | 
    
         
            +
                @property
         
     | 
| 
      
 141 
     | 
    
         
            +
                @abstractmethod
         
     | 
| 
      
 142 
     | 
    
         
            +
                def tz(self):
         
     | 
| 
      
 143 
     | 
    
         
            +
                    """
         
     | 
| 
      
 144 
     | 
    
         
            +
                    Time zone for the market.
         
     | 
| 
      
 145 
     | 
    
         
            +
             
     | 
| 
      
 146 
     | 
    
         
            +
                    :return: timezone
         
     | 
| 
      
 147 
     | 
    
         
            +
                    """
         
     | 
| 
      
 148 
     | 
    
         
            +
                    raise NotImplementedError()
         
     | 
| 
      
 149 
     | 
    
         
            +
             
     | 
| 
      
 150 
     | 
    
         
            +
                @property
         
     | 
| 
      
 151 
     | 
    
         
            +
                def market_times(self):
         
     | 
| 
      
 152 
     | 
    
         
            +
                    return self._market_times
         
     | 
| 
      
 153 
     | 
    
         
            +
             
     | 
| 
      
 154 
     | 
    
         
            +
                def _prepare_regular_market_times(self):
         
     | 
| 
      
 155 
     | 
    
         
            +
                    oc_map = self.open_close_map
         
     | 
| 
      
 156 
     | 
    
         
            +
                    assert all(isinstance(x, bool) for x in oc_map.values()), "Values in open_close_map need to be True or False"
         
     | 
| 
      
 157 
     | 
    
         
            +
             
     | 
| 
      
 158 
     | 
    
         
            +
                    regular = self.regular_market_times
         
     | 
| 
      
 159 
     | 
    
         
            +
                    discontinued = ProtectedDict()
         
     | 
| 
      
 160 
     | 
    
         
            +
                    regular_tds = {}
         
     | 
| 
      
 161 
     | 
    
         
            +
             
     | 
| 
      
 162 
     | 
    
         
            +
                    for market_time, times in regular.items():
         
     | 
| 
      
 163 
     | 
    
         
            +
                        # in case a market_time has been discontinued, extend the last time
         
     | 
| 
      
 164 
     | 
    
         
            +
                        # and add it to the discontinued_market_times dictionary
         
     | 
| 
      
 165 
     | 
    
         
            +
                        if market_time.startswith("interruption_"):
         
     | 
| 
      
 166 
     | 
    
         
            +
                            raise ValueError("'interruption_' prefix is reserved")
         
     | 
| 
      
 167 
     | 
    
         
            +
             
     | 
| 
      
 168 
     | 
    
         
            +
                        if times[-1][1] is None:
         
     | 
| 
      
 169 
     | 
    
         
            +
                            discontinued._set(market_time, times[-1][0])
         
     | 
| 
      
 170 
     | 
    
         
            +
                            times = times[:-1]
         
     | 
| 
      
 171 
     | 
    
         
            +
                            regular._set(market_time, times)
         
     | 
| 
      
 172 
     | 
    
         
            +
             
     | 
| 
      
 173 
     | 
    
         
            +
                        regular_tds[market_time] = tuple((t[0], self._tdelta(t[1], self._off(t))) for t in times)
         
     | 
| 
      
 174 
     | 
    
         
            +
             
     | 
| 
      
 175 
     | 
    
         
            +
                    if discontinued:
         
     | 
| 
      
 176 
     | 
    
         
            +
                        warnings.warn(
         
     | 
| 
      
 177 
     | 
    
         
            +
                            f"{list(discontinued.keys())} are discontinued, the dictionary"
         
     | 
| 
      
 178 
     | 
    
         
            +
                            f" `.discontinued_market_times` has the dates on which these were discontinued."
         
     | 
| 
      
 179 
     | 
    
         
            +
                            f" The times as of those dates are incorrect, use .remove_time(market_time)"
         
     | 
| 
      
 180 
     | 
    
         
            +
                            f" to ignore a market_time."
         
     | 
| 
      
 181 
     | 
    
         
            +
                        )
         
     | 
| 
      
 182 
     | 
    
         
            +
             
     | 
| 
      
 183 
     | 
    
         
            +
                    self.discontinued_market_times = discontinued
         
     | 
| 
      
 184 
     | 
    
         
            +
                    self.regular_market_times = regular
         
     | 
| 
      
 185 
     | 
    
         
            +
             
     | 
| 
      
 186 
     | 
    
         
            +
                    self._regular_market_timedeltas = regular_tds
         
     | 
| 
      
 187 
     | 
    
         
            +
                    self._market_times = sorted(regular.keys(), key=lambda x: regular_tds[x][-1][1])
         
     | 
| 
      
 188 
     | 
    
         
            +
                    self._oc_market_times = list(filter(oc_map.__contains__, self._market_times))
         
     | 
| 
      
 189 
     | 
    
         
            +
             
     | 
| 
      
 190 
     | 
    
         
            +
                def _set_time(self, market_time, times, opens):
         
     | 
| 
      
 191 
     | 
    
         
            +
                    if isinstance(times, (tuple, list)):  # passed a tuple
         
     | 
| 
      
 192 
     | 
    
         
            +
                        if not isinstance(times[0], (tuple, list)):  # doesn't have a tuple inside
         
     | 
| 
      
 193 
     | 
    
         
            +
                            if times[0] is None:  # seems to be a tuple indicating starting time
         
     | 
| 
      
 194 
     | 
    
         
            +
                                times = (times,)
         
     | 
| 
      
 195 
     | 
    
         
            +
                            else:  # must be a tuple with: (time, offset)
         
     | 
| 
      
 196 
     | 
    
         
            +
                                times = ((None, times[0], times[1]),)
         
     | 
| 
      
 197 
     | 
    
         
            +
                    else:  # should be a datetime.time object
         
     | 
| 
      
 198 
     | 
    
         
            +
                        times = ((None, times),)
         
     | 
| 
      
 199 
     | 
    
         
            +
             
     | 
| 
      
 200 
     | 
    
         
            +
                    ln = len(times)
         
     | 
| 
      
 201 
     | 
    
         
            +
                    for i, t in enumerate(times):
         
     | 
| 
      
 202 
     | 
    
         
            +
                        try:
         
     | 
| 
      
 203 
     | 
    
         
            +
                            assert t[0] is None or isinstance(t[0], str) or isinstance(t[0], pd.Timestamp)
         
     | 
| 
      
 204 
     | 
    
         
            +
                            assert isinstance(t[1], time) or (ln > 1 and i == ln - 1 and t[1] is None)
         
     | 
| 
      
 205 
     | 
    
         
            +
                            assert isinstance(self._off(t), int)
         
     | 
| 
      
 206 
     | 
    
         
            +
                        except AssertionError:
         
     | 
| 
      
 207 
     | 
    
         
            +
                            raise AssertionError(
         
     | 
| 
      
 208 
     | 
    
         
            +
                                "The passed time information is not in the right format, "
         
     | 
| 
      
 209 
     | 
    
         
            +
                                "please consult the docs for how to set market times"
         
     | 
| 
      
 210 
     | 
    
         
            +
                            )
         
     | 
| 
      
 211 
     | 
    
         
            +
             
     | 
| 
      
 212 
     | 
    
         
            +
                    if opens is DEFAULT:
         
     | 
| 
      
 213 
     | 
    
         
            +
                        opens = self.__class__.open_close_map.get(market_time, None)
         
     | 
| 
      
 214 
     | 
    
         
            +
             
     | 
| 
      
 215 
     | 
    
         
            +
                    if opens in (True, False):
         
     | 
| 
      
 216 
     | 
    
         
            +
                        self.open_close_map._set(market_time, opens)
         
     | 
| 
      
 217 
     | 
    
         
            +
             
     | 
| 
      
 218 
     | 
    
         
            +
                    elif opens is None:  # make sure it's ignored
         
     | 
| 
      
 219 
     | 
    
         
            +
                        try:
         
     | 
| 
      
 220 
     | 
    
         
            +
                            self.open_close_map._del(market_time)
         
     | 
| 
      
 221 
     | 
    
         
            +
                        except KeyError:
         
     | 
| 
      
 222 
     | 
    
         
            +
                            pass
         
     | 
| 
      
 223 
     | 
    
         
            +
                    else:
         
     | 
| 
      
 224 
     | 
    
         
            +
                        raise ValueError("when you pass `opens`, it needs to be True, False, or None")
         
     | 
| 
      
 225 
     | 
    
         
            +
             
     | 
| 
      
 226 
     | 
    
         
            +
                    self.regular_market_times._set(market_time, times)
         
     | 
| 
      
 227 
     | 
    
         
            +
             
     | 
| 
      
 228 
     | 
    
         
            +
                    if not self.is_custom(market_time):
         
     | 
| 
      
 229 
     | 
    
         
            +
                        self._customized_market_times.append(market_time)
         
     | 
| 
      
 230 
     | 
    
         
            +
             
     | 
| 
      
 231 
     | 
    
         
            +
                    self._prepare_regular_market_times()
         
     | 
| 
      
 232 
     | 
    
         
            +
             
     | 
| 
      
 233 
     | 
    
         
            +
                def change_time(self, market_time, times, opens=DEFAULT):
         
     | 
| 
      
 234 
     | 
    
         
            +
                    """
         
     | 
| 
      
 235 
     | 
    
         
            +
                    Changes the specified market time in regular_market_times and makes the necessary adjustments.
         
     | 
| 
      
 236 
     | 
    
         
            +
             
     | 
| 
      
 237 
     | 
    
         
            +
                    :param market_time: the market_time to change
         
     | 
| 
      
 238 
     | 
    
         
            +
                    :param times: new time information
         
     | 
| 
      
 239 
     | 
    
         
            +
                    :param opens: whether the market_time is a time that closes or opens the market
         
     | 
| 
      
 240 
     | 
    
         
            +
                        this is only needed if the market_time should be respected by .open_at_time
         
     | 
| 
      
 241 
     | 
    
         
            +
                        True: opens
         
     | 
| 
      
 242 
     | 
    
         
            +
                        False: closes
         
     | 
| 
      
 243 
     | 
    
         
            +
                        None: consider it neither opening nor closing, don't add to open_close_map (ignore in .open_at_time)
         
     | 
| 
      
 244 
     | 
    
         
            +
                        DEFAULT: same as None, unless the market_time is in self.__class__.open_close_map. Then it will take
         
     | 
| 
      
 245 
     | 
    
         
            +
                            the default value as defined by the class.
         
     | 
| 
      
 246 
     | 
    
         
            +
                    :return: None
         
     | 
| 
      
 247 
     | 
    
         
            +
                    """
         
     | 
| 
      
 248 
     | 
    
         
            +
                    assert market_time in self.regular_market_times, (
         
     | 
| 
      
 249 
     | 
    
         
            +
                        f"{market_time} is not in regular_market_times:" f"\n{self._market_times}."
         
     | 
| 
      
 250 
     | 
    
         
            +
                    )
         
     | 
| 
      
 251 
     | 
    
         
            +
                    return self._set_time(market_time, times, opens)
         
     | 
| 
      
 252 
     | 
    
         
            +
             
     | 
| 
      
 253 
     | 
    
         
            +
                def add_time(self, market_time, times, opens=DEFAULT):
         
     | 
| 
      
 254 
     | 
    
         
            +
                    """
         
     | 
| 
      
 255 
     | 
    
         
            +
                    Adds the specified market time to regular_market_times and makes the necessary adjustments.
         
     | 
| 
      
 256 
     | 
    
         
            +
             
     | 
| 
      
 257 
     | 
    
         
            +
                    :param market_time: the market_time to add
         
     | 
| 
      
 258 
     | 
    
         
            +
                    :param times: the time information
         
     | 
| 
      
 259 
     | 
    
         
            +
                    :param opens: see .change_time docstring
         
     | 
| 
      
 260 
     | 
    
         
            +
                    :return: None
         
     | 
| 
      
 261 
     | 
    
         
            +
                    """
         
     | 
| 
      
 262 
     | 
    
         
            +
                    assert market_time not in self.regular_market_times, (
         
     | 
| 
      
 263 
     | 
    
         
            +
                        f"{market_time} is already in regular_market_times:" f"\n{self._market_times}"
         
     | 
| 
      
 264 
     | 
    
         
            +
                    )
         
     | 
| 
      
 265 
     | 
    
         
            +
             
     | 
| 
      
 266 
     | 
    
         
            +
                    return self._set_time(market_time, times, opens)
         
     | 
| 
      
 267 
     | 
    
         
            +
             
     | 
| 
      
 268 
     | 
    
         
            +
                def remove_time(self, market_time):
         
     | 
| 
      
 269 
     | 
    
         
            +
                    """
         
     | 
| 
      
 270 
     | 
    
         
            +
                    Removes the specified market time from regular_market_times and makes the necessary adjustments.
         
     | 
| 
      
 271 
     | 
    
         
            +
             
     | 
| 
      
 272 
     | 
    
         
            +
                    :param market_time: the market_time to remove
         
     | 
| 
      
 273 
     | 
    
         
            +
                    :return: None
         
     | 
| 
      
 274 
     | 
    
         
            +
                    """
         
     | 
| 
      
 275 
     | 
    
         
            +
             
     | 
| 
      
 276 
     | 
    
         
            +
                    self.regular_market_times._del(market_time)
         
     | 
| 
      
 277 
     | 
    
         
            +
                    try:
         
     | 
| 
      
 278 
     | 
    
         
            +
                        self.open_close_map._del(market_time)
         
     | 
| 
      
 279 
     | 
    
         
            +
                    except KeyError:
         
     | 
| 
      
 280 
     | 
    
         
            +
                        pass
         
     | 
| 
      
 281 
     | 
    
         
            +
             
     | 
| 
      
 282 
     | 
    
         
            +
                    self._prepare_regular_market_times()
         
     | 
| 
      
 283 
     | 
    
         
            +
                    if self.is_custom(market_time):
         
     | 
| 
      
 284 
     | 
    
         
            +
                        self._customized_market_times.remove(market_time)
         
     | 
| 
      
 285 
     | 
    
         
            +
             
     | 
| 
      
 286 
     | 
    
         
            +
                def is_custom(self, market_time):
         
     | 
| 
      
 287 
     | 
    
         
            +
                    return market_time in self._customized_market_times
         
     | 
| 
      
 288 
     | 
    
         
            +
             
     | 
| 
      
 289 
     | 
    
         
            +
                @property
         
     | 
| 
      
 290 
     | 
    
         
            +
                def has_custom(self):
         
     | 
| 
      
 291 
     | 
    
         
            +
                    return len(self._customized_market_times) > 0
         
     | 
| 
      
 292 
     | 
    
         
            +
             
     | 
| 
      
 293 
     | 
    
         
            +
                def is_discontinued(self, market_time):
         
     | 
| 
      
 294 
     | 
    
         
            +
                    return market_time in self.discontinued_market_times
         
     | 
| 
      
 295 
     | 
    
         
            +
             
     | 
| 
      
 296 
     | 
    
         
            +
                @property
         
     | 
| 
      
 297 
     | 
    
         
            +
                def has_discontinued(self):
         
     | 
| 
      
 298 
     | 
    
         
            +
                    return len(self.discontinued_market_times) > 0
         
     | 
| 
      
 299 
     | 
    
         
            +
             
     | 
| 
      
 300 
     | 
    
         
            +
                def get_time(self, market_time, all_times=False):
         
     | 
| 
      
 301 
     | 
    
         
            +
                    try:
         
     | 
| 
      
 302 
     | 
    
         
            +
                        times = self.regular_market_times[market_time]
         
     | 
| 
      
 303 
     | 
    
         
            +
                    except KeyError as e:
         
     | 
| 
      
 304 
     | 
    
         
            +
                        if "break_start" in market_time or "break_end" in market_time:
         
     | 
| 
      
 305 
     | 
    
         
            +
                            return None  # in case of no breaks
         
     | 
| 
      
 306 
     | 
    
         
            +
                        elif market_time in ["market_open", "market_close"]:
         
     | 
| 
      
 307 
     | 
    
         
            +
                            raise NotImplementedError("You need to set market_times")
         
     | 
| 
      
 308 
     | 
    
         
            +
                        else:
         
     | 
| 
      
 309 
     | 
    
         
            +
                            raise e
         
     | 
| 
      
 310 
     | 
    
         
            +
             
     | 
| 
      
 311 
     | 
    
         
            +
                    if all_times:
         
     | 
| 
      
 312 
     | 
    
         
            +
                        return times
         
     | 
| 
      
 313 
     | 
    
         
            +
                    return times[-1][1].replace(tzinfo=self.tz)
         
     | 
| 
      
 314 
     | 
    
         
            +
             
     | 
| 
      
 315 
     | 
    
         
            +
                def get_time_on(self, market_time, date):
         
     | 
| 
      
 316 
     | 
    
         
            +
                    times = self.get_time(market_time, all_times=True)
         
     | 
| 
      
 317 
     | 
    
         
            +
                    if times is None:
         
     | 
| 
      
 318 
     | 
    
         
            +
                        return None
         
     | 
| 
      
 319 
     | 
    
         
            +
             
     | 
| 
      
 320 
     | 
    
         
            +
                    date = pd.Timestamp(date)
         
     | 
| 
      
 321 
     | 
    
         
            +
                    for d, t in times[::-1]:
         
     | 
| 
      
 322 
     | 
    
         
            +
                        if d is None or pd.Timestamp(d) < date:
         
     | 
| 
      
 323 
     | 
    
         
            +
                            return t.replace(tzinfo=self.tz)
         
     | 
| 
      
 324 
     | 
    
         
            +
             
     | 
| 
      
 325 
     | 
    
         
            +
                def open_time_on(self, date):
         
     | 
| 
      
 326 
     | 
    
         
            +
                    return self.get_time_on("market_open", date)
         
     | 
| 
      
 327 
     | 
    
         
            +
             
     | 
| 
      
 328 
     | 
    
         
            +
                def close_time_on(self, date):
         
     | 
| 
      
 329 
     | 
    
         
            +
                    return self.get_time_on("market_close", date)
         
     | 
| 
      
 330 
     | 
    
         
            +
             
     | 
| 
      
 331 
     | 
    
         
            +
                def break_start_on(self, date):
         
     | 
| 
      
 332 
     | 
    
         
            +
                    return self.get_time_on("break_start", date)
         
     | 
| 
      
 333 
     | 
    
         
            +
             
     | 
| 
      
 334 
     | 
    
         
            +
                def break_end_on(self, date):
         
     | 
| 
      
 335 
     | 
    
         
            +
                    return self.get_time_on("break_end", date)
         
     | 
| 
      
 336 
     | 
    
         
            +
             
     | 
| 
      
 337 
     | 
    
         
            +
                @property
         
     | 
| 
      
 338 
     | 
    
         
            +
                def open_time(self):
         
     | 
| 
      
 339 
     | 
    
         
            +
                    """
         
     | 
| 
      
 340 
     | 
    
         
            +
                    Default open time for the market
         
     | 
| 
      
 341 
     | 
    
         
            +
             
     | 
| 
      
 342 
     | 
    
         
            +
                    :return: time
         
     | 
| 
      
 343 
     | 
    
         
            +
                    """
         
     | 
| 
      
 344 
     | 
    
         
            +
                    return self.get_time("market_open")
         
     | 
| 
      
 345 
     | 
    
         
            +
             
     | 
| 
      
 346 
     | 
    
         
            +
                @property
         
     | 
| 
      
 347 
     | 
    
         
            +
                def close_time(self):
         
     | 
| 
      
 348 
     | 
    
         
            +
                    """
         
     | 
| 
      
 349 
     | 
    
         
            +
                    Default close time for the market
         
     | 
| 
      
 350 
     | 
    
         
            +
             
     | 
| 
      
 351 
     | 
    
         
            +
                    :return: time
         
     | 
| 
      
 352 
     | 
    
         
            +
                    """
         
     | 
| 
      
 353 
     | 
    
         
            +
                    return self.get_time("market_close")
         
     | 
| 
      
 354 
     | 
    
         
            +
             
     | 
| 
      
 355 
     | 
    
         
            +
                @property
         
     | 
| 
      
 356 
     | 
    
         
            +
                def break_start(self):
         
     | 
| 
      
 357 
     | 
    
         
            +
                    """
         
     | 
| 
      
 358 
     | 
    
         
            +
                    Break time start. If None then there is no break
         
     | 
| 
      
 359 
     | 
    
         
            +
             
     | 
| 
      
 360 
     | 
    
         
            +
                    :return: time or None
         
     | 
| 
      
 361 
     | 
    
         
            +
                    """
         
     | 
| 
      
 362 
     | 
    
         
            +
                    return self.get_time("break_start")
         
     | 
| 
      
 363 
     | 
    
         
            +
             
     | 
| 
      
 364 
     | 
    
         
            +
                @property
         
     | 
| 
      
 365 
     | 
    
         
            +
                def break_end(self):
         
     | 
| 
      
 366 
     | 
    
         
            +
                    """
         
     | 
| 
      
 367 
     | 
    
         
            +
                    Break time end. If None then there is no break
         
     | 
| 
      
 368 
     | 
    
         
            +
             
     | 
| 
      
 369 
     | 
    
         
            +
                    :return: time or None
         
     | 
| 
      
 370 
     | 
    
         
            +
                    """
         
     | 
| 
      
 371 
     | 
    
         
            +
                    return self.get_time("break_end")
         
     | 
| 
      
 372 
     | 
    
         
            +
             
     | 
| 
      
 373 
     | 
    
         
            +
                @property
         
     | 
| 
      
 374 
     | 
    
         
            +
                def regular_holidays(self):
         
     | 
| 
      
 375 
     | 
    
         
            +
                    """
         
     | 
| 
      
 376 
     | 
    
         
            +
             
     | 
| 
      
 377 
     | 
    
         
            +
                    :return: pd.AbstractHolidayCalendar: a calendar containing the regular holidays for this calendar
         
     | 
| 
      
 378 
     | 
    
         
            +
                    """
         
     | 
| 
      
 379 
     | 
    
         
            +
                    return None
         
     | 
| 
      
 380 
     | 
    
         
            +
             
     | 
| 
      
 381 
     | 
    
         
            +
                @property
         
     | 
| 
      
 382 
     | 
    
         
            +
                def adhoc_holidays(self):
         
     | 
| 
      
 383 
     | 
    
         
            +
                    """
         
     | 
| 
      
 384 
     | 
    
         
            +
             
     | 
| 
      
 385 
     | 
    
         
            +
                    :return: list of ad-hoc holidays
         
     | 
| 
      
 386 
     | 
    
         
            +
                    """
         
     | 
| 
      
 387 
     | 
    
         
            +
                    return []
         
     | 
| 
      
 388 
     | 
    
         
            +
             
     | 
| 
      
 389 
     | 
    
         
            +
                @property
         
     | 
| 
      
 390 
     | 
    
         
            +
                def weekmask(self):
         
     | 
| 
      
 391 
     | 
    
         
            +
                    return "Mon Tue Wed Thu Fri"
         
     | 
| 
      
 392 
     | 
    
         
            +
             
     | 
| 
      
 393 
     | 
    
         
            +
                @property
         
     | 
| 
      
 394 
     | 
    
         
            +
                def special_opens(self):
         
     | 
| 
      
 395 
     | 
    
         
            +
                    """
         
     | 
| 
      
 396 
     | 
    
         
            +
                    A list of special open times and corresponding AbstractHolidayCalendar.
         
     | 
| 
      
 397 
     | 
    
         
            +
             
     | 
| 
      
 398 
     | 
    
         
            +
                    :return: List of (time, AbstractHolidayCalendar) tuples
         
     | 
| 
      
 399 
     | 
    
         
            +
                    """
         
     | 
| 
      
 400 
     | 
    
         
            +
                    return []
         
     | 
| 
      
 401 
     | 
    
         
            +
             
     | 
| 
      
 402 
     | 
    
         
            +
                @property
         
     | 
| 
      
 403 
     | 
    
         
            +
                def special_opens_adhoc(self):
         
     | 
| 
      
 404 
     | 
    
         
            +
                    """
         
     | 
| 
      
 405 
     | 
    
         
            +
             
     | 
| 
      
 406 
     | 
    
         
            +
                    :return: List of (time, DatetimeIndex) tuples that represent special opens that cannot be codified into rules.
         
     | 
| 
      
 407 
     | 
    
         
            +
                    """
         
     | 
| 
      
 408 
     | 
    
         
            +
                    return []
         
     | 
| 
      
 409 
     | 
    
         
            +
             
     | 
| 
      
 410 
     | 
    
         
            +
                @property
         
     | 
| 
      
 411 
     | 
    
         
            +
                def special_closes(self):
         
     | 
| 
      
 412 
     | 
    
         
            +
                    """
         
     | 
| 
      
 413 
     | 
    
         
            +
                    A list of special close times and corresponding HolidayCalendars.
         
     | 
| 
      
 414 
     | 
    
         
            +
             
     | 
| 
      
 415 
     | 
    
         
            +
                    :return: List of (time, AbstractHolidayCalendar) tuples
         
     | 
| 
      
 416 
     | 
    
         
            +
                    """
         
     | 
| 
      
 417 
     | 
    
         
            +
                    return []
         
     | 
| 
      
 418 
     | 
    
         
            +
             
     | 
| 
      
 419 
     | 
    
         
            +
                @property
         
     | 
| 
      
 420 
     | 
    
         
            +
                def special_closes_adhoc(self):
         
     | 
| 
      
 421 
     | 
    
         
            +
                    """
         
     | 
| 
      
 422 
     | 
    
         
            +
             
     | 
| 
      
 423 
     | 
    
         
            +
                    :return: List of (time, DatetimeIndex) tuples that represent special closes that cannot be codified into rules.
         
     | 
| 
      
 424 
     | 
    
         
            +
                    """
         
     | 
| 
      
 425 
     | 
    
         
            +
                    return []
         
     | 
| 
      
 426 
     | 
    
         
            +
             
     | 
| 
      
 427 
     | 
    
         
            +
                def get_special_times(self, market_time):
         
     | 
| 
      
 428 
     | 
    
         
            +
                    return getattr(self, "special_" + market_time, [])
         
     | 
| 
      
 429 
     | 
    
         
            +
             
     | 
| 
      
 430 
     | 
    
         
            +
                def get_special_times_adhoc(self, market_time):
         
     | 
| 
      
 431 
     | 
    
         
            +
                    return getattr(self, "special_" + market_time + "_adhoc", [])
         
     | 
| 
      
 432 
     | 
    
         
            +
             
     | 
| 
      
 433 
     | 
    
         
            +
                def get_offset(self, market_time):
         
     | 
| 
      
 434 
     | 
    
         
            +
                    return self._off(self.get_time(market_time, all_times=True)[-1])
         
     | 
| 
      
 435 
     | 
    
         
            +
             
     | 
| 
      
 436 
     | 
    
         
            +
                @property
         
     | 
| 
      
 437 
     | 
    
         
            +
                def open_offset(self):
         
     | 
| 
      
 438 
     | 
    
         
            +
                    """
         
     | 
| 
      
 439 
     | 
    
         
            +
                    :return: open offset
         
     | 
| 
      
 440 
     | 
    
         
            +
                    """
         
     | 
| 
      
 441 
     | 
    
         
            +
                    return self.get_offset("market_open")
         
     | 
| 
      
 442 
     | 
    
         
            +
             
     | 
| 
      
 443 
     | 
    
         
            +
                @property
         
     | 
| 
      
 444 
     | 
    
         
            +
                def close_offset(self):
         
     | 
| 
      
 445 
     | 
    
         
            +
                    """
         
     | 
| 
      
 446 
     | 
    
         
            +
                    :return: close offset
         
     | 
| 
      
 447 
     | 
    
         
            +
                    """
         
     | 
| 
      
 448 
     | 
    
         
            +
                    return self.get_offset("market_close")
         
     | 
| 
      
 449 
     | 
    
         
            +
             
     | 
| 
      
 450 
     | 
    
         
            +
                @property
         
     | 
| 
      
 451 
     | 
    
         
            +
                def interruptions(self):
         
     | 
| 
      
 452 
     | 
    
         
            +
                    """
         
     | 
| 
      
 453 
     | 
    
         
            +
                    This needs to be a list with a tuple for each date that had an interruption.
         
     | 
| 
      
 454 
     | 
    
         
            +
                    The tuple should have this layout:
         
     | 
| 
      
 455 
     | 
    
         
            +
             
     | 
| 
      
 456 
     | 
    
         
            +
                        (date, start_time, end_time[, start_time2, end_time2, ...])
         
     | 
| 
      
 457 
     | 
    
         
            +
             
     | 
| 
      
 458 
     | 
    
         
            +
                    E.g.:
         
     | 
| 
      
 459 
     | 
    
         
            +
                    [
         
     | 
| 
      
 460 
     | 
    
         
            +
                        ("2002-02-03", (time(11), -1), time(11, 2)),
         
     | 
| 
      
 461 
     | 
    
         
            +
                        ("2010-01-11", time(11), (time(11, 1), 1)),
         
     | 
| 
      
 462 
     | 
    
         
            +
                        ("2010-01-13", time(9, 59), time(10), time(10, 29), time(10, 30)),
         
     | 
| 
      
 463 
     | 
    
         
            +
                        ("2011-01-10", time(11), time(11, 1))
         
     | 
| 
      
 464 
     | 
    
         
            +
                    ]
         
     | 
| 
      
 465 
     | 
    
         
            +
             
     | 
| 
      
 466 
     | 
    
         
            +
                    The date needs to be a string in this format: 'yyyy-mm-dd'.
         
     | 
| 
      
 467 
     | 
    
         
            +
                    Times need to be two datetime.time objects for each interruption, indicating start and end.
         
     | 
| 
      
 468 
     | 
    
         
            +
                     Optionally these can be wrapped in a tuple, where the
         
     | 
| 
      
 469 
     | 
    
         
            +
                     second element needs to be an integer indicating an offset.
         
     | 
| 
      
 470 
     | 
    
         
            +
                    On "2010-01-13" in the example, it is shown that there can be multiple interruptions in a day.
         
     | 
| 
      
 471 
     | 
    
         
            +
                    """
         
     | 
| 
      
 472 
     | 
    
         
            +
                    return []
         
     | 
| 
      
 473 
     | 
    
         
            +
             
     | 
| 
      
 474 
     | 
    
         
            +
                def _convert(self, col: pd.Series):
         
     | 
| 
      
 475 
     | 
    
         
            +
                    """
         
     | 
| 
      
 476 
     | 
    
         
            +
                    col is a series indexed by dates at which interruptions occurred. The values are either the start or end times
         
     | 
| 
      
 477 
     | 
    
         
            +
                    of an interruption, represented by either a timedelta or a tuple with a timedelta and day offset of the form
         
     | 
| 
      
 478 
     | 
    
         
            +
                    (timedelta, offset). _convert produces a new series where the values are replaced by datetimes equal to the
         
     | 
| 
      
 479 
     | 
    
         
            +
                    index of the original series plus the offset if present, at the timedelta.
         
     | 
| 
      
 480 
     | 
    
         
            +
             
     | 
| 
      
 481 
     | 
    
         
            +
                    E.g.:
         
     | 
| 
      
 482 
     | 
    
         
            +
                    >>> self._convert(
         
     | 
| 
      
 483 
     | 
    
         
            +
                            pd.Series(
         
     | 
| 
      
 484 
     | 
    
         
            +
                                [datetime.time(11, 2), (datetime.time(11, 1), 1), datetime.time(10, 0), None],
         
     | 
| 
      
 485 
     | 
    
         
            +
                                index=pd.DatetimeIndex(['2002-02-03', '2010-01-11', '2010-01-13', '2011-01-10'])
         
     | 
| 
      
 486 
     | 
    
         
            +
                            )
         
     | 
| 
      
 487 
     | 
    
         
            +
                        )
         
     | 
| 
      
 488 
     | 
    
         
            +
                    2002-02-03   2002-02-03 11:02:00+00:00
         
     | 
| 
      
 489 
     | 
    
         
            +
                    2010-01-11   2010-01-12 11:01:00+00:00
         
     | 
| 
      
 490 
     | 
    
         
            +
                    2010-01-13   2010-01-13 10:00:00+00:00
         
     | 
| 
      
 491 
     | 
    
         
            +
                    2011-01-10                         NaT
         
     | 
| 
      
 492 
     | 
    
         
            +
                    dtype: datetime64[ns, UTC]
         
     | 
| 
      
 493 
     | 
    
         
            +
                    """
         
     | 
| 
      
 494 
     | 
    
         
            +
                    col = col.dropna()  # Python 3.8, pandas 2.0.3 cannot create time deltas from NaT
         
     | 
| 
      
 495 
     | 
    
         
            +
                    try:
         
     | 
| 
      
 496 
     | 
    
         
            +
                        times = col.str[0]
         
     | 
| 
      
 497 
     | 
    
         
            +
                    except AttributeError:  # no tuples, only offset 0
         
     | 
| 
      
 498 
     | 
    
         
            +
                        return (
         
     | 
| 
      
 499 
     | 
    
         
            +
                            (pd.to_timedelta(col.astype("string").fillna(""), errors="coerce") + col.index)
         
     | 
| 
      
 500 
     | 
    
         
            +
                            .dt.tz_localize(self.tz)
         
     | 
| 
      
 501 
     | 
    
         
            +
                            .dt.tz_convert("UTC")
         
     | 
| 
      
 502 
     | 
    
         
            +
                        )
         
     | 
| 
      
 503 
     | 
    
         
            +
             
     | 
| 
      
 504 
     | 
    
         
            +
                    return (
         
     | 
| 
      
 505 
     | 
    
         
            +
                        (
         
     | 
| 
      
 506 
     | 
    
         
            +
                            pd.to_timedelta(times.fillna(col).astype("string").fillna(""), errors="coerce")
         
     | 
| 
      
 507 
     | 
    
         
            +
                            + pd.to_timedelta(col.str[1].fillna(0), unit="D")
         
     | 
| 
      
 508 
     | 
    
         
            +
                            + col.index
         
     | 
| 
      
 509 
     | 
    
         
            +
                        )
         
     | 
| 
      
 510 
     | 
    
         
            +
                        .dt.tz_localize(self.tz)
         
     | 
| 
      
 511 
     | 
    
         
            +
                        .dt.tz_convert("UTC")
         
     | 
| 
      
 512 
     | 
    
         
            +
                    )
         
     | 
| 
      
 513 
     | 
    
         
            +
             
     | 
| 
      
 514 
     | 
    
         
            +
                @staticmethod
         
     | 
| 
      
 515 
     | 
    
         
            +
                def _col_name(n: int):
         
     | 
| 
      
 516 
     | 
    
         
            +
                    return f"interruption_start_{n // 2 + 1}" if n % 2 == 1 else f"interruption_end_{n // 2}"
         
     | 
| 
      
 517 
     | 
    
         
            +
             
     | 
| 
      
 518 
     | 
    
         
            +
                @property
         
     | 
| 
      
 519 
     | 
    
         
            +
                def interruptions_df(self):
         
     | 
| 
      
 520 
     | 
    
         
            +
                    """
         
     | 
| 
      
 521 
     | 
    
         
            +
                    Will return a pd.DataFrame only containing interruptions.
         
     | 
| 
      
 522 
     | 
    
         
            +
                    """
         
     | 
| 
      
 523 
     | 
    
         
            +
                    if not self.interruptions:
         
     | 
| 
      
 524 
     | 
    
         
            +
                        return pd.DataFrame(index=pd.DatetimeIndex([]))
         
     | 
| 
      
 525 
     | 
    
         
            +
                    intr = pd.DataFrame(self.interruptions)
         
     | 
| 
      
 526 
     | 
    
         
            +
                    intr.index = pd.to_datetime(intr.pop(0))
         
     | 
| 
      
 527 
     | 
    
         
            +
             
     | 
| 
      
 528 
     | 
    
         
            +
                    intr.columns = map(self._col_name, intr.columns)
         
     | 
| 
      
 529 
     | 
    
         
            +
                    intr.index.name = None
         
     | 
| 
      
 530 
     | 
    
         
            +
             
     | 
| 
      
 531 
     | 
    
         
            +
                    return intr.apply(self._convert).sort_index()
         
     | 
| 
      
 532 
     | 
    
         
            +
             
     | 
| 
      
 533 
     | 
    
         
            +
                def holidays(self) -> pd.tseries.offsets.CustomBusinessDay:
         
     | 
| 
      
 534 
     | 
    
         
            +
                    """
         
     | 
| 
      
 535 
     | 
    
         
            +
                    Returns the complete CustomBusinessDay object of holidays that can be used in any Pandas function that take
         
     | 
| 
      
 536 
     | 
    
         
            +
                    that input.
         
     | 
| 
      
 537 
     | 
    
         
            +
             
     | 
| 
      
 538 
     | 
    
         
            +
                    :return: CustomBusinessDay object of holidays
         
     | 
| 
      
 539 
     | 
    
         
            +
                    """
         
     | 
| 
      
 540 
     | 
    
         
            +
                    try:
         
     | 
| 
      
 541 
     | 
    
         
            +
                        return self._holidays
         
     | 
| 
      
 542 
     | 
    
         
            +
                    except AttributeError:
         
     | 
| 
      
 543 
     | 
    
         
            +
                        self._holidays = CustomBusinessDay(
         
     | 
| 
      
 544 
     | 
    
         
            +
                            holidays=self.adhoc_holidays,
         
     | 
| 
      
 545 
     | 
    
         
            +
                            calendar=self.regular_holidays,
         
     | 
| 
      
 546 
     | 
    
         
            +
                            weekmask=self.weekmask,
         
     | 
| 
      
 547 
     | 
    
         
            +
                        )
         
     | 
| 
      
 548 
     | 
    
         
            +
                    return self._holidays
         
     | 
| 
      
 549 
     | 
    
         
            +
             
     | 
| 
      
 550 
     | 
    
         
            +
                def valid_days(self, start_date, end_date, tz="UTC") -> pd.DatetimeIndex:
         
     | 
| 
      
 551 
     | 
    
         
            +
                    """
         
     | 
| 
      
 552 
     | 
    
         
            +
                    Get a DatetimeIndex of valid open business days.
         
     | 
| 
      
 553 
     | 
    
         
            +
             
     | 
| 
      
 554 
     | 
    
         
            +
                    :param start_date: start date
         
     | 
| 
      
 555 
     | 
    
         
            +
                    :param end_date: end date
         
     | 
| 
      
 556 
     | 
    
         
            +
                    :param tz: time zone in either string or pytz.timezone
         
     | 
| 
      
 557 
     | 
    
         
            +
                    :return: DatetimeIndex of valid business days
         
     | 
| 
      
 558 
     | 
    
         
            +
                    """
         
     | 
| 
      
 559 
     | 
    
         
            +
                    return pd.date_range(start_date, end_date, freq=self.holidays(), normalize=True, tz=tz)
         
     | 
| 
      
 560 
     | 
    
         
            +
             
     | 
| 
      
 561 
     | 
    
         
            +
                def _get_market_times(self, start, end):
         
     | 
| 
      
 562 
     | 
    
         
            +
                    mts = self._market_times
         
     | 
| 
      
 563 
     | 
    
         
            +
                    return mts[mts.index(start) : mts.index(end) + 1]
         
     | 
| 
      
 564 
     | 
    
         
            +
             
     | 
| 
      
 565 
     | 
    
         
            +
                def days_at_time(self, days, market_time, day_offset=0):
         
     | 
| 
      
 566 
     | 
    
         
            +
                    """
         
     | 
| 
      
 567 
     | 
    
         
            +
                    Create an index of days at time ``t``, interpreted in timezone ``tz``. The returned index is localized to UTC.
         
     | 
| 
      
 568 
     | 
    
         
            +
             
     | 
| 
      
 569 
     | 
    
         
            +
                    In the example below, the times switch from 13:45 to 12:45 UTC because
         
     | 
| 
      
 570 
     | 
    
         
            +
                    March 13th is the daylight savings transition for US/Eastern.  All the
         
     | 
| 
      
 571 
     | 
    
         
            +
                    times are still 8:45 when interpreted in US/Eastern.
         
     | 
| 
      
 572 
     | 
    
         
            +
             
     | 
| 
      
 573 
     | 
    
         
            +
                    >>> import pandas as pd; import datetime; import pprint
         
     | 
| 
      
 574 
     | 
    
         
            +
                    >>> dts = pd.date_range('2016-03-12', '2016-03-14')
         
     | 
| 
      
 575 
     | 
    
         
            +
                    >>> dts_at_845 = days_at_time(dts, datetime.time(8, 45), 'US/Eastern')
         
     | 
| 
      
 576 
     | 
    
         
            +
                    >>> pprint.pprint([str(dt) for dt in dts_at_845])
         
     | 
| 
      
 577 
     | 
    
         
            +
                    ['2016-03-12 13:45:00+00:00',
         
     | 
| 
      
 578 
     | 
    
         
            +
                     '2016-03-13 12:45:00+00:00',
         
     | 
| 
      
 579 
     | 
    
         
            +
                     '2016-03-14 12:45:00+00:00']
         
     | 
| 
      
 580 
     | 
    
         
            +
             
     | 
| 
      
 581 
     | 
    
         
            +
                    :param days: DatetimeIndex An index of dates (represented as midnight).
         
     | 
| 
      
 582 
     | 
    
         
            +
                    :param market_time: datetime.time The time to apply as an offset to each day in ``days``.
         
     | 
| 
      
 583 
     | 
    
         
            +
                    :param day_offset: int The number of days we want to offset @days by
         
     | 
| 
      
 584 
     | 
    
         
            +
                    :return: pd.Series of date with the time requested.
         
     | 
| 
      
 585 
     | 
    
         
            +
                    """
         
     | 
| 
      
 586 
     | 
    
         
            +
                    # Offset days without tz to avoid timezone issues.
         
     | 
| 
      
 587 
     | 
    
         
            +
                    days = pd.DatetimeIndex(days).tz_localize(None).to_series()
         
     | 
| 
      
 588 
     | 
    
         
            +
             
     | 
| 
      
 589 
     | 
    
         
            +
                    if isinstance(market_time, str):  # if string, assume its a reference to saved market times
         
     | 
| 
      
 590 
     | 
    
         
            +
                        timedeltas = self._regular_market_timedeltas[market_time]
         
     | 
| 
      
 591 
     | 
    
         
            +
                        datetimes = days + timedeltas[0][1]
         
     | 
| 
      
 592 
     | 
    
         
            +
                        for cut_off, timedelta in timedeltas[1:]:
         
     | 
| 
      
 593 
     | 
    
         
            +
                            datetimes = datetimes.where(days < pd.Timestamp(cut_off), days + timedelta)
         
     | 
| 
      
 594 
     | 
    
         
            +
             
     | 
| 
      
 595 
     | 
    
         
            +
                    else:  # otherwise, assume it is a datetime.time object
         
     | 
| 
      
 596 
     | 
    
         
            +
                        datetimes = days + self._tdelta(market_time, day_offset)
         
     | 
| 
      
 597 
     | 
    
         
            +
             
     | 
| 
      
 598 
     | 
    
         
            +
                    return datetimes.dt.tz_localize(self.tz).dt.tz_convert("UTC")
         
     | 
| 
      
 599 
     | 
    
         
            +
             
     | 
| 
      
 600 
     | 
    
         
            +
                def _tryholidays(self, cal, s, e):
         
     | 
| 
      
 601 
     | 
    
         
            +
                    try:
         
     | 
| 
      
 602 
     | 
    
         
            +
                        # If the Calendar is all single Observance Holidays then it is far
         
     | 
| 
      
 603 
     | 
    
         
            +
                        # more efficient to extract and return those dates
         
     | 
| 
      
 604 
     | 
    
         
            +
                        observed_dates = u.all_single_observance_rules(cal)
         
     | 
| 
      
 605 
     | 
    
         
            +
                        if observed_dates is not None:
         
     | 
| 
      
 606 
     | 
    
         
            +
                            return pd.DatetimeIndex([date for date in observed_dates if s <= date <= e])
         
     | 
| 
      
 607 
     | 
    
         
            +
                        else:
         
     | 
| 
      
 608 
     | 
    
         
            +
                            return cal.holidays(s, e)
         
     | 
| 
      
 609 
     | 
    
         
            +
                    except ValueError:
         
     | 
| 
      
 610 
     | 
    
         
            +
                        return pd.DatetimeIndex([])
         
     | 
| 
      
 611 
     | 
    
         
            +
             
     | 
| 
      
 612 
     | 
    
         
            +
                def _special_dates(self, calendars, ad_hoc_dates, start, end):
         
     | 
| 
      
 613 
     | 
    
         
            +
                    """
         
     | 
| 
      
 614 
     | 
    
         
            +
                    Union an iterable of pairs of the forms (time, calendar),
         
     | 
| 
      
 615 
     | 
    
         
            +
                    (time, [dates]), and (time, int). If the second item in the pair
         
     | 
| 
      
 616 
     | 
    
         
            +
                    is an int it will be interpreted as a specific day of the week.
         
     | 
| 
      
 617 
     | 
    
         
            +
             
     | 
| 
      
 618 
     | 
    
         
            +
                    (This is shared logic for computing special opens and special closes.)
         
     | 
| 
      
 619 
     | 
    
         
            +
                    """
         
     | 
| 
      
 620 
     | 
    
         
            +
                    indexes = []
         
     | 
| 
      
 621 
     | 
    
         
            +
                    for time_, calendar in calendars:
         
     | 
| 
      
 622 
     | 
    
         
            +
                        if isinstance(calendar, int):
         
     | 
| 
      
 623 
     | 
    
         
            +
                            day_of_week = CustomBusinessDay(weekmask=WEEKMASK_ABBR[calendar])
         
     | 
| 
      
 624 
     | 
    
         
            +
                            indexes.append(self.days_at_time(pd.date_range(start, end, freq=day_of_week), time_))
         
     | 
| 
      
 625 
     | 
    
         
            +
                        else:
         
     | 
| 
      
 626 
     | 
    
         
            +
                            indexes.append(self.days_at_time(self._tryholidays(calendar, start, end), time_))
         
     | 
| 
      
 627 
     | 
    
         
            +
             
     | 
| 
      
 628 
     | 
    
         
            +
                    indexes += [self.days_at_time(dates, time_) for time_, dates in ad_hoc_dates]
         
     | 
| 
      
 629 
     | 
    
         
            +
             
     | 
| 
      
 630 
     | 
    
         
            +
                    if indexes:
         
     | 
| 
      
 631 
     | 
    
         
            +
                        dates = pd.concat(indexes).sort_index().drop_duplicates()
         
     | 
| 
      
 632 
     | 
    
         
            +
                        return dates.loc[start : end.replace(hour=23, minute=59, second=59)]
         
     | 
| 
      
 633 
     | 
    
         
            +
             
     | 
| 
      
 634 
     | 
    
         
            +
                    return pd.Series([], dtype="datetime64[ns, UTC]", index=pd.DatetimeIndex([]))
         
     | 
| 
      
 635 
     | 
    
         
            +
             
     | 
| 
      
 636 
     | 
    
         
            +
                def special_dates(self, market_time, start_date, end_date, filter_holidays=True):
         
     | 
| 
      
 637 
     | 
    
         
            +
                    """
         
     | 
| 
      
 638 
     | 
    
         
            +
                    Calculate a datetimeindex that only contains the specail times of the requested market time.
         
     | 
| 
      
 639 
     | 
    
         
            +
             
     | 
| 
      
 640 
     | 
    
         
            +
                    :param market_time: market_time reference
         
     | 
| 
      
 641 
     | 
    
         
            +
                    :param start_date: first possible date of the index
         
     | 
| 
      
 642 
     | 
    
         
            +
                    :param end_date: last possible date of the index
         
     | 
| 
      
 643 
     | 
    
         
            +
                    :param filter_holidays: will filter days by self.valid_days, which can be useful when debugging
         
     | 
| 
      
 644 
     | 
    
         
            +
             
     | 
| 
      
 645 
     | 
    
         
            +
                    :return: schedule DatetimeIndex
         
     | 
| 
      
 646 
     | 
    
         
            +
                    """
         
     | 
| 
      
 647 
     | 
    
         
            +
                    start_date, end_date = self.clean_dates(start_date, end_date)
         
     | 
| 
      
 648 
     | 
    
         
            +
                    calendars = self.get_special_times(market_time)
         
     | 
| 
      
 649 
     | 
    
         
            +
                    ad_hoc = self.get_special_times_adhoc(market_time)
         
     | 
| 
      
 650 
     | 
    
         
            +
                    special = self._special_dates(calendars, ad_hoc, start_date, end_date)
         
     | 
| 
      
 651 
     | 
    
         
            +
             
     | 
| 
      
 652 
     | 
    
         
            +
                    if filter_holidays:
         
     | 
| 
      
 653 
     | 
    
         
            +
                        valid = self.valid_days(start_date, end_date, tz=None)
         
     | 
| 
      
 654 
     | 
    
         
            +
                        special = special[special.index.isin(valid)]  # some sources of special times don't exclude holidays
         
     | 
| 
      
 655 
     | 
    
         
            +
                    return special
         
     | 
| 
      
 656 
     | 
    
         
            +
             
     | 
| 
      
 657 
     | 
    
         
            +
                def schedule(
         
     | 
| 
      
 658 
     | 
    
         
            +
                    self,
         
     | 
| 
      
 659 
     | 
    
         
            +
                    start_date,
         
     | 
| 
      
 660 
     | 
    
         
            +
                    end_date,
         
     | 
| 
      
 661 
     | 
    
         
            +
                    tz="UTC",
         
     | 
| 
      
 662 
     | 
    
         
            +
                    start="market_open",
         
     | 
| 
      
 663 
     | 
    
         
            +
                    end="market_close",
         
     | 
| 
      
 664 
     | 
    
         
            +
                    force_special_times=True,
         
     | 
| 
      
 665 
     | 
    
         
            +
                    market_times=None,
         
     | 
| 
      
 666 
     | 
    
         
            +
                    interruptions=False,
         
     | 
| 
      
 667 
     | 
    
         
            +
                ) -> pd.DataFrame:
         
     | 
| 
      
 668 
     | 
    
         
            +
                    """
         
     | 
| 
      
 669 
     | 
    
         
            +
                    Generates the schedule DataFrame. The resulting DataFrame will have all the valid business days as the index
         
     | 
| 
      
 670 
     | 
    
         
            +
                    and columns for the requested market times. The columns can be determined either by setting a range (inclusive
         
     | 
| 
      
 671 
     | 
    
         
            +
                    on both sides), using `start` and `end`, or by passing a list to `market_times'. A range of market_times is
         
     | 
| 
      
 672 
     | 
    
         
            +
                    derived from a list of market_times that are available to the instance, which are sorted based on the current
         
     | 
| 
      
 673 
     | 
    
         
            +
                    regular time. See examples/usage.ipynb for demonstrations.
         
     | 
| 
      
 674 
     | 
    
         
            +
             
     | 
| 
      
 675 
     | 
    
         
            +
                    All time zones are set to UTC by default. Setting the tz parameter will convert the columns to the desired
         
     | 
| 
      
 676 
     | 
    
         
            +
                    timezone, such as 'America/New_York'.
         
     | 
| 
      
 677 
     | 
    
         
            +
             
     | 
| 
      
 678 
     | 
    
         
            +
                    :param start_date: first date of the schedule
         
     | 
| 
      
 679 
     | 
    
         
            +
                    :param end_date: last date of the schedule
         
     | 
| 
      
 680 
     | 
    
         
            +
                    :param tz: timezone that the columns of the returned schedule are in, default: "UTC"
         
     | 
| 
      
 681 
     | 
    
         
            +
                    :param start: the first market_time to include as a column, default: "market_open"
         
     | 
| 
      
 682 
     | 
    
         
            +
                    :param end: the last market_time to include as a column, default: "market_close"
         
     | 
| 
      
 683 
     | 
    
         
            +
                    :param force_special_times: how to handle special times.
         
     | 
| 
      
 684 
     | 
    
         
            +
                        True: overwrite regular times of the column itself, conform other columns to special times of
         
     | 
| 
      
 685 
     | 
    
         
            +
                            market_open/market_close if those are requested.
         
     | 
| 
      
 686 
     | 
    
         
            +
                        False: only overwrite regular times of the column itself, leave others alone
         
     | 
| 
      
 687 
     | 
    
         
            +
                        None: completely ignore special times
         
     | 
| 
      
 688 
     | 
    
         
            +
                    :param market_times: alternative to start/end, list of market_times that are in self.regular_market_times
         
     | 
| 
      
 689 
     | 
    
         
            +
                    :param interruptions: bool, whether to add interruptions to the schedule, default: False
         
     | 
| 
      
 690 
     | 
    
         
            +
                        These will be added as columns to the right of the DataFrame. Any interruption on a day between
         
     | 
| 
      
 691 
     | 
    
         
            +
                        start_date and end_date will be included, regardless of the market_times requested.
         
     | 
| 
      
 692 
     | 
    
         
            +
                        Also, `force_special_times` does not take these into consideration.
         
     | 
| 
      
 693 
     | 
    
         
            +
                    :return: schedule DataFrame
         
     | 
| 
      
 694 
     | 
    
         
            +
                    """
         
     | 
| 
      
 695 
     | 
    
         
            +
                    start_date, end_date = self.clean_dates(start_date, end_date)
         
     | 
| 
      
 696 
     | 
    
         
            +
                    if not (start_date <= end_date):
         
     | 
| 
      
 697 
     | 
    
         
            +
                        raise ValueError("start_date must be before or equal to end_date.")
         
     | 
| 
      
 698 
     | 
    
         
            +
             
     | 
| 
      
 699 
     | 
    
         
            +
                    _all_days = self.valid_days(start_date, end_date)
         
     | 
| 
      
 700 
     | 
    
         
            +
             
     | 
| 
      
 701 
     | 
    
         
            +
                    # Setup all valid trading days and the requested market_times
         
     | 
| 
      
 702 
     | 
    
         
            +
                    if market_times is None:
         
     | 
| 
      
 703 
     | 
    
         
            +
                        market_times = self._get_market_times(start, end)
         
     | 
| 
      
 704 
     | 
    
         
            +
                    elif market_times == "all":
         
     | 
| 
      
 705 
     | 
    
         
            +
                        market_times = self._market_times
         
     | 
| 
      
 706 
     | 
    
         
            +
             
     | 
| 
      
 707 
     | 
    
         
            +
                    if not _all_days.size:  # If no valid days return an empty DataFrame
         
     | 
| 
      
 708 
     | 
    
         
            +
                        return pd.DataFrame(columns=market_times, index=pd.DatetimeIndex([], freq="C"))
         
     | 
| 
      
 709 
     | 
    
         
            +
             
     | 
| 
      
 710 
     | 
    
         
            +
                    return self.schedule_from_days(_all_days, tz, start, end, force_special_times, market_times, interruptions)
         
     | 
| 
      
 711 
     | 
    
         
            +
             
     | 
| 
      
 712 
     | 
    
         
            +
                def schedule_from_days(
         
     | 
| 
      
 713 
     | 
    
         
            +
                    self,
         
     | 
| 
      
 714 
     | 
    
         
            +
                    days: pd.DatetimeIndex,
         
     | 
| 
      
 715 
     | 
    
         
            +
                    tz="UTC",
         
     | 
| 
      
 716 
     | 
    
         
            +
                    start="market_open",
         
     | 
| 
      
 717 
     | 
    
         
            +
                    end="market_close",
         
     | 
| 
      
 718 
     | 
    
         
            +
                    force_special_times=True,
         
     | 
| 
      
 719 
     | 
    
         
            +
                    market_times=None,
         
     | 
| 
      
 720 
     | 
    
         
            +
                    interruptions=False,
         
     | 
| 
      
 721 
     | 
    
         
            +
                ) -> pd.DataFrame:
         
     | 
| 
      
 722 
     | 
    
         
            +
                    """
         
     | 
| 
      
 723 
     | 
    
         
            +
                    Generates a schedule DataFrame for the days provided. The days are assumed to be valid trading days.
         
     | 
| 
      
 724 
     | 
    
         
            +
             
     | 
| 
      
 725 
     | 
    
         
            +
                    The columns can be determined either by setting a range (inclusive on both sides), using `start` and `end`,
         
     | 
| 
      
 726 
     | 
    
         
            +
                    or by passing a list to `market_times'. A range of market_times is derived from a list of market_times that
         
     | 
| 
      
 727 
     | 
    
         
            +
                    are available to the instance, which are sorted based on the current regular time.
         
     | 
| 
      
 728 
     | 
    
         
            +
                    See examples/usage.ipynb for demonstrations.
         
     | 
| 
      
 729 
     | 
    
         
            +
             
     | 
| 
      
 730 
     | 
    
         
            +
                    All time zones are set to UTC by default. Setting the tz parameter will convert the columns to the desired
         
     | 
| 
      
 731 
     | 
    
         
            +
                    timezone, such as 'America/New_York'.
         
     | 
| 
      
 732 
     | 
    
         
            +
             
     | 
| 
      
 733 
     | 
    
         
            +
                    :param days: pd.DatetimeIndex of all the desired days in ascending order. This function does not double check
         
     | 
| 
      
 734 
     | 
    
         
            +
                        that these are valid trading days, it is assumed they are. It is intended that this parameter is generated
         
     | 
| 
      
 735 
     | 
    
         
            +
                        by either the .valid_days() or .date_range_htf() methods. Time & Timezone Information is ignored.
         
     | 
| 
      
 736 
     | 
    
         
            +
                    :param tz: timezone that the columns of the returned schedule are in, default: "UTC"
         
     | 
| 
      
 737 
     | 
    
         
            +
                    :param start: the first market_time to include as a column, default: "market_open"
         
     | 
| 
      
 738 
     | 
    
         
            +
                    :param end: the last market_time to include as a column, default: "market_close"
         
     | 
| 
      
 739 
     | 
    
         
            +
                    :param force_special_times: how to handle special times.
         
     | 
| 
      
 740 
     | 
    
         
            +
                        True: overwrite regular times of the column itself, conform other columns to special times of
         
     | 
| 
      
 741 
     | 
    
         
            +
                            market_open/market_close if those are requested.
         
     | 
| 
      
 742 
     | 
    
         
            +
                        False: only overwrite regular times of the column itself, leave others alone
         
     | 
| 
      
 743 
     | 
    
         
            +
                        None: completely ignore special times
         
     | 
| 
      
 744 
     | 
    
         
            +
                    :param market_times: alternative to start/end, list of market_times that are in self.regular_market_times
         
     | 
| 
      
 745 
     | 
    
         
            +
                    :param interruptions: bool, whether to add interruptions to the schedule, default: False
         
     | 
| 
      
 746 
     | 
    
         
            +
                        These will be added as columns to the right of the DataFrame. Any interruption on a day between
         
     | 
| 
      
 747 
     | 
    
         
            +
                        start_date and end_date will be included, regardless of the market_times requested.
         
     | 
| 
      
 748 
     | 
    
         
            +
                        Also, `force_special_times` does not take these into consideration.
         
     | 
| 
      
 749 
     | 
    
         
            +
                    :return: schedule DataFrame
         
     | 
| 
      
 750 
     | 
    
         
            +
                    """
         
     | 
| 
      
 751 
     | 
    
         
            +
             
     | 
| 
      
 752 
     | 
    
         
            +
                    if days.dtype != "datetime64[ns]":
         
     | 
| 
      
 753 
     | 
    
         
            +
                        days = pd.DatetimeIndex(days).normalize().tz_localize(None)
         
     | 
| 
      
 754 
     | 
    
         
            +
             
     | 
| 
      
 755 
     | 
    
         
            +
                    # Setup all valid trading days and the requested market_times
         
     | 
| 
      
 756 
     | 
    
         
            +
                    if market_times is None:
         
     | 
| 
      
 757 
     | 
    
         
            +
                        market_times = self._get_market_times(start, end)
         
     | 
| 
      
 758 
     | 
    
         
            +
                    elif market_times == "all":
         
     | 
| 
      
 759 
     | 
    
         
            +
                        market_times = self._market_times
         
     | 
| 
      
 760 
     | 
    
         
            +
             
     | 
| 
      
 761 
     | 
    
         
            +
                    _adj_others = force_special_times is True
         
     | 
| 
      
 762 
     | 
    
         
            +
                    _adj_col = force_special_times is not None
         
     | 
| 
      
 763 
     | 
    
         
            +
                    _open_adj = _close_adj = []
         
     | 
| 
      
 764 
     | 
    
         
            +
             
     | 
| 
      
 765 
     | 
    
         
            +
                    schedule = pd.DataFrame()
         
     | 
| 
      
 766 
     | 
    
         
            +
                    for market_time in market_times:
         
     | 
| 
      
 767 
     | 
    
         
            +
                        temp = self.days_at_time(days, market_time).copy()  # standard times
         
     | 
| 
      
 768 
     | 
    
         
            +
                        if _adj_col:
         
     | 
| 
      
 769 
     | 
    
         
            +
                            # create an array of special times
         
     | 
| 
      
 770 
     | 
    
         
            +
                            special = self.special_dates(market_time, days[0], days[-1], filter_holidays=False)
         
     | 
| 
      
 771 
     | 
    
         
            +
                            # overwrite standard times
         
     | 
| 
      
 772 
     | 
    
         
            +
                            specialix = special.index[
         
     | 
| 
      
 773 
     | 
    
         
            +
                                special.index.isin(temp.index)
         
     | 
| 
      
 774 
     | 
    
         
            +
                            ]  # some sources of special times don't exclude holidays
         
     | 
| 
      
 775 
     | 
    
         
            +
                            temp.loc[specialix] = special
         
     | 
| 
      
 776 
     | 
    
         
            +
             
     | 
| 
      
 777 
     | 
    
         
            +
                            if _adj_others:
         
     | 
| 
      
 778 
     | 
    
         
            +
                                if market_time == "market_open":
         
     | 
| 
      
 779 
     | 
    
         
            +
                                    _open_adj = specialix
         
     | 
| 
      
 780 
     | 
    
         
            +
                                elif market_time == "market_close":
         
     | 
| 
      
 781 
     | 
    
         
            +
                                    _close_adj = specialix
         
     | 
| 
      
 782 
     | 
    
         
            +
             
     | 
| 
      
 783 
     | 
    
         
            +
                        schedule[market_time] = temp
         
     | 
| 
      
 784 
     | 
    
         
            +
             
     | 
| 
      
 785 
     | 
    
         
            +
                    cols = schedule.columns
         
     | 
| 
      
 786 
     | 
    
         
            +
                    if _adj_others and len(_open_adj) > 0:
         
     | 
| 
      
 787 
     | 
    
         
            +
                        mkt_open_ind = cols.get_loc("market_open")
         
     | 
| 
      
 788 
     | 
    
         
            +
             
     | 
| 
      
 789 
     | 
    
         
            +
                        # Can't use Lambdas here since numpy array assignment doesn't return the array.
         
     | 
| 
      
 790 
     | 
    
         
            +
                        def adjust_opens(x):  # x is an np.Array.
         
     | 
| 
      
 791 
     | 
    
         
            +
                            x[x <= x[mkt_open_ind]] = x[mkt_open_ind]
         
     | 
| 
      
 792 
     | 
    
         
            +
                            return x
         
     | 
| 
      
 793 
     | 
    
         
            +
             
     | 
| 
      
 794 
     | 
    
         
            +
                        adjusted = schedule.loc[_open_adj].apply(adjust_opens, axis=1, raw=True)
         
     | 
| 
      
 795 
     | 
    
         
            +
                        schedule.loc[_open_adj] = adjusted
         
     | 
| 
      
 796 
     | 
    
         
            +
             
     | 
| 
      
 797 
     | 
    
         
            +
                    if _adj_others and len(_close_adj) > 0:
         
     | 
| 
      
 798 
     | 
    
         
            +
                        mkt_close_ind = cols.get_loc("market_close")
         
     | 
| 
      
 799 
     | 
    
         
            +
             
     | 
| 
      
 800 
     | 
    
         
            +
                        def adjust_closes(x):
         
     | 
| 
      
 801 
     | 
    
         
            +
                            x[x >= x[mkt_close_ind]] = x[mkt_close_ind]
         
     | 
| 
      
 802 
     | 
    
         
            +
                            return x
         
     | 
| 
      
 803 
     | 
    
         
            +
             
     | 
| 
      
 804 
     | 
    
         
            +
                        adjusted = schedule.loc[_close_adj].apply(adjust_closes, axis=1, raw=True)
         
     | 
| 
      
 805 
     | 
    
         
            +
                        schedule.loc[_close_adj] = adjusted
         
     | 
| 
      
 806 
     | 
    
         
            +
             
     | 
| 
      
 807 
     | 
    
         
            +
                    if interruptions:
         
     | 
| 
      
 808 
     | 
    
         
            +
                        interrs = self.interruptions_df
         
     | 
| 
      
 809 
     | 
    
         
            +
                        schedule[interrs.columns] = interrs
         
     | 
| 
      
 810 
     | 
    
         
            +
                        schedule = schedule.dropna(how="all", axis=1)
         
     | 
| 
      
 811 
     | 
    
         
            +
             
     | 
| 
      
 812 
     | 
    
         
            +
                    if tz != "UTC":
         
     | 
| 
      
 813 
     | 
    
         
            +
                        schedule = schedule.apply(lambda s: s.dt.tz_convert(tz))
         
     | 
| 
      
 814 
     | 
    
         
            +
             
     | 
| 
      
 815 
     | 
    
         
            +
                    return schedule
         
     | 
| 
      
 816 
     | 
    
         
            +
             
     | 
| 
      
 817 
     | 
    
         
            +
                def date_range_htf(
         
     | 
| 
      
 818 
     | 
    
         
            +
                    self,
         
     | 
| 
      
 819 
     | 
    
         
            +
                    frequency: Union[str, pd.Timedelta, int, float],
         
     | 
| 
      
 820 
     | 
    
         
            +
                    start: Union[str, pd.Timestamp, int, float, None] = None,
         
     | 
| 
      
 821 
     | 
    
         
            +
                    end: Union[str, pd.Timestamp, int, float, None] = None,
         
     | 
| 
      
 822 
     | 
    
         
            +
                    periods: Union[int, None] = None,
         
     | 
| 
      
 823 
     | 
    
         
            +
                    closed: Union[Literal["left", "right"], None] = "right",
         
     | 
| 
      
 824 
     | 
    
         
            +
                    *,
         
     | 
| 
      
 825 
     | 
    
         
            +
                    day_anchor: u.Day_Anchor = "SUN",
         
     | 
| 
      
 826 
     | 
    
         
            +
                    month_anchor: u.Month_Anchor = "JAN",
         
     | 
| 
      
 827 
     | 
    
         
            +
                ) -> pd.DatetimeIndex:
         
     | 
| 
      
 828 
     | 
    
         
            +
                    """
         
     | 
| 
      
 829 
     | 
    
         
            +
                    Returns a Normalized DatetimeIndex from the start-date to End-Date for Time periods of 1D and Higher.
         
     | 
| 
      
 830 
     | 
    
         
            +
             
     | 
| 
      
 831 
     | 
    
         
            +
                    PARAMETERS:
         
     | 
| 
      
 832 
     | 
    
         
            +
             
     | 
| 
      
 833 
     | 
    
         
            +
                    :param frequency: String, Int/float (POSIX seconds) or pd.Timedelta of the desired frequency.
         
     | 
| 
      
 834 
     | 
    
         
            +
                        :Must be Greater than '1D' and an integer multiple of the base frequency (D, W, M, Q, or Y)
         
     | 
| 
      
 835 
     | 
    
         
            +
                        :Important Note: Ints/Floats & Timedeltas are always considered as 'Open Business Days',
         
     | 
| 
      
 836 
     | 
    
         
            +
                            '2D' == Every Other Buisness Day, '3D' == Every 3rd B.Day, '7D' == Every 7th B.Day
         
     | 
| 
      
 837 
     | 
    
         
            +
                        :Higher periods (passed as strings) align to the beginning or end of the relevant period
         
     | 
| 
      
 838 
     | 
    
         
            +
                        :i.e. '1W' == First/[Last] Trading Day of each Week, '1Q' == First/[Last] Day of every Quarter
         
     | 
| 
      
 839 
     | 
    
         
            +
             
     | 
| 
      
 840 
     | 
    
         
            +
                    :param start: String, Int/float (POSIX seconds) or pd.Timestamp of the desired start time.
         
     | 
| 
      
 841 
     | 
    
         
            +
                        :The Time & Timezone information is ignored. Only the Normalized Day is considered.
         
     | 
| 
      
 842 
     | 
    
         
            +
             
     | 
| 
      
 843 
     | 
    
         
            +
                    :param end: String, Int/float (POSIX seconds) or pd.Timestamp of the desired start time.
         
     | 
| 
      
 844 
     | 
    
         
            +
                        :The Time & Timezone information is ignored. Only the Normalized Day is considered.
         
     | 
| 
      
 845 
     | 
    
         
            +
             
     | 
| 
      
 846 
     | 
    
         
            +
                    :param periods: Optional Integer number of periods to return. If a Period count, Start time,
         
     | 
| 
      
 847 
     | 
    
         
            +
                        and End time are given the period count is ignored.
         
     | 
| 
      
 848 
     | 
    
         
            +
             
     | 
| 
      
 849 
     | 
    
         
            +
                    :param closed: Literal['left', 'right']. Method used to close each range.
         
     | 
| 
      
 850 
     | 
    
         
            +
                        :Left: First open trading day of the Session is returned (e.g. First Open Day of The Month)
         
     | 
| 
      
 851 
     | 
    
         
            +
                        :right: Last open trading day of the Session is returned (e.g. Last Open Day of The Month)
         
     | 
| 
      
 852 
     | 
    
         
            +
                        :Note, This has no effect when the desired frequency is a number of days.
         
     | 
| 
      
 853 
     | 
    
         
            +
             
     | 
| 
      
 854 
     | 
    
         
            +
                    :param day_anchor: Day to Anchor the start of the Weekly timeframes to. Default 'SUN'.
         
     | 
| 
      
 855 
     | 
    
         
            +
                        : To get the First/Last Days of the trading Week then the Anchor needs to be on a day the relevant
         
     | 
| 
      
 856 
     | 
    
         
            +
                            market is closed.
         
     | 
| 
      
 857 
     | 
    
         
            +
                        : This can be set so that a specific day each week is returned.
         
     | 
| 
      
 858 
     | 
    
         
            +
                        : freq='1W' & day_anchor='WED' Will return Every 'WED' when the market is open, and nearest day
         
     | 
| 
      
 859 
     | 
    
         
            +
                            to the left or right (based on 'closed') when the market is closed.
         
     | 
| 
      
 860 
     | 
    
         
            +
                        Options: ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
         
     | 
| 
      
 861 
     | 
    
         
            +
             
     | 
| 
      
 862 
     | 
    
         
            +
                    :param month_anchor: Month to Anchor the start of the year to for Quarter and yearly timeframes.
         
     | 
| 
      
 863 
     | 
    
         
            +
                        : Default 'JAN' for Calendar Quarters/Years. Can be set to 'JUL' to return Fiscal Years
         
     | 
| 
      
 864 
     | 
    
         
            +
                        Options: ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"]
         
     | 
| 
      
 865 
     | 
    
         
            +
                    """
         
     | 
| 
      
 866 
     | 
    
         
            +
                    return u.date_range_htf(
         
     | 
| 
      
 867 
     | 
    
         
            +
                        self.holidays(),
         
     | 
| 
      
 868 
     | 
    
         
            +
                        frequency,
         
     | 
| 
      
 869 
     | 
    
         
            +
                        start,
         
     | 
| 
      
 870 
     | 
    
         
            +
                        end,
         
     | 
| 
      
 871 
     | 
    
         
            +
                        periods,
         
     | 
| 
      
 872 
     | 
    
         
            +
                        closed,
         
     | 
| 
      
 873 
     | 
    
         
            +
                        day_anchor=day_anchor,
         
     | 
| 
      
 874 
     | 
    
         
            +
                        month_anchor=month_anchor,
         
     | 
| 
      
 875 
     | 
    
         
            +
                    )
         
     | 
| 
      
 876 
     | 
    
         
            +
             
     | 
| 
      
 877 
     | 
    
         
            +
                def open_at_time(self, schedule, timestamp, include_close=False, only_rth=False):
         
     | 
| 
      
 878 
     | 
    
         
            +
                    """
         
     | 
| 
      
 879 
     | 
    
         
            +
                    Determine if a given timestamp is during an open time for the market. If the timestamp is
         
     | 
| 
      
 880 
     | 
    
         
            +
                    before the first open time or after the last close time of `schedule`, a ValueError will be raised.
         
     | 
| 
      
 881 
     | 
    
         
            +
             
     | 
| 
      
 882 
     | 
    
         
            +
                    :param schedule: schedule DataFrame
         
     | 
| 
      
 883 
     | 
    
         
            +
                    :param timestamp: the timestamp to check for. Assumed to be UTC, if it doesn't include tz information.
         
     | 
| 
      
 884 
     | 
    
         
            +
                    :param include_close: if False then the timestamp that equals the closing timestamp will return False and not be
         
     | 
| 
      
 885 
     | 
    
         
            +
                        considered a valid open date and time. If True then it will be considered valid and return True. Use True
         
     | 
| 
      
 886 
     | 
    
         
            +
                        if using bars and would like to include the last bar as a valid open date and time. The close refers to the
         
     | 
| 
      
 887 
     | 
    
         
            +
                        latest market_time available, which could be after market_close (e.g. 'post').
         
     | 
| 
      
 888 
     | 
    
         
            +
                    :param only_rth: whether to ignore columns that are before market_open or after market_close. If true,
         
     | 
| 
      
 889 
     | 
    
         
            +
                        include_close will be referring to market_close.
         
     | 
| 
      
 890 
     | 
    
         
            +
                    :return: True if the timestamp is a valid open date and time, False if not
         
     | 
| 
      
 891 
     | 
    
         
            +
                    """
         
     | 
| 
      
 892 
     | 
    
         
            +
                    timestamp = pd.Timestamp(timestamp)
         
     | 
| 
      
 893 
     | 
    
         
            +
                    try:
         
     | 
| 
      
 894 
     | 
    
         
            +
                        timestamp = timestamp.tz_localize("UTC")
         
     | 
| 
      
 895 
     | 
    
         
            +
                    except TypeError:
         
     | 
| 
      
 896 
     | 
    
         
            +
                        pass
         
     | 
| 
      
 897 
     | 
    
         
            +
             
     | 
| 
      
 898 
     | 
    
         
            +
                    cols = schedule.columns
         
     | 
| 
      
 899 
     | 
    
         
            +
                    interrs = cols.str.startswith("interruption_")
         
     | 
| 
      
 900 
     | 
    
         
            +
                    if not (cols.isin(self._oc_market_times) | interrs).all():
         
     | 
| 
      
 901 
     | 
    
         
            +
                        raise ValueError(
         
     | 
| 
      
 902 
     | 
    
         
            +
                            "You seem to be using a schedule that isn't based on the market_times, "
         
     | 
| 
      
 903 
     | 
    
         
            +
                            "or includes market_times that are not represented in the open_close_map."
         
     | 
| 
      
 904 
     | 
    
         
            +
                        )
         
     | 
| 
      
 905 
     | 
    
         
            +
             
     | 
| 
      
 906 
     | 
    
         
            +
                    if only_rth:
         
     | 
| 
      
 907 
     | 
    
         
            +
                        lowest, highest = "market_open", "market_close"
         
     | 
| 
      
 908 
     | 
    
         
            +
                    else:
         
     | 
| 
      
 909 
     | 
    
         
            +
                        cols = cols[~interrs]
         
     | 
| 
      
 910 
     | 
    
         
            +
                        ix = cols.map(self._oc_market_times.index)
         
     | 
| 
      
 911 
     | 
    
         
            +
                        lowest, highest = cols[ix == ix.min()][0], cols[ix == ix.max()][0]
         
     | 
| 
      
 912 
     | 
    
         
            +
             
     | 
| 
      
 913 
     | 
    
         
            +
                    if timestamp < schedule[lowest].iat[0] or timestamp > schedule[highest].iat[-1]:
         
     | 
| 
      
 914 
     | 
    
         
            +
                        raise ValueError("The provided timestamp is not covered by the schedule")
         
     | 
| 
      
 915 
     | 
    
         
            +
             
     | 
| 
      
 916 
     | 
    
         
            +
                    day = schedule[schedule[lowest].le(timestamp)].iloc[-1].dropna().sort_values()
         
     | 
| 
      
 917 
     | 
    
         
            +
                    day = day.loc[lowest:highest]
         
     | 
| 
      
 918 
     | 
    
         
            +
                    day = day.index.to_series(index=day)
         
     | 
| 
      
 919 
     | 
    
         
            +
             
     | 
| 
      
 920 
     | 
    
         
            +
                    if interrs.any():
         
     | 
| 
      
 921 
     | 
    
         
            +
                        starts = day.str.startswith("interruption_start_")
         
     | 
| 
      
 922 
     | 
    
         
            +
                        ends = day.str.startswith("interruption_end_")
         
     | 
| 
      
 923 
     | 
    
         
            +
                        day.loc[starts] = False
         
     | 
| 
      
 924 
     | 
    
         
            +
                        day.loc[ends] = True
         
     | 
| 
      
 925 
     | 
    
         
            +
             
     | 
| 
      
 926 
     | 
    
         
            +
                    # When post follows market_close, market_close should not be considered a close
         
     | 
| 
      
 927 
     | 
    
         
            +
                    day.loc[day.eq("market_close") & day.shift(-1).eq("post")] = "market_open"
         
     | 
| 
      
 928 
     | 
    
         
            +
                    day = day.map(lambda x: (self.open_close_map.get(x) if x in self.open_close_map.keys() else x))
         
     | 
| 
      
 929 
     | 
    
         
            +
             
     | 
| 
      
 930 
     | 
    
         
            +
                    if include_close:
         
     | 
| 
      
 931 
     | 
    
         
            +
                        below = day.index < timestamp
         
     | 
| 
      
 932 
     | 
    
         
            +
                    else:
         
     | 
| 
      
 933 
     | 
    
         
            +
                        below = day.index <= timestamp
         
     | 
| 
      
 934 
     | 
    
         
            +
                    return bool(day[below].iat[-1])  # returns numpy.bool_ if not bool(...)
         
     | 
| 
      
 935 
     | 
    
         
            +
             
     | 
| 
      
 936 
     | 
    
         
            +
                # need this to make is_open_now testable
         
     | 
| 
      
 937 
     | 
    
         
            +
                @staticmethod
         
     | 
| 
      
 938 
     | 
    
         
            +
                def _get_current_time():
         
     | 
| 
      
 939 
     | 
    
         
            +
                    return pd.Timestamp.now(tz="UTC")
         
     | 
| 
      
 940 
     | 
    
         
            +
             
     | 
| 
      
 941 
     | 
    
         
            +
                def is_open_now(self, schedule, include_close=False, only_rth=False):
         
     | 
| 
      
 942 
     | 
    
         
            +
                    """
         
     | 
| 
      
 943 
     | 
    
         
            +
                    To determine if the current local system time (converted to UTC) is an open time for the market
         
     | 
| 
      
 944 
     | 
    
         
            +
             
     | 
| 
      
 945 
     | 
    
         
            +
                    :param schedule: schedule DataFrame
         
     | 
| 
      
 946 
     | 
    
         
            +
                    :param include_close: if False then the function will return False if the current local system time is equal to
         
     | 
| 
      
 947 
     | 
    
         
            +
                        the closing timestamp. If True then it will return True if the current local system time is equal to the
         
     | 
| 
      
 948 
     | 
    
         
            +
                        closing timestamp. Use True if using bars and would like to include the last bar as a valid open date
         
     | 
| 
      
 949 
     | 
    
         
            +
                        and time.
         
     | 
| 
      
 950 
     | 
    
         
            +
                    :param only_rth: whether to consider columns that are before market_open or after market_close
         
     | 
| 
      
 951 
     | 
    
         
            +
             
     | 
| 
      
 952 
     | 
    
         
            +
                    :return: True if the current local system time is a valid open date and time, False if not
         
     | 
| 
      
 953 
     | 
    
         
            +
                    """
         
     | 
| 
      
 954 
     | 
    
         
            +
                    current_time = MarketCalendar._get_current_time()
         
     | 
| 
      
 955 
     | 
    
         
            +
                    return self.open_at_time(schedule, current_time, include_close=include_close, only_rth=only_rth)
         
     | 
| 
      
 956 
     | 
    
         
            +
             
     | 
| 
      
 957 
     | 
    
         
            +
                def clean_dates(self, start_date, end_date):
         
     | 
| 
      
 958 
     | 
    
         
            +
                    """
         
     | 
| 
      
 959 
     | 
    
         
            +
                    Strips the inputs of time and time zone information
         
     | 
| 
      
 960 
     | 
    
         
            +
             
     | 
| 
      
 961 
     | 
    
         
            +
                    :param start_date: start date
         
     | 
| 
      
 962 
     | 
    
         
            +
                    :param end_date: end date
         
     | 
| 
      
 963 
     | 
    
         
            +
                    :return: (start_date, end_date) with just date, no time and no time zone
         
     | 
| 
      
 964 
     | 
    
         
            +
                    """
         
     | 
| 
      
 965 
     | 
    
         
            +
                    start_date = pd.Timestamp(start_date).tz_localize(None).normalize()
         
     | 
| 
      
 966 
     | 
    
         
            +
                    end_date = pd.Timestamp(end_date).tz_localize(None).normalize()
         
     | 
| 
      
 967 
     | 
    
         
            +
                    return start_date, end_date
         
     | 
| 
      
 968 
     | 
    
         
            +
             
     | 
| 
      
 969 
     | 
    
         
            +
                def is_different(self, col, diff=None):
         
     | 
| 
      
 970 
     | 
    
         
            +
                    if diff is None:
         
     | 
| 
      
 971 
     | 
    
         
            +
                        diff = pd.Series.ne
         
     | 
| 
      
 972 
     | 
    
         
            +
                    normal = self.days_at_time(col.index, col.name)
         
     | 
| 
      
 973 
     | 
    
         
            +
                    return diff(col.dt.tz_convert("UTC"), normal)
         
     | 
| 
      
 974 
     | 
    
         
            +
             
     | 
| 
      
 975 
     | 
    
         
            +
                def early_closes(self, schedule):
         
     | 
| 
      
 976 
     | 
    
         
            +
                    """
         
     | 
| 
      
 977 
     | 
    
         
            +
                    Get a DataFrame of the dates that are an early close.
         
     | 
| 
      
 978 
     | 
    
         
            +
             
     | 
| 
      
 979 
     | 
    
         
            +
                    :param schedule: schedule DataFrame
         
     | 
| 
      
 980 
     | 
    
         
            +
                    :return: schedule DataFrame with rows that are early closes
         
     | 
| 
      
 981 
     | 
    
         
            +
                    """
         
     | 
| 
      
 982 
     | 
    
         
            +
                    return schedule[self.is_different(schedule["market_close"], pd.Series.lt)]
         
     | 
| 
      
 983 
     | 
    
         
            +
             
     | 
| 
      
 984 
     | 
    
         
            +
                def late_opens(self, schedule):
         
     | 
| 
      
 985 
     | 
    
         
            +
                    """
         
     | 
| 
      
 986 
     | 
    
         
            +
                    Get a DataFrame of the dates that are an late opens.
         
     | 
| 
      
 987 
     | 
    
         
            +
             
     | 
| 
      
 988 
     | 
    
         
            +
                    :param schedule: schedule DataFrame
         
     | 
| 
      
 989 
     | 
    
         
            +
                    :return: schedule DataFrame with rows that are late opens
         
     | 
| 
      
 990 
     | 
    
         
            +
                    """
         
     | 
| 
      
 991 
     | 
    
         
            +
                    return schedule[self.is_different(schedule["market_open"], pd.Series.gt)]
         
     | 
| 
      
 992 
     | 
    
         
            +
             
     | 
| 
      
 993 
     | 
    
         
            +
                def __getitem__(self, item):
         
     | 
| 
      
 994 
     | 
    
         
            +
                    if isinstance(item, (tuple, list)):
         
     | 
| 
      
 995 
     | 
    
         
            +
                        if item[1] == "all":
         
     | 
| 
      
 996 
     | 
    
         
            +
                            return self.get_time(item[0], all_times=True)
         
     | 
| 
      
 997 
     | 
    
         
            +
                        else:
         
     | 
| 
      
 998 
     | 
    
         
            +
                            return self.get_time_on(item[0], item[1])
         
     | 
| 
      
 999 
     | 
    
         
            +
                    else:
         
     | 
| 
      
 1000 
     | 
    
         
            +
                        return self.get_time(item)
         
     | 
| 
      
 1001 
     | 
    
         
            +
             
     | 
| 
      
 1002 
     | 
    
         
            +
                def __setitem__(self, key, value):
         
     | 
| 
      
 1003 
     | 
    
         
            +
                    return self.add_time(key, value)
         
     | 
| 
      
 1004 
     | 
    
         
            +
             
     | 
| 
      
 1005 
     | 
    
         
            +
                def __delitem__(self, key):
         
     | 
| 
      
 1006 
     | 
    
         
            +
                    return self.remove_time(key)
         
     |