Exemple #1
0
    def plot_macd_histogram(self, plot, macd_data, dates=None):
        close = [f['close'] for f in macd_data]
        xs = [x for x in range(len(close))]

        i = Indicators()
        ema_slow, ema_fast, macd = i.moving_average_convergence(close,
                                                                nslow=26,
                                                                nfast=12)
        sig_line = i.exp_moving_average(macd, 9)

        if dates:
            self.axis_list[plot].plot(dates, macd)
            self.axis_list[plot].plot(dates, sig_line)
            self.axis_list[plot].plot(dates, macd - sig_line, 'k')
            self.axis_list[plot].axhline(y=0, color='b', linestyle='-')
            self.axis_list[plot].fill_between(dates,
                                              macd - sig_line,
                                              0,
                                              alpha=.5,
                                              facecolor='#00ffe8',
                                              edgecolor='#00ffe8')
            self.axis_list[plot].spines['bottom'].set_color('#5998ff')
            self.axis_list[plot].spines['top'].set_color('#5998ff')
            self.axis_list[plot].spines['left'].set_color('#5998ff')
            self.axis_list[plot].spines['right'].set_color('#5998ff')
        else:
            # self.axis_list[plot].plot(macd)
            # self.axis_list[plot].plot(sig_line)
            self.axis_list[plot].plot(macd - sig_line, color='k')
            self.axis_list[plot].axhline(y=0, color='b', linestyle='-')
            self.axis_list[plot].fill_between(xs,
                                              macd - sig_line,
                                              0,
                                              alpha=.5,
                                              facecolor='#00ffe8',
                                              edgecolor='#00ffe8')
            self.axis_list[plot].spines['bottom'].set_color('#5998ff')
            self.axis_list[plot].spines['top'].set_color('#5998ff')
            self.axis_list[plot].spines['left'].set_color('#5998ff')
            self.axis_list[plot].spines['right'].set_color('#5998ff')
Exemple #2
0
    def make_graph_year(self, stock):
        self.current_view = 'Year'
        print('Current view year')
        i = Indicators()
        ema_slow, ema_fast, macd = i.moving_average_convergence(
            stock.get_closes(), nslow=26, nfast=12)
        sig_line = i.exp_moving_average(macd, 9)
        rsi = i.relative_strength(stock.get_closes())

        sma_window = 9
        ema_window = 9

        my_sma = i.simple_moving_average(stock.get_closes(), sma_window)
        my_ema = i.exp_moving_average(stock.get_closes(), ema_window)

        dates = stock.get_dates_as_formatted(fmt='3')
        for x in range(len(dates)):
            dates[x] = x
        # self.axis_list[3].plot(dates, macd)
        # self.axis_list[3].plot(dates, sig_line)
        # self.axis_list[3].plot(dates, macd - sig_line, 'k')
        # self.axis_list[3].axhline(y=0, color='b', linestyle='-')
        # self.axis_list[3].fill_between(dates, macd - sig_line, 0, alpha=.5, facecolor='#00ffe8', edgecolor='#00ffe8')
        # self.axis_list[3].spines['bottom'].set_color('#5998ff')
        # self.axis_list[3].spines['top'].set_color('#5998ff')
        # self.axis_list[3].spines['left'].set_color('#5998ff')
        # self.axis_list[3].spines['right'].set_color('#5998ff')

        ohlc = stock.get_candle_stick_data(fmt='np')
        for x in range(len(ohlc)):
            ohlc[x][0] = x
        candlestick_ohlc(self.axis_list[2],
                         ohlc,
                         colorup='green',
                         colordown='red',
                         width=.6)

        # self.axis_list[2].plot(dates[sma_window - 1:], my_sma, label='SMA')
        # self.axis_list[2].plot(dates, my_ema, label='EMA')
        self.axis_list[2].set_ylabel('Price')
        self.axis_list[2].legend(loc='upper right')
        self.__plot.suptitle(stock.get_symbol())

        # self.axis_list[1].plot(dates, rsi)
        # self.axis_list[1].xaxis.set_major_locator(mticker.MaxNLocator(10))
        # self.axis_list[1].get_xaxis().set_visible(False)
        # self.axis_list[2].get_xaxis().set_visible(False)

        self.axis_list[3].xaxis.set_major_locator(mticker.MaxNLocator(10))

        # md_dates = [datetime.datetime.strftime(mdates.num2date(i), '%Y-%m-%d') for i in dates]

        def my_date(x, pos):
            try:
                return md_dates[int(x)]
            except IndexError:
                return ''

        # self.axis_list[3].xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))

        for lab in self.axis_list[3].xaxis.get_ticklabels():
            lab.set_rotation(30)

        return self.__plot
Exemple #3
0
    def make_graph_rt(self, stock):
        self.current_view = 'RT'
        print('Current view real-time')

        i = Indicators()
        close = stock.get_rt_closes()

        ema_slow, ema_fast, macd = i.moving_average_convergence(close,
                                                                nslow=26,
                                                                nfast=12)
        sig_line = i.exp_moving_average(macd, 9)
        rsi = i.relative_strength(close)

        sma_window = 10
        ema_window = 10

        my_sma = i.simple_moving_average(close, sma_window)
        my_ema = i.exp_moving_average(close, ema_window)

        dates = stock.get_dates_as_formatted(fmt='3', rt=True)

        ohlc = stock.get_rt_candle_stick_data(fmt='np')

        for i in range(len(dates)):
            ohlc[i][0] = dates[i]

        for x in range(len(ohlc)):
            ohlc[x][0] = x

        print('OHLC RT is: %s' % ohlc)

        # self.axis_list[3].plot(dates, macd)
        # self.axis_list[3].plot(dates, sig_line)
        # self.axis_list[3].plot(dates, macd - sig_line, 'k')
        # self.axis_list[3].axhline(y=0, color='b', linestyle='-')
        # self.axis_list[3].fill_between(dates, macd - sig_line, 0, alpha=.5, facecolor='#00ffe8', edgecolor='#00ffe8')
        # self.axis_list[3].spines['bottom'].set_color('#5998ff')
        # self.axis_list[3].spines['top'].set_color('#5998ff')
        # self.axis_list[3].spines['left'].set_color('#5998ff')
        # self.axis_list[3].spines['right'].set_color('#5998ff')

        candlestick_ohlc(self.axis_list[2],
                         ohlc,
                         width=(.001 / 2),
                         colorup='green',
                         colordown='red')

        # self.axis_list[2].plot(dates[sma_window - 1:], my_sma, label='SMA')
        # self.axis_list[2].plot(dates, my_ema, label='EMA')
        self.axis_list[2].set_ylabel('Price')
        self.axis_list[2].legend(loc='upper right')
        self.__plot.suptitle(stock.get_symbol())

        # self.axis_list[1].plot(dates, rsi)
        # self.axis_list[1].xaxis.set_major_locator(mticker.MaxNLocator(10))
        # self.axis_list[1].get_xaxis().set_visible(False)
        # self.axis_list[2].get_xaxis().set_visible(False)
        #
        # self.axis_list[3].xaxis.set_major_locator(mticker.MaxNLocator(10))
        # self.axis_list[3].xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
        #
        # for lab in self.axis_list[3].xaxis.get_ticklabels():
        #     lab.set_rotation(30)

        return self.__plot