Пример #1
0
def display_dividends(ticker: str,
                      limit: int = 12,
                      plot: bool = False,
                      export: str = ""):
    """Display historical dividends
    Parameters
    ----------
    ticker: str
        Stock ticker
    limit: int
        Number to show
    plot: bool
        Plots hitsorical data
    export: str
        Format to export data
    """
    div_history = yahoo_finance_model.get_dividends(ticker)
    if div_history.empty:
        console.print("No dividends found.\n")
        return
    div_history["Dif"] = div_history.diff()
    div_history = div_history[::-1]
    if plot:
        fig, ax = plt.subplots(figsize=plot_autoscale(),
                               constrained_layout=False,
                               dpi=PLOT_DPI)
        ax.plot(
            div_history.index,
            div_history["Dividends"],
            ls="-",
            linewidth=0.75,
            marker=".",
            markersize=4,
            mfc="k",
            mec="k",
            c="k",
            alpha=1,
        )
        ax.set_xlabel("Date")
        ax.set_ylabel("Amount ($)")
        ax.set_title(f"Dividend History for {ticker}")
        ax.set_xlim(div_history.index[-1], div_history.index[0])
        if gtff.USE_ION:
            plt.ion()
        fig.tight_layout()
        plt.show()
    else:
        div_history.index = pd.to_datetime(
            div_history.index, format="%Y%m%d").strftime("%Y-%m-%d")
        print_rich_table(
            div_history.head(limit),
            headers=["Amount Paid ($)", "Change"],
            title="Ticker Historical Dividends",
        )
    console.print("")
    export_data(export, os.path.dirname(os.path.abspath(__file__)), "divs",
                div_history)
Пример #2
0
def display_dividends(
    ticker: str,
    limit: int = 12,
    plot: bool = False,
    export: str = "",
    external_axes: Optional[List[plt.Axes]] = None,
):
    """Display historical dividends
    Parameters
    ----------
    ticker: str
        Stock ticker
    limit: int
        Number to show
    plot: bool
        Plots historical data
    export: str
        Format to export data
    external_axes : Optional[List[plt.Axes]], optional
        External axes (1 axis is expected in the list), by default None
    """
    div_history = yahoo_finance_model.get_dividends(ticker)
    if div_history.empty:
        console.print("No dividends found.\n")
        return
    div_history["Dif"] = div_history.diff()
    div_history = div_history[::-1]
    if plot:

        # This plot has 1 axis
        if not external_axes:
            _, ax = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
        else:
            if len(external_axes) != 1:
                logger.error("Expected list of one axis item.")
                console.print("[red]Expected list of one axis item./n[/red]")
                return
            (ax,) = external_axes

        ax.plot(
            div_history.index,
            div_history["Dividends"],
            ls="-",
            linewidth=0.75,
            marker=".",
            markersize=4,
            mfc=theme.down_color,
            mec=theme.down_color,
            alpha=1,
            label="Dividends Payout",
        )
        ax.set_ylabel("Amount ($)")
        ax.set_title(f"Dividend History for {ticker}")
        ax.set_xlim(div_history.index[-1], div_history.index[0])
        ax.legend()
        theme.style_primary_axis(ax)

        if not external_axes:
            theme.visualize_output()

    else:
        div_history.index = pd.to_datetime(div_history.index, format="%Y%m%d").strftime(
            "%Y-%m-%d"
        )
        print_rich_table(
            div_history.head(limit),
            headers=["Amount Paid ($)", "Change"],
            title=f"{ticker.upper()} Historical Dividends",
            show_index=True,
        )
    console.print()
    export_data(export, os.path.dirname(os.path.abspath(__file__)), "divs", div_history)