示例#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")
示例#2
0
文件: sl.py 项目: 4crash/4crash
    async def get_inday_price_graph(self, sym=None):

        if sym is None:
            sym = self.selected_stock

        inday_df = self.db.get_last_n_days(sym,
                                           n_days_back=self.inday_days,
                                           table=TableName.MIN15)

        inday_df = FinI.add_indicators(sdf.retype(inday_df))

        await self.inday_price_graph(sym, inday_df)
示例#3
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()
示例#4
0
文件: plot_i.py 项目: 4crash/4crash
    def plot_macd_boll(ax, df):
        """
        docstring
        """

        # df = self.add_bollinger_bands(df)
        if "boll" not in df or "macd" not in df:
            df = FinI.add_indicators(df)

        df.plot(kind="line",
                use_index=True,
                y=["macd", "boll_lb_macd", "boll_ub_macd"],
                legend=False,
                ax=ax,
                grid=True,
                linewidth=0.7,
                color=["black", "red", "green"],
                alpha=0.7)

        ax.fill_between(df.index,
                        df.boll_lb_macd,
                        df.macd,
                        where=df.boll_lb_macd > df.macd,
                        facecolor='red',
                        interpolate=True,
                        alpha=0.3)
        ax.fill_between(df.index,
                        df.boll_ub_macd,
                        df.macd,
                        where=df.boll_ub_macd < df.macd,
                        facecolor='green',
                        interpolate=True,
                        alpha=0.3)

        ax.fill_between(df.index,
                        df.boll_ub_macd,
                        df.boll_lb_macd,
                        facecolor='blue',
                        interpolate=True,
                        alpha=0.3)

        for tick in ax.get_xticklabels():
            tick.set_rotation(0)

        return ax
示例#5
0
文件: sl.py 项目: 4crash/4crash
    async def get_price_detail(self, sym=None):

        if sym is None:
            sym = self.selected_stock
        time_from = self.set_time_to()
        df = self.db.load_data(
            table_name=TableName.DAY,
            symbols=sym,
            time_from=time_from,
            time_to=self.time_to,
        )
        m_df_spy = self.db.load_data(table_name=TableName.DAY,
                                     time_from=time_from,
                                     time_to=self.time_to,
                                     symbols=["SPY"])
        m_df_spy["oc_mean"] = (m_df_spy.close + m_df_spy.open) / 2
        # self.stocks = FinI.add_change(self.stocks)
        df = FinI.add_indicators(sdf.retype(df))
        await self.price_graph(sym, df, m_df_spy=m_df_spy)

        # self.macd_rsi_graph(option, df)
        self._max_width_()
示例#6
0
文件: plot_p.py 项目: 4crash/4crash
    def plot_macd_boll(df=None, ax="y"):
        """
        docstring
        """
        out = []
        # df = self.add_bollinger_bands(df)
        if "boll" not in df or "macd" not in df:
            df = FinI.add_indicators(df)

        out += [{
            'x': df.index,
            'y': df.macd,
            'yaxis': ax,
            'type': 'scatter',
            'mode': 'lines',
            'line': {
                'width': 1,
                'color': 'rgba(128, 128, 256,1)'
            },
            'name': 'Macd'
        }]

        out += [{
            'x': df.index,
            'y': df.boll_lb_macd,
            'yaxis': ax,
            'type': 'scatter',
            'line': {
                'width': 0,
                'color': 'rgba(256, 128, 128,0.1)'
            },
            "fill": 'tonexty',
            "fillcolor": 'rgba(128, 128, 128,0.2)'
        }]

        out += [{
            'x': df.index,
            'y': df.boll_ub_macd,
            'yaxis': ax,
            'type': 'scatter',
            'mode': 'lines',
            'line': {
                'width': 0.6,
                'color': 'rgba(128, 128, 256,0.6)'
            },
            'name': 'bollup'
        }]

        # out += [{'x': df.index, 'y': df.macd, 'yaxis':  ax,
        #          'type': 'scatter', "fill": 'tonexty', "fillcolor": 'rgba(51, 204, 51,0.3)'}]

        out += [{
            'x': df.index,
            'y': df.boll_lb_macd,
            'yaxis': ax,
            'type': 'scatter',
            'mode': 'lines',
            'line': {
                'width': 0.6,
                'color': 'rgba(128, 128, 256,0.6)'
            },
            'name': 'boll dwn'
        }]

        out += [{
            'x': df.index,
            'y': df.boll_ub_macd,
            'yaxis': ax,
            'type': 'scatter',
            'line': {
                'width': 0,
                'color': 'rgba(128, 128, 256,0.6)'
            },
            "fill": 'tonexty',
            "fillcolor": 'rgba(128, 128, 128,0.2)'
        }]

        # print(out)
        return out
示例#7
0
文件: plot_p.py 项目: 4crash/4crash
    def plot_boll(ax, df, sym, fib=True):
        """
        docstring
        """

        # df = self.add_bollinger_bands(df)
        df = FinI.add_indicators(df)

        df.plot(kind="line",
                use_index=True,
                y=["boll", "boll_lb", "boll_ub"],
                legend=False,
                ax=ax,
                grid=True,
                linewidth=0.7,
                color=["brown", "orange", "green"],
                alpha=0.7)

        ax.fill_between(df.index,
                        df.boll_lb,
                        df.boll_ub,
                        where=df.boll > df.close,
                        facecolor='red',
                        interpolate=True,
                        alpha=0.2)
        ax.fill_between(df.index,
                        df.boll_lb,
                        df.boll_ub,
                        where=df.boll <= df.close,
                        facecolor='green',
                        interpolate=True,
                        alpha=0.2)

        def fill_bands(boll, bmin, bmax, alpha=0.2, color="white"):
            nonlocal ax
            ax.fill_between(df.index,
                            boll + bmin,
                            boll + bmax,
                            facecolor=color,
                            interpolate=True,
                            alpha=alpha)
            ax.fill_between(df.index,
                            boll - bmin,
                            boll - bmax,
                            facecolor=color,
                            interpolate=True,
                            alpha=alpha)
            return ax

        if fib:

            # print("slnfvadklngůdnfsld s")
            ax = fill_bands(df.boll, 0, df.boll_2, alpha=0.1, color="white")
            ax = fill_bands(df.boll,
                            df.boll_2,
                            df.boll_3,
                            alpha=0.2,
                            color="white")
            # ax = fill_bands(df.boll, df.boll_3, df.boll_5,
            #                 alpha=0.1, color="blue")
            ax = fill_bands(df.boll,
                            df.boll_5,
                            df.boll_6,
                            alpha=0.2,
                            color="green")
            ax = fill_bands(df.boll,
                            df.boll_6,
                            df.boll_10,
                            alpha=0,
                            color="brown")

        else:
            ax.fill_between(df.index,
                            df.boll_mid_lb,
                            df.boll_lb,
                            facecolor='brown',
                            interpolate=True,
                            alpha=0.2)
            ax.fill_between(df.index,
                            df.boll_mid_ub,
                            df.boll_ub,
                            facecolor='brown',
                            interpolate=True,
                            alpha=0.2)

        for tick in ax.get_xticklabels():
            tick.set_rotation(0)

        return ax