Beispiel #1
0
 def df_conv_str_to_datetime(t_colulmn_name):
     """文字列 -> 日付変換"""
     try:
         df[t_colulmn_name] = pd_to_datetime(df[t_colulmn_name])
     except (TypeError, ValueError):
         print('変換エラー %s conv_str_to_num で再試行' % t_colulmn_name)
         df[t_colulmn_name] = df[t_colulmn_name].apply(conv_str_to_num)
     return
Beispiel #2
0
def add_info2p_df(d_p_df: pd_DataFrame) -> pd_DataFrame:
    d_t_df = d_p_df.copy()
    d_t_df["tao"] = (pd_to_datetime(OBS_DT) - d_t_df.index).days / DAYS_IN_YEAR

    # TODO: add term structure, or real financing costs
    d_t_df["r"] = 0.03
    d_t_df["q"] = 0.15

    return d_t_df
Beispiel #3
0
def local_to_utc(df):
    """ converts naive (usually local) timezone to UTC) """
    try:
        offset_hour = -(datetime.now() - datetime.utcnow()).seconds
    except:
        offset_hour = time.altzone if time.daylight else time.timezone

    offset_hour = offset_hour // 3600
    offset_hour = offset_hour if offset_hour < 10 else offset_hour // 10

    df = df.copy()
    df.index = pd_to_datetime(df.index, utc=True) + timedelta(hours=offset_hour)

    return df