Пример #1
0
def main():

    args = sys.argv
    start = date.today()
    try:
        start = parse_date(args[1]).date()
    except:
        pass

    end = date.today()
    try:
        end = parse_date(args[2]).date()
    except:
        pass
    if (start.year > end.year):
        start, end = end, start

    holidays = filter(lambda holiday: start <= holiday[0].date() <= end,
                      CountryHolidays.between('JP', start.year, end.year))

    dom = xml.dom.minidom.Document()
    root = dom.createElement('holidays')
    root.setAttribute('start', start.strftime('%Y/%m/%d'))
    root.setAttribute('end', end.strftime('%Y/%m/%d'))
    dom.appendChild(root)

    for holiday in holidays:
        node = dom.createElement('holiday')
        node.setAttribute('date', holiday[0].strftime('%Y/%m/%d'))
        node.setAttribute('name', holiday[1])
        root.appendChild(node)

    print(dom.toprettyxml())
Пример #2
0
 def testJP2015(self):
     from holidays_jp import CountryHolidays
     holidays = CountryHolidays.get('JP', 2015)
     self.assertEqual(len(holidays), 17)
     self.assertHoliday(holidays[0], datetime.datetime(2015, 1, 1), '元日')
     self.assertHoliday(holidays[1], datetime.datetime(2015, 1, 12), '成人の日')
     self.assertHoliday(holidays[2], datetime.datetime(2015, 2, 11),
                        '建国記念の日')
     self.assertHoliday(holidays[3], datetime.datetime(2015, 3, 21), '春分の日')
     self.assertHoliday(holidays[4], datetime.datetime(2015, 4, 29), '昭和の日')
     self.assertHoliday(holidays[5], datetime.datetime(2015, 5, 3), '憲法記念日')
     self.assertHoliday(holidays[6], datetime.datetime(2015, 5, 4), 'みどりの日')
     self.assertHoliday(holidays[7], datetime.datetime(2015, 5, 5), 'こどもの日')
     self.assertHoliday(holidays[8], datetime.datetime(2015, 5, 6), '振替休日')
     self.assertHoliday(holidays[9], datetime.datetime(2015, 7, 20), '海の日')
     self.assertHoliday(holidays[10], datetime.datetime(2015, 9, 21),
                        '敬老の日')
     self.assertHoliday(holidays[11], datetime.datetime(2015, 9, 22),
                        '国民の休日')
     self.assertHoliday(holidays[12], datetime.datetime(2015, 9, 23),
                        '秋分の日')
     self.assertHoliday(holidays[13], datetime.datetime(2015, 10, 12),
                        '体育の日')
     self.assertHoliday(holidays[14], datetime.datetime(2015, 11, 3),
                        '文化の日')
     self.assertHoliday(holidays[15], datetime.datetime(2015, 11, 23),
                        '勤労感謝の日')
     self.assertHoliday(holidays[16], datetime.datetime(2015, 12, 23),
                        '天皇誕生日')
Пример #3
0
def bbg_volcurve(ind, event, edate, numdays, interval, fld_lst):
    sec_list = blp.get_index(ind)
    volcurves = pd.DataFrame()
    fmt = "%Y-%m-%d" + 'T' + "%H:%M:%S"  #Assumes no milliseconds
    endDateTime = dt.datetime.strptime(edate, fmt)
    bday_jp = CustomBusinessDay(holidays=zip(
        *CountryHolidays.get('JP', int(edate[0:4])))[0])
    startDateTime = endDateTime.replace(hour=9) - numdays * BDay()
    timedelta = pd.date_range(startDateTime, endDateTime,
                              freq=bday_jp).nunique()
    sdate = startDateTime.strftime(fmt)
    for stock in sec_list:
        output = get_Bars(stock, event, sdate, edate, interval, fld_lst)
        output.rename(columns={'VOLUME': stock}, inplace=True)
        volcurves = volcurves.join(output, how="outer")

    #process the raw data into historical averages
    volcurves.rename(columns=lambda x: x[:4], inplace=True)
    timevect = pd.Series(volcurves.index.values)
    timeframet = timevect.to_frame()
    timeframet.columns = ['date']
    timeframet.set_index(timevect, inplace="True")
    timeframet['bucket'] = timeframet['date'].apply(
        lambda x: dt.datetime.strftime(x, '%H:%M:%S'))
    timeframet = timeframet.join(volcurves)
    volcurvesum = timeframet.groupby(['bucket']).sum()
    adv = volcurvesum.sum() / timedelta
    volcurves = volcurvesum / volcurvesum.sum()
    volcurves = volcurves.cumsum()
    volcurves = volcurves.interpolate()
    volcurvesum = volcurvesum.interpolate()

    return adv, volcurvesum.fillna(method=bfill), volcurves.fillna(
        method=bfill)
Пример #4
0
 def testJP2021(self):
     from holidays_jp import CountryHolidays
     holidays = CountryHolidays.get('JP', 2021)
     self.assertEqual(len(holidays), 15)
     self.assertHoliday(holidays[0], datetime.datetime(2021, 1, 1), '元日')
     self.assertHoliday(holidays[1], datetime.datetime(2021, 1, 11), '成人の日')
     self.assertHoliday(holidays[2], datetime.datetime(2021, 2, 11),
                        '建国記念の日')
     self.assertHoliday(holidays[3], datetime.datetime(2021, 3, 20), '春分の日')
     self.assertHoliday(holidays[4], datetime.datetime(2021, 4, 29), '昭和の日')
     self.assertHoliday(holidays[5], datetime.datetime(2021, 5, 3), '憲法記念日')
     self.assertHoliday(holidays[6], datetime.datetime(2021, 5, 4), 'みどりの日')
     self.assertHoliday(holidays[7], datetime.datetime(2021, 5, 5), 'こどもの日')
     self.assertHoliday(holidays[8], datetime.datetime(2021, 7, 19), '海の日')
     self.assertHoliday(holidays[9], datetime.datetime(2021, 8, 11), '山の日')
     self.assertHoliday(holidays[10], datetime.datetime(2021, 9, 20),
                        '敬老の日')
     self.assertHoliday(holidays[11], datetime.datetime(2021, 9, 23),
                        '秋分の日')
     self.assertHoliday(holidays[12], datetime.datetime(2021, 10, 11),
                        'スポーツの日')
     self.assertHoliday(holidays[13], datetime.datetime(2021, 11, 3),
                        '文化の日')
     self.assertHoliday(holidays[14], datetime.datetime(2021, 11, 23),
                        '勤労感謝の日')
Пример #5
0
 def testJPBetween(self):
     from holidays_jp import CountryHolidays
     holidays = CountryHolidays.between('JP', 1948, 2015)
     year_count = {}
     for holiday in holidays:
         if holiday[0].year not in year_count:
             year_count[holiday[0].year] = 0
         year_count[holiday[0].year] += 1
     for year in year_count:
         self.assertTrue(year_count[year] > 1)
Пример #6
0
def holidaysList(year):
    """
    input 4 digit in year
    """
    holidays = CountryHolidays.get('JP',int(year))
    
    return_list = []
    
    for i in holidays:
        return_list.append(i[0].strftime("%Y-%m-%d"))
    return(return_list)
Пример #7
0
 def testJP2019(self):
     from holidays_jp import CountryHolidays
     holidays = CountryHolidays.get('JP', 2019)
     self.assertEqual(len(holidays), 22)
     self.assertHoliday(holidays[0], datetime.datetime(2019, 1, 1), '元日')
     self.assertHoliday(holidays[1], datetime.datetime(2019, 1, 14), '成人の日')
     self.assertHoliday(holidays[2], datetime.datetime(2019, 2, 11),
                        '建国記念の日')
     self.assertHoliday(holidays[3], datetime.datetime(2019, 3, 21), '春分の日')
     self.assertHoliday(holidays[4], datetime.datetime(2019, 4, 29), '昭和の日')
     self.assertHoliday(holidays[5], datetime.datetime(2019, 4, 30),
                        '国民の休日')
     self.assertHoliday(holidays[6], datetime.datetime(2019, 5, 1),
                        '天皇の即位の日')
     self.assertHoliday(holidays[7], datetime.datetime(2019, 5, 2), '国民の休日')
     self.assertHoliday(holidays[8], datetime.datetime(2019, 5, 3), '憲法記念日')
     self.assertHoliday(holidays[9], datetime.datetime(2019, 5, 4), 'みどりの日')
     self.assertHoliday(holidays[10], datetime.datetime(2019, 5, 5),
                        'こどもの日')
     self.assertHoliday(holidays[11], datetime.datetime(2019, 5, 6), '振替休日')
     self.assertHoliday(holidays[12], datetime.datetime(2019, 7, 15), '海の日')
     self.assertHoliday(holidays[13], datetime.datetime(2019, 8, 11), '山の日')
     self.assertHoliday(holidays[14], datetime.datetime(2019, 8, 12),
                        '振替休日')
     self.assertHoliday(holidays[15], datetime.datetime(2019, 9, 16),
                        '敬老の日')
     self.assertHoliday(holidays[16], datetime.datetime(2019, 9, 23),
                        '秋分の日')
     self.assertHoliday(holidays[17], datetime.datetime(2019, 10, 14),
                        '体育の日')
     self.assertHoliday(holidays[18], datetime.datetime(2019, 10, 22),
                        '即位礼正殿の儀の行われる日')
     self.assertHoliday(holidays[19], datetime.datetime(2019, 11, 3),
                        '文化の日')
     self.assertHoliday(holidays[20], datetime.datetime(2019, 11, 4),
                        '振替休日')
     self.assertHoliday(holidays[21], datetime.datetime(2019, 11, 23),
                        '勤労感謝の日')
Пример #8
0

#main
parser = argparse.ArgumentParser()
parser.add_argument("start_year",
                    type=int,
                    help="year, from which to generate table (inclusive)")
parser.add_argument("end_year",
                    type=int,
                    help="year, till which to generate table (inclusive)")
parser.add_argument("--dry_run",
                    help="dry run (default: false)",
                    action="store_true")
args = parser.parse_args()

holidays = CountryHolidays.between("JP", args.start_year, args.end_year)
cal = calendar.Calendar()

#行 date	year    month	day	weekday	holiday	holiday_name	week_name	week
#1  2018-01-01	2018	1	1	1	1	元旦	        月	        W02
with open(TMP_FILE_NAME, "w") as calfile:
    #calfile.write("date,year,month,day,weekday,holiday,holiday_name,week_name,week\n");
    for year, month in product(range(args.start_year, args.end_year + 1),
                               range(1, 13)):
        myiter = list(cal.itermonthdays(year, month))
        for date in range(1, max(myiter) + 1):
            match = [
                x for x in enumerate(holidays)
                if x[1][0] == datetime.datetime(year, month, date)
            ]
            calfile.write(
Пример #9
0
#LOADING the data
"""
This is the file holding the market data. Unfortunately, I cannot make the data set public. 
The structure of the excel file is prettu basic: column A holds the dates, and then each column after B holds a stock
"""

t = 'path_to_market_data_file_name.xlsx'  #use YOUR own file here
bb = proc(t)

#GETTING RID of the JAPANESE holidays from the data. You can use, add or subtract the relevant years for your data in the list below

years = [2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020]
hol = []
for k in years:
    holidays = CountryHolidays.get('JP', k)
    for j in holidays:
        hol.append(j[0])


def elim_holidays(bb, hol):
    for k in range(len(bb) - 1, 0, -1):
        if bb.index[k] in hol:  #to py_datetime() when we have a Timestamp
            bb = bb.drop(bb.index[k])
    return bb


bb = elim_holidays(bb, hol)
bb = bb[-400:]

Пример #10
0
 CountryHolidays([
     Holiday(
         'New Year\'s Day',
         rrule(
             YEARLY, dtstart=datetime(2000, 1,
                                      1), bymonth=1, bymonthday=1)),
     Holiday(
         'Martin Luther King Jr.\'S Birthday',
         rrule(YEARLY,
               dtstart=datetime(2000, 1, 1),
               bymonth=1,
               byweekday=MO,
               bysetpos=3)),
     Holiday(
         'Washington\'s Birthday',
         rrule(YEARLY,
               dtstart=datetime(2000, 1, 1),
               bymonth=2,
               byweekday=MO,
               bysetpos=3)),
     Holiday(
         'Memorial Day',
         rrule(YEARLY,
               dtstart=datetime(2000, 1, 1),
               bymonth=5,
               byweekday=MO,
               bysetpos=-1)),
     Holiday(
         'Independence Day',
         rrule(
             YEARLY, dtstart=datetime(2000, 1,
                                      1), bymonth=7, bymonthday=4)),
     Holiday(
         'Labor Day',
         rrule(YEARLY,
               dtstart=datetime(2000, 1, 1),
               bymonth=9,
               byweekday=MO,
               bysetpos=1)),
     Holiday(
         'Columbus Day',
         rrule(YEARLY,
               dtstart=datetime(2000, 1, 1),
               bymonth=10,
               byweekday=MO,
               bysetpos=2)),
     Holiday(
         'Veterans Day',
         rrule(YEARLY,
               dtstart=datetime(2000, 1, 1),
               bymonth=11,
               bymonthday=11)),
     Holiday(
         'Thanksgiving Day',
         rrule(YEARLY,
               dtstart=datetime(2000, 1, 1),
               bymonth=11,
               byweekday=TH,
               bysetpos=4)),
     Holiday(
         'Christmas Day',
         rrule(YEARLY,
               dtstart=datetime(2000, 1, 1),
               bymonth=12,
               bymonthday=25)),
 ], [
     Substitute(None, None, None, US_substitute),
 ]))
Пример #11
0
 CountryHolidays([
     Holiday(
         '元日',
         rrule(
             YEARLY, dtstart=datetime(1948, 7,
                                      20), bymonth=1, bymonthday=1)),
     Holiday(
         '成人の日',
         rrule(YEARLY,
               dtstart=datetime(1948, 7, 20),
               until=datetime(1999, 12, 31),
               bymonth=1,
               bymonthday=15)),
     Holiday(
         '成人の日',
         rrule(YEARLY,
               dtstart=datetime(2000, 1, 1),
               bymonth=1,
               byweekday=MO,
               bysetpos=2)),
     Holiday(
         '建国記念の日',
         rrule(YEARLY,
               dtstart=datetime(1966, 6, 25),
               bymonth=2,
               bymonthday=11)),
     Holiday(
         '春分の日',
         rrule(YEARLY,
               dtstart=datetime(1948, 7, 20),
               bymonth=3,
               bymonthday=(20, 21)), JP_vernal_equinox_day),
     Holiday(
         '昭和の日',
         rrule(
             YEARLY, dtstart=datetime(2007, 1,
                                      1), bymonth=4, bymonthday=29)),
     Holiday(
         'みどりの日',
         rrule(YEARLY,
               dtstart=datetime(1989, 2, 17),
               until=datetime(2006, 12, 31),
               bymonth=4,
               bymonthday=29)),
     Holiday(
         '憲法記念日',
         rrule(
             YEARLY, dtstart=datetime(1948, 7,
                                      20), bymonth=5, bymonthday=3)),
     Holiday(
         '国民の休日',
         rrule(YEARLY,
               dtstart=datetime(1985, 12, 27),
               until=datetime(2006, 12, 31),
               bymonth=5,
               bymonthday=4), JP_national_holiday_1985),
     Holiday(
         'みどりの日',
         rrule(
             YEARLY, dtstart=datetime(2007, 1,
                                      1), bymonth=5, bymonthday=4)),
     Holiday(
         'こどもの日',
         rrule(
             YEARLY, dtstart=datetime(1948, 7,
                                      20), bymonth=5, bymonthday=5)),
     Holiday(
         '海の日',
         rrule(YEARLY,
               dtstart=datetime(1996, 1, 1),
               until=datetime(2002, 12, 31),
               bymonth=7,
               bymonthday=20)),
     Holiday(
         '海の日',
         rrule(YEARLY,
               dtstart=datetime(2003, 1, 1),
               until=datetime(2019, 12, 31),
               bymonth=7,
               byweekday=MO,
               bysetpos=3)),
     Holiday(
         '海の日',
         rrule(YEARLY,
               dtstart=datetime(2020, 7, 23),
               until=datetime(2020, 7, 23),
               bymonth=7,
               bymonthday=23)),
     Holiday(
         '海の日',
         rrule(YEARLY,
               dtstart=datetime(2021, 1, 1),
               bymonth=7,
               byweekday=MO,
               bysetpos=3)),
     Holiday(
         '山の日',
         rrule(YEARLY,
               dtstart=datetime(2016, 1, 1),
               until=datetime(2019, 12, 31),
               bymonth=8,
               bymonthday=11)),
     Holiday(
         '山の日',
         rrule(YEARLY,
               dtstart=datetime(2020, 8, 10),
               until=datetime(2020, 8, 10),
               bymonth=8,
               bymonthday=10)),
     Holiday(
         '山の日',
         rrule(
             YEARLY, dtstart=datetime(2021, 1,
                                      1), bymonth=8, bymonthday=11)),
     Holiday(
         '敬老の日',
         rrule(YEARLY,
               dtstart=datetime(1966, 6, 25),
               until=datetime(2002, 12, 31),
               bymonth=9,
               bymonthday=15)),
     Holiday(
         '敬老の日',
         rrule(YEARLY,
               dtstart=datetime(2003, 1, 1),
               bymonth=9,
               byweekday=MO,
               bysetpos=3)),
     Holiday(
         '秋分の日',
         rrule(YEARLY,
               dtstart=datetime(1948, 7, 20),
               bymonth=9,
               bymonthday=(22, 23, 24)), JP_autumnal_equinox_day),
     Holiday(
         '体育の日',
         rrule(YEARLY,
               dtstart=datetime(1966, 6, 25),
               until=datetime(1999, 12, 31),
               bymonth=10,
               bymonthday=10)),
     Holiday(
         '体育の日',
         rrule(YEARLY,
               dtstart=datetime(2000, 1, 1),
               until=datetime(2019, 12, 31),
               bymonth=10,
               byweekday=MO,
               bysetpos=2)),
     Holiday(
         'スポーツの日',
         rrule(YEARLY,
               dtstart=datetime(2020, 7, 24),
               until=datetime(2020, 7, 24),
               bymonth=7,
               bymonthday=24)),
     Holiday(
         'スポーツの日',
         rrule(YEARLY,
               dtstart=datetime(2021, 1, 1),
               bymonth=10,
               byweekday=MO,
               bysetpos=2)),
     Holiday(
         '文化の日',
         rrule(YEARLY,
               dtstart=datetime(1948, 7, 20),
               bymonth=11,
               bymonthday=3)),
     Holiday(
         '勤労感謝の日',
         rrule(YEARLY,
               dtstart=datetime(1948, 7, 20),
               bymonth=11,
               bymonthday=23)),
     Holiday(
         '天皇誕生日',
         rrule(YEARLY,
               dtstart=datetime(1948, 7, 20),
               until=datetime(1989, 2, 16),
               bymonth=4,
               bymonthday=29)),
     Holiday(
         '天皇誕生日',
         rrule(YEARLY,
               dtstart=datetime(1989, 2, 17),
               until=datetime(2018, 12, 31),
               bymonth=12,
               bymonthday=23)),
     Holiday(
         '皇太子明仁親王の結婚の儀',
         rrule(YEARLY,
               dtstart=datetime(1959, 4, 10),
               until=datetime(1959, 4, 10),
               bymonth=4,
               bymonthday=10)),
     Holiday(
         '昭和天皇の大喪の礼',
         rrule(YEARLY,
               dtstart=datetime(1989, 2, 24),
               until=datetime(1989, 2, 24),
               bymonth=2,
               bymonthday=24)),
     Holiday(
         '即位礼正殿の儀',
         rrule(YEARLY,
               dtstart=datetime(1990, 11, 12),
               until=datetime(1990, 11, 12),
               bymonth=11,
               bymonthday=12)),
     Holiday(
         '皇太子徳仁親王の結婚の儀',
         rrule(YEARLY,
               dtstart=datetime(1993, 6, 9),
               until=datetime(1993, 6, 9),
               bymonth=6,
               bymonthday=9)),
     Holiday(
         '国民の休日',
         rrule(YEARLY,
               dtstart=datetime(2019, 4, 30),
               until=datetime(2019, 4, 30),
               bymonth=4,
               bymonthday=30)),
     Holiday(
         '天皇の即位の日',
         rrule(YEARLY,
               dtstart=datetime(2019, 5, 1),
               until=datetime(2019, 5, 1),
               bymonth=5,
               bymonthday=1)),
     Holiday(
         '国民の休日',
         rrule(YEARLY,
               dtstart=datetime(2019, 5, 2),
               until=datetime(2019, 5, 2),
               bymonth=5,
               bymonthday=2)),
     Holiday(
         '即位礼正殿の儀の行われる日',
         rrule(YEARLY,
               dtstart=datetime(2019, 10, 22),
               until=datetime(2019, 10, 22),
               bymonth=10,
               bymonthday=22)),
 ], [
     Substitute('国民の休日', datetime(2007, 1, 1), None, JP_national_holiday),
     Substitute('振替休日', datetime(1973, 4, 12), datetime(2006, 12, 31),
                JP_substitute_1973),
     Substitute('振替休日', datetime(2007, 1, 1), None, JP_substitute),
 ]))