Exemplo n.º 1
0
def get_comparison_data(data_type: str, similar: List[str]):
    """Screener Overview

    Parameters
    ----------
    data_type : str
        Data type between: overview, valuation, financial, ownership, performance, technical

    Returns
    ----------
    pd.DataFrame
        Dataframe with overview, valuation, financial, ownership, performance or technical
    """
    if data_type == "overview":
        screen = overview.Overview()
    elif data_type == "valuation":
        screen = valuation.Valuation()
    elif data_type == "financial":
        screen = financial.Financial()
    elif data_type == "ownership":
        screen = ownership.Ownership()
    elif data_type == "performance":
        screen = performance.Performance()
    elif data_type == "technical":
        screen = technical.Technical()
    else:
        print("Invalid selected screener type")
        return pd.DataFrame()

    screen.set_filter(ticker=",".join(similar))
    df_screen = screen.ScreenerView(verbose=0)

    return df_screen
Exemplo n.º 2
0
def get_screener_data(preset_loaded: str, data_type: str, signal: str,
                      limit: int, ascend: bool):
    """Screener Overview

    Parameters
    ----------
    preset_loaded : str
        Loaded preset filter
    data_type : str
        Data type between: overview, valuation, financial, ownership, performance, technical
    signal : str
        Signal to use to filter data
    limit : int
        Limit of stocks filtered with presets to print
    ascend : bool
        Ascended order of stocks filtered to print

    Returns
    ----------
    pd.DataFrame
        Dataframe with loaded filtered stocks
    """
    preset_filter = configparser.RawConfigParser()
    preset_filter.optionxform = str  # type: ignore
    preset_filter.read(presets_path + preset_loaded + ".ini")

    d_general = preset_filter["General"]
    d_filters = {
        **preset_filter["Descriptive"],
        **preset_filter["Fundamental"],
        **preset_filter["Technical"],
    }

    d_filters = {k: v for k, v in d_filters.items() if v}

    if data_type == "overview":
        screen = overview.Overview()
    elif data_type == "valuation":
        screen = valuation.Valuation()
    elif data_type == "financial":
        screen = financial.Financial()
    elif data_type == "ownership":
        screen = ownership.Ownership()
    elif data_type == "performance":
        screen = performance.Performance()
    elif data_type == "technical":
        screen = technical.Technical()
    else:
        print("Invalid selected screener type")
        return pd.DataFrame()

    if signal:
        screen.set_filter(signal=d_signals[signal])
    else:
        if "Signal" in d_general:
            screen.set_filter(filters_dict=d_filters,
                              signal=d_general["Signal"])
        else:
            screen.set_filter(filters_dict=d_filters)

    if "Order" in d_general:
        if limit > 0:
            df_screen = screen.ScreenerView(
                order=d_general["Order"],
                limit=limit,
                ascend=ascend,
            )
        else:
            df_screen = screen.ScreenerView(order=d_general["Order"],
                                            ascend=ascend)

    else:
        if limit > 0:
            df_screen = screen.ScreenerView(limit=limit, ascend=ascend)
        else:
            df_screen = screen.ScreenerView(ascend=ascend)

    return df_screen
Exemplo n.º 3
0
def get_screener_data(preset_loaded: str, data_type: str, limit: int,
                      ascend: bool):
    """Screener Overview

    Parameters
    ----------
    preset_loaded : str
        Loaded preset filter
    data_type : str
        Data type between: overview, valuation, financial, ownership, performance, technical
    limit : int
        Limit of stocks filtered with presets to print
    ascend : bool
        Ascended order of stocks filtered to print

    Returns
    ----------
    pd.DataFrame
        Dataframe with loaded filtered stocks
    """
    if data_type == "overview":
        screen = overview.Overview()
    elif data_type == "valuation":
        screen = valuation.Valuation()
    elif data_type == "financial":
        screen = financial.Financial()
    elif data_type == "ownership":
        screen = ownership.Ownership()
    elif data_type == "performance":
        screen = performance.Performance()
    elif data_type == "technical":
        screen = technical.Technical()
    else:
        console.print("Invalid selected screener type")
        return pd.DataFrame()

    if preset_loaded in d_signals:
        screen.set_filter(signal=d_signals[preset_loaded])

        try:
            if limit > 0:
                df_screen = screen.screener_view(limit=limit, ascend=ascend)
            else:
                df_screen = screen.screener_view(ascend=ascend)
        except IndexError:
            console.print("[red]Invalid data provided by the website[/red]\n")
            return pd.DataFrame()

    else:
        preset_filter = configparser.RawConfigParser()
        preset_filter.optionxform = str  # type: ignore
        preset_filter.read(presets_path + preset_loaded + ".ini")

        d_general = preset_filter["General"]
        d_filters = {
            **preset_filter["Descriptive"],
            **preset_filter["Fundamental"],
            **preset_filter["Technical"],
        }

        for section in ["General", "Descriptive", "Fundamental", "Technical"]:
            for key, val in {**preset_filter[section]}.items():
                if key not in d_check_screener:
                    console.print(
                        f"The screener variable {section}.{key} shouldn't exist!\n"
                    )
                    return pd.DataFrame()

                if val not in d_check_screener[key]:
                    console.print(
                        f"Invalid [{section}] {key}={val}. "
                        f"Choose one of the following options:\n{', '.join(d_check_screener[key])}.\n"
                    )
                    return pd.DataFrame()

        d_filters = {k: v for k, v in d_filters.items() if v}

        screen.set_filter(filters_dict=d_filters)

        if "Order" in d_general:
            if limit > 0:
                df_screen = screen.screener_view(
                    order=d_general["Order"],
                    limit=limit,
                    ascend=ascend,
                )
            else:
                df_screen = screen.screener_view(order=d_general["Order"],
                                                 ascend=ascend)

        else:
            if limit > 0:
                df_screen = screen.screener_view(limit=limit, ascend=ascend)
            else:
                df_screen = screen.screener_view(ascend=ascend)

    return df_screen