Ejemplo n.º 1
0
    def set_prices(self,
                   sym=None,
                   last_date=None,
                   time_from="-90d",
                   time_to="0d"):
        if last_date:
            self.db.last_date = last_date

        self.in_day_stocks = sdf.retype(self.db.get_last_n_days(sym))

        self.stocks = sdf.retype(
            self.db.load_data(TableName.DAY,
                              sym,
                              time_from=time_from,
                              time_to=time_to))

        self.stocks = FinI.add_indicators(sdf.retype(self.stocks))

        self.stocks = FinI.add_fib(self.stocks, last_rows=10)

        self.spy = sdf.retype(
            self.db.load_data(TableName.DAY, ["SPY"],
                              time_from=time_from,
                              time_to=time_to))
        print("set_prices() - done")
Ejemplo n.º 2
0
    def show_sym_bs_stats(self, sym: str):

        self.db.limit = None
        dfp, financials, sentiment, earnings, spy = self.db.get_all_data(
            self.db.time_from, sym)
        dfp = FinI.add_indicators(dfp)
        dfp = FinI.add_fib(dfp, last_rows=10)
        # print(dfp)
        # last 5 financials
        financials = financials.tail(5)
        days_to_earnings = FinI.days_to_earnings(earnings)
        # print(earnings)
        if days_to_earnings is None:
            earnings = None
        fig, axs = plt.subplots(2, 1, figsize=(16, 16))
        PlotI.set_margins(plt)

        PlotI.plot_spy(axs[0], spy.loc[spy.index.isin(dfp.index)])
        axsp = PlotI.plot_stock_prices(axs[0].twinx(), dfp, sym, 0.5)
        axsp = PlotI.plot_sma(axsp, dfp, ["sma9", "sma50"])
        axsp.xaxis.set_major_formatter(plt.NullFormatter())
        axsp = PlotI.plot_candles(dfp,
                                  axsp,
                                  body_w=0.5,
                                  shadow_w=0.1,
                                  alpha=0.5)
        axsp = PlotI.plot_fib(dfp, axsp, alpha=0.4)
        axsp = PlotI.plot_fib(dfp, axsp, alpha=0.4, fib_name="fb_mid")
        axsp = PlotI.plot_fib(dfp, axsp, alpha=0.4, fib_name="fb_bot")
        axsp = PlotI.plot_weeks(axsp, dfp)

        PlotI.plot_boll(axsp, dfp, sym)

        axsp2 = PlotI.plot_volume_bars(axsp.twinx(), dfp)

        axsp2 = PlotI.plot_rsi(axs[1], dfp)
        axsp2 = PlotI.plot_macd_boll(axs[1].twinx(), dfp)
        # ax_macd = PlotI.plot_macd(ax_macd,dfp)
        axsp2 = PlotI.plot_volume_bars(axs[1].twinx(), dfp)

        if self.buy_sell_closed is not None and len(self.buy_sell_closed) > 0:
            axsp = PlotI.plot_bs(axsp, self.buy_sell_closed)
            axsp2 = PlotI.plot_bs(axsp2.twinx(), self.buy_sell_closed)

        plt.show()