コード例 #1
0
def MACDEXT(data,
            fast_period=12,
            fast_ma_type=0,
            slow_period=26,
            slow_ma_type=0,
            signal_period=9,
            signal_ma_type=0):
    """
    Moving Average Convergence Divergence Extended

    :param pd.DataFrame data: pandas DataFrame with open, high, low, close data
    :param int fast_period: fast period used for indicator calculation
    :param int fast_ma_type: fast moving average type (0 simple, 1 exponential)
    :param int slow_period: slow period used for indicator calculation
    :param int slow_ma_type: slow moving average type (0 simple, 1 exponential)
    :param int signal_period: period used for signal calculation
    :param int signal_ma_type: signal moving average type (0 simple, 1 exponential)
    :return pd.Series: with indicator data calculation results with indicator data calculation results
    """
    fn = Function('MACDEXT')
    return fn(data,
              fastperiod=fast_period,
              fastmatype=fast_ma_type,
              slowperiod=slow_period,
              slowmatype=slow_ma_type,
              signalperiod=signal_period,
              signalmatype=signal_ma_type)
コード例 #2
0
def SAREXT(data,
           start=0,
           offset_on_reverse=0,
           accel_init_long=0.02,
           accel_long=0.02,
           accel_max_long=0.2,
           accel_init_short=0.02,
           accel_short=0.02,
           accel_max_short=0.2):
    """
    Parabolic SAR - Extended

    :param pd.DataFrame data: pandas DataFrame with open, high, low, close data
    :param start: start value
    :param int offset_on_reverse: offset on reverse
    :param float accel_init_long: initial long acceleration factor
    :param float accel_long: long acceleration factor
    :param float accel_max_long: max long acceleration factor
    :param float accel_init_short: initial short acceleration factor
    :param float accel_short: short acceleration factor
    :param float accel_max_short: max short acceleration factor
    :return pd.Series: with indicator data calculation results with indicator data calculation results
    """
    fn = Function('SAREXT')
    return fn(data,
              startvalue=start,
              offsetonreverse=offset_on_reverse,
              accelerationinitlong=accel_init_long,
              accelerationlong=accel_long,
              accelerationmaxlong=accel_max_long,
              accelerationinitshort=accel_init_short,
              accelerationshort=accel_short,
              accelerationmaxshort=accel_max_short)
コード例 #3
0
def STOCH(data,
          fastk_period=5,
          slowk_period=3,
          slowk_ma_type=0,
          slowd_period=3,
          slowd_ma_type=0):
    """
    Stochastic Oscillator

    The Stochastic Oscillator is a momentum indicator comparing the closing price of a security to the range of it's
    prices over a certain period of time.

    The sensitivity of the oscillator to market movements is reducible by adjusting that time period or by taking a
    moving average of the result.

    :param pd.DataFrame data: pandas DataFrame with open, high, low, close data
    :param int fastk_period: period used for K fast indicator calculation
    :param int slowk_period: period used for K slow indicator calculation
    :param int slowk_ma_type: slow K moving average type (0 simple, 1 exponential)
    :param int slowd_period: period used for D slow indicator calculation
    :param int slowd_ma_type: slow D moving average type (0 simple, 1 exponential)
    :return pd.Series: with indicator data calculation results
    """
    fn = Function('STOCH')
    return fn(data,
              fastk_period=fastk_period,
              slowk_period=slowk_period,
              slowk_matype=slowk_ma_type,
              slowd_matype=slowd_ma_type,
              slowd_period=slowd_period)
コード例 #4
0
def ULTOSC(data, period1=7, period2=14, period3=28):
    """
    Ultimate Oscillator

    UO or ULTOSC is a momentum oscillator designed to capture momentum across three different time frames.

    The multiple time frame objective seeks to avoid the pitfalls of other oscillators.

    Many momentum oscillators surge at the beginning of a strong advance and then form bearish divergence as the
    advance continues.

    This is because they are stuck with one time frame. The Ultimate Oscillator attempts to correct this fault by
    incorporating longer time frames into the basic formula.

    :param pd.DataFrame data: pandas DataFrame with open, high, low, close data
    :param int period1: first period used for indicator calculation period used for indicator calculation
    :param int period2: second period used for indicator calculation period used for indicator calculation
    :param int period3: third period used for indicator calculation period used for indicator calculation
    :return pd.Series: with indicator data calculation results
    """
    fn = Function('ULTOSC')
    return fn(data,
              timeperiod1=period1,
              timeperiod2=period2,
              timeperiod3=period3)
コード例 #5
0
def abstract_example():
    sma = Function('sma')
    input_arrays = sma.get_input_arrays()
    for key in input_arrays.keys():
        input_arrays[key] = idata
    sma.set_input_arrays(input_arrays)
    odata = sma(30)  # timePeriod=30, specified as an arg

    bbands = Function('bbands', input_arrays)
    bbands.parameters = {'timeperiod': 20, 'nbdevup': 2, 'nbdevdn': 2}
    upper, middle, lower = bbands(
    )  # multiple output values unpacked (these will always have the correct order)

    kama = Function('kama').run(
        input_arrays)  # alternative run() calling method.
    plot(odata, upper, middle, lower, kama)
コード例 #6
0
def ta(symbol, indicators, timeframe='15m', limit=100, csv=False, params=''):
    args = []
    if len(params):
        args = params.split(',') if ',' in params else [params]
    args = map(lambda a: float(a) if '.' in a else int(a), args)

    df = ohlc(symbol, timeframe, limit, _raw=True)  # type: pd.DataFrame
    df.index = df.pop('date')
    table_data = list()
    for indicator in indicators.split(','):
        fn = Function(indicator.upper())
        d = fn(df, *args).bfill().round(8)
        if csv:
            df[indicator.lower()] = d
        else:
            table_data.append(
                [indicator.upper(), d[-1],
                 d.diff().round(8)[-1]])
    if csv:
        from io import StringIO
        str_io = StringIO()
        df.insert(0, 'date', [int(d.timestamp()) for d in df.index])
        df = df.reset_index(drop=True)
        df.to_csv(str_io, index=False, float_format='.8f')
        print(str_io.getvalue())

    else:
        print('    === {} ==='.format(symbol))
        print(
            tabulate(table_data,
                     headers=['Indicator', 'Value', 'Diff'],
                     stralign='center',
                     numalign='right',
                     tablefmt='fancy_grid'))
コード例 #7
0
def get_ta_functions():
    # func_names = []
    func_groups = ['Volume Indicators', 'Volatility Indicators',
                   'Overlap Studies', 'Momentum Indicators']
    func_names = [func_name for g in func_groups for func_name in ta.get_function_groups()[g]]
    funcs = {func_name: Function(func_name) for func_name in func_names}
    return funcs
コード例 #8
0
def ABANDONED_BABY(data):
    """
    Abandoned Baby
    :param pd.DataFrame data: pandas DataFrame with open, high, low, close data
    :return pd.Series: with indicator data calculation results
    """
    fn = Function('CDLABANDONEDBABY')
    return fn(data)
コード例 #9
0
def THRUSTING(data):
    """
    Thrusting Pattern
    :param pd.DataFrame data: pandas DataFrame with open, high, low, close data
    :return pd.Series: with indicator data calculation results
    """
    fn = Function('CDLTHRUSTING')
    return fn(data)
コード例 #10
0
def THREE_STARSINSOUTH(data):
    """
    Three Stars In The South
    :param pd.DataFrame data: pandas DataFrame with open, high, low, close data
    :return pd.Series: with indicator data calculation results
    """
    fn = Function('CDL3STARSINSOUTH')
    return fn(data)
コード例 #11
0
def BOP(data):
    """
    Balance of Power Indicator

    :param pd.DataFrame data: pandas DataFrame with open, high, low, close data
    :return pd.Series: with indicator data calculation results
    """
    fn = Function('BOP')
    return fn(data)
コード例 #12
0
def TASUKI_GAP(data):
    """
    Tasuki Gap

    :param pd.DataFrame data: pandas DataFrame with open, high, low, close data
    :return pd.Series: with indicator data calculation results
    """
    fn = Function('CDLTASUKIGAP')
    return fn(data)
コード例 #13
0
def THREE_BLACK_CROWS(data):
    """
    Three Black Crows

    :param pd.DataFrame data: pandas DataFrame with open, high, low, close data
    :return pd.Series: with indicator data calculation results
    """
    fn = Function('CDL3BLACKCROWS')
    return fn(data)
コード例 #14
0
def CLOSING_MARUBOZU(data):
    """
    Closing Marubozu

    :param pd.DataFrame data: pandas DataFrame with open, high, low, close data
    :return pd.Series: with indicator data calculation results
    """
    fn = Function('CDLCLOSINGMARUBOZU')
    return fn(data)
コード例 #15
0
def THREE_OUTSIDE(data):
    """
    Three Outside Up/Down

    :param pd.DataFrame data: pandas DataFrame with open, high, low, close data
    :return pd.Series: with indicator data calculation results
    """
    fn = Function('CDL3OUTSIDE')
    return fn(data)
コード例 #16
0
def HT_SINE(data):
    """
    Hilbert Transform - SineWave Indicator

    :param pd.DataFrame data: pandas DataFrame with open, high, low, close data
    :return pd.Series: with indicator data calculation results
    """
    fn = Function('HT_SINE')
    return fn(data)
コード例 #17
0
def STICK_SANDWICH(data):
    """
    Stick Sandwich

    :param pd.DataFrame data: pandas DataFrame with open, high, low, close data
    :return pd.Series: with indicator data calculation results
    """
    fn = Function('CDLSTICKSANDWICH')
    return fn(data)
コード例 #18
0
def UNIQUE_THREE_RIVER(data):
    """
    Unique 3 River

    :param pd.DataFrame data: pandas DataFrame with open, high, low, close data
    :return pd.Series: with indicator data calculation results
    """
    fn = Function('CDLUNIQUE3RIVER')
    return fn(data)
コード例 #19
0
def SHORT_LINE(data):
    """
    Short Line Candle

    :param pd.DataFrame data: pandas DataFrame with open, high, low, close data
    :return pd.Series: with indicator data calculation results
    """
    fn = Function('CDLSHORTLINE')
    return fn(data)
コード例 #20
0
def BELT_HOLD(data):
    """
    Belt-hold

    :param pd.DataFrame data: pandas DataFrame with open, high, low, close data
    :return pd.Series: with indicator data calculation results
    """
    fn = Function('CDLBELTHOLD')
    return fn(data)
コード例 #21
0
def TRISTAR(data):
    """
    Tristar Pattern

    :param pd.DataFrame data: pandas DataFrame with open, high, low, close data
    :return pd.Series: with indicator data calculation results
    """
    fn = Function('CDLTRISTAR')
    return fn(data)
コード例 #22
0
def THREE_WHITE_SOLDIERS(data):
    """
    Three Advancing White Soldiers

    :param pd.DataFrame data: pandas DataFrame with open, high, low, close data
    :return pd.Series: with indicator data calculation results
    """
    fn = Function('CDL3WHITESOLDIERS')
    return fn(data)
コード例 #23
0
def TAKURI(data):
    """
    Takuri (Dragonfly Doji with very long lower shadow)

    :param pd.DataFrame data: pandas DataFrame with open, high, low, close data
    :return pd.Series: with indicator data calculation results
    """
    fn = Function('CDLTAKURI')
    return fn(data)
コード例 #24
0
def UPSIDE_GAP_TWO_CROWS(data):
    """


    :param pd.DataFrame data: pandas DataFrame with open, high, low, close data
    :return pd.Series: with indicator data calculation results
    """
    fn = Function('CDLUPSIDEGAP2CROWS')
    return fn(data)
コード例 #25
0
def ADVANCE_BLOCK(data):
    """
    Advance Block

    :param pd.DataFrame data: pandas DataFrame with open, high, low, close data
    :return pd.Series: with indicator data calculation results
    """
    fn = Function('CDLADVANCEBLOCK')
    return fn(data)
コード例 #26
0
def X_SIDE_GAP_THREE_METHODS(data):
    """
    Upside/Downside Gap Three Methods

    :param pd.DataFrame data: pandas DataFrame with open, high, low, close data
    :return pd.Series: with indicator data calculation results
    """
    fn = Function('CDLXSIDEGAP3METHODS')
    return fn(data)
コード例 #27
0
def STALLED_PATTERN(data):
    """
    Stalled Pattern

    :param pd.DataFrame data: pandas DataFrame with open, high, low, close data
    :return pd.Series: with indicator data calculation results
    """
    fn = Function('CDLSTALLEDPATTERN')
    return fn(data)
コード例 #28
0
def BREAKAWAY(data):
    """
    Breakaway

    :param pd.DataFrame data: pandas DataFrame with open, high, low, close data
    :return pd.Series: with indicator data calculation results
    """
    fn = Function('CDLBREAKAWAY')
    return fn(data)
コード例 #29
0
def TWO_CROWS(data):
    """
    Two Crows

    :param pd.DataFrame data: pandas DataFrame with open, high, low, close data
    :return pd.Series: with indicator data calculation results
    """
    fn = Function('CDL2CROWS')
    return fn(data)
コード例 #30
0
def THREE_LINE_STRIKE(data):
    """
    Three-Line Strike

    :param pd.DataFrame data: pandas DataFrame with open, high, low, close data
    :return pd.Series: with indicator data calculation results
    """
    fn = Function('CDL3LINESTRIKE')
    return fn(data)