Esempio n. 1
0
def get_industries(country: str = "", sector: str = ""):
    """Get all industries in Yahoo Finance data based on country or sector. [Source: Finance Database]

    Parameters
    ----------
    country : str
        Filter retrieved industries by country
    sector : str
        Filter retrieved industries by sector

    Returns
    -------
    list
        List of possible industries
    """
    if country and sector:
        return fd.show_options("equities", country=country, sector=sector)

    if country:
        return fd.show_options("equities", country=country)["Industries"]

    if sector:
        return fd.show_options("equities", sector=sector)["Industries"]

    return fd.show_options("equities", "industries")
Esempio n. 2
0
def industry_autocomp(inter, industry: str):
    data = fd.show_options("equities", "industries")
    if not industry:
        industry = "a"
    ilow = industry.lower()
    return [
        industry for industry in data if industry.lower().startswith(ilow)
    ][:24]
Esempio n. 3
0
def get_etfs_categories() -> List[str]:
    """Return a selection of ETF categories. [Source: Finance Database]

    Returns
    ----------
    List[str]
        ETF categories
    """

    return fd.show_options("etfs")
def get_countries(industry: str = "", sector: str = ""):
    """Get all countries in Yahoo Finance data based on sector or industry. [Source: Finance Database]

    Parameters
    ----------
    industry : str
        Filter retrieved countries by industry
    sector : str
        Filter retrieved countries by sector

    Returns
    -------
    list
        List of possible countries
    """
    # industry takes priority since there's 1 sector per industry, but multiple industries per sector
    if industry:
        return fd.show_options("equities", industry=True)[industry]["Countries"]
    if sector:
        return fd.show_options("equities", sector=sector)["Countries"]
    return fd.show_options("equities", "countries")
Esempio n. 5
0
def get_sectors(industry: str = "", country: str = ""):
    """Get all sectors in Yahoo Finance data based on country or industry. [Source: Finance Database]

    Parameters
    ----------
    industry : str
        Filter retrieved sectors by industry
    country : str
        Filter retrieved sectors by country

    Returns
    -------
    list
        List of possible sectors
    """
    # industry takes priority since there's 1 sector per industry, but multiple industries per country
    if industry:
        return [fd.show_options("equities", industry=True)[industry]["Sector"]]
    if country:
        return fd.show_options("equities", country=country)["Sectors"]

    return fd.show_options("equities", "sectors")
Esempio n. 6
0
def country_autocomp(inter, country: str):
    data = fd.show_options("equities", "countries")
    clow = country.lower()
    return [country for country in data
            if country.lower().startswith(clow)][:24]
Esempio n. 7
0
def show_equities(
    country: str,
    sector: str,
    industry: str,
    name: str,
    description: str,
    marketcap: str,
    amount: int,
    include_exchanges: bool,
    options: str,
):
    """
    Display a selection of Equities based on country, sector, industry, name and/or description filtered
    by market cap. If no arguments are given, return equities categorized as Large Cap.
    [Source: Finance Database]

    Parameters
    ----------
    country: str
        Search by country to find stocks matching the criteria.
    sector : str
        Search by sector to find stocks matching the criteria.
    industry : str
        Search by industry to find stocks matching the criteria.
    name : str
        Search by name to find stocks matching the criteria.
    description : str
        Search by description to find stocks matching the criteria.
    marketcap : str
        Select stocks based on the market cap.
    amount : int
        Number of stocks to display, default is 10.
    include_exchanges: bool
        When you wish to include different exchanges use this boolean.
    options : str
        Show the country, sector or industry options.
    """
    if options is not None:
        for option in fd.show_options("equities", options):
            print(option)
        return

    if country is not None:
        country = " ".join(country).title()
    if sector is not None:
        sector = " ".join(sector).title()
    if industry is not None:
        industry = " ".join(industry).title()

    data = fd.select_equities(
        country=country,
        sector=sector,
        industry=industry,
        exclude_exchanges=include_exchanges,
    )

    if name is not None:
        data = fd.search_products(data, query=" ".join(name), search="long_name")
    if description is not None:
        data = fd.search_products(data, query=" ".join(description), search="summary")
    if marketcap is not None:
        data = fd.search_products(
            data, query=f"{''.join(marketcap)} Cap", search="market_cap"
        )

    tabulate_data = pd.DataFrame(data).T[
        [
            "long_name",
            "sector",
            "industry",
            "country",
            "city",
            "website",
            "market_cap",
        ]
    ]

    if gtff.USE_TABULATE_DF:
        print(
            tabulate(
                tabulate_data.iloc[:amount],
                showindex=True,
                headers=[
                    "Name",
                    "Sector",
                    "Industry",
                    "Country",
                    "City",
                    "Website",
                    "Market Cap",
                ],
                floatfmt=".2f",
                tablefmt="fancy_grid",
            ),
            "\n",
        )
    else:
        print(tabulate_data.iloc[:amount].to_string(), "\n")