Ejemplo n.º 1
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()
Ejemplo n.º 2
0
    def get_subj_mess(self, subject, sym=None):

        mess = ""

        if self.stocks is None or sym != self.stocks.iloc[0].sym:
            self.stocks = self.ss.get_trend_slice(table_name=None,
                                                  time_from="-120d",
                                                  time_to="0d",
                                                  symbol=sym)

        curr_price = self.stocks.iloc[-1].close

        # print(self.stocks)

        days_to_earnings = FinI.days_to_earnings(self.earnings)
        sector_mess, spy_mess, vol_mess = self.get_common_mess(self.stocks)

        mess = subject + " " + str(sym) + \
            self.subject_fund_info(self.financials, self.sentiment,
                                   self.earnings, days_to_earnings = days_to_earnings)

        mess += str(sector_mess)
        mess += str(spy_mess)
        mess += str(vol_mess)

        self.stocks = FinI.add_levels(self.stocks)
        # hl = FinI.get_fib_hl(self.stocks,  self.stocks.iloc[-1].close)
        pl = self.stocks.price_level.dropna()
        low, high = FinI.get_nearest_values(pl, curr_price)
        mess += " Price: " + str(curr_price)
        mess += " | Loss: " + str(Utils.calc_perc(
            curr_price,
            low[0])) + "%, " if low is not None and len(low) > 0 else ""
        mess += " " + "Prof.: " + str(Utils.calc_perc(
            curr_price,
            high[0])) + "% " if high is not None and len(high) > 0 else " | "

        print("get_subj_mess() - done")
        return mess, curr_price, days_to_earnings
Ejemplo n.º 3
0
    def show_sym_stats(self, sym, save_img=False):

        # last  financials
        if self.financials is not None and len(self.financials) > 0:
            self.financials = self.financials.tail(5)
        days_to_earnings = FinI.days_to_earnings(self.earnings)
        # print(earnings)
        if days_to_earnings is None:
            self.earnings = None
        plots_num = 4 if save_img else 5

        fig, axs = plt.subplots(plots_num, 1, figsize=(16, 18))
        PlotI.set_margins(plt)

        if self.spy is not None:
            PlotI.plot_spy(
                axs[0], self.spy.loc[self.spy.index.isin(self.stocks.index)])

        axsp = PlotI.plot_stock_prices(axs[0].twinx(),
                                       self.stocks,
                                       sym,
                                       alpha=0.3)
        axsp = PlotI.plot_sma(axsp, self.stocks, ["sma9", "sma50"])
        axsp = PlotI.plot_candles(self.stocks,
                                  axsp,
                                  body_w=0.5,
                                  shadow_w=0.1,
                                  alpha=0.5)
        axsp = PlotI.plot_fib(self.stocks, axsp, alpha=0.4)
        axsp = PlotI.plot_fib(self.stocks, axsp, alpha=0.4, fib_name="fb_mid")
        axsp = PlotI.plot_fib(self.stocks, axsp, alpha=0.4, fib_name="fb_bot")

        PlotI.plot_boll(axsp, self.stocks, sym)
        PlotI.plot_weeks(axsp, self.stocks)

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

        PlotI.plot_volume_bars(axs[1].twinx(), self.stocks)

        if self.in_day_stocks is None:
            self.in_day_stocks = sdf.retype(
                self.db.load_data(TableName.MIN15,
                                  sym,
                                  time_from="-1d",
                                  time_to="0d"))
            if len(self.in_day_stocks) < 1:
                self.in_day_stocks = sdf.retype(
                    self.db.load_data(TableName.MIN15, sym, limit=20))

        # self.plot_volume(axs[2], last_prices)

        ax = PlotI.plot_candlesticks2(axs[2], self.in_day_stocks)
        self.in_day_stocks = FinI.add_fib_from_day_df(self.in_day_stocks,
                                                      self.stocks)
        ax = PlotI.plot_fib(self.in_day_stocks,
                            axs[2],
                            alpha=0.4,
                            fib_name="fb_mid")
        # PlotI.plot_boll(ax, last_prices, sym)

        sectors = self.ss.sectors_day_stats()
        PlotI.plot_sector_stats(axs[3], sectors, self.stocks.iloc[0].sector)
        if (save_img):
            return plt

        # self.plot_spy(axs[2], self.spy)
        #self.plot_yahoo_candles(last_prices)
        # self.plot_volume(axs[2], last_prices)
        # set rotation of tick labels

        axs[3].text(0.02,
                    0.9,
                    str(self.financials.beta.name) + ' | ' +
                    str(self.financials.beta.to_list()),
                    fontsize=8)
        axs[3].text(
            0.02,
            0.8,
            str(self.financials.priceToSalesTrailing12Months.name) + ' | ' +
            str(self.financials.priceToSalesTrailing12Months.to_list()),
            fontsize=8)
        axs[3].text(0.02,
                    0.7,
                    str(self.financials.enterpriseToRevenue.name) + ' | ' +
                    str(self.financials.enterpriseToRevenue.to_list()),
                    fontsize=8)
        axs[3].text(0.02,
                    0.6,
                    str(self.financials.profitMargins.name) + ' | ' +
                    str(self.financials.profitMargins.to_list()),
                    fontsize=8)
        axs[3].text(0.02,
                    0.5,
                    str(self.financials.enterpriseToEbitda.name) + ' | ' +
                    str(self.financials.enterpriseToEbitda.to_list()),
                    fontsize=8)
        axs[3].text(0.02,
                    0.4,
                    str(self.financials.trailingEps.name) + ' | ' +
                    str(self.financials.trailingEps.to_list()),
                    fontsize=8)
        axs[3].text(0.02,
                    0.3,
                    str(self.financials.forwardEps.name) + ' | ' +
                    str(self.financials.forwardEps.to_list()),
                    fontsize=8)
        axs[3].text(0.02,
                    0.2,
                    str(self.financials.priceToBook.name) + ' | ' +
                    str(self.financials.priceToBook.to_list()),
                    fontsize=8)
        axs[3].text(0.02,
                    0.1,
                    str(self.financials.bookValue.name) + ' | ' +
                    str(self.financials.bookValue.to_list()),
                    fontsize=8)
        axs[3].text(0.4,
                    0.9,
                    str(self.financials.shortRatio.name) + ' | ' +
                    str(self.financials.shortRatio.to_list()),
                    fontsize=8)
        axs[3].text(0.4,
                    0.8,
                    str(self.financials.sharesShortPriorMonth.name) + ' | ' +
                    str(self.financials.sharesShortPriorMonth.to_list()),
                    fontsize=8)
        axs[3].text(0.4,
                    0.7,
                    str(self.financials.pegRatio.name) + ' | ' +
                    str(self.financials.pegRatio.to_list()),
                    fontsize=8)
        axs[3].text(0.4,
                    0.6,
                    str(self.financials.earningsQuarterlyGrowth.name) + ' | ' +
                    str(self.financials.earningsQuarterlyGrowth.to_list()),
                    fontsize=8)
        axs[3].text(0.4,
                    0.5,
                    str(self.financials.bid.name) + ' | ' +
                    str(self.financials.bid.to_list()),
                    fontsize=8)
        axs[3].text(0.4,
                    0.4,
                    str(self.financials.trailingPE.name) + ' | ' +
                    str(self.financials.trailingPE.to_list()),
                    fontsize=8)
        axs[3].text(0.4,
                    0.3,
                    str(self.financials.forwardPE.name) + ' | ' +
                    str(self.financials.forwardPE.to_list()),
                    fontsize=8)
        axs[3].text(0.4,
                    0.2,
                    str(self.financials.industry.to_list()) + ' | ' +
                    str(self.financials.sector.to_list()),
                    fontsize=8)
        axs[3].text(0.4,
                    0.1,
                    str(self.financials.heldPercentInstitutions.name) + ' | ' +
                    str(self.financials.heldPercentInstitutions.to_list()) +
                    ' ||| ' + str(self.financials.heldPercentInsiders.name) +
                    ' | ' + str(self.financials.heldPercentInsiders.to_list()),
                    fontsize=8)
        axs[3].text(0.6,
                    0.9,
                    str(self.financials.fiftyDayAverage.name) + ' | ' +
                    str(self.financials.fiftyDayAverage.to_list()),
                    fontsize=8)
        axs[3].text(0.6,
                    0.7,
                    str("Last CLose Price: ") + ' | ' +
                    str(self.in_day_stocks.iloc[-1].close),
                    fontsize=8)
        axs[3].text(
            0.6,
            0.5,
            str("Days to earn.: ") + ' | ' + str(days_to_earnings.days) +
            " D" if self.earnings is not None else str("Days to earn.: NaN "),
            fontsize=8)
        axs[3].text(0.6,
                    0.4,
                    str("Earn. est. | act. | surp.:  ") +
                    str(self.earnings.iloc[-1].epsestimate) + ' | ' +
                    str(self.earnings.iloc[-1].epsactual) + ' | ' +
                    str(self.earnings.iloc[-1].epssurprisepct)
                    if self.earnings is not None else str("Earn est.: NaN "),
                    fontsize=8)
        axs[3].text(0.6,
                    0.3,
                    str("  Sentiment article/title: ") +
                    str(self.sentiment.sentiment_summary_avg.to_list()) + '/' +
                    str(self.sentiment.sentiment_title_avg.to_list())
                    if self.sentiment is not None and len(self.sentiment) > 0
                    else str("  Sentiment: NaN "),
                    fontsize=8)

        axs[3].text(0.02,
                    0.01,
                    str(self.financials.longBusinessSummary.to_list()),
                    fontsize=8)

        # self.plot_candlesticks(last_prices)
        # axs[3].plot([2], [1], 'o')
        # plt.text()

        # plt.show()
        return plt