Exemplo n.º 1
0
        def create_biz_hol_index(start_date: datetime.date,
                                 end_date: datetime.date) -> pd.date_range:
            """
            平日と休日のindexを返す
            """
            year = start_date.year
            holiday = []
            holiday_dict = jpholiday.year_holidays(year)
            for i in range(len(holiday_dict)):
                holiday.append(holiday_dict[i][0])
            holiday = holiday + [
                date(year, 1, 1),
                date(year, 1, 2),
                date(year, 1, 3),
                date(year, 12, 31)
            ]
            holiday = sorted(list(set(holiday)))
            holiday = pd.to_datetime(holiday)

            calendar_full = pd.date_range(start_date, end_date, freq="D")
            business_index = []
            holiday_index = []
            for idx, calendar in enumerate(calendar_full):
                if (not calendar in holiday) and (
                        calendar.weekday() >= 0) and (calendar.weekday() <= 4):
                    business_index.append(idx)
                else:
                    holiday_index.append(idx)

            return business_index, holiday_index
Exemplo n.º 2
0
def tse_date_range(start_date: datetime.date,
                   end_date: datetime.date) -> pd.date_range:
    """
    東証の営業日を返す
    """
    cal = []
    for year in range(start_date.year, end_date.year):
        calendar = jpholiday.year_holidays(year)  # 日本の祝日(辞書形式)
        for i in range(len(calendar)):  # 日本の祝日(リスト)
            cal.append(calendar[i][0])
        cal = cal + [
            datetime.date(year, 1, 1),
            datetime.date(year, 1, 2),
            datetime.date(year, 1, 3),
            datetime.date(year, 12, 31),
        ]  # 年末年始追加
    cal = sorted(list(set(cal)))  # for uniqueness
    cal = pd.to_datetime(cal)

    calendar_full = pd.date_range(start_date, end_date, freq="D")
    index = []
    for i in range(len(calendar_full)):
        if not calendar_full[i] in cal:
            index.append(i)
    business_day = calendar_full[index]
    business_day = business_day[(business_day.weekday >= 0)
                                & (business_day.weekday <= 4)]

    return business_day
Exemplo n.º 3
0
def get_holiday_list():
    #現在日時のオブジェクトを取得
    now = datetime.datetime.now()
    #休日格納用配列
    holiday_list = []
    #現在年の祝日ループし取得
    for holday in jpholiday.year_holidays(now.year):
        holiday_list.append(holday[0])

    # 現在日取得
    today = datetime.date.today()
    # 現在日から10日分ループ
    for cnt in range(1, 10):
        cale_date = datetime.timedelta(days=cnt)
        add_date = today + cale_date
        #土曜日または日曜日の場合 休日の配列に格納
        if add_date.weekday() == 5 or add_date.weekday() == 6:
            holiday_list.append(add_date)

    #重複を削除
    holiday_list_uniq = list(set(holiday_list))
    #配列のソートする
    holiday_list_uniq.sort()

    return (holiday_list_uniq)
Exemplo n.º 4
0
 def test_count_year(self):
     """
     2021年祝日数
     """
     self.assertEqual(len(jpholiday.year_holidays(2021)), 17)
Exemplo n.º 5
0
 def test_count_year(self):
     """
     1999年祝日数
     """
     self.assertEqual(len(jpholiday.year_holidays(1999)), 17)
Exemplo n.º 6
0
 def test_count_year(self):
     """
     2019年祝日数
     """
     self.assertEqual(len(jpholiday.year_holidays(2019)), 22)
Exemplo n.º 7
0
 def getHolidayList(year):
     return jpholiday.year_holidays(year)