Exemple #1
0
def display_usbonds(export: str):
    """US bonds. [Source: Wall St. Journal]

    Parameters
    ----------
    export : str
        Export dataframe data to csv,json,xlsx file
    """
    df_data = wsj_model.us_bonds()
    if df_data.empty:
        console.print("No US bonds data available\n")
        return

    print_rich_table(df_data,
                     show_index=False,
                     headers=list(df_data.columns),
                     title="US Bonds")
    console.print("")

    export_data(
        export,
        os.path.dirname(os.path.abspath(__file__)),
        "usbonds",
        df_data,
    )
def display_usbonds(export: str):
    """US bonds. [Source: Wall St. Journal]

    Parameters
    ----------
    export : str
        Export dataframe data to csv,json,xlsx file
    """
    df_data = wsj_model.us_bonds()
    if df_data.empty:
        print("No US bonds data available\n")
        return

    if gtff.USE_TABULATE_DF:
        print(
            tabulate(
                df_data,
                showindex=False,
                headers=df_data.columns,
                floatfmt=".2f",
                tablefmt="fancy_grid",
            )
        )
    else:
        print(df_data.to_string(index=False))
    print("")

    export_data(
        export,
        os.path.dirname(os.path.abspath(__file__)),
        "usbonds",
        df_data,
    )
Exemple #3
0
def usbonds_command():
    """US bonds overview [Wall St. Journal]"""

    # Debug user input
    if cfg.DEBUG:
        logger.debug("econ-usbonds")

    # Retrieve data
    df = wsj_model.us_bonds()

    # Check for argument
    if df.empty:
        raise Exception("No available data found")

    df["Rate (%)"] = pd.to_numeric(df["Rate (%)"].astype(float))
    df["Yld (%)"] = pd.to_numeric(df["Yld (%)"].astype(float))
    df["Yld Chg (%)"] = pd.to_numeric(df["Yld Chg (%)"].astype(float))

    formats = {
        "Rate (%)": "{:.2f}%",
        "Yld (%)": "{:.2f}%",
        "Yld Chg (%)": "{:.2f}%",
    }
    for col, value in formats.items():
        df[col] = df[col].map(lambda x: value.format(x))  # pylint: disable=W0640

    df = df.fillna("")
    df.set_index(" ", inplace=True)

    df = df.set_axis(
        [
            "Rate",
            "Yld",
            "Yld Chg",
        ],
        axis="columns",
    )

    dindex = len(df.index)
    fig = df2img.plot_dataframe(
        df,
        fig_size=(800, (40 + (40 * dindex))),
        col_width=[8, 3, 3],
        tbl_cells=dict(
            align="left",
            height=35,
        ),
        template="plotly_dark",
        font=dict(
            family="Consolas",
            size=20,
        ),
        paper_bgcolor="rgba(0, 0, 0, 0)",
    )

    imagefile = save_image("econ-usbonds.png", fig)
    return {
        "title": "Economy: [WSJ] US Bonds",
        "imagefile": imagefile,
    }
Exemple #4
0
async def usbonds_command(ctx):
    """US bonds overview [Wall St. Journal]"""

    try:
        # Debug user input
        if cfg.DEBUG:
            print("\n!economy.usbonds")

        # Retrieve data
        df_data = wsj_model.us_bonds()

        # Debug user output
        if cfg.DEBUG:
            print(df_data.to_string())

        # Output data
        if df_data.empty:
            df_data_str = "No US bonds data available"
        else:
            df_data_str = "```" + df_data.to_string(index=False) + "```"

        embed = discord.Embed(
            title="Economy: [WSJ] US Bonds",
            description=df_data_str,
            colour=cfg.COLOR,
        )
        embed.set_author(
            name=cfg.AUTHOR_NAME,
            icon_url=cfg.AUTHOR_ICON_URL,
        )

        await ctx.send(embed=embed)

    except Exception as e:
        embed = discord.Embed(
            title="ERROR Economy: [WSJ] US Bonds",
            colour=cfg.COLOR,
            description=e,
        )
        embed.set_author(
            name=cfg.AUTHOR_NAME,
            icon_url=cfg.AUTHOR_ICON_URL,
        )

        await ctx.send(embed=embed)
Exemple #5
0
async def usbonds_command(ctx, arg=""):
    """Gets the US bond data from GST and sends it

    Parameters
    -----------
    arg: str
        -h or help

    Returns
    -------
    discord message
        Sends a message containing an embed of US bond data to the user
    """

    try:
        # Debug
        if cfg.DEBUG:
            print(f"!stocks.economy.usbonds {arg}")

        # Help
        if arg == "-h" or arg == "help":
            help_txt = "US Bonds [Source: Wall St. Journal]\n"
            embed = discord.Embed(
                title="Economy: [WSJ] US Bonds HELP",
                description=help_txt,
                colour=cfg.COLOR,
            )
            embed.set_author(
                name=cfg.AUTHOR_NAME,
                icon_url=cfg.AUTHOR_ICON_URL,
            )

            await ctx.send(embed=embed)

        else:
            df_data = wsj_model.us_bonds()
            if df_data.empty:
                df_data_str = "No US bonds data available"
            else:
                df_data_str = "```" + df_data.to_string(index=False) + "```"

            embed = discord.Embed(
                title="Economy: [WSJ] US Bonds",
                description=df_data_str,
                colour=cfg.COLOR,
            )
            embed.set_author(
                name=cfg.AUTHOR_NAME,
                icon_url=cfg.AUTHOR_ICON_URL,
            )

            await ctx.send(embed=embed)

    except Exception as e:
        title = "INTERNAL ERROR"
        embed = discord.Embed(title=title, colour=cfg.COLOR)
        embed.set_author(
            name=cfg.AUTHOR_NAME,
            icon_url=cfg.AUTHOR_ICON_URL,
        )
        embed.set_description(
            "Try updating the bot, make sure DEBUG is True in the config "
            "and restart it.\nIf the error still occurs open a issue at: "
            "https://github.com/GamestonkTerminal/GamestonkTerminal/issues"
            f"\n{e}"
        )
        await ctx.send(embed=embed)
        if cfg.DEBUG:
            print(e)
Exemple #6
0
def usbonds_command():
    """US bonds overview [Wall St. Journal]"""

    # Debug user input
    if imps.DEBUG:
        logger.debug("econ-usbonds")

    # Retrieve data
    df = wsj_model.us_bonds()

    # Check for argument
    if df.empty:
        raise Exception("No available data found")

    df["Rate (%)"] = pd.to_numeric(df["Rate (%)"].astype(float))
    df["Yld (%)"] = pd.to_numeric(df["Yld (%)"].astype(float))
    df["Yld Chg (%)"] = pd.to_numeric(df["Yld Chg (%)"].astype(float))

    formats = {
        "Rate (%)": "{:.2f}%",
        "Yld (%)": "{:.2f}%",
        "Yld Chg (%)": "<b>{:.2f}%</b>",
    }
    for col, value in formats.items():
        df[col] = df[col].map(lambda x: value.format(x))  # pylint: disable=W0640

    df = df.fillna("")
    df.set_index(" ", inplace=True)

    df = df.set_axis(
        [
            "Rate",
            "Yld",
            "Yld Chg",
        ],
        axis="columns",
    )

    font_color = ["white"] * 3 + [[
        "#e4003a" if boolv else "#00ACFF"
        for boolv in df["Yld Chg"].str.contains("-")
    ]]

    fig = imps.plot_df(
        df,
        fig_size=(550, (40 + (40 * len(df.index)))),
        col_width=[4, 2, 2, 2.1],
        tbl_header=imps.PLT_TBL_HEADER,
        tbl_cells=imps.PLT_TBL_CELLS,
        font=imps.PLT_TBL_FONT,
        row_fill_color=imps.PLT_TBL_ROW_COLORS,
        paper_bgcolor="rgba(0, 0, 0, 0)",
    )
    fig.update_traces(cells=(dict(
        align=["center", "right"],
        font=dict(color=font_color),
    )))
    fig.update_traces(cells=(dict(align=["center", "right"])))

    imagefile = imps.save_image("econ-usbonds.png", fig)
    return {
        "title": "Economy: [WSJ] US Bonds",
        "imagefile": imagefile,
    }