def test_get_financial_comparisons(quarter, timeframe, recorder):
    result_df = marketwatch_model.get_financial_comparisons(
        all_stocks=["TSLA", "GM"],
        data="income",
        timeframe=timeframe,
        quarter=quarter,
    )

    recorder.capture(result_df)
Example #2
0
def display_cashflow_comparison(
    ticker: str,
    similar: List[str],
    timeframe: str,
    quarter: bool = False,
    export: str = "",
):
    """Compare cashflow between companies

    Parameters
    ----------
    ticker : str
        Main ticker to compare income
    similar : List[str]
        Similar companies to compare income with
    timeframe : str
        Whether to use quarterly or annual
    quarter : bool, optional
        Whether to use quarterly statements, by default False
    export : str, optional
        Format to export data
    """
    all_stocks = [ticker, *similar]
    df_financials_compared = marketwatch_model.get_financial_comparisons(
        all_stocks, "cashflow", timeframe, quarter)

    # Export data before the color
    export_data(
        export,
        os.path.dirname(os.path.abspath(__file__)),
        "cashflow",
        df_financials_compared,
    )

    if gtff.USE_COLOR:
        df_financials_compared = df_financials_compared.applymap(
            financials_colored_values)
        patch_pandas_text_adjustment()

    if not quarter:
        df_financials_compared.index.name = timeframe

    if gtff.USE_TABULATE_DF:
        print(
            tabulate(
                df_financials_compared,
                headers=df_financials_compared.columns,
                showindex=True,
                tablefmt="fancy_grid",
            ),
            "\n",
        )
    else:
        print(df_financials_compared.to_string(), "\n")
def display_cashflow_comparison(
    similar: List[str],
    timeframe: str,
    quarter: bool = False,
    export: str = "",
):
    """Compare cashflow between companies. [Source: Marketwatch]

    Parameters
    ----------
    ticker : str
        Main ticker to compare income
    similar : List[str]
        Similar companies to compare income with
    timeframe : str
        Whether to use quarterly or annual
    quarter : bool, optional
        Whether to use quarterly statements, by default False
    export : str, optional
        Format to export data
    """
    df_financials_compared = marketwatch_model.get_financial_comparisons(
        similar, "cashflow", timeframe, quarter
    )

    # Export data before the color
    export_data(
        export,
        os.path.dirname(os.path.abspath(__file__)),
        "cashflow",
        df_financials_compared,
    )

    if rich_config.USE_COLOR:
        df_financials_compared = df_financials_compared.applymap(
            lambda_financials_colored_values
        )
        patch_pandas_text_adjustment()

    if not quarter:
        df_financials_compared.index.name = timeframe

    print_rich_table(
        df_financials_compared,
        headers=list(df_financials_compared.columns),
        show_index=True,
        title="Cashflow Comparison",
    )
    console.print("")
Example #4
0
def display_income_comparison(
    similar: List[str],
    timeframe: str,
    quarter: bool = False,
    export: str = "",
):
    """Display income data. [Source: Marketwatch]

    Parameters
    ----------
    similar : List[str]
        List of tickers to compare
    timeframe : str
        Whether to use quarterly or annual
    quarter : bool, optional
        Whether to use quarterly statements, by default False
    export : str, optional
        Format to export data
    """
    df_financials_compared = marketwatch_model.get_financial_comparisons(
        similar, "income", timeframe, quarter)
    # Export data before the color
    export_data(
        export,
        os.path.dirname(os.path.abspath(__file__)),
        "income",
        df_financials_compared,
    )

    if gtff.USE_COLOR:
        df_financials_compared = df_financials_compared.applymap(
            financials_colored_values)
        patch_pandas_text_adjustment()

    if not quarter:
        df_financials_compared.index.name = timeframe

    if gtff.USE_TABULATE_DF:
        print(
            tabulate(
                df_financials_compared,
                headers=df_financials_compared.columns,
                showindex=True,
                tablefmt="fancy_grid",
            ),
            "\n",
        )
    else:
        print(df_financials_compared.to_string(), "\n")