Ejemplo n.º 1
0
def display_sentiment_analysis(ticker: str, export: str = ""):
    """Sentiment analysis from FinBrain

    Parameters
    ----------
    ticker : str
        Ticker to get the sentiment analysis from
    export : str
        Format to export data
    """
    df_sentiment = finbrain_model.get_sentiment(ticker)
    if df_sentiment.empty:
        print("No sentiment data found.\n")
        return

    plot_sentiment(df_sentiment, ticker)

    df_sentiment.sort_index(ascending=True, inplace=True)

    if gtff.USE_COLOR:
        color_df = df_sentiment["Sentiment Analysis"].apply(sentiment_coloring,
                                                            last_val=0)
        if gtff.USE_TABULATE_DF:
            color_df = pd.DataFrame(
                data=color_df.values,
                index=pd.to_datetime(df_sentiment.index).strftime("%Y-%m-%d"),
            )
            print(
                tabulate(color_df,
                         headers=["Sentiment"],
                         tablefmt="fancy_grid"))
        else:
            print(color_df.to_string())
    else:
        if gtff.USE_TABULATE_DF:
            print(
                tabulate(
                    pd.DataFrame(
                        data=df_sentiment.values,
                        index=pd.to_datetime(
                            df_sentiment.index).strftime("%Y-%m-%d"),
                    ),
                    headers=["Sentiment"],
                    tablefmt="fancy_grid",
                ))

        else:
            print(df_sentiment.to_string())
    print("")
    export_data(export, os.path.dirname(os.path.abspath(__file__)),
                "headlines", df_sentiment)
Ejemplo n.º 2
0
def display_sentiment_analysis(ticker: str,
                               export: str = "",
                               external_axes: Optional[List[plt.Axes]] = None):
    """Sentiment analysis from FinBrain

    Parameters
    ----------
    ticker : str
        Ticker to get the sentiment analysis from
    export : str
        Format to export data
    """
    df_sentiment = finbrain_model.get_sentiment(ticker)
    if df_sentiment.empty:
        console.print("No sentiment data found.\n")
        return

    plot_sentiment(sentiment=df_sentiment,
                   ticker=ticker,
                   external_axes=external_axes)

    df_sentiment.sort_index(ascending=True, inplace=True)

    if gtff.USE_COLOR:
        color_df = df_sentiment["Sentiment Analysis"].apply(
            lambda_sentiment_coloring, last_val=0)
        color_df = pd.DataFrame(
            data=color_df.values,
            index=pd.to_datetime(df_sentiment.index).strftime("%Y-%m-%d"),
        )
        print_rich_table(
            color_df,
            headers=["Sentiment"],
            title="FinBrain Ticker Sentiment",
            show_index=True,
        )
    else:
        print_rich_table(
            pd.DataFrame(
                data=df_sentiment.values,
                index=pd.to_datetime(df_sentiment.index).strftime("%Y-%m-%d"),
            ),
            headers=["Sentiment"],
            title="FinBrain Ticker Sentiment",
            show_index=True,
        )

    console.print("")
    export_data(export, os.path.dirname(os.path.abspath(__file__)),
                "headlines", df_sentiment)
Ejemplo n.º 3
0
def display_crypto_sentiment_analysis(coin: str, export: str) -> None:
    """Sentiment analysis from FinBrain for Cryptocurrencies

    FinBrain collects the news headlines from 15+ major financial news
    sources on a daily basis and analyzes them to generate sentiment scores
    for more than 4500 US stocks. FinBrain Technologies develops deep learning
    algorithms for financial analysis and prediction, which currently serves
    traders from more than 150 countries all around the world.
    [Source:  https://finbrain.tech]

    Parameters
    ----------
    coin: str
        Cryptocurrency
    export : str
        Export dataframe data to csv,json,xlsx file
    """

    df_sentiment = get_sentiment(
        f"{coin}-USD")  # Currently only USD pairs are available

    if df_sentiment.empty:
        console.print(f"Couldn't find Sentiment Data for {coin}\n")
        return

    plot_sentiment(df_sentiment, coin)
    df_sentiment.sort_index(ascending=True, inplace=True)

    if gtff.USE_COLOR:
        console.print(
            df_sentiment["Sentiment Analysis"].apply(sentiment_coloring,
                                                     last_val=0).to_string(),
            "\n",
        )
    else:
        console.print(df_sentiment.to_string(), "\n")

    export_data(
        export,
        os.path.dirname(os.path.abspath(__file__)),
        "finbrain",
        df_sentiment,
    )
Ejemplo n.º 4
0
def test_get_sentiment(recorder):
    df = finbrain_model.get_sentiment(ticker="PM")
    recorder.capture(df)