mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-29 05:21:48 +00:00
* First commit * Renamed to bot * change from discordbot to bots imports * refractor cmds + autocomplete helpers + updated dps plots/candle + quote cmd * isort fix * Update helpers.py * Added first refactor * Added commands and refactor * Added description handler * Through grains * ta + image border helper * Added indices * merged * Finished econ * options refactor * dark_pool_shorts, candle, quote done * pagination/dropdown logic to helpers + fixes * dd/disc/insider done + add image logic to helpers * linting * removed plt style * Almost done with Gov * fixing conflicts * Finished gov (excpect ones mentioned) * screener done * Test bug refactor * Store changes to switch * Finished refactor * Fixed error * Delete ::40 * Fixed issue * Fixed black * finished * fixes Co-authored-by: teh_coderer <me@tehcoderer.com> Co-authored-by: didierlopes.eth <dro.lopes@campus.fct.unl.pt>
76 lines
2.3 KiB
Python
76 lines
2.3 KiB
Python
from datetime import datetime, timedelta
|
|
|
|
from matplotlib import pyplot as plt
|
|
|
|
import bots.config_discordbot as cfg
|
|
import bots.helpers
|
|
from bots.config_discordbot import logger
|
|
from gamestonk_terminal.config_plot import PLOT_DPI
|
|
from gamestonk_terminal.helper_funcs import plot_autoscale
|
|
from gamestonk_terminal.stocks.due_diligence import business_insider_model
|
|
|
|
|
|
def pt_command(ticker: str = "", raw: bool = False, start=""):
|
|
"""Displays price targets [Business Insider]"""
|
|
|
|
# Debug
|
|
if cfg.DEBUG:
|
|
logger.debug("dd-pt %s", ticker)
|
|
|
|
# Check for argument
|
|
if ticker == "":
|
|
raise Exception("Stock ticker is required")
|
|
|
|
if start == "":
|
|
start = datetime.now() - timedelta(days=365)
|
|
else:
|
|
start = datetime.strptime(start, cfg.DATE_FORMAT)
|
|
|
|
if raw not in [True, False]:
|
|
raise Exception("raw argument has to be true or false")
|
|
|
|
df_analyst_data = business_insider_model.get_price_target_from_analysts(ticker)
|
|
stock = bots.helpers.load(ticker, start)
|
|
title = f"Stocks: [Business Insider] Price Targets {ticker}"
|
|
if df_analyst_data.empty or stock.empty:
|
|
raise Exception("Enter valid ticker")
|
|
|
|
# Output Data
|
|
|
|
if raw:
|
|
df_analyst_data.sort_index(ascending=False)
|
|
report = "```" + df_analyst_data.to_string() + "```"
|
|
|
|
output = {
|
|
"title": title,
|
|
"description": report,
|
|
}
|
|
else:
|
|
plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
|
|
if start:
|
|
df_analyst_data = df_analyst_data[start:]
|
|
|
|
plt.plot(stock.index, stock["Adj Close"].values, lw=3)
|
|
|
|
plt.plot(df_analyst_data.groupby(by=["Date"]).mean())
|
|
|
|
plt.scatter(df_analyst_data.index, df_analyst_data["Price Target"], c="r", s=40)
|
|
|
|
plt.legend(["Closing Price", "Average Price Target", "Price Target"])
|
|
|
|
plt.title(f"{ticker.upper} (Time Series) and Price Target")
|
|
plt.xlim(stock.index[0], stock.index[-1])
|
|
plt.xlabel("Time")
|
|
plt.ylabel("Share Price")
|
|
plt.grid(b=True, which="major", color="#666666", linestyle="-")
|
|
plt.savefig("ta_pt.png")
|
|
|
|
imagefile = bots.helpers.image_border("ta_pt.png")
|
|
|
|
output = {
|
|
"title": title,
|
|
"imagefile": imagefile,
|
|
}
|
|
|
|
return output
|