Esempio n. 1
0
    def populate_indicators(self, dataframe: DataFrame) -> DataFrame:
        dataframe['sma5'] = ta.SMA(dataframe, timeperiod=5)
        dataframe['sma200'] = ta.SMA(dataframe, timeperiod=200)

        # resample our dataframes
        dataframe_short = resample_to_interval(dataframe, self.get_ticker_indicator() * 2)
        dataframe_long = resample_to_interval(dataframe, self.get_ticker_indicator() * 8)

        # compute our RSI's
        dataframe_short['rsi'] = ta.RSI(dataframe_short, timeperiod=14)
        dataframe_long['rsi'] = ta.RSI(dataframe_long, timeperiod=14)
        dataframe_short['cmf'] = cmf(dataframe_short, 14)
        dataframe_long['cmf'] = cmf(dataframe_long, 14)

        dataframe_short['osc'] = osc(dataframe_short, 14)
        dataframe_long['osc'] = osc(dataframe_long, 14)

        # merge dataframe back together
        dataframe = resampled_merge(dataframe, dataframe_short)
        dataframe = resampled_merge(dataframe, dataframe_long)

        dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)

        # fill NA values with previes
        dataframe.fillna(method='ffill', inplace=True)

        # Volume Flow Index: Add VFI, VFIMA, Histogram to DF
        dataframe['vfi'], dataframe['vfima'], dataframe['vfi_hist'] =  \
            vfi(dataframe, length=130, coef=0.2, vcoef=2.5, signalLength=5, smoothVFI=True)

        return dataframe
Esempio n. 2
0
def test_resampled_merge_contains_indicator(testdata_1m_btc):
    resampled = resample_to_interval(testdata_1m_btc, 5)
    resampled['cmf'] = cmf(resampled, 5)
    merged = resampled_merge(testdata_1m_btc, resampled)

    print(merged)
    assert "resample_5_cmf" in merged
Esempio n. 3
0
def test_cmf(testdata_1m_btc):
    from technical.indicators import cmf

    result = cmf(testdata_1m_btc, 14)

    #drop nan, they are exspected, based on the period
    result = result[~numpy.isnan(result)]

    assert result.min() >= -1
    assert result.max() <= 1
    def populate_indicators(self, dataframe: DataFrame) -> DataFrame:

        # otherwise freqshow import won't work
        # since lambda is too large with all the dependencies

        from technical.util import resample_to_interval
        from technical.util import resampled_merge
        from technical.indicators import cmf
        from technical.indicators import osc

        dataframe['sma5'] = ta.SMA(dataframe, timeperiod=5)
        dataframe['sma200'] = ta.SMA(dataframe, timeperiod=200)

        # resample our dataframes
        dataframe_short = resample_to_interval(dataframe,
                                               self.get_ticker_indicator() * 2)
        dataframe_long = resample_to_interval(dataframe,
                                              self.get_ticker_indicator() * 8)

        # compute our RSI's
        dataframe_short['rsi'] = ta.RSI(dataframe_short, timeperiod=14)
        dataframe_long['rsi'] = ta.RSI(dataframe_long, timeperiod=14)
        dataframe_short['cmf'] = cmf(dataframe_short, 14)
        dataframe_long['cmf'] = cmf(dataframe_long, 14)

        dataframe_short['osc'] = osc(dataframe_short, 14)
        dataframe_long['osc'] = osc(dataframe_long, 14)

        # merge dataframe back together
        dataframe = resampled_merge(dataframe, dataframe_short)
        dataframe = resampled_merge(dataframe, dataframe_long)

        dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)

        # fill NA values with previes
        dataframe.fillna(method='ffill', inplace=True)

        return dataframe
Esempio n. 5
0
    def evaluate_cmf(self,
                     period=12,
                     prefix="cmf",
                     impact_buy=1,
                     impact_sell=1):
        """
        evaluates the osc
        :param dataframe:
        :param period:
        :param prefix:
        :return:
        """
        from technical.indicators import cmf

        self._weights(impact_buy, impact_sell)
        dataframe = self.dataframe
        name = '{}_{}'.format(prefix, period)
        dataframe[name] = cmf(dataframe, period)

        dataframe.loc[((dataframe[name] > 0.5)),
                      'buy_{}'.format(name)] = (1 * impact_buy)

        dataframe.loc[((dataframe[name] < -0.5)),
                      'sell_{}'.format(name)] = (1 * impact_sell)
Esempio n. 6
0
    def evaluate_cmf(self,
                     period=12,
                     prefix="cmf",
                     impact_buy=1,
                     impact_sell=1):
        """
        evaluates the cmf
        :param dataframe:
        :param period:
        :param prefix:
        :return:
        """
        from technical.indicators import cmf

        self._weights(impact_buy, impact_sell)
        dataframe = self.dataframe
        name = f"{prefix}_{period}"
        dataframe[name] = cmf(dataframe, period)

        dataframe.loc[((dataframe[name] > 0.5)),
                      f"buy_{name}"] = 1 * impact_buy

        dataframe.loc[((dataframe[name] < -0.5)),
                      f"sell_{name}"] = 1 * impact_sell
    def populate_indicators(self, dataframe: DataFrame,
                            metadata: dict) -> DataFrame:
        dataframe['cmf'] = cmf(dataframe, 21)

        return dataframe