Dividend History Chart (#1053)

* Dividend History Chart

* changed to default number 10

* changed divs flag default to false

* updating the expected result for test_fa_controller.

* else statement
This commit is contained in:
Danglewood
2021-12-15 07:17:43 -08:00
committed by GitHub
parent aacbc911be
commit b82e4225b6
6 changed files with 57 additions and 33 deletions

View File

@@ -77,7 +77,6 @@ class FundamentalAnalysisController:
def __init__(self, ticker: str, start: str, interval: str, suffix: str = ""):
"""Constructor
Parameters
----------
ticker : str
@@ -109,7 +108,6 @@ Fundamental Analysis:
q quit this menu, and shows back to main menu
quit quit to abandon program
load load a new ticker
Ticker: {self.ticker}
{f"Note that only Yahoo Finance currently supports foreign exchanges{Style.DIM}{newline}" if self.suffix else ""}
data fundamental and technical data of company [FinViz]
@@ -147,7 +145,6 @@ Other Sources:
def switch(self, an_input: str):
"""Process and dispatch input
Returns
-------
True, False or None
@@ -460,23 +457,34 @@ Other Sources:
add_help=False,
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
prog="divs",
description="Get historical dividends for company",
description="Historical dividends for a company",
)
parser.add_argument(
"-n",
"--num",
dest="num",
type=check_positive,
default=12,
default=16,
help="Number of previous dividends to show",
)
parser.add_argument(
"-p",
"--plot",
dest="plot",
default=False,
action="store_true",
help="Plots changes in dividend over time",
)
ns_parser = parse_known_args_and_warn(
parser, other_args, export_allowed=EXPORT_ONLY_RAW_DATA_ALLOWED
)
if not ns_parser:
return
yahoo_finance_view.display_dividends(
ticker=self.ticker, num=ns_parser.num, export=ns_parser.export
ticker=self.ticker,
num=ns_parser.num,
plot=ns_parser.plot,
export=ns_parser.export,
)
@try_except
@@ -837,7 +845,6 @@ Other Sources:
@try_except
def key_metrics_explained(other_args: List[str]):
"""Key metrics explained
Parameters
----------
other_args : List[str]
@@ -867,7 +874,6 @@ def key_metrics_explained(other_args: List[str]):
def menu(ticker: str, start: str, interval: str, suffix: str = ""):
"""Fundamental Analysis menu
Parameters
----------
ticker : str

View File

@@ -3,17 +3,18 @@ __docformat__ = "numpy"
import os
import webbrowser
import matplotlib.pyplot as plt
import pandas as pd
from tabulate import tabulate
from gamestonk_terminal.stocks.fundamental_analysis import yahoo_finance_model
from gamestonk_terminal import feature_flags as gtff
from gamestonk_terminal.helper_funcs import export_data
from gamestonk_terminal.helper_funcs import export_data, plot_autoscale
from gamestonk_terminal.config_plot import PLOT_DPI
def open_headquarters_map(ticker: str):
"""Headquarters location of the company
Parameters
----------
ticker : str
@@ -25,7 +26,6 @@ def open_headquarters_map(ticker: str):
def open_web(ticker: str):
"""Website of the company
Parameters
----------
ticker : str
@@ -37,7 +37,6 @@ def open_web(ticker: str):
def display_info(ticker: str):
"""Yahoo Finance ticker info
Parameters
----------
ticker : str
@@ -64,7 +63,6 @@ def display_info(ticker: str):
def display_shareholders(ticker: str):
"""Yahoo Finance ticker shareholders
Parameters
----------
ticker : str
@@ -92,7 +90,6 @@ def display_shareholders(ticker: str):
def display_sustainability(ticker: str):
"""Yahoo Finance ticker sustainability
Parameters
----------
other_args : List[str]
@@ -123,7 +120,6 @@ def display_sustainability(ticker: str):
def display_calendar_earnings(ticker: str):
"""Yahoo Finance ticker calendar earnings
Parameters
----------
ticker : str
@@ -147,15 +143,16 @@ def display_calendar_earnings(ticker: str):
print("")
def display_dividends(ticker: str, num: int = 12, export: str = ""):
def display_dividends(ticker: str, num: int = 12, plot: bool = False, export: str = ""):
"""Display historical dividends
Parameters
----------
ticker: str
Stock ticker
num: int
Number to show
plot: bool
Plots hitsorical data
export: str
Format to export data
"""
@@ -165,19 +162,44 @@ def display_dividends(ticker: str, num: int = 12, export: str = ""):
return
div_history["Dif"] = div_history.diff()
div_history = div_history[::-1]
div_history.index = pd.to_datetime(div_history.index, format="%Y%m%d").strftime(
"%Y-%m-%d"
)
if gtff.USE_TABULATE_DF:
print(
tabulate(
div_history.head(num),
tablefmt="fancy_grid",
headers=["Amount Paid ($)", "Change"],
floatfmt=".2f",
)
if plot:
fig, ax = plt.subplots(
figsize=plot_autoscale(), constrained_layout=False, dpi=PLOT_DPI
)
ax.plot(
div_history.index,
div_history["Dividends"],
ls="-",
linewidth=0.75,
marker=".",
markersize=4,
mfc="k",
mec="k",
c="k",
alpha=1,
)
ax.set_xlabel("Date")
ax.set_ylabel("Amount ($)")
ax.set_title(f"Dividend History for {ticker}")
ax.set_xlim(div_history.index[-1], div_history.index[0])
if gtff.USE_ION:
plt.ion()
fig.tight_layout()
plt.show()
else:
print(div_history.to_string())
div_history.index = pd.to_datetime(div_history.index, format="%Y%m%d").strftime(
"%Y-%m-%d"
)
if gtff.USE_TABULATE_DF:
print(
tabulate(
div_history.head(num),
tablefmt="fancy_grid",
headers=["Amount Paid ($)", "Change"],
floatfmt=".2f",
)
)
else:
print(div_history.to_string())
print("")
export_data(export, os.path.dirname(os.path.abspath(__file__)), "divs", div_history)

View File

@@ -5,7 +5,6 @@ Fundamental Analysis:
q quit this menu, and shows back to main menu
quit quit to abandon program
load load a new ticker
Ticker: TSLA
data fundamental and technical data of company [FinViz]

View File

@@ -5,7 +5,6 @@ Fundamental Analysis:
q quit this menu, and shows back to main menu
quit quit to abandon program
load load a new ticker
Ticker: TSLA
data fundamental and technical data of company [FinViz]

View File

@@ -5,7 +5,6 @@ Fundamental Analysis:
q quit this menu, and shows back to main menu
quit quit to abandon program
load load a new ticker
Ticker:
data fundamental and technical data of company [FinViz]

View File

@@ -5,7 +5,6 @@ Fundamental Analysis:
q quit this menu, and shows back to main menu
quit quit to abandon program
load load a new ticker
Ticker:
data fundamental and technical data of company [FinViz]