def get_last_working_day_of_a_month(last_day_of_month: date) -> date:
    """
    When provided with a date object representing the last day of a month,
    this function will return the last working day of that month.
    """
    uk_holidays = holidays.UnitedKingdom()
    if last_day_of_month in uk_holidays or last_day_of_month.weekday() > 4:
        return get_last_working_day_of_a_month(last_day_of_month -
                                               timedelta(days=1))
    else:
        return last_day_of_month
예제 #2
0
def uk_holiday(df,colm_dat,colm_reg):
  holdiay_list=[]
  for x in range(len(df)):
    
    if df.loc[x,colm_reg]=='England':
      uk_holidays =holidays.England()
      holdy=int(df_pharma_sales_raw.loc[x,'DATE'] in uk_holidays)
    elif df.loc[x,colm_reg]=='Scotland':
      uk_holidays =holidays.Scotland()
      holdy=int(df_pharma_sales_raw.loc[x,'DATE'] in uk_holidays)
    elif df.loc[x,colm_reg]=='Wales':
      uk_holidays =holidays.Wales()
      holdy=int(df_pharma_sales_raw.loc[x,'DATE'] in uk_holidays)
    elif df.loc[x,colm_reg]=='Northern Ireland':
      uk_holidays =holidays.NorthernIreland()
      holdy=int(df_pharma_sales_raw.loc[x,'DATE'] in uk_holidays)
    else:
      uk_holidays =holidays.UnitedKingdom()
      holdy=int(df_pharma_sales_raw.loc[x,'DATE'] in uk_holidays)
    holdiay_list.append(holdy)
  return holdiay_list
예제 #3
0
data = []
f = open('./python_ann/data.txt', 'r')
data = json.loads(f.read())
x_pred = []
pred_out = []
dates = []
for item in data:
    formattedDate = datetime.datetime.strptime(
        "{} {}".format(item[0][0:10], item[0][11:16]), "%Y-%m-%d %H:%M")
    dates.append(datetime.datetime.strftime(formattedDate, '%Y-%m-%d %H:%M'))
    NotWeekend = 0 if formattedDate.weekday() == 5 or formattedDate.weekday(
    ) == 6 else 1
    InOperatingHours = 1 if 6 <= formattedDate.hour <= 19 else 0
    NotHoliday = 1
    for date in holidays.UnitedKingdom(years=int(formattedDate.year)).items():
        if "[" not in date[1] or "England" in date[1]:
            if formattedDate == (date[0].strftime('%Y-%m-%d')):
                NotHoliday = 0
                break
    x_pred.append([
        item[1], item[2], item[3], item[4], item[5], item[6], NotWeekend,
        InOperatingHours, NotHoliday
    ])
    pred_out.append([
        item[1], item[2], item[3], item[4], item[5], item[6], NotWeekend,
        InOperatingHours, NotHoliday
    ])

model = keras.models.load_model("./python_ann/{}_{}_Model.h5".format(
    building, reading))
예제 #4
0
	def fit(self, X, y=None):
		self.USh = holidays.UnitedStates()
		self.CAh = holidays.Canada()
		self.UKh = holidays.UnitedKingdom()
		self.IEh = holidays.Ireland()
		return self
# In[29]:


df1 = df1.groupby(['Date'])['Quantity'].sum().reset_index()
df1.head(5)


# Let us integrate national holidays from UK in out dataset and will have a bad impact on our forcasted values. Let us first filter it out.

# In[30]:


# holidays
uk_holidays = []
for date in holidays.UnitedKingdom(years = 2017).items():
    uk_holidays.append(str(date[0]))

holidays = pd.DataFrame(uk_holidays, columns=['Holiday Date']) 
holidays.head()


# In[31]:


df1['Holidays'] = df1['Date'].isin(uk_holidays)
df1.head()


# In[32]:
예제 #6
0

# 증시 휴장
def get_holidays(county):
    nyse = mcal.get_calendar(county)
    holidays = nyse.holidays()
    return list(holidays.holidays)


today = datetime.now()
expiration = datetime(2019, 2, 13, 0, 0)
holidays = get_holidays('NYSE')  # NYSE Holidays

# count trading date
days_to_expiration = np.busday_count(today.date(),
                                     expiration.date(),
                                     holidays=holidays)
print(days_to_expiration)


def find_date():
    return


# Select country
uk_holidays = holidays.UnitedKingdom()

# Print all the holidays in UnitedKingdom in year 2018
for ptr in holidays.UnitedKingdom(years=2018).items():
    print(ptr)
예제 #7
0
czech_holidays = holidays.Czech()
denmark_holidays = holidays.Denmark()
england_holidays = holidays.England()
europeancentralbank_holidays = holidays.EuropeanCentralBank()
germany_holidays = holidays.Germany()
ireland_holidays = holidays.Ireland()
mexico_holidays = holidays.Mexico()
netherlands_holidays = holidays.Netherlands()
newzealand_holidays = holidays.NewZealand()
northernireland_holidays = holidays.NorthernIreland()
norway_holidays = holidays.Norway()
portugal_holidays = holidays.Portugal()
portugalext_holidays = holidays.PortugalExt()
scotland_holidays = holidays.Scotland()
spain_holidays = holidays.Spain()
unitedkingdom_holidays = holidays.UnitedKingdom()
unitedstates_holidays = holidays.UnitedStates()
wales_holidays = holidays.Wales()

def isDateHoliday(date, countryHolidays):
	return date in country

def isTodayHoliday(countryHolidays):
	return today in countryHolidays

def whatIsTodaysHoliday(countryHolidays):
	if isTodayHoliday(countryHolidays):
		return countryHolidays(today)
	return "Today is not a holiday in " + str(countryHolidays.country)

예제 #8
0
def populate_date_dim(year):
    # Leap Year Check and assign value for the periods accordingly
    if (int(year) % 4) == 0:
        if (int(year) % 100) == 0:
            if (int(year) % 400) == 0:
                data['THEDATE'] = pd.date_range(start='01/01/' + year,
                                                periods=366)
            else:
                data['THEDATE'] = pd.date_range(start='01/01/' + year,
                                                periods=365)
        else:
            data['THEDATE'] = pd.date_range(start='01/01/' + year, periods=366)
    else:
        data['THEDATE'] = pd.date_range(start='01/01/' + year, periods=365)

    uk_holidays = holidays.UnitedKingdom()
    for index, val in enumerate(data.THEDATE):
        data['DATEKEY'].loc[index] = int(str(val.date()).replace('-', ''))
        data['YEAR'].loc[index] = val.year
        data['CURRENTYEAR'].loc[index] = str(val.year)
        data['PRIORYEAR'].loc[index] = str((val.year) - 1)
        data['YEARMONTH'].loc[index] = val.to_period('M')
        data['MONTH'].loc[index] = val.month
        data['CURRENTMONTH'].loc[index] = str(val.month)
        data['MONTHNAME'].loc[index] = val.month_name()
        data['MONTHABBR'].loc[index] = val.month_name()[0:3]
        data['DAY'].loc[index] = val.day
        data['DAYOFWEEK'].loc[index] = val.dayofweek + 1
        data['DAYOFWEEKNAME'].loc[index] = val.day_name()
        data['DAYOFWEEKABBR'].loc[index] = val.day_name()[0:3]
        data['QUARTER'].loc[index] = val.quarter

        # prior month
        if data['MONTHABBR'].loc[index] == 'Jan':
            data['PRIORMONTH'].loc[index] = '12'
        else:
            data['PRIORMONTH'].loc[index] = str((val.month) - 1)

        # season
        if data['MONTHABBR'].loc[index] in ('Apr', 'May', 'Jun'):
            data['SEASON'].loc[index] = 'Summer'
        elif data['MONTHABBR'].loc[index] in ('Oct', 'Nov', 'Dec', 'Jan'):
            data['SEASON'].loc[index] = 'Winter'
        elif data['MONTHABBR'].loc[index] in ('Jul', 'Aug', 'Sep'):
            data['SEASON'].loc[index] = 'Monsoon'
        elif data['MONTHABBR'].loc[index] in ('Feb', 'Mar'):
            data['SEASON'].loc[index] = 'Spring'

        # Holidays: considering holidays for UK. the holidays module has various other countries as well
        if (val in uk_holidays):
            data['HOLIDAY'].loc[index] = uk_holidays.get(val)
        elif data['DAYOFWEEKABBR'].loc[index] in ('Sat', 'Sun'):
            data['HOLIDAY'].loc[index] = 'Weekend'
        else:
            data['HOLIDAY'].loc[index] = 'No Holiday'

        # bussiness day (if holiday then 0 and if no holiday then 1)
        if (data['HOLIDAY'].loc[index] == 'No Holiday'):
            data['BUSINESSDAY'].loc[index] = '1'
        else:
            data['BUSINESSDAY'].loc[index] = '0'

        # first of month (if day in the date is 01 then set firstofmonth flag to true (1) or esle False (0) )
        if (data['DAY'].loc[index] == 1.0):
            data['FIRSTOFMONTH'].loc[index] = '1'
        else:
            data['FIRSTOFMONTH'].loc[index] = '0'
        '''fiscal month considering that the fiscal year starts from 01-apr-2020'''

        if data['MONTHABBR'].loc[index] == 'Apr':
            data['FISCALMONTH'].loc[index] = 'One'
        elif data['MONTHABBR'].loc[index] == 'May':
            data['FISCALMONTH'].loc[index] = 'Two'
        elif data['MONTHABBR'].loc[index] == 'Jun':
            data['FISCALMONTH'].loc[index] = 'Three'
        elif data['MONTHABBR'].loc[index] == 'Jul':
            data['FISCALMONTH'].loc[index] = 'Four'
        elif data['MONTHABBR'].loc[index] == 'Aug':
            data['FISCALMONTH'].loc[index] = 'Five'
        elif data['MONTHABBR'].loc[index] == 'Sep':
            data['FISCALMONTH'].loc[index] = 'Six'
        elif data['MONTHABBR'].loc[index] == 'Oct':
            data['FISCALMONTH'].loc[index] = 'Seven'
        elif data['MONTHABBR'].loc[index] == 'Nov':
            data['FISCALMONTH'].loc[index] = 'Eight'
        elif data['MONTHABBR'].loc[index] == 'Dec':
            data['FISCALMONTH'].loc[index] = 'Nine'
        elif data['MONTHABBR'].loc[index] == 'Jan':
            data['FISCALMONTH'].loc[index] = '10th fiscal month of 2019'
        elif data['MONTHABBR'].loc[index] == 'Feb':
            data['FISCALMONTH'].loc[index] = '11th fiscal month of 2019'
        elif data['MONTHABBR'].loc[index] == 'Mar':
            data['FISCALMONTH'].loc[index] = '12th fiscal month of 2019'
    return data
예제 #9
0
def get_holidays():
    dates = []
    for date, name in sorted(holidays.UnitedKingdom().items()):
        dates.append(date)
    return dates
예제 #10
0
from datetime import date 
import holidays 
uk_holidays = holidays.UnitedKingdom() 
print('01-01-2018' in uk_holidays) 
print('02-01-2018' in uk_holidays)
  print(uk_holidays.get('01-01-2018')) 
print(uk_holidays.get('02-01-2018'))