Example #1
0
 def __init__(self, live=None):
     """
     Sets the data source
     :param live: LiveTA object containing live TA results. set to None to use historic data
     """
     if live is None:
         self.db = AccessDB()
     elif isinstance(live, LiveTA):
         self.db = live
     else:
         raise ValueError("live must be of type None or LiveTA")
Example #2
0
class Others:
    def __init__(self, live=None):
        """
        Sets the data source
        :param live: LiveTA object containing live TA results. set to None to use historic data
        """
        if live is None:
            self.db = AccessDB()
        elif isinstance(live, LiveTA):
            self.db = live
        else:
            raise ValueError("live must be of type None or LiveTA")

    def get_dr(self, offset, window_size):
        return self.db.get_window_column(["others_dr"], offset, window_size)

    def get_dlr(self, offset, window_size):
        return self.db.get_window_column(["others_dlr"], offset, window_size)

    def get_cr(self, offset, window_size):
        return self.db.get_window_column(["others_cr"], offset, window_size)
Example #3
0
class TrenAnalisys:
    def __init__(self, live=None):
        """
        Sets the data source
        :param live: LiveTA object containing live TA results. set to None to use historic data
        """
        if live is None:
            self.db = AccessDB()
        elif isinstance(live, LiveTA):
            self.db = live
        else:
            raise ValueError("live must be of type None or LiveTA")

    def get_MACD(self, offset, window_size):
        """
        Moving Average Convergence Divergence (MACD) is a trend-following momentum indicator. The signal of a change
        of trend is given with the crossover of the values of MACD, therefore, we retrieve the difference between them.

        :param offset: offset of the window
        :param window_size: size of the window
        :return: pandas with the column: trend_macd_diff
        """
        return self.db.get_window_column(["trend_macd_diff"], offset,
                                         window_size)

    def get_ADX(self, offset, window_size):
        """
        Get the Average Directional Index, a momentum strength indicators. The ADX identifies a strong positive trend
        when the ADX is over 25 and a weak trend when the ADX is below 20.

        :param offset: offset of the window
        :param window_size: size of the window
        :return: pandas with the column: trend_adx
        """
        return self.db.get_window_column(["trend_adx"], offset, window_size)

    def get_VI(self, offset, window_size):
        """
        Get the vortex indicator values. It is composed of 2 lines that show both positive (VI +) and negative (VI -)
        trend movement. The signal of a change of trend is given when the lines cross, therefore, we retrieve the
        difference between them.

        :param offset: offset of the window
        :param window_size: size of the window
        :return: pandas with the column: trend_vortex_diff
        """
        return self.db.get_window_column(["trend_vortex_diff"], offset,
                                         window_size)

    def get_TRIX(self, offset, window_size):
        """
        Get the TRIX values. It is designed to filter out price movements that are considered insignificant or
        unimportant.

        :param offset: offset of the window
        :param window_size: size of the window
        :return: pandas with the column: trend_trix
        """
        return self.db.get_window_column(["trend_trix"], offset, window_size)

    def get_MI(self, offset, window_size):
        """
        Get Mass index. This indicator examines the range between high and low stock prices over a period of time.

        :param offset: offset of the window
        :param window_size: size of the window
        :return: pandas with the column: trend_mass_index
        """
        return self.db.get_window_column(["trend_mass_index"], offset,
                                         window_size)

    def get_CCI(self, offset, window_size):
        """
        Get the Commodity Channel Index. Momentum-based technical trading tool used most often to help determine when
        an investment vehicle is reaching a condition of being overbought or oversold.

        :param offset: offset of the window
        :param window_size: size of the window
        :return: pandas with the column: trend_cci
        """
        return self.db.get_window_column(["trend_cci"], offset, window_size)

    def get_DPO(self, offset, window_size):
        """
        Get the Detrended Price Oscillator. Oscillator that strips out price trends in an effort to estimate the length
        of price cycles from peak to peak, or trough to trough.

        :param offset: offset of the window
        :param window_size: size of the window
        :return: pandas with the column: trend_dpo
        """
        return self.db.get_window_column(["trend_dpo"], offset, window_size)

    def get_KST(self, offset, window_size):
        """
        In Know Sure Thing indicator it is important not only the crossover but also the trend of the indicator itself.
        For this reason, the three values are needed.

        :param offset: offset of the window
        :param window_size: size of the window
        :return: pandas with the columns: trend_kst, trend_kst_sig, trend_kst_diff
        """
        return self.db.get_window_column(
            ["trend_kst, trend_kst_sig, trend_kst_diff"], offset, window_size)

    def get_Ichimoku(self, offset, window_size):
        """
        Get the values of the Ichimoku cloud. Shows support and resistance, and momentum and trend directions.

        :param offset: offset of the window
        :param window_size: size of the window
        :return: pandas with the columns: trend_ichimoku_a, trend_ichimoku_b
        """
        return self.db.get_window_column(
            ["trend_ichimoku_a, trend_ichimoku_b"], offset, window_size)
Example #4
0
class VolatilityAnalisys:
    def __init__(self, live=None):
        """
        Sets the data source
        :param live: LiveTA object containing live TA results. set to None to use historic data
        """
        if live is None:
            self.db = AccessDB()
        elif isinstance(live, LiveTA):
            self.db = live
        else:
            raise ValueError("live must be of type None or LiveTA")

    def get_ATR(self, offset, window_size):
        """
        Average True Range (ATR) is a measure of volatility that attempts to decompose a longer trend.
        In general, ATR is higher when the volatility is higher and lower when the volatility is lower.
        https://www.investopedia.com/terms/a/atr.asp

        :param offset: offset of the window
        :param window_size: size of the window
        :return: pandas with the column: volatility_atr
        """
        return self.db.get_window_column(["volatility_atr"], offset,
                                         window_size)

    def get_BollingerBands(self, offset, window_size):
        """
        The BollingerBands are a function of the moving average.
        The upper band is 2 standard deviations above the moving average; if the price crosses this band, the stock is overbought => SELL
        The lower band is 2 standard deviations below the moving average; if the price crosses this band, the stock is oversold => BUY
        The bands can also squeeze together, this indicates low volatility and thus future increased volatility
        When the bands expand, this indicates high volatility and thus future decreased volatility
        The middle band 'volatility_bbm' is omitted from this response
        https://www.investopedia.com/terms/b/bollingerbands.asp

        :param offset: offset of the window
        :param window_size: size of the window
        :return: pandas with the column: volatility_bbh (upper band), volatility_bbl (lower band)
        """
        return self.db.get_window_column(["volatility_bbh", "volatility_bbl"],
                                         offset, window_size)

    def get_BollingerBandsIndicators(self, offset, window_size):
        """
        These values are derived from the bollinger bands and might perform better as a buy or sell signal.
        volatility_bbhi has a value of 1 if the candle close is higher than the upper band, otherwise has value 0
        volatility_bbli has a value of 1 if the candle close is lower than the lower band, otherwise has value 0

        :param offset: offset of the window
        :param window_size: size of the window
        :return: pandas with the column: volatility_bbhi, volatility_bbli
        """
        return self.db.get_window_column(
            ["volatility_bbhi", "volatility_bbli"], offset, window_size)

    def get_KeltnerChannel(self, offset, window_size):
        """
        Very similar to the bollinger bands in their purpose but slightly differently calcuolated.
        Basically the Keltner Channel produces much thinner bands as a volatility indicator
        https://www.investopedia.com/terms/k/keltnerchannel.asp

        :param offset: offset of the window
        :param window_size: size of the window
        :return: pandas with the column: volatility_kch(upper band), volatility_kcl (lower band)
        """
        return self.db.get_window_column(["volatility_kch", "volatility_kcl"],
                                         offset, window_size)

    def get_KeltnerChannelIndicators(self, offset, window_size):
        """
        These values are derived from the keltner channel and might perform better as a buy or sell signal.
        volatility_kchi has a value of 1 if the candle close is higher than the upper keltner channel, otherwise has value 0
        volatility_kcli has a value of 1 if the candle close is lower than the lower keltner channel, otherwise has value 0

        :param offset: offset of the window
        :param window_size: size of the window
        :return: pandas with the column: volatility_kchi, volatility_kcli
        """
        return self.db.get_window_column(
            ["volatility_kchi", "volatility_kcli"], offset, window_size)

    def get_DonchianChannel(self, offset, window_size):
        """
        The donchian channel is very different from the other volatility indicators.
        The upper and lower bands are 'pushed' by the candle close price.
        E.g. if the price reaches a low after 20 days of decreasing, the lower band will be horizantal for 20 days before chaning again.
        https://www.investopedia.com/terms/d/donchianchannels.asp

        :param offset: offset of the window
        :param window_size: size of the window
        :return: pandas with the column: volatility_dch(upper band), volatility_dcl (lower band)
        """
        return self.db.get_window_column(["volatility_dch", "volatility_dcl"],
                                         offset, window_size)

    def get_DonchianChannelIndicators(self, offset, window_size):
        """
        These values are derived from the donchian channels and might perform better as a buy or sell signal.
        volatility_dchi has a value of 1 if the candle close is higher than the upper donchian channel, otherwise has value 0
        volatility_dcli has a value of 1 if the candle close is lower than the lower donchian channel, otherwise has value 0

        :param offset: offset of the window
        :param window_size: size of the window
        :return: pandas with the column: volatility_dchi, volatility_dcli
        """
        return self.db.get_window_column(
            ["volatility_dchi", "volatility_dcli"], offset, window_size)
Example #5
0
    def __init__(self, batch_size, sequence_size, sequence_overlap,
                 output_size):
        self.batch_size = batch_size
        self.sequence_size = sequence_size
        self.sequence_overlap = sequence_overlap
        self.output_size = output_size
        self.test_offset = 0
        self.stats = {}

        try:
            with open(settings.cachePath + '/cache_v2.p', 'rb') as cacheFile:
                cache = pickle.load(cacheFile)

                self.TA_train = cache["TA_train"]
                self.TA_test = cache["TA_test"]

                self.price_train = cache["price_train"]
                self.price_test = cache["price_test"]

                self.train_size = self.TA_train.shape[0]
                self.test_size = self.TA_test.shape[0]

        except:
            db_access = AccessDB()

            print("Loading TA database into RAM... (version 2)")
            TA = db_access.get_column(self.technical_indicators).values

            print("Loading price database into RAM... (version 2)")
            price = db_access.get_column([
                'DateTimeStamp', 'BarOPENBid', 'BarHIGHBid', 'BarLOWBid',
                'BarCLOSEBid'
            ])

            # Parse datetime
            price['DateTimeStamp'] = pd.to_datetime(price['DateTimeStamp'],
                                                    format='%Y%m%d %H%M%S')
            price = price.values

            testMinutes = 60 * 24 * 200

            self.TA_train = TA[:-testMinutes, :]
            self.TA_test = TA[-testMinutes:, :]

            mean = np.mean(self.TA_train, axis=0, keepdims=True)
            std = np.std(self.TA_train, axis=0, keepdims=True)

            print(mean, std)

            self.TA_train = (self.TA_train - mean) / std
            self.TA_test = (self.TA_test - mean) / std

            self.price_train = price[:-testMinutes, :]
            self.price_test = price[-testMinutes:, :]

            self.train_size = self.TA_train.shape[0]
            self.test_size = self.TA_test.shape[0]

            cache = {}
            cache["TA_train"] = self.TA_train
            cache["TA_test"] = self.TA_test

            cache["price_train"] = self.price_train
            cache["price_test"] = self.price_test

            with open(settings.cachePath + '/cache_v2.p', 'wb') as cacheFile:
                pickle.dump(cache, cacheFile)

        print("Database loaded")
Example #6
0
class MomentumAnalyses:
    def __init__(self, live=None):
        """
        Sets the data source
        :param live: LiveTA object containing live TA results. set to None to use historic data
        """
        if live is None:
            self.db = AccessDB()
        elif isinstance(live, LiveTA):
            self.db = live
        else:
            raise ValueError("live must be of type None or LiveTA")

    def get_RSI(self, offset, window_size):
        """Relative Strength Index (RSI)
            Compares the magnitude of recent gains and losses over a specified time
            period to measure speed and change of price movements of a security. It is
            primarily used to attempt to identify overbought or oversold conditions in
            the trading of an asset.

            :param offset: offset of the window
            :param window_size: size of the window
            :return: pandas with the column: momentum_rsi
        """
        return self.db.get_window_column(["momentum_rsi"], offset, window_size)

    def get_TSI(self, offset, window_size):
        """True strength index (TSI)
            Shows both trend direction and overbought/oversold conditions.

            :param offset: offset of the window
            :param window_size: size of the window
            :return: pandas with the column: momentum_tsi
        """
        return self.db.get_window_column(["momentum_tsi"], offset, window_size)

    def get_UO(self, offset, window_size):
        """Ultimate Oscillator
            Larry Williams' (1976) signal, a momentum oscillator designed to capture momentum
            across three different timeframes.

            :param offset: offset of the window
            :param window_size: size of the window
            :return: pandas with the column: momentum_uo
        """
        return self.db.get_window_column(["momentum_uo"], offset, window_size)

    def get_Stoch(self, offset, window_size):
        """Stochastic Oscillator
            Developed in the late 1950s by George Lane. The stochastic
            oscillator presents the location of the closing price of a
            stock in relation to the high and low range of the price
            of a stock over a period of time, typically a 14-day period.

            :param offset: offset of the window
            :param window_size: size of the window
            :return: pandas with the column: momentum_stoch
        """

        return self.db.get_window_column(["momentum_stoch"], offset,
                                         window_size)

    def get_Stoch_Signal(self, offset, window_size):
        """Stochastic Oscillator Signal
            Shows SMA of Stochastic Oscillator. Typically a 3 day SMA.

            :param offset: offset of the window
            :param window_size: size of the window
            :return: pandas with the column: momentum_stoch_signal
        """
        return self.db.get_window_column(["momentum_stoch_signal"], offset,
                                         window_size)

    def get_WR(self, offset, window_size):
        """Readings from 0 to -20 are considered overbought. Readings from -80 to -100 are considered oversold.
            The Fast Stochastic Oscillator and Williams %R produce the exact same lines,
            only the scaling is different. Williams %R oscillates from 0 to -100.

            :param offset: offset of the window
            :param window_size: size of the window
            :return: pandas with the column: momentum_wr
        """
        return self.db.get_window_column(["momentum_wr"], offset, window_size)

    def get_AO(self, offset, window_size):
        """
        The Awesome Oscillator is an indicator used to measure market momentum. AO calculates the difference of a
        34 Period and 5 Period Simple Moving Averages. The Simple Moving Averages that are used are not calculated
        using closing price but rather each bar's midpoints. AO is generally used to affirm trends or to anticipate
        possible reversals.

        :param offset: offset of the window
        :param window_size: size of the window
        :return: pandas with the column: momentum_ao
        """

        return self.db.get_window_column(["momentum_ao"], offset, window_size)
Example #7
0
class VolumeAnalysis:
    def __init__(self, live=None):
        """
        Sets the data source
        :param live: LiveTA object containing live TA results. set to None to use historic data
        """
        if live is None:
            self.db = AccessDB()
        elif isinstance(live, LiveTA):
            self.db = live
        else:
            raise ValueError("live must be of type None or LiveTA")

    def get_ADI(self, offset, window_size):
        """
        Accumulation distribution indicator (ADI) The ADI is an indicator that helps predict reversals

        :param offset: offset of the window
        :param window_size: size of the window
        :return: pandas with the column: volume_adi
        """
        return self.db.get_window_column(["volume_adi"], offset, window_size)

    def get_OBV(self, offset, window_size):
        """
        On-balance volume is a technical analysis indicator intended to relate price and volume in the stock marke

        :param offset: offset of the window
        :param window_size: size of the window
        :return: pandas with the column: volume_obv
        """
        return self.db.get_window_column(["volume_obv"], offset, window_size)

    def get_OBV_mean(self, offset, window_size):
        """
        :param offset: offset of the window
        :param window_size: size of the window
        :return: pandas with the column: volume_obvm
        """
        return self.db.get_window_column(["volume_obvm"], offset, window_size)

    def get_CMF(self, offset, window_size):
        """
        :param offset: offset of the window
        :param window_size: size of the window
        :return: pandas with the column: volume_cmf
        """
        return self.db.get_window_column(["volume_cmf"], offset, window_size)

    def get_FI(self, offset, window_size):
        """
        :param offset: offset of the window
        :param window_size: size of the window
        :return: pandas with the column: volume_fi
        """
        return self.db.get_window_column(["volume_fi"], offset, window_size)

    def get_EMV(self, offset, window_size):
        """
        :param offset: offset of the window
        :param window_size: size of the window
        :return: pandas with the column: volume_em'
        """
        return self.db.get_window_column(["volume_em"], offset, window_size)

    def get_VPT(self, offset, window_size):
        """
        :param offset: offset of the window
        :param window_size: size of the window
        :return: pandas with the column: volume_vpt'
        """
        return self.db.get_window_column(["volume_vpt"], offset, window_size)

    def get_NVI(self, offset, window_size):
        """
        :param offset: offset of the window
        :param window_size: size of the window
        :return: pandas with the column: volume_nvi'
        """
        return self.db.get_window_column(["volume_nvi"], offset, window_size)