def test_isholiday(): assert dtvals.isholiday() assert dtvals.isholiday(None) assert dtvals.isholiday(date=None) assert not dtvals.isholiday(date=datetime.date(2018, 12, 22)) assert not dtvals.isholiday(datetime.date(2018, 12, 22)) assert dtvals.isholiday() assert dtvals.isholiday(None, None) assert dtvals.isholiday(hdays=None) assert dtvals.isholiday(date=datetime.date(2019, 1, 14), hdays=holidays.Japan()) assert not dtvals.isholiday(date=datetime.date(2019, 1, 15), hdays=holidays.Japan())
def holiday_adjust(trade_date, delta): forward_date = trade_date + delta year = forward_date.year # if trade_date is holiday if (forward_date in hol.Australia() or forward_date in hol.US() or forward_date in hol.UK() or forward_date in hol.Japan()): forward_date = forward_date + dt.timedelta(days=1) holiday_adjust(forward_date, dt.timedelta()) # date is weekend elif forward_date.weekday() >= 5: forward_date = forward_date + dt.timedelta(days=1) holiday_adjust(forward_date, dt.timedelta()) return forward_date
def __init__(self, nominal, initial, knockIn, knockOut, highRate, lowRate, strike, startDate, endDate, frequency, currency, dayCount="Act/365", adjMethod="Mod. Following", isStub=True): self.nominal = nominal self.startDate = startDate self.endDate = endDate self.frequency = frequency self.dayCount = dayCount self.adjMethod = adjMethod self.currency = currency self.isStub = isStub self.initial = initial self.knockInLevel = knockIn * initial self.knockOutLevel = knockOut * initial self.highRate = highRate self.lowRate = lowRate self.strikeLevel = strike * initial #""" Additional structure to store prices for different dates: Makes it faster and easier to run bootstrap """ self.prices = {} if self.currency == "USD": self.holidayArray = holidays.UnitedStates() elif self.currency == "SEK": self.holidayArray = holidays.Sweden() elif self.currency == "JPY": self.holidayArray = holidays.Japan() self.cfDates = DateUtils.GenerateCashFlowDates(startDate, endDate, None, frequency, adjMethod, isStub, self.holidayArray) self.pv = 0.0 self.cfs = [] self.cfPVs = [] self.cfDays = [] self.dfs = [] self.pvTotal = 0.0
def __init__( self, nominal, startDate, endDate, spread, frequency, currency, # koProb, dayCount="Act/365", adjMethod="Mod. Following", isStub=True): self.nominal = nominal self.startDate = startDate self.endDate = endDate self.spread = spread self.frequency = frequency self.dayCount = dayCount self.adjMethod = adjMethod self.currency = currency # self.koProb = koProb self.isStub = isStub #""" Additional structure to store prices for different dates: Makes it faster and easier to run bootstrap """ self.prices = {} if self.currency == "USD": self.holidayArray = holidays.UnitedStates() elif self.currency == "SEK": self.holidayArray = holidays.Sweden() elif self.currency == "JPY": self.holidayArray = holidays.Japan() self.cfDates = DateUtils.GenerateCashFlowDates(startDate, endDate, None, frequency, adjMethod, isStub, self.holidayArray) self.pv = 0.0 self.cfs = [] self.cfPVs = [] self.cfDays = [] self.dfs = [] self.pvTotal = 0.0
def TellMarkets(self): # Grabs the Current time in two different formats, adjust in future today = datetime.date.today() currentTime = datetime.datetime.utcnow().replace(tzinfo=pytz.utc) # standard holidays for United States, Great Britian, Japan, and Australia us_holidays = holidays.US() britian_holidays = holidays.England() japan_holidays = holidays.Japan() australia_holidays = holidays.Australia() # Exchange Holiday is not included in the Standard Holiday's of Japan exchange_holiday = "{}-12-31".format(currentTime.year) japan_holidays.append({exchange_holiday: "Exchange Holiday"}) # Translator needed because Japanese holiday's are returned in Japanese translator = Translator() # The Holidays that close Markets In the Given Countries, Unsure if all of Japan's Holiday's Close the Currency Markets us_market_holidays = [ "New Year's Day", "Martin Luther King, Jr. Day", "Presidents Day or Washington's Birthday", "Good Friday", "Memorial Day", "Independence Day", "Labor Day", "Thanksgiving Day", "Christmas Day", ] britian_market_holidays = [ "New Year's Day", "Good Friday", "Easter Monday", "May Day", "Spring Bank Holiday", "Summer Bank Holiday", "Christmas Day", "Boxing Day", "Exchange Holiday", ] japan_market_holidays = [ "New Year's Day", "Adult Day", "Foundation Day", "Vernal Equinox Day", "Showa Day", "Constitution Memorial Day", "Greenery Day", "Children's Day", "Sea Day", "Respect for the Aged Day", "Autumnal Equinox Day", "Health and Sports Day", "Culture Day", "Labor Thanksgiving Day", "The birth of the Emperor", "Exchange Holiday", ] australian_market_holidays = [ "New Year's Day", "Australia Day", "Good Friday", "Easter Monday", "Anzac Day", "Queen's Birthday", "Christmas Day", "Boxing Day", ] us_has_holiday = False japan_has_holiday = False britian_has_holiday = False australia_has_holiday = False markets_closed = False if int(currentTime.weekday()) == 4 or 5 or 6: if currentTime.hour >= 21 and int(currentTime.weekday()) == 4: markets_closed = True if currentTime.hour < 21 and int(currentTime.weekday()) == 6: markets_closed = True if int(currentTime.weekday()) == 5: markets_closed = True if markets_closed == True: self.open_markets = 'None' return self if us_holidays.get(today) is not None: for i in us_market_holidays: if us_holidays.get(today) == i: self.returned_items['US-Holiday'] = us_holidays.get(today) us_has_holiday = True if britian_holidays.get(today) is not None: for i in britian_market_holidays: if britian_holidays.get(today) == i: self.returned_items[ 'British-Holiday'] = britian_holidays.get(today) britian_has_holiday = True if japan_holidays.get(today) is not None: holiday_in_english = translator.translate( japan_holidays.get(today)) for i in japan_market_holidays: if holiday_in_english.text == i: self.returned_items[ 'Japanese-Holiday'] = holiday_in_english japan_has_holiday = True if australia_holidays.get(today) is not None: for i in australian_market_holidays: if australia_holidays == i: self.returned_items[ 'Australian-Holiday'] = australia_holidays.get(today) australia_has_holiday = True # checks to see if we are in daylight saving time # need to make dynamic for what is being returned if bool(datetime.datetime.now(pytz.timezone("UTC")).dst()): if currentTime.hour >= 22 or currentTime.hour == 7: if not australia_has_holiday: self.open_markets.append('Australia') if currentTime.hour >= 23 or currentTime.hour <= 8: if not japan_has_holiday: self.open_markets.append('Japan') if currentTime.hour >= 7 and currentTime.hour <= 16: if not britian_has_holiday: self.open_markets.append('Britian') if currentTime.hour >= 13 and currentTime.hour <= 21: if not us_has_holiday: self.open_markets.append('US') else: if currentTime.hour >= 20 and currentTime.hour <= 5: if not australia_has_holiday: self.open_markets.append('Australia') if currentTime.hour >= 22 or currentTime.hour == 7: if not japan_has_holiday: self.open_markets.append('Japan') if currentTime.hour >= 7 and currentTime.hour <= 16: if not britian_has_holiday: self.open_markets.append('Britian') if currentTime.hour >= 12 and currentTime.hour <= 21: if not us_has_holiday: self.open_markets.append('US') return (self)
def setUp(self): self.holidays = holidays.Japan(observed=False)