def ensure_pyfin_date(date, date_format='%Y-%m-%d'):
    """
    :param date: str, datetime, 日期
    :param date_format: str, 时间格式
    :return: PyFin.Date object 
    """
    if isinstance(date, Date):
        return date
    elif isinstance(date, str):
        return Date.strptime(date, date_format)
    else:
        return Date.fromDateTime(date)
Exemple #2
0
def ensure_pyfin_date(date, date_format='%Y-%m-%d'):
    """
    :param date: str, datetime, 日期
    :param date_format: str, 时间格式
    :return: PyFin.Date object 
    """
    if isinstance(date, Date):
        return date
    elif isinstance(date, str):
        return Date.strptime(date, date_format)
    else:
        return Date.fromDateTime(date)
Exemple #3
0
def map_to_biz_day(date_series, calendar='China.SSE', convention=BizDayConventions.Preceding):
    """
    :param date_series: array-like of datetime.datetime
    :param calendar: str, optional, 日历名称,见PyFin.DateUtilities.Calendar, default='China.SSE'
    :param convention: str, optional, 如果日期为节假日,如何调整成交易日,见PyFin.DateUtilities.Schedule, default = preceding
    :return: pd.Series, datetime.datetime, 交易日列表
    """
    unique_date_list = sorted(set(date_series))
    py_date_list = [Date.fromDateTime(date) for date in unique_date_list]
    py_date_list = [Calendar(calendar).adjustDate(date, convention) for date in py_date_list]
    biz_day_list = [Date.toDateTime(date) for date in py_date_list]
    dict_date_map = dict(zip(unique_date_list, biz_day_list))
    ret = date_series.map(dict_date_map)
    return ret
Exemple #4
0
def map_to_biz_day(date_series,
                   calendar='China.SSE',
                   convention=BizDayConventions.Preceding):
    """
    :param date_series: array-like of datetime.datetime
    :param calendar: str, optional, 日历名称,见PyFin.DateUtilities.Calendar, default='China.SSE'
    :param convention: str, optional, 如果日期为节假日,如何调整成交易日,见PyFin.DateUtilities.Schedule, default = preceding
    :return: pd.Series, datetime.datetime, 交易日列表
    """
    unique_date_list = sorted(set(date_series))
    py_date_list = [Date.fromDateTime(date) for date in unique_date_list]
    py_date_list = [
        Calendar(calendar).adjustDate(date, convention)
        for date in py_date_list
    ]
    biz_day_list = [Date.toDateTime(date) for date in py_date_list]
    dict_date_map = dict(zip(unique_date_list, biz_day_list))
    ret = date_series.map(dict_date_map)
    return ret