mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 20:42:26 +00:00
sentiment stats
This commit is contained in:
@@ -14,6 +14,7 @@ from gamestonk_terminal.behavioural_analysis import (
|
||||
reddit_view,
|
||||
stocktwits_view,
|
||||
finbrain_view,
|
||||
finnhub_view,
|
||||
)
|
||||
|
||||
|
||||
@@ -41,6 +42,7 @@ class BehaviouralAnalysisController:
|
||||
"queries",
|
||||
"rise",
|
||||
"finbrain",
|
||||
"stats",
|
||||
]
|
||||
|
||||
def __init__(self, ticker: str, start: datetime):
|
||||
@@ -63,6 +65,7 @@ class BehaviouralAnalysisController:
|
||||
print(" quit quit to abandon program")
|
||||
print("")
|
||||
print(" finbrain sentiment from 15+ major news headlines")
|
||||
print(" stats sentiment stats including comparison with sector")
|
||||
print("")
|
||||
print("Reddit:")
|
||||
print(
|
||||
@@ -218,6 +221,10 @@ class BehaviouralAnalysisController:
|
||||
"""Process finbrain command"""
|
||||
finbrain_view.sentiment_analysis(other_args, self.ticker)
|
||||
|
||||
def call_stats(self, other_args: List[str]):
|
||||
"""Process stats command"""
|
||||
finnhub_view.sentiment_stats(other_args, self.ticker)
|
||||
|
||||
|
||||
def menu(ticker: str, start: datetime):
|
||||
"""Behavioural Analysis Menu"""
|
||||
|
||||
80
gamestonk_terminal/behavioural_analysis/finnhub_view.py
Normal file
80
gamestonk_terminal/behavioural_analysis/finnhub_view.py
Normal file
@@ -0,0 +1,80 @@
|
||||
import argparse
|
||||
from typing import List, Dict
|
||||
import requests
|
||||
import pandas as pd
|
||||
from gamestonk_terminal import config_terminal as cfg
|
||||
from gamestonk_terminal.helper_funcs import (
|
||||
parse_known_args_and_warn,
|
||||
)
|
||||
|
||||
|
||||
def get_sentiment_stats(ticker: str) -> Dict:
|
||||
"""Get sentiment stats
|
||||
|
||||
Parameters
|
||||
----------
|
||||
ticker : str
|
||||
Ticker to get sentiment stats
|
||||
|
||||
Returns
|
||||
-------
|
||||
Dict
|
||||
Get sentiment stats
|
||||
"""
|
||||
response = requests.get(
|
||||
f"https://finnhub.io/api/v1/news-sentiment?symbol={ticker}&token={cfg.API_FINNHUB_KEY}"
|
||||
)
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
|
||||
return {}
|
||||
|
||||
|
||||
def sentiment_stats(other_args: List[str], ticker: str):
|
||||
"""Sentiment stats
|
||||
|
||||
Parameters
|
||||
----------
|
||||
other_args : List[str]
|
||||
Command line arguments to be processed with argparse
|
||||
ticker : str
|
||||
Ticker to get sentiment stats
|
||||
"""
|
||||
parser = argparse.ArgumentParser(
|
||||
add_help=False,
|
||||
prog="stats",
|
||||
description="""
|
||||
Sentiment stats. [Source: https://finnhub.io]
|
||||
""",
|
||||
)
|
||||
|
||||
try:
|
||||
ns_parser = parse_known_args_and_warn(parser, other_args)
|
||||
if not ns_parser:
|
||||
return
|
||||
|
||||
d_stats = get_sentiment_stats(ticker)
|
||||
|
||||
if d_stats:
|
||||
print(f"Buzz: {round(100*d_stats['buzz']['buzz'],2)} %")
|
||||
print(f"News Score: {round(100*d_stats['companyNewsScore'],2)} %")
|
||||
print("")
|
||||
print(f"Articles Last Week: {d_stats['buzz']['articlesInLastWeek']}")
|
||||
print(f"Articles Weekly Week: {d_stats['buzz']['weeklyAverage']}")
|
||||
print("")
|
||||
print(f"Bullish: {round(100*d_stats['sentiment']['bullishPercent'],2)} %")
|
||||
print(f"Bearish: {round(100*d_stats['sentiment']['bearishPercent'],2)} %")
|
||||
print("")
|
||||
print(
|
||||
f"Sector Average Bullish: {round(100*d_stats['sectorAverageBullishPercent'],2)} %"
|
||||
)
|
||||
print(
|
||||
f"Sector Average News Score: {round(100*d_stats['sectorAverageNewsScore'],2)} %"
|
||||
)
|
||||
else:
|
||||
print("No sentiment stats found.")
|
||||
|
||||
print("")
|
||||
|
||||
except Exception as e:
|
||||
print(e, "\n")
|
||||
Reference in New Issue
Block a user