예제 #1
0
    def test_HT_PHASOR(self):
        class MyHT_PHASOR(OperatorHT_PHASOR):
            def __init__(self, name, **kwargs):
                super(MyHT_PHASOR, self).__init__(100, name, **kwargs)

        self.env.add_operator('ht_phasor', {
            'operator': MyHT_PHASOR,
        })
        string = 'ht_phasor(2, open)'
        gene = self.env.parse_string(string)
        self.assertFalse(gene.validate())

        string = 'ht_phasor(0, open)'
        gene = self.env.parse_string(string)
        self.assertRaises(IndexError, gene.eval, self.env, self.dates[98],
                          self.dates[-1])
        ser = gene.eval(self.env, self.dates[99], self.dates[99]).iloc[0]
        data = self.env.get_data_value('open')
        res = []
        for i, val in ser.iteritems():
            res.append(talib.HT_PHASOR(data[i].values[:100])[0][-1] == val)
        self.assertTrue(all(res))

        string = 'ht_phasor(1, open)'
        gene = self.env.parse_string(string)
        ser = gene.eval(self.env, self.dates[99], self.dates[99]).iloc[0]
        res = []
        for i, val in ser.iteritems():
            res.append(talib.HT_PHASOR(data[i].values[:100])[1][-1] == val)
        self.assertTrue(all(res))
예제 #2
0
def HT_phasor(close_ts):
    import talib
    close_np = close_ts.cpu().detach().numpy()
    close_df = pd.DataFrame(close_np)
    inphase = close_df.apply(lambda x: talib.HT_PHASOR(x)[0])
    quadrature = close_df.apply(lambda x: talib.HT_PHASOR(x)[1])
    inphase_ts = torch.tensor(inphase.values, dtype=close_ts.dtype, device=close_ts.device)
    quadrature_ts = torch.tensor(quadrature.values, dtype=close_ts.dtype, device=close_ts.device)
    return inphase_ts, quadrature_ts
예제 #3
0
def Cylcle_Indicators(dataframe):
	"""

	Cycle Indicators

	HT_DCPERIOD          Hilbert Transform - Dominant Cycle Period
	HT_DCPHASE           Hilbert Transform - Dominant Cycle Phase
	HT_PHASOR            Hilbert Transform - Phasor Components
	HT_SINE              Hilbert Transform - SineWave
	HT_TRENDMODE         Hilbert Transform - Trend vs Cycle Mode

	"""

	#Cycle Indicator Functions
	#HT_DCPERIOD - Hilbert Transform - Dominant Cycle Period
	df[f'{ratio}_HT_DCPERIOD'] = talib.HT_DCPERIOD(Close)
	#HT_DCPHASE - Hilbert Transform - Dominant Cycle Phase
	df[f'{ratio}_HT_DCPHASE'] = talib.HT_DCPHASE(Close)
	#HT_PHASOR - Hilbert Transform - Phasor Components
	inphase, quadrature = talib.HT_PHASOR(Close)
	#HT_SINE - Hilbert Transform - SineWave
	sine, leadsine = talib.HT_SINE(Close)
	#HT_TRENDMODE - Hilbert Transform - Trend vs Cycle Mode
	integer = talib.HT_TRENDMODE(Close)

	return
예제 #4
0
def cycle_process(event):
    print(event.widget.get())
    cycle = event.widget.get()

    upperband, middleband, lowerband = ta.BBANDS(close, timeperiod=5, nbdevup=2, nbdevdn=2, matype=0)
    fig, axes = plt.subplots(2, 1, sharex=True)
    ax1, ax2 = axes[0], axes[1]
    axes[0].plot(close, 'rd-', markersize=3)
    axes[0].plot(upperband, 'y-')
    axes[0].plot(middleband, 'b-')
    axes[0].plot(lowerband, 'y-')
    axes[0].set_title(cycle, fontproperties="SimHei")

    if cycle == '希尔伯特变换——主要的循环周期':
        real = ta.HT_DCPERIOD(close)
        axes[1].plot(real, 'r-')
    elif cycle == '希尔伯特变换,占主导地位的周期阶段':
        real = ta.HT_DCPHASE(close)
        axes[1].plot(real, 'r-')
    elif cycle == '希尔伯特变换——相量组件':
        inphase, quadrature = ta.HT_PHASOR(close)
        axes[1].plot(inphase, 'r-')
        axes[1].plot(quadrature, 'g-')
    elif cycle == '希尔伯特变换——正弦曲线':
        sine, leadsine = ta.HT_SINE(close)
        axes[1].plot(sine, 'r-')
        axes[1].plot(leadsine, 'g-')
    elif cycle == '希尔伯特变换——趋势和周期模式':
        integer = ta.HT_TRENDMODE(close)
        axes[1].plot(integer, 'r-')

    plt.show()
예제 #5
0
def get_ht_phasor(ohlc):
    inphase, quadrature = ta.HT_PHASOR(ohlc['4_close'])

    ohlc['ht_phasor_inphase'] = inphase
    ohlc['ht_phasor_quadrature'] = quadrature

    return ohlc
예제 #6
0
def add_cycle_indicators(data_list):
    for data in data_list:
        #HT_DCPERIOD - Hilbert Transform - Dominant Cycle Period
        real = talib.HT_DCPERIOD(data.Close)
        data['HT_DCPERIOD'] = real

        #HT_DCPHASE - Hilbert Transform - Dominant Cycle Phase
        real = talib.HT_DCPHASE(data.Close)
        data['HT_DCPHASE'] = real

        #HT_PHASOR - Hilbert Transform - Phasor Components
        inphase, quadrature = talib.HT_PHASOR(data.Close)
        data['HT_PHASOR_inphase'] = inphase
        data['HT_PHASOR_quadrature'] = quadrature

        #HT_SINE - Hilbert Transform - SineWave
        sine, leadsine = talib.HT_SINE(data.Close)
        data['HT_SINE_sine'] = sine
        data['HT_SINE_leadsine'] = leadsine

        #HT_TRENDMODE - Hilbert Transform - Trend vs Cycle Mode
        integer = talib.HT_TRENDMODE(data.Close)
        data['HT_TRENDMODE'] = integer

    return data_list
예제 #7
0
def hilbert_transform_phasor_components(close):
    try:
        inphase_data, quadrature_data = talib.HT_PHASOR(close)
        df = pd.DataFrame()
        df['inphase'] = inphase_data
        df['quadrature'] = quadrature_data
        return df
    except Exception as e:
        raise (e)
예제 #8
0
def HT_PHASOR(close):
    ''' Hilbert Transform - Phasor Components 希尔伯特变换-希尔伯特变换相量分量

    分组: Cycle Indicators 周期指标

    简介:

    inphase, quadrature = HT_PHASOR(close)
    '''
    return talib.HT_PHASOR(close)
예제 #9
0
 def _get_indicators(security, open_name, close_name, high_name, low_name,
                     volume_name):
     """
     expand the features of the data through technical analysis across 26 different signals
     :param security: data which features are going to be expanded
     :param open_name: open price column name
     :param close_name: close price column name
     :param high_name: high price column name
     :param low_name: low price column name
     :param volume_name: traded volumn column name
     :return: expanded and extracted data
     """
     open_price = security[open_name].values
     close_price = security[close_name].values
     low_price = security[low_name].values
     high_price = security[high_name].values
     volume = security[volume_name].values if volume_name else None
     security['MOM'] = talib.MOM(close_price)
     security['HT_DCPERIOD'] = talib.HT_DCPERIOD(close_price)
     security['HT_DCPHASE'] = talib.HT_DCPHASE(close_price)
     security['SINE'], security['LEADSINE'] = talib.HT_SINE(close_price)
     security['INPHASE'], security['QUADRATURE'] = talib.HT_PHASOR(
         close_price)
     security['ADXR'] = talib.ADXR(high_price, low_price, close_price)
     security['APO'] = talib.APO(close_price)
     security['AROON_UP'], _ = talib.AROON(high_price, low_price)
     security['CCI'] = talib.CCI(high_price, low_price, close_price)
     security['PLUS_DI'] = talib.PLUS_DI(high_price, low_price, close_price)
     security['PPO'] = talib.PPO(close_price)
     security['MACD'], security['MACD_SIG'], security[
         'MACD_HIST'] = talib.MACD(close_price)
     security['CMO'] = talib.CMO(close_price)
     security['ROCP'] = talib.ROCP(close_price)
     security['FASTK'], security['FASTD'] = talib.STOCHF(
         high_price, low_price, close_price)
     security['TRIX'] = talib.TRIX(close_price)
     security['ULTOSC'] = talib.ULTOSC(high_price, low_price, close_price)
     security['WILLR'] = talib.WILLR(high_price, low_price, close_price)
     security['NATR'] = talib.NATR(high_price, low_price, close_price)
     security['RSI'] = talib.RSI(close_price)
     security['EMA'] = talib.EMA(close_price)
     security['SAREXT'] = talib.SAREXT(high_price, low_price)
     # security['TEMA'] = talib.EMA(close_price)
     security['RR'] = security[close_name] / security[close_name].shift(
         1).fillna(1)
     security['LOG_RR'] = np.log(security['RR'])
     if volume_name:
         security['MFI'] = talib.MFI(high_price, low_price, close_price,
                                     volume)
         # security['AD'] = talib.AD(high_price, low_price, close_price, volume)
         # security['OBV'] = talib.OBV(close_price, volume)
         security[volume_name] = np.log(security[volume_name])
     security.drop([open_name, close_name, high_name, low_name], axis=1)
     security = security.dropna().astype(np.float32)
     return security
예제 #10
0
 def eval(self, environment, gene, date1, date2):
     return_type = int(gene.next_value(environment, date1, date2))
     date1_ = environment.shift_date(date1, -(self.window - 1), -1)
     df = gene.next_value(environment, date1_, date2)
     res = pd.DataFrame(np.nan,
                        index=df.ix[date1:date2].index,
                        columns=df.columns)
     for i, j in product(range(res.shape[0]), range(res.shape[1])):
         res.iloc[i, j] = talib.HT_PHASOR(df.values[i:i + self.window,
                                                    j])[return_type][-1]
     return res
예제 #11
0
def getCycleIndicators(df):
    high = df['High']
    low = df['Low']
    close = df['Close']
    open = df['Open']
    volume = df['Volume']

    df['DCPERIOD'] = ta.HT_DCPERIOD(close)
    df['DCPHASE'] = ta.HT_DCPHASE(close)
    df['INPHASE'], df['QUADRATURE'] = ta.HT_PHASOR(close)
    df['SINE'], df['LEADSINE'] = ta.HT_SINE(close)
    df['TRENDMODE'] = ta.HT_TRENDMODE(close)
예제 #12
0
def sexy(k):
    if len(k) > 3:
        vm = wrap(k)
        print("--talib--")
        print(list(talib.HT_DCPERIOD(vm)))
        print(list(talib.HT_DCPHASE(vm)))
        print(list(talib.HT_PHASOR(vm)))
        print(list(talib.HT_SINE(vm)))
        print(list(talib.HT_TRENDMODE(vm)))
        print("--talib--")
    else:
        pass
예제 #13
0
def computeHilbertTransformSignals(ticker, pd):
    closeField = config.ticker2ReturnFieldMap[ticker]
    close = numpy.array(pd[closeField])
    pd['Hilbert.DCPeriod'] = talib.HT_DCPERIOD(close)
    pd['Hilbert.DCPhase'] = talib.HT_DCPHASE(close)
    pd['Hilbert.inphase'], pd['Hilbert.quadrature'] = talib.HT_PHASOR(close)
    pd['Hilbert.sine'], pd['Hilbert.leadsine'] = talib.HT_SINE(close)
    pd['Hilbert.TrendMode'] = talib.HT_TRENDMODE(close)
    fields = [
        'Hilbert.DCPeriod', 'Hilbert.DCPhase', 'Hilbert.inphase',
        'Hilbert.quadrature', 'Hilbert.sine', 'Hilbert.leadsine',
        'Hilbert.TrendMode'
    ]
    return pd, fields
예제 #14
0
def generate_tech_data_default(stock,
                               open_name,
                               close_name,
                               high_name,
                               low_name,
                               volume_name='vol'):
    open_price = stock[open_name].values
    close_price = stock[close_name].values
    low_price = stock[low_name].values
    high_price = stock[high_name].values
    volume = stock[volume_name].values
    data = stock.copy()
    data['MOM'] = talib.MOM(close_price)
    data['HT_DCPERIOD'] = talib.HT_DCPERIOD(close_price)
    data['HT_DCPHASE'] = talib.HT_DCPHASE(close_price)
    data['sine'], data['leadsine'] = talib.HT_SINE(close_price)
    data['inphase'], data['quadrature'] = talib.HT_PHASOR(close_price)
    data['ADXR'] = talib.ADXR(high_price, low_price, close_price)
    data['APO'] = talib.APO(close_price)
    data['AROON_UP'], _ = talib.AROON(high_price, low_price)
    data['CCI'] = talib.CCI(high_price, low_price, close_price)
    data['PLUS_DI'] = talib.PLUS_DI(high_price, low_price, close_price)
    data['PPO'] = talib.PPO(close_price)
    data['macd'], data['macd_sig'], data['macd_hist'] = talib.MACD(close_price)
    data['CMO'] = talib.CMO(close_price)
    data['ROCP'] = talib.ROCP(close_price)
    data['fastk'], data['fastd'] = talib.STOCHF(high_price, low_price,
                                                close_price)
    data['TRIX'] = talib.TRIX(close_price)
    data['ULTOSC'] = talib.ULTOSC(high_price, low_price, close_price)
    data['WILLR'] = talib.WILLR(high_price, low_price, close_price)
    data['NATR'] = talib.NATR(high_price, low_price, close_price)
    data['MFI'] = talib.MFI(high_price, low_price, close_price, volume)
    data['RSI'] = talib.RSI(close_price)
    data['AD'] = talib.AD(high_price, low_price, close_price, volume)
    data['OBV'] = talib.OBV(close_price, volume)
    data['EMA'] = talib.EMA(close_price)
    data['SAREXT'] = talib.SAREXT(high_price, low_price)
    data['TEMA'] = talib.EMA(close_price)
    #data = data.drop([open_name, close_name, high_name, low_name, volume_name, 'amount', 'count'], axis=1)
    data = drop_columns(data, [
        open_name, close_name, high_name, low_name, volume_name, 'amount',
        'count'
    ])
    data = data.dropna().astype(np.float32)
    return data
예제 #15
0
def ht_phasor(client, symbol, timeframe="6m", col="close"):
    """This will return a dataframe of
    Hilbert Transform - Phasor Components
    for the given symbol across
    the given timeframe

    Args:
        client (pyEX.Client); Client
        symbol (string); Ticker
        timeframe (string); timeframe to use, for pyEX.chart
        col (string); column to use to calculate

    Returns:
        DataFrame: result
    """
    df = client.chartDF(symbol, timeframe)
    x, y = t.HT_PHASOR(df[col].values)
    return pd.DataFrame({col: df[col].values, "inphase": x, "quadrature": y})
예제 #16
0
def get_cycle_indicators(df_price):

    df_local = df_price.copy()
    df_nonna_idxs = df_local[~df_local.Close.isna()].Close.index

    np_adj_close = df_local.Adj_Close.values
    np_close = df_local.Close.values
    np_open = df_local.Open.values
    np_high = df_local.High.values
    np_low = df_local.Low.values
    np_volume = df_local.Volume.values

    np_nan_indices = np.isnan(np_close)

    #HT_DCPERIOD-Hilbert Transform - Dominant Cycle Period
    HT_DCPERIOD = pd.Series(ta.HT_DCPERIOD(np_adj_close[~np_nan_indices]),
                            index=df_nonna_idxs)
    df_local['HT_DCPERIOD'] = HT_DCPERIOD

    #HT_DCPHASE-Hilbert Transform - Dominant Cycle Phase
    HT_DCPHASE = pd.Series(ta.HT_DCPHASE(np_adj_close[~np_nan_indices]),
                           index=df_nonna_idxs)
    df_local['HT_DCPHASE'] = HT_DCPHASE

    #HT_PHASOR-Hilbert Transform - Phasor Components
    HT_PHASOR = ta.HT_PHASOR(np_adj_close[~np_nan_indices])

    df_local['HT_PHASOR_INPHASE'] = pd.Series(HT_PHASOR[0],
                                              index=df_nonna_idxs)
    df_local['HT_PHASOR_QUADRATURE'] = pd.Series(HT_PHASOR[1],
                                                 index=df_nonna_idxs)

    #HT_SINE - Hilbert Transform - SineWave
    HT_SINE = ta.HT_SINE(np_adj_close[~np_nan_indices])

    df_local['HT_SINE_SINE'] = pd.Series(HT_SINE[0], index=df_nonna_idxs)
    df_local['HT_SINE_LEADSINE'] = pd.Series(HT_SINE[1], index=df_nonna_idxs)

    #HT_TRENDMODE-Hilbert Transform - Trend vs Cycle Mode
    HT_TRENDMODE = pd.Series(ta.HT_TRENDMODE(np_adj_close[~np_nan_indices]),
                             index=df_nonna_idxs)
    df_local['HT_TRENDMODE'] = HT_TRENDMODE

    return df_local
예제 #17
0
파일: ht_phasor.py 프로젝트: xsa-dev/jesse
def ht_phasor(candles: np.ndarray, source_type: str = "close", sequential: bool = False) -> IQ:
    """
    HT_PHASOR - Hilbert Transform - Phasor Components

    :param candles: np.ndarray
    :param source_type: str - default: "close"
    :param sequential: bool - default: False

    :return: IQ(inphase, quadrature)
    """
    candles = slice_candles(candles, sequential)

    source = get_candle_source(candles, source_type=source_type)
    inphase, quadrature = talib.HT_PHASOR(source)

    if sequential:
        return IQ(inphase, quadrature)
    else:
        return IQ(inphase[-1], quadrature[-1])
예제 #18
0
 def _get_indicators(security, open_name, close_name, high_name, low_name,
                     volume_name):
     open_price = security[open_name].values
     close_price = security[close_name].values
     low_price = security[low_name].values
     high_price = security[high_name].values
     volume = security[volume_name].values if volume_name else None
     security['MOM'] = talib.MOM(close_price)
     security['HT_DCPERIOD'] = talib.HT_DCPERIOD(close_price)
     security['HT_DCPHASE'] = talib.HT_DCPHASE(close_price)
     security['SINE'], security['LEADSINE'] = talib.HT_SINE(close_price)
     security['INPHASE'], security['QUADRATURE'] = talib.HT_PHASOR(
         close_price)
     security['ADXR'] = talib.ADXR(high_price, low_price, close_price)
     security['APO'] = talib.APO(close_price)
     security['AROON_UP'], _ = talib.AROON(high_price, low_price)
     security['CCI'] = talib.CCI(high_price, low_price, close_price)
     security['PLUS_DI'] = talib.PLUS_DI(high_price, low_price, close_price)
     security['PPO'] = talib.PPO(close_price)
     security['MACD'], security['MACD_SIG'], security[
         'MACD_HIST'] = talib.MACD(close_price)
     security['CMO'] = talib.CMO(close_price)
     security['ROCP'] = talib.ROCP(close_price)
     security['FASTK'], security['FASTD'] = talib.STOCHF(
         high_price, low_price, close_price)
     security['TRIX'] = talib.TRIX(close_price)
     security['ULTOSC'] = talib.ULTOSC(high_price, low_price, close_price)
     security['WILLR'] = talib.WILLR(high_price, low_price, close_price)
     security['NATR'] = talib.NATR(high_price, low_price, close_price)
     security['RSI'] = talib.RSI(close_price)
     security['EMA'] = talib.EMA(close_price)
     security['SAREXT'] = talib.SAREXT(high_price, low_price)
     security['RR'] = security[close_name] / security[close_name].shift(
         1).fillna(1)
     security['LOG_RR'] = np.log(security['RR'])
     if volume_name:
         security['MFI'] = talib.MFI(high_price, low_price, close_price,
                                     volume)
         security[volume_name] = np.log(security[volume_name])
     security.drop([open_name, close_name, high_name, low_name], axis=1)
     security = security.dropna().astype(np.float32)
     return security
예제 #19
0
def handle_cycle_indicators(args, axes, i, klines_df, close_times,
                            display_count):
    # talib
    if args.HT_DCPERIOD:
        name = 'HT_DCPERIOD'
        real = talib.HT_DCPERIOD(klines_df["close"])
        i += 1
        axes[i].set_ylabel(name)
        axes[i].grid(True)
        axes[i].plot(close_times, real[-display_count:], "y:", label=name)

    if args.HT_DCPHASE:
        name = 'HT_DCPHASE'
        real = talib.HT_DCPHASE(klines_df["close"])
        i += 1
        axes[i].set_ylabel(name)
        axes[i].grid(True)
        axes[i].plot(close_times, real[-display_count:], "y:", label=name)

    if args.HT_PHASOR:
        name = 'HT_PHASOR'
        real = talib.HT_PHASOR(klines_df["close"])
        i += 1
        axes[i].set_ylabel(name)
        axes[i].grid(True)
        axes[i].plot(close_times, real[-display_count:], "y:", label=name)

    if args.HT_SINE:
        name = 'HT_SINE'
        real = talib.HT_SINE(klines_df["close"])
        i += 1
        axes[i].set_ylabel(name)
        axes[i].grid(True)
        axes[i].plot(close_times, real[-display_count:], "y:", label=name)

    if args.HT_TRENDMODE:
        name = 'HT_TRENDMODE'
        real = talib.HT_TRENDMODE(klines_df["close"])
        i += 1
        axes[i].set_ylabel(name)
        axes[i].grid(True)
        axes[i].plot(close_times, real[-display_count:], "y:", label=name)
예제 #20
0
def generate_tech_data(stock, open_name, close_name, high_name, low_name):
    open_price = stock[open_name].values
    close_price = stock[close_name].values
    low_price = stock[low_name].values
    high_price = stock[high_name].values
    data = pd.DataFrame(stock)
    data['MOM'] = talib.MOM(close_price)
    data['SMA'] = talib.SMA(close_price)
    data['HT_DCPERIOD'] = talib.HT_DCPERIOD(close_price)
    data['HT_DCPHASE'] = talib.HT_DCPHASE(close_price)
    data['sine'], data['leadsine'] = talib.HT_SINE(close_price)
    data['inphase'], data['quadrature'] = talib.HT_PHASOR(close_price)
    data['HT_TRENDMODE'] = talib.HT_TRENDMODE(close_price)
    data['SAREXT'] = talib.SAREXT(high_price, low_price)
    data['ADX'] = talib.ADX(high_price, low_price, close_price)
    data['ADXR'] = talib.ADX(high_price, low_price, close_price)
    data['APO'] = talib.APO(close_price)
    data['AROON_UP'], data['AROON_DOWN'] = talib.AROON(high_price, low_price)
    data['AROONOSC'] = talib.AROONOSC(high_price, low_price)
    data['BOP'] = talib.BOP(open_price, high_price, low_price, close_price)
    data['CCI'] = talib.CCI(high_price, low_price, close_price)
    data['PLUS_DI'] = talib.PLUS_DI(high_price, low_price, close_price)
    data['PLUS_DM'] = talib.PLUS_DM(high_price, low_price)
    data['PPO'] = talib.PPO(close_price)
    data['macd'], data['macd_sig'], data['macd_hist'] = talib.MACD(close_price)
    data['RSI'] = talib.RSI(close_price)
    data['CMO'] = talib.CMO(close_price)
    data['ROC'] = talib.ROC(close_price)
    data['ROCP'] = talib.ROCP(close_price)
    data['ROCR'] = talib.ROCR(close_price)
    data['slowk'], data['slowd'] = talib.STOCH(high_price, low_price,
                                               close_price)
    data['fastk'], data['fastd'] = talib.STOCHF(high_price, low_price,
                                                close_price)
    data['TRIX'] = talib.TRIX(close_price)
    data['ULTOSC'] = talib.ULTOSC(high_price, low_price, close_price)
    data['WILLR'] = talib.WILLR(high_price, low_price, close_price)
    data['NATR'] = talib.NATR(high_price, low_price, close_price)
    data['TRANGE'] = talib.TRANGE(high_price, low_price, close_price)
    data = data.drop([open_name, close_name, high_name, low_name], axis=1)
    data = data.dropna()
    return data
예제 #21
0
def generate_tech_data(stock, open_name, close_name, high_name, low_name, max_time_window=10):
    open_price = stock[open_name].values
    close_price = stock[close_name].values
    low_price = stock[low_name].values
    high_price = stock[high_name].values
    data = pd.DataFrame(stock)
    data['MOM'] = talib.MOM(close_price, timeperiod=max_time_window)
    # data['_SMA'] = talib.SMA(close_price)
    data['HT_DCPERIOD'] = talib.HT_DCPERIOD(close_price)
    data['HT_DCPHASE'] = talib.HT_DCPHASE(close_price)
    data['sine'], data['leadsine'] = talib.HT_SINE(close_price)
    data['inphase'], data['quadrature'] = talib.HT_PHASOR(close_price)
    # data['_HT_TRENDMODE'] = talib.HT_TRENDMODE(close_price)
    # data['_SAREXT'] = talib.SAREXT(high_price, low_price)
    # data['_ADX'] = talib.ADX(high_price, low_price, close_price)
    data['ADXR'] = talib.ADXR(high_price, low_price, close_price, timeperiod=max_time_window)
    data['APO'] = talib.APO(close_price, fastperiod=max_time_window // 2, slowperiod=max_time_window)
    data['AROON_UP'], _ = talib.AROON(high_price, low_price, timeperiod=max_time_window)
    # data['_BOP'] = talib.BOP(open_price, high_price, low_price, close_price)
    data['CCI'] = talib.CCI(high_price, low_price, close_price, timeperiod=max_time_window)
    data['PLUS_DI'] = talib.PLUS_DI(high_price, low_price, close_price, timeperiod=max_time_window)
    # data['_PLUS_DM'] = talib.PLUS_DM(high_price, low_price)
    data['PPO'] = talib.PPO(close_price, fastperiod=max_time_window // 2, slowperiod=max_time_window)
    data['macd'], data['macd_sig'], data['macd_hist'] = talib.MACD(close_price, fastperiod=max_time_window // 2, slowperiod=max_time_window, signalperiod=max_time_window // 2)
    data['CMO'] = talib.CMO(close_price, timeperiod=max_time_window)
    #     data['ROC'] = talib.ROC(close_price)
    data['ROCP'] = talib.ROCP(close_price, timeperiod=max_time_window)
    #     data['ROCR'] = talib.ROCR(close_price)
    #     data['slowk'], data['slowd'] = talib.STOCH(high_price, low_price, close_price)
    data['fastk'], data['fastd'] = talib.STOCHF(high_price, low_price, close_price)
    data['TRIX'] = talib.TRIX(close_price, timeperiod=max_time_window)
    data['ULTOSC'] = talib.ULTOSC(high_price, low_price, close_price, timeperiod1=max_time_window // 2, timeperiod2=max_time_window, timeperiod3=max_time_window * 2)
    data['WILLR'] = talib.WILLR(high_price, low_price, close_price, timeperiod=max_time_window)
    data['NATR'] = talib.NATR(high_price, low_price, close_price, timeperiod=max_time_window)
    # data['_TRANGE'] = talib.TRANGE(high_price, low_price, close_price)
    data = data.drop([open_name, close_name, high_name, low_name], axis=1)
    #     data.columns=data.columns.map(lambda x:x[1:])
    data = data.dropna().astype(np.float32)
    return data
예제 #22
0
def get_df(filename):
    tech = pd.read_csv(filename,index_col=0)
    dclose = np.array(tech.close)
    volume = np.array(tech.volume)
    tech['RSI'] = ta.RSI(np.array(tech.close))
    tech['OBV'] = ta.OBV(np.array(tech.close),np.array(tech.volume))
    tech['NATR'] = ta.NATR(np.array(tech.high),np.array(tech.low),np.array(tech.close))
    tech['upper'],tech['middle'],tech['lower'] = ta.BBANDS(np.array(tech.close), timeperiod=10, nbdevup=2, nbdevdn=2, matype=0)
    tech['DEMA'] = ta.DEMA(dclose, timeperiod=30)
    tech['EMA'] = ta.EMA(dclose, timeperiod=30)
    tech['HT_TRENDLINE'] = ta.HT_TRENDLINE(dclose)
    tech['KAMA'] = ta.KAMA(dclose, timeperiod=30)
    tech['MA'] = ta.MA(dclose, timeperiod=30, matype=0)
#    tech['mama'], tech['fama'] = ta.MAMA(dclose, fastlimit=0, slowlimit=0)
    tech['MIDPOINT'] = ta.MIDPOINT(dclose, timeperiod=14)
    tech['SMA'] = ta.SMA(dclose, timeperiod=30)
    tech['T3'] = ta.T3(dclose, timeperiod=5, vfactor=0)
    tech['TEMA'] = ta.TEMA(dclose, timeperiod=30)
    tech['TRIMA'] = ta.TRIMA(dclose, timeperiod=30)
    tech['WMA'] = ta.WMA(dclose, timeperiod=30)
    tech['APO'] = ta.APO(dclose, fastperiod=12, slowperiod=26, matype=0)
    tech['CMO'] = ta.CMO(dclose, timeperiod=14)
    tech['macd'], tech['macdsignal'], tech['macdhist'] = ta.MACD(dclose, fastperiod=12, slowperiod=26, signalperiod=9)
    tech['MOM'] = ta.MOM(dclose, timeperiod=10)
    tech['PPO'] = ta.PPO(dclose, fastperiod=12, slowperiod=26, matype=0)
    tech['ROC'] = ta.ROC(dclose, timeperiod=10)
    tech['ROCR'] = ta.ROCR(dclose, timeperiod=10)
    tech['ROCP'] = ta.ROCP(dclose, timeperiod=10)
    tech['ROCR100'] = ta.ROCR100(dclose, timeperiod=10)
    tech['RSI'] = ta.RSI(dclose, timeperiod=14)
    tech['fastk'], tech['fastd'] = ta.STOCHRSI(dclose, timeperiod=14, fastk_period=5, fastd_period=3, fastd_matype=0)
    tech['TRIX'] = ta.TRIX(dclose, timeperiod=30)
    tech['OBV'] = ta.OBV(dclose,volume)
    tech['HT_DCPHASE'] = ta.HT_DCPHASE(dclose)
    tech['inphase'], tech['quadrature'] = ta.HT_PHASOR(dclose)
    tech['sine'], tech['leadsine'] = ta.HT_SINE(dclose)
    tech['HT_TRENDMODE'] = ta.HT_TRENDMODE(dclose)
    df = tech.fillna(method='bfill')
    return df
예제 #23
0
def ht_phasor(candles: np.ndarray,
              source_type: str = "close",
              sequential: bool = False) -> IQ:
    """
    HT_PHASOR - Hilbert Transform - Phasor Components

    :param candles: np.ndarray
    :param source_type: str - default: "close"
    :param sequential: bool - default=False

    :return: IQ(inphase, quadrature)
    """
    warmup_candles_num = get_config('env.data.warmup_candles_num', 240)
    if not sequential and len(candles) > warmup_candles_num:
        candles = candles[-warmup_candles_num:]

    source = get_candle_source(candles, source_type=source_type)
    inphase, quadrature = talib.HT_PHASOR(source)

    if sequential:
        return IQ(inphase, quadrature)
    else:
        return IQ(inphase[-1], quadrature[-1])
예제 #24
0
def calc_features(df):
    open = df['op']
    high = df['hi']
    low = df['lo']
    close = df['cl']
    volume = df['volume']

    orig_columns = df.columns

    hilo = (df['hi'] + df['lo']) / 2
    df['BBANDS_upperband'], df['BBANDS_middleband'], df[
        'BBANDS_lowerband'] = talib.BBANDS(close,
                                           timeperiod=5,
                                           nbdevup=2,
                                           nbdevdn=2,
                                           matype=0)
    df['BBANDS_upperband'] -= hilo
    df['BBANDS_middleband'] -= hilo
    df['BBANDS_lowerband'] -= hilo
    df['DEMA'] = talib.DEMA(close, timeperiod=30) - hilo
    df['EMA'] = talib.EMA(close, timeperiod=30) - hilo
    df['HT_TRENDLINE'] = talib.HT_TRENDLINE(close) - hilo
    df['KAMA'] = talib.KAMA(close, timeperiod=30) - hilo
    df['MA'] = talib.MA(close, timeperiod=30, matype=0) - hilo
    df['MIDPOINT'] = talib.MIDPOINT(close, timeperiod=14) - hilo
    df['SMA'] = talib.SMA(close, timeperiod=30) - hilo
    df['T3'] = talib.T3(close, timeperiod=5, vfactor=0) - hilo
    df['TEMA'] = talib.TEMA(close, timeperiod=30) - hilo
    df['TRIMA'] = talib.TRIMA(close, timeperiod=30) - hilo
    df['WMA'] = talib.WMA(close, timeperiod=30) - hilo

    df['ADX'] = talib.ADX(high, low, close, timeperiod=14)
    df['ADXR'] = talib.ADXR(high, low, close, timeperiod=14)
    df['APO'] = talib.APO(close, fastperiod=12, slowperiod=26, matype=0)
    df['AROON_aroondown'], df['AROON_aroonup'] = talib.AROON(high,
                                                             low,
                                                             timeperiod=14)
    df['AROONOSC'] = talib.AROONOSC(high, low, timeperiod=14)
    df['BOP'] = talib.BOP(open, high, low, close)
    df['CCI'] = talib.CCI(high, low, close, timeperiod=14)
    df['DX'] = talib.DX(high, low, close, timeperiod=14)
    df['MACD_macd'], df['MACD_macdsignal'], df['MACD_macdhist'] = talib.MACD(
        close, fastperiod=12, slowperiod=26, signalperiod=9)
    # skip MACDEXT MACDFIX たぶん同じなので
    df['MFI'] = talib.MFI(high, low, close, volume, timeperiod=14)
    df['MINUS_DI'] = talib.MINUS_DI(high, low, close, timeperiod=14)
    df['MINUS_DM'] = talib.MINUS_DM(high, low, timeperiod=14)
    df['MOM'] = talib.MOM(close, timeperiod=10)
    df['PLUS_DI'] = talib.PLUS_DI(high, low, close, timeperiod=14)
    df['PLUS_DM'] = talib.PLUS_DM(high, low, timeperiod=14)
    df['RSI'] = talib.RSI(close, timeperiod=14)
    df['STOCH_slowk'], df['STOCH_slowd'] = talib.STOCH(high,
                                                       low,
                                                       close,
                                                       fastk_period=5,
                                                       slowk_period=3,
                                                       slowk_matype=0,
                                                       slowd_period=3,
                                                       slowd_matype=0)
    df['STOCHF_fastk'], df['STOCHF_fastd'] = talib.STOCHF(high,
                                                          low,
                                                          close,
                                                          fastk_period=5,
                                                          fastd_period=3,
                                                          fastd_matype=0)
    df['STOCHRSI_fastk'], df['STOCHRSI_fastd'] = talib.STOCHRSI(close,
                                                                timeperiod=14,
                                                                fastk_period=5,
                                                                fastd_period=3,
                                                                fastd_matype=0)
    df['TRIX'] = talib.TRIX(close, timeperiod=30)
    df['ULTOSC'] = talib.ULTOSC(high,
                                low,
                                close,
                                timeperiod1=7,
                                timeperiod2=14,
                                timeperiod3=28)
    df['WILLR'] = talib.WILLR(high, low, close, timeperiod=14)

    df['AD'] = talib.AD(high, low, close, volume)
    df['ADOSC'] = talib.ADOSC(high,
                              low,
                              close,
                              volume,
                              fastperiod=3,
                              slowperiod=10)
    df['OBV'] = talib.OBV(close, volume)

    df['ATR'] = talib.ATR(high, low, close, timeperiod=14)
    df['NATR'] = talib.NATR(high, low, close, timeperiod=14)
    df['TRANGE'] = talib.TRANGE(high, low, close)

    df['HT_DCPERIOD'] = talib.HT_DCPERIOD(close)
    df['HT_DCPHASE'] = talib.HT_DCPHASE(close)
    df['HT_PHASOR_inphase'], df['HT_PHASOR_quadrature'] = talib.HT_PHASOR(
        close)
    df['HT_SINE_sine'], df['HT_SINE_leadsine'] = talib.HT_SINE(close)
    df['HT_TRENDMODE'] = talib.HT_TRENDMODE(close)

    df['BETA'] = talib.BETA(high, low, timeperiod=5)
    df['CORREL'] = talib.CORREL(high, low, timeperiod=30)
    df['LINEARREG'] = talib.LINEARREG(close, timeperiod=14) - close
    df['LINEARREG_ANGLE'] = talib.LINEARREG_ANGLE(close, timeperiod=14)
    df['LINEARREG_INTERCEPT'] = talib.LINEARREG_INTERCEPT(
        close, timeperiod=14) - close
    df['LINEARREG_SLOPE'] = talib.LINEARREG_SLOPE(close, timeperiod=14)
    df['STDDEV'] = talib.STDDEV(close, timeperiod=5, nbdev=1)

    return df
예제 #25
0
def generate_tech_data(stock,
                       open_name,
                       close_name,
                       high_name,
                       low_name,
                       max_time_window=10):
    open_price = stock[open_name].values
    close_price = stock[close_name].values
    low_price = stock[low_name].values
    high_price = stock[high_name].values
    data = stock.copy()
    data['MOM'] = talib.MOM(close_price, timeperiod=max_time_window)
    data['HT_DCPERIOD'] = talib.HT_DCPERIOD(close_price)
    data['HT_DCPHASE'] = talib.HT_DCPHASE(close_price)
    data['sine'], data['leadsine'] = talib.HT_SINE(close_price)
    data['inphase'], data['quadrature'] = talib.HT_PHASOR(close_price)
    data['ADXR'] = talib.ADXR(high_price,
                              low_price,
                              close_price,
                              timeperiod=max_time_window)
    data['APO'] = talib.APO(close_price,
                            fastperiod=max_time_window // 2,
                            slowperiod=max_time_window)
    data['AROON_UP'], _ = talib.AROON(high_price,
                                      low_price,
                                      timeperiod=max_time_window)
    data['CCI'] = talib.CCI(high_price,
                            low_price,
                            close_price,
                            timeperiod=max_time_window)
    data['PLUS_DI'] = talib.PLUS_DI(high_price,
                                    low_price,
                                    close_price,
                                    timeperiod=max_time_window)
    data['PPO'] = talib.PPO(close_price,
                            fastperiod=max_time_window // 2,
                            slowperiod=max_time_window)
    data['macd'], data['macd_sig'], data['macd_hist'] = talib.MACD(
        close_price,
        fastperiod=max_time_window // 2,
        slowperiod=max_time_window,
        signalperiod=max_time_window // 2)
    data['CMO'] = talib.CMO(close_price, timeperiod=max_time_window)
    data['ROCP'] = talib.ROCP(close_price, timeperiod=max_time_window)
    data['fastk'], data['fastd'] = talib.STOCHF(high_price, low_price,
                                                close_price)
    data['TRIX'] = talib.TRIX(close_price, timeperiod=max_time_window)
    data['ULTOSC'] = talib.ULTOSC(high_price,
                                  low_price,
                                  close_price,
                                  timeperiod1=max_time_window // 2,
                                  timeperiod2=max_time_window,
                                  timeperiod3=max_time_window * 2)
    data['WILLR'] = talib.WILLR(high_price,
                                low_price,
                                close_price,
                                timeperiod=max_time_window)
    data['NATR'] = talib.NATR(high_price,
                              low_price,
                              close_price,
                              timeperiod=max_time_window)
    data = data.drop([open_name, close_name, high_name, low_name], axis=1)
    data = data.dropna().astype(np.float32)
    return data
예제 #26
0
def HT_PHASOR(Series):
    res = talib.HT_PHASOR(Series.values)
    return pd.Series(res, index=Series.index)
예제 #27
0
    def calculate(self, para):

        self.t = self.inputdata[:, 0]
        self.op = self.inputdata[:, 1]
        self.high = self.inputdata[:, 2]
        self.low = self.inputdata[:, 3]
        self.close = self.inputdata[:, 4]
        #adjusted close
        self.close1 = self.inputdata[:, 5]
        self.volume = self.inputdata[:, 6]
        #Overlap study

        #Overlap Studies
        #Overlap Studies
        if para is 'BBANDS':  #Bollinger Bands
            upperband, middleband, lowerband = ta.BBANDS(self.close,
                                                         timeperiod=self.tp,
                                                         nbdevup=2,
                                                         nbdevdn=2,
                                                         matype=0)
            self.output = [upperband, middleband, lowerband]

        elif para is 'DEMA':  #Double Exponential Moving Average
            self.output = ta.DEMA(self.close, timeperiod=self.tp)

        elif para is 'EMA':  #Exponential Moving Average
            self.output = ta.EMA(self.close, timeperiod=self.tp)

        elif para is 'HT_TRENDLINE':  #Hilbert Transform - Instantaneous Trendline
            self.output = ta.HT_TRENDLINE(self.close)

        elif para is 'KAMA':  #Kaufman Adaptive Moving Average
            self.output = ta.KAMA(self.close, timeperiod=self.tp)

        elif para is 'MA':  #Moving average
            self.output = ta.MA(self.close, timeperiod=self.tp, matype=0)

        elif para is 'MAMA':  #MESA Adaptive Moving Average
            mama, fama = ta.MAMA(self.close, fastlimit=0, slowlimit=0)

        elif para is 'MAVP':  #Moving average with variable period
            self.output = ta.MAVP(self.close,
                                  periods=10,
                                  minperiod=self.tp,
                                  maxperiod=self.tp1,
                                  matype=0)

        elif para is 'MIDPOINT':  #MidPoint over period
            self.output = ta.MIDPOINT(self.close, timeperiod=self.tp)

        elif para is 'MIDPRICE':  #Midpoint Price over period
            self.output = ta.MIDPRICE(self.high, self.low, timeperiod=self.tp)

        elif para is 'SAR':  #Parabolic SAR
            self.output = ta.SAR(self.high,
                                 self.low,
                                 acceleration=0,
                                 maximum=0)

        elif para is 'SAREXT':  #Parabolic SAR - Extended
            self.output = ta.SAREXT(self.high,
                                    self.low,
                                    startvalue=0,
                                    offsetonreverse=0,
                                    accelerationinitlong=0,
                                    accelerationlong=0,
                                    accelerationmaxlong=0,
                                    accelerationinitshort=0,
                                    accelerationshort=0,
                                    accelerationmaxshort=0)

        elif para is 'SMA':  #Simple Moving Average
            self.output = ta.SMA(self.close, timeperiod=self.tp)

        elif para is 'T3':  #Triple Exponential Moving Average (T3)
            self.output = ta.T3(self.close, timeperiod=self.tp, vfactor=0)

        elif para is 'TEMA':  #Triple Exponential Moving Average
            self.output = ta.TEMA(self.close, timeperiod=self.tp)

        elif para is 'TRIMA':  #Triangular Moving Average
            self.output = ta.TRIMA(self.close, timeperiod=self.tp)

        elif para is 'WMA':  #Weighted Moving Average
            self.output = ta.WMA(self.close, timeperiod=self.tp)

        #Momentum Indicators
        elif para is 'ADX':  #Average Directional Movement Index
            self.output = ta.ADX(self.high,
                                 self.low,
                                 self.close,
                                 timeperiod=self.tp)

        elif para is 'ADXR':  #Average Directional Movement Index Rating
            self.output = ta.ADXR(self.high,
                                  self.low,
                                  self.close,
                                  timeperiod=self.tp)

        elif para is 'APO':  #Absolute Price Oscillator
            self.output = ta.APO(self.close,
                                 fastperiod=12,
                                 slowperiod=26,
                                 matype=0)

        elif para is 'AROON':  #Aroon
            aroondown, aroonup = ta.AROON(self.high,
                                          self.low,
                                          timeperiod=self.tp)
            self.output = [aroondown, aroonup]

        elif para is 'AROONOSC':  #Aroon Oscillator
            self.output = ta.AROONOSC(self.high, self.low, timeperiod=self.tp)

        elif para is 'BOP':  #Balance Of Power
            self.output = ta.BOP(self.op, self.high, self.low, self.close)

        elif para is 'CCI':  #Commodity Channel Index
            self.output = ta.CCI(self.high,
                                 self.low,
                                 self.close,
                                 timeperiod=self.tp)

        elif para is 'CMO':  #Chande Momentum Oscillator
            self.output = ta.CMO(self.close, timeperiod=self.tp)

        elif para is 'DX':  #Directional Movement Index
            self.output = ta.DX(self.high,
                                self.low,
                                self.close,
                                timeperiod=self.tp)

        elif para is 'MACD':  #Moving Average Convergence/Divergence
            macd, macdsignal, macdhist = ta.MACD(self.close,
                                                 fastperiod=12,
                                                 slowperiod=26,
                                                 signalperiod=9)
            self.output = [macd, macdsignal, macdhist]
        elif para is 'MACDEXT':  #MACD with controllable MA type
            macd, macdsignal, macdhist = ta.MACDEXT(self.close,
                                                    fastperiod=12,
                                                    fastmatype=0,
                                                    slowperiod=26,
                                                    slowmatype=0,
                                                    signalperiod=9,
                                                    signalmatype=0)
            self.output = [macd, macdsignal, macdhist]
        elif para is 'MACDFIX':  #Moving Average Convergence/Divergence Fix 12/26
            macd, macdsignal, macdhist = ta.MACDFIX(self.close, signalperiod=9)
            self.output = [macd, macdsignal, macdhist]
        elif para is 'MFI':  #Money Flow Index
            self.output = ta.MFI(self.high,
                                 self.low,
                                 self.close,
                                 self.volume,
                                 timeperiod=self.tp)

        elif para is 'MINUS_DI':  #Minus Directional Indicator
            self.output = ta.MINUS_DI(self.high,
                                      self.low,
                                      self.close,
                                      timeperiod=self.tp)

        elif para is 'MINUS_DM':  #Minus Directional Movement
            self.output = ta.MINUS_DM(self.high, self.low, timeperiod=self.tp)

        elif para is 'MOM':  #Momentum
            self.output = ta.MOM(self.close, timeperiod=10)

        elif para is 'PLUS_DI':  #Plus Directional Indicator
            self.output = ta.PLUS_DI(self.high,
                                     self.low,
                                     self.close,
                                     timeperiod=self.tp)

        elif para is 'PLUS_DM':  #Plus Directional Movement
            self.output = ta.PLUS_DM(self.high, self.low, timeperiod=self.tp)

        elif para is 'PPO':  #Percentage Price Oscillator
            self.output = ta.PPO(self.close,
                                 fastperiod=12,
                                 slowperiod=26,
                                 matype=0)

        elif para is 'ROC':  #Rate of change : ((price/prevPrice)-1)*100
            self.output = ta.ROC(self.close, timeperiod=10)

        elif para is 'ROCP':  #Rate of change Percentage: (price-prevPrice)/prevPrice
            self.output = ta.ROCP(self.close, timeperiod=10)

        elif para is 'ROCR':  #Rate of change ratio: (price/prevPrice)
            self.output = ta.ROCR(self.close, timeperiod=10)

        elif para is 'ROCR100':  #Rate of change ratio 100 scale: (price/prevPrice)*100
            self.output = ta.ROCR100(self.close, timeperiod=10)

        elif para is 'RSI':  #Relative Strength Index
            self.output = ta.RSI(self.close, timeperiod=self.tp)

        elif para is 'STOCH':  #Stochastic
            slowk, slowd = ta.STOCH(self.high,
                                    self.low,
                                    self.close,
                                    fastk_period=5,
                                    slowk_period=3,
                                    slowk_matype=0,
                                    slowd_period=3,
                                    slowd_matype=0)
            self.output = [slowk, slowd]

        elif para is 'STOCHF':  #Stochastic Fast
            fastk, fastd = ta.STOCHF(self.high,
                                     self.low,
                                     self.close,
                                     fastk_period=5,
                                     fastd_period=3,
                                     fastd_matype=0)
            self.output = [fastk, fastd]

        elif para is 'STOCHRSI':  #Stochastic Relative Strength Index
            fastk, fastd = ta.STOCHRSI(self.close,
                                       timeperiod=self.tp,
                                       fastk_period=5,
                                       fastd_period=3,
                                       fastd_matype=0)
            self.output = [fastk, fastd]

        elif para is 'TRIX':  #1-day Rate-Of-Change (ROC) of a Triple Smooth EMA
            self.output = ta.TRIX(self.close, timeperiod=self.tp)

        elif para is 'ULTOSC':  #Ultimate Oscillator
            self.output = ta.ULTOSC(self.high,
                                    self.low,
                                    self.close,
                                    timeperiod1=self.tp,
                                    timeperiod2=self.tp1,
                                    timeperiod3=self.tp2)

        elif para is 'WILLR':  #Williams' %R
            self.output = ta.WILLR(self.high,
                                   self.low,
                                   self.close,
                                   timeperiod=self.tp)

        # Volume Indicators    : #
        elif para is 'AD':  #Chaikin A/D Line
            self.output = ta.AD(self.high, self.low, self.close, self.volume)

        elif para is 'ADOSC':  #Chaikin A/D Oscillator
            self.output = ta.ADOSC(self.high,
                                   self.low,
                                   self.close,
                                   self.volume,
                                   fastperiod=3,
                                   slowperiod=10)

        elif para is 'OBV':  #On Balance Volume
            self.output = ta.OBV(self.close, self.volume)

    # Volatility Indicators: #
        elif para is 'ATR':  #Average True Range
            self.output = ta.ATR(self.high,
                                 self.low,
                                 self.close,
                                 timeperiod=self.tp)

        elif para is 'NATR':  #Normalized Average True Range
            self.output = ta.NATR(self.high,
                                  self.low,
                                  self.close,
                                  timeperiod=self.tp)

        elif para is 'TRANGE':  #True Range
            self.output = ta.TRANGE(self.high, self.low, self.close)

        #Price Transform      : #
        elif para is 'AVGPRICE':  #Average Price
            self.output = ta.AVGPRICE(self.op, self.high, self.low, self.close)

        elif para is 'MEDPRICE':  #Median Price
            self.output = ta.MEDPRICE(self.high, self.low)

        elif para is 'TYPPRICE':  #Typical Price
            self.output = ta.TYPPRICE(self.high, self.low, self.close)

        elif para is 'WCLPRICE':  #Weighted Close Price
            self.output = ta.WCLPRICE(self.high, self.low, self.close)

        #Cycle Indicators     : #
        elif para is 'HT_DCPERIOD':  #Hilbert Transform - Dominant Cycle Period
            self.output = ta.HT_DCPERIOD(self.close)

        elif para is 'HT_DCPHASE':  #Hilbert Transform - Dominant Cycle Phase
            self.output = ta.HT_DCPHASE(self.close)

        elif para is 'HT_PHASOR':  #Hilbert Transform - Phasor Components
            inphase, quadrature = ta.HT_PHASOR(self.close)
            self.output = [inphase, quadrature]

        elif para is 'HT_SINE':  #Hilbert Transform - SineWave #2
            sine, leadsine = ta.HT_SINE(self.close)
            self.output = [sine, leadsine]

        elif para is 'HT_TRENDMODE':  #Hilbert Transform - Trend vs Cycle Mode
            self.integer = ta.HT_TRENDMODE(self.close)

        #Pattern Recognition  : #
        elif para is 'CDL2CROWS':  #Two Crows
            self.integer = ta.CDL2CROWS(self.op, self.high, self.low,
                                        self.close)

        elif para is 'CDL3BLACKCROWS':  #Three Black Crows
            self.integer = ta.CDL3BLACKCROWS(self.op, self.high, self.low,
                                             self.close)

        elif para is 'CDL3INSIDE':  #Three Inside Up/Down
            self.integer = ta.CDL3INSIDE(self.op, self.high, self.low,
                                         self.close)

        elif para is 'CDL3LINESTRIKE':  #Three-Line Strike
            self.integer = ta.CDL3LINESTRIKE(self.op, self.high, self.low,
                                             self.close)

        elif para is 'CDL3OUTSIDE':  #Three Outside Up/Down
            self.integer = ta.CDL3OUTSIDE(self.op, self.high, self.low,
                                          self.close)

        elif para is 'CDL3STARSINSOUTH':  #Three Stars In The South
            self.integer = ta.CDL3STARSINSOUTH(self.op, self.high, self.low,
                                               self.close)

        elif para is 'CDL3WHITESOLDIERS':  #Three Advancing White Soldiers
            self.integer = ta.CDL3WHITESOLDIERS(self.op, self.high, self.low,
                                                self.close)

        elif para is 'CDLABANDONEDBABY':  #Abandoned Baby
            self.integer = ta.CDLABANDONEDBABY(self.op,
                                               self.high,
                                               self.low,
                                               self.close,
                                               penetration=0)

        elif para is 'CDLBELTHOLD':  #Belt-hold
            self.integer = ta.CDLBELTHOLD(self.op, self.high, self.low,
                                          self.close)

        elif para is 'CDLBREAKAWAY':  #Breakaway
            self.integer = ta.CDLBREAKAWAY(self.op, self.high, self.low,
                                           self.close)

        elif para is 'CDLCLOSINGMARUBOZU':  #Closing Marubozu
            self.integer = ta.CDLCLOSINGMARUBOZU(self.op, self.high, self.low,
                                                 self.close)

        elif para is 'CDLCONCEALBABYSWALL':  #Concealing Baby Swallow
            self.integer = ta.CDLCONCEALBABYSWALL(self.op, self.high, self.low,
                                                  self.close)

        elif para is 'CDLCOUNTERATTACK':  #Counterattack
            self.integer = ta.CDLCOUNTERATTACK(self.op, self.high, self.low,
                                               self.close)

        elif para is 'CDLDARKCLOUDCOVER':  #Dark Cloud Cover
            self.integer = ta.CDLDARKCLOUDCOVER(self.op,
                                                self.high,
                                                self.low,
                                                self.close,
                                                penetration=0)

        elif para is 'CDLDOJI':  #Doji
            self.integer = ta.CDLDOJI(self.op, self.high, self.low, self.close)

        elif para is 'CDLDOJISTAR':  #Doji Star
            self.integer = ta.CDLDOJISTAR(self.op, self.high, self.low,
                                          self.close)

        elif para is 'CDLDRAGONFLYDOJI':  #Dragonfly Doji
            self.integer = ta.CDLDRAGONFLYDOJI(self.op, self.high, self.low,
                                               self.close)

        elif para is 'CDLENGULFING':  #Engulfing Pattern
            self.integer = ta.CDLENGULFING(self.op, self.high, self.low,
                                           self.close)

        elif para is 'CDLEVENINGDOJISTAR':  #Evening Doji Star
            self.integer = ta.CDLEVENINGDOJISTAR(self.op,
                                                 self.high,
                                                 self.low,
                                                 self.close,
                                                 penetration=0)

        elif para is 'CDLEVENINGSTAR':  #Evening Star
            self.integer = ta.CDLEVENINGSTAR(self.op,
                                             self.high,
                                             self.low,
                                             self.close,
                                             penetration=0)

        elif para is 'CDLGAPSIDESIDEWHITE':  #Up/Down-gap side-by-side white lines
            self.integer = ta.CDLGAPSIDESIDEWHITE(self.op, self.high, self.low,
                                                  self.close)

        elif para is 'CDLGRAVESTONEDOJI':  #Gravestone Doji
            self.integer = ta.CDLGRAVESTONEDOJI(self.op, self.high, self.low,
                                                self.close)

        elif para is 'CDLHAMMER':  #Hammer
            self.integer = ta.CDLHAMMER(self.op, self.high, self.low,
                                        self.close)

        elif para is 'CDLHANGINGMAN':  #Hanging Man
            self.integer = ta.CDLHANGINGMAN(self.op, self.high, self.low,
                                            self.close)

        elif para is 'CDLHARAMI':  #Harami Pattern
            self.integer = ta.CDLHARAMI(self.op, self.high, self.low,
                                        self.close)

        elif para is 'CDLHARAMICROSS':  #Harami Cross Pattern
            self.integer = ta.CDLHARAMICROSS(self.op, self.high, self.low,
                                             self.close)

        elif para is 'CDLHIGHWAVE':  #High-Wave Candle
            self.integer = ta.CDLHIGHWAVE(self.op, self.high, self.low,
                                          self.close)

        elif para is 'CDLHIKKAKE':  #Hikkake Pattern
            self.integer = ta.CDLHIKKAKE(self.op, self.high, self.low,
                                         self.close)

        elif para is 'CDLHIKKAKEMOD':  #Modified Hikkake Pattern
            self.integer = ta.CDLHIKKAKEMOD(self.op, self.high, self.low,
                                            self.close)

        elif para is 'CDLHOMINGPIGEON':  #Homing Pigeon
            self.integer = ta.CDLHOMINGPIGEON(self.op, self.high, self.low,
                                              self.close)

        elif para is 'CDLIDENTICAL3CROWS':  #Identical Three Crows
            self.integer = ta.CDLIDENTICAL3CROWS(self.op, self.high, self.low,
                                                 self.close)

        elif para is 'CDLINNECK':  #In-Neck Pattern
            self.integer = ta.CDLINNECK(self.op, self.high, self.low,
                                        self.close)

        elif para is 'CDLINVERTEDHAMMER':  #Inverted Hammer
            self.integer = ta.CDLINVERTEDHAMMER(self.op, self.high, self.low,
                                                self.close)

        elif para is 'CDLKICKING':  #Kicking
            self.integer = ta.CDLKICKING(self.op, self.high, self.low,
                                         self.close)

        elif para is 'CDLKICKINGBYLENGTH':  #Kicking - bull/bear determined by the longer marubozu
            self.integer = ta.CDLKICKINGBYLENGTH(self.op, self.high, self.low,
                                                 self.close)

        elif para is 'CDLLADDERBOTTOM':  #Ladder Bottom
            self.integer = ta.CDLLADDERBOTTOM(self.op, self.high, self.low,
                                              self.close)

        elif para is 'CDLLONGLEGGEDDOJI':  #Long Legged Doji
            self.integer = ta.CDLLONGLEGGEDDOJI(self.op, self.high, self.low,
                                                self.close)

        elif para is 'CDLLONGLINE':  #Long Line Candle
            self.integer = ta.CDLLONGLINE(self.op, self.high, self.low,
                                          self.close)

        elif para is 'CDLMARUBOZU':  #Marubozu
            self.integer = ta.CDLMARUBOZU(self.op, self.high, self.low,
                                          self.close)

        elif para is 'CDLMATCHINGLOW':  #Matching Low
            self.integer = ta.CDLMATCHINGLOW(self.op, self.high, self.low,
                                             self.close)

        elif para is 'CDLMATHOLD':  #Mat Hold
            self.integer = ta.CDLMATHOLD(self.op,
                                         self.high,
                                         self.low,
                                         self.close,
                                         penetration=0)

        elif para is 'CDLMORNINGDOJISTAR':  #Morning Doji Star
            self.integer = ta.CDLMORNINGDOJISTAR(self.op,
                                                 self.high,
                                                 self.low,
                                                 self.close,
                                                 penetration=0)

        elif para is 'CDLMORNINGSTAR':  #Morning Star
            self.integer = ta.CDLMORNINGSTAR(self.op,
                                             self.high,
                                             self.low,
                                             self.close,
                                             penetration=0)

        elif para is 'CDLONNECK':  #On-Neck Pattern
            self.integer = ta.CDLONNECK(self.op, self.high, self.low,
                                        self.close)

        elif para is 'CDLPIERCING':  #Piercing Pattern
            self.integer = ta.CDLPIERCING(self.op, self.high, self.low,
                                          self.close)

        elif para is 'CDLRICKSHAWMAN':  #Rickshaw Man
            self.integer = ta.CDLRICKSHAWMAN(self.op, self.high, self.low,
                                             self.close)

        elif para is 'CDLRISEFALL3METHODS':  #Rising/Falling Three Methods
            self.integer = ta.CDLRISEFALL3METHODS(self.op, self.high, self.low,
                                                  self.close)

        elif para is 'CDLSEPARATINGLINES':  #Separating Lines
            self.integer = ta.CDLSEPARATINGLINES(self.op, self.high, self.low,
                                                 self.close)

        elif para is 'CDLSHOOTINGSTAR':  #Shooting Star
            self.integer = ta.CDLSHOOTINGSTAR(self.op, self.high, self.low,
                                              self.close)

        elif para is 'CDLSHORTLINE':  #Short Line Candle
            self.integer = ta.CDLSHORTLINE(self.op, self.high, self.low,
                                           self.close)

        elif para is 'CDLSPINNINGTOP':  #Spinning Top
            self.integer = ta.CDLSPINNINGTOP(self.op, self.high, self.low,
                                             self.close)

        elif para is 'CDLSTALLEDPATTERN':  #Stalled Pattern
            self.integer = ta.CDLSTALLEDPATTERN(self.op, self.high, self.low,
                                                self.close)

        elif para is 'CDLSTICKSANDWICH':  #Stick Sandwich
            self.integer = ta.CDLSTICKSANDWICH(self.op, self.high, self.low,
                                               self.close)

        elif para is 'CDLTAKURI':  #Takuri (Dragonfly Doji with very long lower shadow)
            self.integer = ta.CDLTAKURI(self.op, self.high, self.low,
                                        self.close)

        elif para is 'CDLTASUKIGAP':  #Tasuki Gap
            self.integer = ta.CDLTASUKIGAP(self.op, self.high, self.low,
                                           self.close)

        elif para is 'CDLTHRUSTING':  #Thrusting Pattern
            self.integer = ta.CDLTHRUSTING(self.op, self.high, self.low,
                                           self.close)

        elif para is 'CDLTRISTAR':  #Tristar Pattern
            self.integer = ta.CDLTRISTAR(self.op, self.high, self.low,
                                         self.close)

        elif para is 'CDLUNIQUE3RIVER':  #Unique 3 River
            self.integer = ta.CDLUNIQUE3RIVER(self.op, self.high, self.low,
                                              self.close)

        elif para is 'CDLUPSIDEGAP2CROWS':  #Upside Gap Two Crows
            self.integer = ta.CDLUPSIDEGAP2CROWS(self.op, self.high, self.low,
                                                 self.close)

        elif para is 'CDLXSIDEGAP3METHODS':  #Upside/Downside Gap Three Methods
            self.integer = ta.CDLXSIDEGAP3METHODS(self.op, self.high, self.low,
                                                  self.close)

        #Statistic Functions  : #
        elif para is 'BETA':  #Beta
            self.output = ta.BETA(self.high, self.low, timeperiod=5)

        elif para is 'CORREL':  #Pearson's Correlation Coefficient (r)
            self.output = ta.CORREL(self.high, self.low, timeperiod=self.tp)

        elif para is 'LINEARREG':  #Linear Regression
            self.output = ta.LINEARREG(self.close, timeperiod=self.tp)

        elif para is 'LINEARREG_ANGLE':  #Linear Regression Angle
            self.output = ta.LINEARREG_ANGLE(self.close, timeperiod=self.tp)

        elif para is 'LINEARREG_INTERCEPT':  #Linear Regression Intercept
            self.output = ta.LINEARREG_INTERCEPT(self.close,
                                                 timeperiod=self.tp)

        elif para is 'LINEARREG_SLOPE':  #Linear Regression Slope
            self.output = ta.LINEARREG_SLOPE(self.close, timeperiod=self.tp)

        elif para is 'STDDEV':  #Standard Deviation
            self.output = ta.STDDEV(self.close, timeperiod=5, nbdev=1)

        elif para is 'TSF':  #Time Series Forecast
            self.output = ta.TSF(self.close, timeperiod=self.tp)

        elif para is 'VAR':  #Variance
            self.output = ta.VAR(self.close, timeperiod=5, nbdev=1)

        else:
            print('You issued command:' + para)
예제 #28
0
def get_datasets(asset, currency, granularity, datapoints):
    """Fetch the API and precess the desired pair

    Arguments:
        asset {str} -- First pair
        currency {str} -- Second pair
        granularity {str ['day', 'hour']} -- Granularity
        datapoints {int [100 - 2000]} -- [description]

    Returns:
        pandas.Dataframe -- The OHLCV and indicators dataframe
    """
    df_train_path = 'datasets/bot_train_{}_{}_{}.csv'.format(
        asset + currency, datapoints, granularity)
    df_rollout_path = 'datasets/bot_rollout_{}_{}_{}.csv'.format(
        asset + currency, datapoints, granularity)
    emojis = [
        ':moneybag:', ':yen:', ':dollar:', ':pound:', ':euro:',
        ':credit_card:', ':money_with_wings:', ':gem:'
    ]

    if not os.path.exists(df_rollout_path):
        headers = {
            'User-Agent':
            'Mozilla/5.0',
            'authorization':
            'Apikey 3d7d3e9e6006669ac00584978342451c95c3c78421268ff7aeef69995f9a09ce'
        }

        # OHLC
        # url = 'https://min-api.cryptocompare.com/data/histo{}?fsym={}&tsym={}&e=Binance&limit={}'.format(granularity, asset, currency, datapoints)
        url = 'https://min-api.cryptocompare.com/data/histo{}?fsym={}&tsym={}&limit={}'.format(
            granularity, asset, currency, datapoints)
        # print(emoji.emojize(':dizzy: :large_blue_diamond: :gem: :bar_chart: :crystal_ball: :chart_with_downwards_trend: :chart_with_upwards_trend: :large_orange_diamond: loading...', use_aliases=True))
        print(
            colored(
                emoji.emojize('> ' + random.choice(emojis) + ' downloading ' +
                              asset + '/' + currency,
                              use_aliases=True), 'green'))
        # print(colored('> downloading ' + asset + '/' + currency, 'green'))
        response = requests.get(url, headers=headers)
        json_response = response.json()
        status = json_response['Response']
        if status == "Error":
            print(colored('=== {} ==='.format(json_response['Message']),
                          'red'))
            raise AssertionError()
        result = json_response['Data']
        df = pd.DataFrame(result)
        print(df.tail())
        df['Date'] = pd.to_datetime(df['time'], utc=True, unit='s')
        df.drop('time', axis=1, inplace=True)

        # indicators
        # https://github.com/mrjbq7/ta-lib/blob/master/docs/func.md
        open_price, high, low, close = np.array(df['open']), np.array(
            df['high']), np.array(df['low']), np.array(df['close'])
        volume = np.array(df['volumefrom'])
        # cycle indicators
        df.loc[:, 'HT_DCPERIOD'] = talib.HT_DCPERIOD(close)
        df.loc[:, 'HT_DCPHASE'] = talib.HT_DCPHASE(close)
        df.loc[:,
               'HT_PHASOR_inphase'], df.loc[:,
                                            'HT_PHASOR_quadrature'] = talib.HT_PHASOR(
                                                close)
        df.loc[:, 'HT_SINE_sine'], df.loc[:,
                                          'HT_SINE_leadsine'] = talib.HT_SINE(
                                              close)
        df.loc[:, 'HT_TRENDMODE'] = talib.HT_TRENDMODE(close)
        # momemtum indicators
        df.loc[:, 'ADX'] = talib.ADX(high, low, close, timeperiod=12)
        df.loc[:, 'ADXR'] = talib.ADXR(high, low, close, timeperiod=13)
        df.loc[:, 'APO'] = talib.APO(close,
                                     fastperiod=5,
                                     slowperiod=10,
                                     matype=0)
        df.loc[:,
               'AROON_down'], df.loc[:,
                                     'AROON_up'] = talib.AROON(high,
                                                               low,
                                                               timeperiod=15)
        df.loc[:, 'AROONOSC'] = talib.AROONOSC(high, low, timeperiod=13)
        df.loc[:, 'BOP'] = talib.BOP(open_price, high, low, close)
        df.loc[:, 'CCI'] = talib.CCI(high, low, close, timeperiod=13)
        df.loc[:, 'CMO'] = talib.CMO(close, timeperiod=14)
        df.loc[:, 'DX'] = talib.DX(high, low, close, timeperiod=10)
        df['MACD'], df['MACD_signal'], df['MACD_hist'] = talib.MACD(
            close, fastperiod=5, slowperiod=10, signalperiod=20)
        df.loc[:, 'MFI'] = talib.MFI(high, low, close, volume, timeperiod=12)
        df.loc[:, 'MINUS_DI'] = talib.MINUS_DI(high, low, close, timeperiod=10)
        df.loc[:, 'MINUS_DM'] = talib.MINUS_DM(high, low, timeperiod=14)
        df.loc[:, 'MOM'] = talib.MOM(close, timeperiod=20)
        df.loc[:, 'PPO'] = talib.PPO(close,
                                     fastperiod=17,
                                     slowperiod=35,
                                     matype=2)
        df.loc[:, 'ROC'] = talib.ROC(close, timeperiod=12)
        df.loc[:, 'RSI'] = talib.RSI(close, timeperiod=25)
        df.loc[:, 'STOCH_k'], df.loc[:,
                                     'STOCH_d'] = talib.STOCH(high,
                                                              low,
                                                              close,
                                                              fastk_period=35,
                                                              slowk_period=12,
                                                              slowk_matype=0,
                                                              slowd_period=7,
                                                              slowd_matype=0)
        df.loc[:,
               'STOCHF_k'], df.loc[:,
                                   'STOCHF_d'] = talib.STOCHF(high,
                                                              low,
                                                              close,
                                                              fastk_period=28,
                                                              fastd_period=14,
                                                              fastd_matype=0)
        df.loc[:, 'STOCHRSI_K'], df.loc[:, 'STOCHRSI_D'] = talib.STOCHRSI(
            close,
            timeperiod=35,
            fastk_period=12,
            fastd_period=10,
            fastd_matype=1)
        df.loc[:, 'TRIX'] = talib.TRIX(close, timeperiod=30)
        df.loc[:, 'ULTOSC'] = talib.ULTOSC(high,
                                           low,
                                           close,
                                           timeperiod1=14,
                                           timeperiod2=28,
                                           timeperiod3=35)
        df.loc[:, 'WILLR'] = talib.WILLR(high, low, close, timeperiod=35)
        # overlap studies
        df.loc[:,
               'BBANDS_upper'], df.loc[:,
                                       'BBANDS_middle'], df.loc[:,
                                                                'BBANDS_lower'] = talib.BBANDS(
                                                                    close,
                                                                    timeperiod=
                                                                    12,
                                                                    nbdevup=2,
                                                                    nbdevdn=2,
                                                                    matype=0)
        df.loc[:, 'DEMA'] = talib.DEMA(close, timeperiod=30)
        df.loc[:, 'EMA'] = talib.EMA(close, timeperiod=7)
        df.loc[:, 'HT_TRENDLINE'] = talib.HT_TRENDLINE(close)
        df.loc[:, 'KAMA'] = talib.KAMA(close, timeperiod=5)
        df.loc[:, 'MA'] = talib.MA(close, timeperiod=5, matype=0)
        df.loc[:, 'MIDPOINT'] = talib.MIDPOINT(close, timeperiod=20)
        df.loc[:, 'WMA'] = talib.WMA(close, timeperiod=15)
        df.loc[:, 'SMA'] = talib.SMA(close)
        # pattern recoginition
        df.loc[:, 'CDL2CROWS'] = talib.CDL2CROWS(open_price, high, low, close)
        df.loc[:, 'CDL3BLACKCROWS'] = talib.CDL3BLACKCROWS(
            open_price, high, low, close)
        df.loc[:, 'CDL3INSIDE'] = talib.CDL3INSIDE(open_price, high, low,
                                                   close)
        df.loc[:, 'CDL3LINESTRIKE'] = talib.CDL3LINESTRIKE(
            open_price, high, low, close)
        # price transform
        df.loc[:, 'WCLPRICE'] = talib.WCLPRICE(high, low, close)
        # statistic funcitons
        df.loc[:, 'BETA'] = talib.BETA(high, low, timeperiod=20)
        df.loc[:, 'CORREL'] = talib.CORREL(high, low, timeperiod=20)
        df.loc[:, 'STDDEV'] = talib.STDDEV(close, timeperiod=20, nbdev=1)
        df.loc[:, 'TSF'] = talib.TSF(close, timeperiod=20)
        df.loc[:, 'VAR'] = talib.VAR(close, timeperiod=20, nbdev=1)
        # volatility indicators
        df.loc[:, 'ATR'] = talib.ATR(high, low, close, timeperiod=7)
        df.loc[:, 'NATR'] = talib.NATR(high, low, close, timeperiod=20)
        df.loc[:, 'TRANGE'] = talib.TRANGE(high, low, close)
        # volume indicators
        df.loc[:, 'AD'] = talib.AD(high, low, close, volume)
        df.loc[:, 'ADOSC'] = talib.ADOSC(high,
                                         low,
                                         close,
                                         volume,
                                         fastperiod=10,
                                         slowperiod=20)
        df.loc[:, 'OBV'] = talib.OBV(close, volume)

        # df.fillna(df.mean(), inplace=True)
        df.dropna(inplace=True)
        df.set_index('Date', inplace=True)
        print(colored('> caching' + asset + '/' + currency + ':)', 'cyan'))
        train_size = round(
            len(df) *
            DF_TRAIN_SIZE)  # 75% to train -> test with different value
        df_train = df[:train_size]
        df_rollout = df[train_size:]
        df_train.to_csv(df_train_path)
        df_rollout.to_csv(df_rollout_path)
        df_train = pd.read_csv(
            df_train_path)  # re-read to avoid indexing issue w/ Ray
        df_rollout = pd.read_csv(df_rollout_path)
    else:

        print(
            colored(
                emoji.emojize('> ' + random.choice(emojis) + ' feching ' +
                              asset + '/' + currency + ' from cache',
                              use_aliases=True), 'magenta'))

        # print(colored('> feching ' + asset + '/' + currency + ' from cache :)', 'magenta'))
        df_train = pd.read_csv(df_train_path)
        df_rollout = pd.read_csv(df_rollout_path)
        # df_train.set_index('Date', inplace=True)
        # df_rollout.set_index('Date', inplace=True)

    return df_train, df_rollout
예제 #29
0
def TALIB_HT_PHASOR(close):
    '''00343,1,2'''
    return talib.HT_PHASOR(close)
df['Unique_3_River'] = ta.CDLUNIQUE3RIVER(np.array(df['Open']),
                                          np.array(df['High']),
                                          np.array(df['Low']),
                                          np.array(df['Adj Close']))
df['Upside_Gap_Two_Crows'] = ta.CDLUPSIDEGAP2CROWS(np.array(df['Open']),
                                                   np.array(df['High']),
                                                   np.array(df['Low']),
                                                   np.array(df['Adj Close']))
df['Upside_Downside_Gap_Three_Methods'] = ta.CDLXSIDEGAP3METHODS(
    np.array(df['Open']), np.array(df['High']), np.array(df['Low']),
    np.array(df['Adj Close']))

# Cycle Indicator Functions
df['HT_DCPERIOD'] = ta.HT_DCPERIOD(np.array(df['Adj Close'].shift(1)))
df['HT_DCPHASE'] = ta.HT_DCPHASE(np.array(df['Adj Close'].shift(1)))
df['inphase'], df['quadrature'] = ta.HT_PHASOR(
    np.array(df['Adj Close'].shift(1)))
df['sine'], df['leadsine'] = ta.HT_SINE(np.array(df['Adj Close'].shift(1)))
df['HT_TRENDMODE'] = ta.HT_TRENDMODE(np.array(df['Adj Close'].shift(1)))

df['ATR1'] = abs(np.array(df['High'].shift(1)) - np.array(df['Low'].shift(1)))
df['ATR2'] = abs(
    np.array(df['High'].shift(1)) - np.array(df['Adj Close'].shift(1)))
df['ATR3'] = abs(
    np.array(df['Low'].shift(1)) - np.array(df['Adj Close'].shift(1)))
df['AverageTrueRange'] = df[['ATR1', 'ATR2', 'ATR3']].max(axis=1)

# df['EMA']=pd.Series(pd.ewma(df['Adj Close'], span = n, min_periods = n - 1))

# Statistic Functions
df['Beta'] = ta.BETA(np.array(df['High'].shift(1)),
                     np.array(df['Low'].shift(1)),