def display_overview(country: str = "united states",
                     limit: int = 10,
                     export: str = ""):
    """Displays an overview of the main funds from a country.

    Parameters
    ----------
    country: str
        Country to get overview for
    limit: int
        Number to show
    export : str
        Format to export data
    """
    overview = investpy_model.get_overview(country=country, limit=limit)
    overview["Assets (1B)"] = overview.total_assets / 1_000_000_000
    overview = overview.drop(columns=["country", "total_assets"])
    if gtff.USE_TABULATE_DF:
        t_console.print(
            rich_table_from_df(
                overview,
                title=f"[bold]Fund overview for {country.title()}[/bold]"))
    else:
        t_console.print(overview.to_string())
    export_data(
        export,
        os.path.dirname(os.path.abspath(__file__)),
        f"overview_{country.replace(' ','_')}",
        overview,
    )
    t_console.print("\n")
def display_search(
    by: str = "name",
    value: str = "",
    country: str = "united states",
    limit: int = 10,
    sortby: str = "",
    ascending: bool = False,
):
    """Display results of searching for Mutual Funds

    Parameters
    ----------
    by : str
        Field to match on.  Can be name, issuer, isin or symbol
    value : str
        String that will be searched for
    country: str
        Country to filter on
    limit: int
        Number to show
    sortby: str
        Column to sort by
    ascending: bool
        Flag to sort in ascending order
    """
    searches = investpy_model.search_funds(by, value)
    if searches.empty:
        t_console.print("No matches found.\n")
        return
    if country:
        searches = searches[searches.country == country]
        if searches.empty:
            t_console.print(f"No matches found in {country}.\n")
            return
        searches = searches.drop(columns=["country", "underlying"])

    if sortby:
        searches = searches.sort_values(by=sortby, ascending=ascending)

    # If we want to move forward with rich -- should rename this gtff
    # Additionally, I recreated the tabulate functions with the rich.Table class.
    if gtff.USE_TABULATE_DF:
        t_console.print(
            rich_table_from_df(
                searches.head(limit),
                show_index=False,
                title=f"[bold]Mutual Funds with {by} matching {value}[/bold]",
            ))
    else:
        t_console.print(searches.head(limit).to_string())
    t_console.print("\n")
Beispiel #3
0
def display_equity(fund: str):
    """Display equity holdings for fund

    Parameters
    ----------
    fund: str
        Fund symbol
    """
    title_map = {
        "priceToCashflow": "Price To Cash Flow",
        "priceToSales": "Price To Sales",
        "priceToBookCat": "Price To Book Cat",
        "priceToEarningsCat": "Price To Earnings Cat",
        "medianMarketCapCat": "Median Market Cap Cat",
        "threeYearEarningsGrowthCat": "3Yr Earnings Growth Cat",
        "threeYearEarningsGrowth": "3Y Earnings Growth",
        "medianMarketCap": "Median Market Cap",
        "priceToEarnings": "Price To Earnings",
        "priceToBook": "Price To Book",
        "priceToSalesCat": "Price To Sales Cat",
        "priceToCashflowCat": "Price To Cashflow Cat",
    }

    equity_hold = yfinance_model.get_information(fund)["equityHoldings"]
    df_weight = pd.DataFrame.from_dict(equity_hold, orient="index")
    df_weight = df_weight.apply(lambda x: round(100 * x, 3))
    df_weight.index = df_weight.index.map(title_map)
    if gtff.USE_TABULATE_DF:
        console.print(
            rich_table_from_df(
                df_weight,
                show_index=True,
                index_name="Equity",
                headers=["Holding"],
                title=f"[bold]{fund.upper()} Equity Holdings[/bold] ",
            ))
    else:
        console.print(df_weight.to_string())
    console.print("\n")
def display_fund_info(fund_name: str, country: str = "united states"):
    """Display fund infomration.  Finds name from symbol first if name is false

    Parameters
    ----------
    fund: str
        Fund name to get info for
    country : str
        Country of fund
    """
    info = (investpy_model.get_fund_info(fund_name, country).reset_index(
        drop=False).applymap(lambda x: np.nan if not x else x).dropna())
    if gtff.USE_TABULATE_DF:
        t_console.print(
            rich_table_from_df(
                info,
                title=f"[bold]{fund_name.title()} Information[/bold]",
                show_index=False,
                headers=["Info", "Value"],
            ))
    else:
        t_console.print(info.to_string())
    t_console.print("\n")
Beispiel #5
0
def display_sector(fund: str, min_pct_to_display: float = 5, export: str = ""):
    """Display sector weightings for fund

    Parameters
    ----------
    fund: str
        Fund symbol
    min_pct_to_display: float
        Minimum percentage to display sector
    export: str
        Type of format to export data
    """
    sector_weights = yfinance_model.get_information(fund)
    if "sectorWeightings" not in sector_weights.keys():
        console.print(
            f"Sector Weights are not found f for {fund}. Either the symbol is incorrect or there is an issue "
            "in pulling from yahoo.\n")
        return
    sector_weights = sector_weights["sectorWeightings"]
    weights = {}
    for weight in sector_weights:
        weights.update(weight)
    df_weight = pd.DataFrame.from_dict(weights, orient="index")
    if df_weight.empty:
        console.print("No sector data found.\n")
    df_weight = df_weight.apply(lambda x: round(100 * x, 3))
    df_weight.columns = ["Weight"]
    df_weight.sort_values(by="Weight", inplace=True, ascending=False)
    df_weight.index = [
        "Real Estate" if x == "realestate" else x.replace("_", " ").title()
        for x in df_weight.index
    ]
    if gtff.USE_TABULATE_DF:
        console.print(
            rich_table_from_df(
                df_weight,
                show_index=True,
                index_name="Sector",
                headers=["Weight (%)"],
                title=f"[bold]{fund.upper()} Sector Weightings[/bold] ",
            ))
    else:
        console.print(df_weight.to_string())
    console.print("\n")
    main_holdings = df_weight[df_weight.Weight > min_pct_to_display].to_dict()[
        df_weight.columns[0]]
    if len(main_holdings) < len(df_weight):
        main_holdings["Others"] = 100 - sum(main_holdings.values())

    legend, values = zip(*main_holdings.items())
    leg = [f"{le}\n{round(v, 2)}%" for le, v in zip(legend, values)]

    fig, ax = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
    ax.pie(
        values,
        labels=leg,
        wedgeprops={
            "linewidth": 0.5,
            "edgecolor": "white"
        },
        labeldistance=1.05,
        startangle=90,
    )
    ax.set_title(f"Sector holdings of {fund.upper()}")
    fig.tight_layout()
    if gtff.USE_ION:
        plt.ion()
    plt.show()
    export_data(export, os.path.dirname(os.path.abspath(__file__)), "sector",
                df_weight)