예제 #1
0
def ta_volume_as_time(df: _t.PatchedPandas, volume="Volume"):
    if df.ndim > 1:
        res = df.copy()
        res.index = df[volume].cumsum()
        return res
    else:
        return _pd.Series(df.index, index=df.cumsum())
예제 #2
0
def ta_week(po: _t.PatchedPandas):
    if not isinstance(po.index, _pd.DatetimeIndex):
        df = po.copy()
        df.index = _pd.to_datetime(df.index)
    else:
        df = po

    return (df.index.week / 52.0).to_series(index=po.index, name="week")
예제 #3
0
def ta_sinusoidial_week_day(po: _t.PatchedPandas):
    if not isinstance(po.index, _pd.DatetimeIndex):
        df = po.copy()
        df.index = _pd.to_datetime(df.index)
    else:
        df = po

    return _np.sin(2 * _np.pi * (df.index.dayofweek / 6.0)).to_series(
        index=po.index, name="dow")
예제 #4
0
def ta_sinusoidal_week(po: _t.PatchedPandas):
    if not isinstance(po.index, _pd.DatetimeIndex):
        df = po.copy()
        df.index = _pd.to_datetime(df.index)
    else:
        df = po

    return _np.sin(2 * _np.pi *
                   (df.index.isocalendar().week / 52.0)).rename("week")
예제 #5
0
def ta_ewma_covariance(df: Typing.PatchedPandas,
                       convert_to='returns',
                       alpha=0.97):
    data = df.copy()

    if convert_to == 'returns':
        data = df.pct_change()
    if convert_to == 'log-returns':
        data = _np.log(df) - _np.log(df.shift(1))

    data.columns = data.columns.to_list()
    return data.ewm(com=alpha).cov()