From 984fc67b73bce48931adef10824b54b74247242c Mon Sep 17 00:00:00 2001 From: didier Date: Sat, 6 Mar 2021 11:38:21 +0000 Subject: [PATCH 1/8] Improve TA plotting, dont block plots --- .../business_insider_api.py | 6 +- gamestonk_terminal/helper_funcs.py | 66 +--- .../prediction_techniques/arima.py | 29 +- .../technical_analysis/momentum.py | 344 +++++++----------- .../technical_analysis/overlap.py | 185 +++++----- .../technical_analysis/ta_menu.py | 27 +- .../technical_analysis/trend.py | 113 +++--- .../technical_analysis/volatility.py | 94 ++--- .../technical_analysis/volume.py | 171 ++++----- 9 files changed, 393 insertions(+), 642 deletions(-) diff --git a/gamestonk_terminal/fundamental_analysis/business_insider_api.py b/gamestonk_terminal/fundamental_analysis/business_insider_api.py index eaad59dd5b7..4f52b474c94 100644 --- a/gamestonk_terminal/fundamental_analysis/business_insider_api.py +++ b/gamestonk_terminal/fundamental_analysis/business_insider_api.py @@ -91,7 +91,11 @@ def management(l_args, s_ticker): for ind in df_management.index: s_name = f"{ind}{(max([len(x) for x in df_management.index])-len(ind))*' '}" - s_title = f"{df_management['Title'][ind]}{(max([len(x) for x in df_management['Title']])-len(df_management['Title'][ind]))*' '}" + spacing = ( + max([len(x) for x in df_management["Title"]]) + - len(df_management["Title"][ind]) + ) * " " + s_title = f"{df_management['Title'][ind]}{spacing}" s_management = f"""{s_name} {s_title} {df_management['Info'][ind]}""" print(s_management) if df_management["Insider Activity"][ind] not in "-": diff --git a/gamestonk_terminal/helper_funcs.py b/gamestonk_terminal/helper_funcs.py index 7f9f21b0759..525616c0fe5 100644 --- a/gamestonk_terminal/helper_funcs.py +++ b/gamestonk_terminal/helper_funcs.py @@ -9,6 +9,9 @@ import matplotlib.pyplot as plt import pandas.io.formats.format from pandas._config.config import get_option from holidays import US as holidaysUS +from pandas.plotting import register_matplotlib_converters + +register_matplotlib_converters() def check_non_negative(value) -> int: @@ -51,69 +54,6 @@ def plot_view_stock(df, symbol): print("") -def plot_stock_ta(df_stock, s_ticker, df_ta, s_ta): - plt.plot(df_stock.index, df_stock.values, color="k") - plt.plot(df_ta.index, df_ta.values) - plt.title(f"{s_ta} on {s_ticker}") - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.xlabel("Time") - plt.ylabel("Share Price ($)") - # Pandas series - if len(df_ta.shape) == 1: - l_legend = [s_ticker, s_ta] - # Pandas dataframe - else: - l_legend = df_ta.columns.tolist() - l_legend.insert(0, s_ticker) - plt.legend(l_legend) - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.show() - print("") - - -def plot_stock_and_ta(df_stock, s_ticker, df_ta, s_ta): - _, axPrice = plt.subplots() - plt.title(f"{s_ta} on {s_ticker}") - plt.plot(df_stock.index, df_stock.values, "k", lw=3) - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.xlabel("Time") - plt.ylabel(f"Share Price of {s_ticker} ($)") - axTa = axPrice.twinx() - plt.plot(df_ta.index, df_ta.values) - # Pandas series - if len(df_ta.shape) == 1: - l_legend = [s_ta] - # Pandas dataframe - else: - l_legend = df_ta.columns.tolist() - plt.legend(l_legend) - axTa.set_ylabel(s_ta, color="tab:blue") - axTa.spines["right"].set_color("tab:blue") - axTa.tick_params(axis="y", colors="tab:blue") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.show() - print("") - - -def plot_ta(s_ticker, df_ta, s_ta): - plt.plot(df_ta.index, df_ta.values) - plt.title(f"{s_ta} on {s_ticker}") - plt.xlim(df_ta.index[0], df_ta.index[-1]) - plt.xlabel("Time") - # plt.ylabel('Share Price ($)') - # if isinstance(df_ta, pd.DataFrame): - # plt.legend(df_ta.columns) - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.show() - print("") - - def b_is_stock_market_open() -> bool: """ checks if the stock market is open """ # Get current US time diff --git a/gamestonk_terminal/prediction_techniques/arima.py b/gamestonk_terminal/prediction_techniques/arima.py index a66cbf847ae..bcd33f8714a 100644 --- a/gamestonk_terminal/prediction_techniques/arima.py +++ b/gamestonk_terminal/prediction_techniques/arima.py @@ -4,24 +4,27 @@ import pandas as pd from pandas.plotting import register_matplotlib_converters import pmdarima from statsmodels.tsa.arima.model import ARIMA -from gamestonk_terminal.helper_funcs import check_positive, get_next_stock_market_days +from gamestonk_terminal.helper_funcs import ( + check_positive, + get_next_stock_market_days, + parse_known_args_and_warn, +) register_matplotlib_converters() -# -------------------------------------------------- ARIMA -------------------------------------------------- + # pylint: disable=unused-argument def arima(l_args, s_ticker, s_interval, df_stock): parser = argparse.ArgumentParser( prog="arima", description=""" - In statistics and econometrics, and in particular in time - series analysis, an autoregressive integrated moving average (ARIMA) model - is a generalization of an autoregressive moving average (ARMA) model. Both - of these models are fitted to time series data either to better understand - the data or to predict future points in the series (forecasting). - ARIMA(p,d,q) where parameters p, d, and q are non-negative integers, p is - the order (number of time lags) of the autoregressive model, d is the degree - of differencing (the number of times the data have had past values subtracted), + In statistics and econometrics, and in particular in time series analysis, an + autoregressive integrated moving average (ARIMA) model is a generalization of an + autoregressive moving average (ARMA) model. Both of these models are fitted to time + series data either to better understand the data or to predict future points in the + series (forecasting). ARIMA(p,d,q) where parameters p, d, and q are non-negative + integers, p is the order (number of time lags) of the autoregressive model, d is the + degree of differencing (the number of times the data have had past values subtracted), and q is the order of the moving-average model. """, ) @@ -71,11 +74,7 @@ def arima(l_args, s_ticker, s_interval, df_stock): ) try: - (ns_parser, l_unknown_args) = parser.parse_known_args(l_args) - - if l_unknown_args: - print(f"The following args couldn't be interpreted: {l_unknown_args}\n") - return + ns_parser = parse_known_args_and_warn(parser, l_args) # Machine Learning model if ns_parser.s_order: diff --git a/gamestonk_terminal/technical_analysis/momentum.py b/gamestonk_terminal/technical_analysis/momentum.py index 566badfe539..f24df060607 100644 --- a/gamestonk_terminal/technical_analysis/momentum.py +++ b/gamestonk_terminal/technical_analysis/momentum.py @@ -2,11 +2,11 @@ import argparse import matplotlib.pyplot as plt import pandas_ta as ta from pandas.plotting import register_matplotlib_converters -from gamestonk_terminal.helper_funcs import check_positive +from gamestonk_terminal.helper_funcs import check_positive, parse_known_args_and_warn register_matplotlib_converters() -# ----------------------------------------------------- CCI ----------------------------------------------------- + def cci(l_args, s_ticker, s_interval, df_stock): parser = argparse.ArgumentParser( prog="cci", @@ -48,11 +48,7 @@ def cci(l_args, s_ticker, s_interval, df_stock): ) try: - (ns_parser, l_unknown_args) = parser.parse_known_args(l_args) - - if l_unknown_args: - print(f"The following args couldn't be interpreted: {l_unknown_args}\n") - return + ns_parser = parse_known_args_and_warn(parser, l_args) # Daily if s_interval == "1440min": @@ -65,30 +61,6 @@ def cci(l_args, s_ticker, s_interval, df_stock): offset=ns_parser.n_offset, ).dropna() - plt.subplot(211) - plt.title(f"Commodity Channel Index (CCI) on {s_ticker}") - plt.plot(df_stock.index, df_stock["5. adjusted close"].values, "k", lw=2) - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.ylabel("Share Price ($)") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.subplot(212) - plt.plot(df_ta.index, df_ta.values, "b", lw=2) - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.axhspan(100, plt.gca().get_ylim()[1], facecolor="r", alpha=0.2) - plt.axhspan(plt.gca().get_ylim()[0], -100, facecolor="g", alpha=0.2) - plt.axhline(100, linewidth=3, color="r", ls="--") - plt.axhline(-100, linewidth=3, color="g", ls="--") - plt.xlabel("Time") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.gca().twinx() - plt.ylim(plt.gca().get_ylim()) - plt.yticks([0.2, 0.8], ("OVERSOLD", "OVERBOUGHT")) - plt.show() - # Intraday else: df_ta = ta.cci( @@ -100,29 +72,35 @@ def cci(l_args, s_ticker, s_interval, df_stock): offset=ns_parser.n_offset, ).dropna() - plt.subplot(211) - plt.title(f"Commodity Channel Index (CCI) on {s_ticker}") + plt.figure() + plt.subplot(211) + plt.title(f"Commodity Channel Index (CCI) on {s_ticker}") + if s_interval == "1440min": + plt.plot(df_stock.index, df_stock["5. adjusted close"].values, "k", lw=2) + else: plt.plot(df_stock.index, df_stock["4. close"].values, "k", lw=2) - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.ylabel("Share Price ($)") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.subplot(212) - plt.plot(df_ta.index, df_ta.values, "b", lw=2) - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.axhspan(100, plt.gca().get_ylim()[1], facecolor="r", alpha=0.2) - plt.axhspan(plt.gca().get_ylim()[0], -100, facecolor="g", alpha=0.2) - plt.axhline(100, linewidth=3, color="r", ls="--") - plt.axhline(-100, linewidth=3, color="g", ls="--") - plt.xlabel("Time") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.gca().twinx() - plt.ylim(plt.gca().get_ylim()) - plt.yticks([0.2, 0.8], ("OVERSOLD", "OVERBOUGHT")) - plt.show() + plt.xlim(df_stock.index[0], df_stock.index[-1]) + plt.ylabel("Share Price ($)") + plt.grid(b=True, which="major", color="#666666", linestyle="-") + plt.minorticks_on() + plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) + plt.subplot(212) + plt.plot(df_ta.index, df_ta.values, "b", lw=2) + plt.xlim(df_stock.index[0], df_stock.index[-1]) + plt.axhspan(100, plt.gca().get_ylim()[1], facecolor="r", alpha=0.2) + plt.axhspan(plt.gca().get_ylim()[0], -100, facecolor="g", alpha=0.2) + plt.axhline(100, linewidth=3, color="r", ls="--") + plt.axhline(-100, linewidth=3, color="g", ls="--") + plt.xlabel("Time") + plt.grid(b=True, which="major", color="#666666", linestyle="-") + plt.minorticks_on() + plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) + plt.gca().twinx() + plt.ylim(plt.gca().get_ylim()) + plt.yticks([0.2, 0.8], ("OVERSOLD", "OVERBOUGHT")) + plt.ion() + plt.show() + print("") except Exception as e: @@ -130,7 +108,6 @@ def cci(l_args, s_ticker, s_interval, df_stock): print("") -# ----------------------------------------------------- MACD ----------------------------------------------------- def macd(l_args, s_ticker, s_interval, df_stock): parser = argparse.ArgumentParser( prog="macd", @@ -184,11 +161,7 @@ def macd(l_args, s_ticker, s_interval, df_stock): ) try: - (ns_parser, l_unknown_args) = parser.parse_known_args(l_args) - - if l_unknown_args: - print(f"The following args couldn't be interpreted: {l_unknown_args}\n") - return + ns_parser = parse_known_args_and_warn(parser, l_args) # Daily if s_interval == "1440min": @@ -200,32 +173,6 @@ def macd(l_args, s_ticker, s_interval, df_stock): offset=ns_parser.n_offset, ).dropna() - plt.subplot(211) - plt.title(f"Moving Average Convergence Divergence (MACD) on {s_ticker}") - plt.plot(df_stock.index, df_stock["4. close"].values, "k", lw=2) - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.ylabel("Share Price ($)") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.subplot(212) - plt.plot(df_ta.index, df_ta.iloc[:, 0].values, "b", lw=2) - plt.plot(df_ta.index, df_ta.iloc[:, 2].values, "r", lw=2) - plt.bar(df_ta.index, df_ta.iloc[:, 1].values, color="g") - plt.legend( - [ - f"MACD Line {df_ta.columns[0]}", - f"Signal Line {df_ta.columns[2]}", - f"Histogram {df_ta.columns[1]}", - ] - ) - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.xlabel("Time") - plt.show() - # Intraday else: df_ta = ta.macd( @@ -236,31 +183,36 @@ def macd(l_args, s_ticker, s_interval, df_stock): offset=ns_parser.n_offset, ).dropna() - plt.subplot(211) - plt.title(f"Moving Average Convergence Divergence (MACD) on {s_ticker}") + plt.figure() + plt.subplot(211) + plt.title(f"Moving Average Convergence Divergence (MACD) on {s_ticker}") + if s_interval == "1440min": + plt.plot(df_stock.index, df_stock["5. adjusted close"].values, "k", lw=2) + else: plt.plot(df_stock.index, df_stock["4. close"].values, "k", lw=2) - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.ylabel("Share Price ($)") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.subplot(212) - plt.plot(df_ta.index, df_ta.iloc[:, 0].values, "b", lw=2) - plt.plot(df_ta.index, df_ta.iloc[:, 2].values, "r", lw=2) - plt.bar(df_ta.index, df_ta.iloc[:, 1].values, color="g") - plt.legend( - [ - f"MACD Line {df_ta.columns[0]}", - f"Signal Line {df_ta.columns[2]}", - f"Histogram {df_ta.columns[1]}", - ] - ) - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.xlabel("Time") - plt.show() + plt.xlim(df_stock.index[0], df_stock.index[-1]) + plt.ylabel("Share Price ($)") + plt.grid(b=True, which="major", color="#666666", linestyle="-") + plt.minorticks_on() + plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) + plt.subplot(212) + plt.plot(df_ta.index, df_ta.iloc[:, 0].values, "b", lw=2) + plt.plot(df_ta.index, df_ta.iloc[:, 2].values, "r", lw=2) + plt.bar(df_ta.index, df_ta.iloc[:, 1].values, color="g") + plt.legend( + [ + f"MACD Line {df_ta.columns[0]}", + f"Signal Line {df_ta.columns[2]}", + f"Histogram {df_ta.columns[1]}", + ] + ) + plt.xlim(df_stock.index[0], df_stock.index[-1]) + plt.grid(b=True, which="major", color="#666666", linestyle="-") + plt.minorticks_on() + plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) + plt.xlabel("Time") + plt.ion() + plt.show() print("") except Exception as e: @@ -268,7 +220,6 @@ def macd(l_args, s_ticker, s_interval, df_stock): print("") -# ----------------------------------------------------- RSI ----------------------------------------------------- def rsi(l_args, s_ticker, s_interval, df_stock): parser = argparse.ArgumentParser( prog="rsi", @@ -319,11 +270,7 @@ def rsi(l_args, s_ticker, s_interval, df_stock): ) try: - (ns_parser, l_unknown_args) = parser.parse_known_args(l_args) - - if l_unknown_args: - print(f"The following args couldn't be interpreted: {l_unknown_args}\n") - return + ns_parser = parse_known_args_and_warn(parser, l_args) # Daily if s_interval == "1440min": @@ -335,31 +282,6 @@ def rsi(l_args, s_ticker, s_interval, df_stock): offset=ns_parser.n_offset, ).dropna() - plt.subplot(211) - plt.plot(df_stock.index, df_stock["5. adjusted close"].values, "k", lw=2) - plt.title(f"Relative Strength Index (RSI) on {s_ticker}") - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.ylabel("Share Price ($)") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.subplot(212) - plt.plot(df_ta.index, df_ta.values, "b", lw=2) - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.axhspan(70, 100, facecolor="r", alpha=0.2) - plt.axhspan(0, 30, facecolor="g", alpha=0.2) - plt.axhline(70, linewidth=3, color="r", ls="--") - plt.axhline(30, linewidth=3, color="g", ls="--") - plt.xlabel("Time") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.ylim([0, 100]) - plt.gca().twinx() - plt.ylim(plt.gca().get_ylim()) - plt.yticks([0.15, 0.85], ("OVERSOLD", "OVERBOUGHT")) - plt.show() - # Intraday else: df_ta = ta.rsi( @@ -370,30 +292,36 @@ def rsi(l_args, s_ticker, s_interval, df_stock): offset=ns_parser.n_offset, ).dropna() - plt.subplot(211) + plt.figure() + plt.subplot(211) + if s_interval == "1440min": + plt.plot(df_stock.index, df_stock["5. adjusted close"].values, "k", lw=2) + else: plt.plot(df_stock.index, df_stock["4. close"].values, "k", lw=2) - plt.title(f"Relative Strength Index (RSI) on {s_ticker}") - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.ylabel("Share Price ($)") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.subplot(212) - plt.plot(df_ta.index, df_ta.values, "b", lw=2) - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.axhspan(70, 100, facecolor="r", alpha=0.2) - plt.axhspan(0, 30, facecolor="g", alpha=0.2) - plt.axhline(70, linewidth=3, color="r", ls="--") - plt.axhline(30, linewidth=3, color="g", ls="--") - plt.xlabel("Time") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.ylim([0, 100]) - plt.gca().twinx() - plt.ylim(plt.gca().get_ylim()) - plt.yticks([0.15, 0.85], ("OVERSOLD", "OVERBOUGHT")) - plt.show() + plt.title(f"Relative Strength Index (RSI) on {s_ticker}") + plt.xlim(df_stock.index[0], df_stock.index[-1]) + plt.ylabel("Share Price ($)") + plt.grid(b=True, which="major", color="#666666", linestyle="-") + plt.minorticks_on() + plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) + plt.subplot(212) + plt.plot(df_ta.index, df_ta.values, "b", lw=2) + plt.xlim(df_stock.index[0], df_stock.index[-1]) + plt.axhspan(70, 100, facecolor="r", alpha=0.2) + plt.axhspan(0, 30, facecolor="g", alpha=0.2) + plt.axhline(70, linewidth=3, color="r", ls="--") + plt.axhline(30, linewidth=3, color="g", ls="--") + plt.xlabel("Time") + plt.grid(b=True, which="major", color="#666666", linestyle="-") + plt.minorticks_on() + plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) + plt.ylim([0, 100]) + plt.gca().twinx() + plt.ylim(plt.gca().get_ylim()) + plt.yticks([0.15, 0.85], ("OVERSOLD", "OVERBOUGHT")) + plt.ion() + plt.show() + print("") except Exception as e: @@ -401,7 +329,6 @@ def rsi(l_args, s_ticker, s_interval, df_stock): print("") -# ----------------------------------------------------- STOCH ----------------------------------------------------- def stoch(l_args, s_ticker, s_interval, df_stock): parser = argparse.ArgumentParser( prog="stoch", @@ -452,11 +379,7 @@ def stoch(l_args, s_ticker, s_interval, df_stock): ) try: - (ns_parser, l_unknown_args) = parser.parse_known_args(l_args) - - if l_unknown_args: - print(f"The following args couldn't be interpreted: {l_unknown_args}\n") - return + ns_parser = parse_known_args_and_warn(parser, l_args) # Daily if s_interval == "1440min": @@ -470,33 +393,6 @@ def stoch(l_args, s_ticker, s_interval, df_stock): offset=ns_parser.n_offset, ).dropna() - plt.subplot(211) - plt.plot(df_stock.index, df_stock["5. adjusted close"].values, "k", lw=2) - plt.title(f"Stochastic Relative Strength Index (STOCH RSI) on {s_ticker}") - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.ylabel("Share Price ($)") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.subplot(212) - plt.plot(df_ta.index, df_ta.iloc[:, 0].values, "k", lw=2) - plt.plot(df_ta.index, df_ta.iloc[:, 1].values, "b", lw=2, ls="--") - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.axhspan(80, 100, facecolor="r", alpha=0.2) - plt.axhspan(0, 20, facecolor="g", alpha=0.2) - plt.axhline(80, linewidth=3, color="r", ls="--") - plt.axhline(20, linewidth=3, color="g", ls="--") - plt.legend([f"%K {df_ta.columns[0]}", f"%D {df_ta.columns[1]}"]) - plt.xlabel("Time") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.ylim([0, 100]) - plt.gca().twinx() - plt.ylim(plt.gca().get_ylim()) - plt.yticks([0.1, 0.9], ("OVERSOLD", "OVERBOUGHT")) - plt.show() - # Intraday else: df_ta = ta.stoch( @@ -509,32 +405,38 @@ def stoch(l_args, s_ticker, s_interval, df_stock): offset=ns_parser.n_offset, ).dropna() - plt.subplot(211) + plt.figure() + plt.subplot(211) + if s_interval == "1440min": + plt.plot(df_stock.index, df_stock["5. adjusted close"].values, "k", lw=2) + else: plt.plot(df_stock.index, df_stock["4. close"].values, "k", lw=2) - plt.title(f"Stochastic Relative Strength Index (STOCH RSI) on {s_ticker}") - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.ylabel("Share Price ($)") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.subplot(212) - plt.plot(df_ta.index, df_ta.iloc[:, 0].values, "k", lw=2) - plt.plot(df_ta.index, df_ta.iloc[:, 1].values, "b", lw=2, ls="--") - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.axhspan(80, 100, facecolor="r", alpha=0.2) - plt.axhspan(0, 20, facecolor="g", alpha=0.2) - plt.axhline(80, linewidth=3, color="r", ls="--") - plt.axhline(20, linewidth=3, color="g", ls="--") - plt.legend([f"%K {df_ta.columns[0]}", f"%D {df_ta.columns[1]}"]) - plt.xlabel("Time") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.ylim([0, 100]) - plt.gca().twinx() - plt.ylim(plt.gca().get_ylim()) - plt.yticks([0.1, 0.9], ("OVERSOLD", "OVERBOUGHT")) - plt.show() + plt.title(f"Stochastic Relative Strength Index (STOCH RSI) on {s_ticker}") + plt.xlim(df_stock.index[0], df_stock.index[-1]) + plt.ylabel("Share Price ($)") + plt.grid(b=True, which="major", color="#666666", linestyle="-") + plt.minorticks_on() + plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) + plt.subplot(212) + plt.plot(df_ta.index, df_ta.iloc[:, 0].values, "k", lw=2) + plt.plot(df_ta.index, df_ta.iloc[:, 1].values, "b", lw=2, ls="--") + plt.xlim(df_stock.index[0], df_stock.index[-1]) + plt.axhspan(80, 100, facecolor="r", alpha=0.2) + plt.axhspan(0, 20, facecolor="g", alpha=0.2) + plt.axhline(80, linewidth=3, color="r", ls="--") + plt.axhline(20, linewidth=3, color="g", ls="--") + plt.legend([f"%K {df_ta.columns[0]}", f"%D {df_ta.columns[1]}"]) + plt.xlabel("Time") + plt.grid(b=True, which="major", color="#666666", linestyle="-") + plt.minorticks_on() + plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) + plt.ylim([0, 100]) + plt.gca().twinx() + plt.ylim(plt.gca().get_ylim()) + plt.yticks([0.1, 0.9], ("OVERSOLD", "OVERBOUGHT")) + plt.ion() + plt.show() + print("") except Exception as e: diff --git a/gamestonk_terminal/technical_analysis/overlap.py b/gamestonk_terminal/technical_analysis/overlap.py index bc433b0a532..8e6ba2db373 100644 --- a/gamestonk_terminal/technical_analysis/overlap.py +++ b/gamestonk_terminal/technical_analysis/overlap.py @@ -2,12 +2,11 @@ import argparse import matplotlib.pyplot as plt import pandas_ta as ta from pandas.plotting import register_matplotlib_converters -from gamestonk_terminal.helper_funcs import check_positive, plot_stock_ta +from gamestonk_terminal.helper_funcs import check_positive, parse_known_args_and_warn register_matplotlib_converters() -# ----------------------------------------------------- EMA ----------------------------------------------------- def ema(l_args, s_ticker, s_interval, df_stock): parser = argparse.ArgumentParser( prog="ema", @@ -43,11 +42,7 @@ def ema(l_args, s_ticker, s_interval, df_stock): ) try: - (ns_parser, l_unknown_args) = parser.parse_known_args(l_args) - - if l_unknown_args: - print(f"The following args couldn't be interpreted: {l_unknown_args}\n") - return + ns_parser = parse_known_args_and_warn(parser, l_args) # Daily if s_interval == "1440min": @@ -56,12 +51,6 @@ def ema(l_args, s_ticker, s_interval, df_stock): length=ns_parser.n_length, offset=ns_parser.n_offset, ).dropna() - plot_stock_ta( - df_stock["5. adjusted close"], - s_ticker, - df_ta, - f"{ns_parser.n_length} EMA", - ) # Intraday else: @@ -70,16 +59,49 @@ def ema(l_args, s_ticker, s_interval, df_stock): length=ns_parser.n_length, offset=ns_parser.n_offset, ).dropna() - plot_stock_ta( - df_stock["4. close"], s_ticker, df_ta, f"{ns_parser.n_length} EMA" + + _, axPrice = plt.subplots() + plt.title(f"{ns_parser.n_length} EMA on {s_ticker}") + if s_interval == "1440min": + plt.plot( + df_stock["5. adjusted close"].index, + df_stock["5. adjusted close"].values, + "k", + lw=3, ) + plt.xlim( + df_stock["5. adjusted close"].index[0], + df_stock["5. adjusted close"].index[-1], + ) + else: + plt.plot(df_stock["4. close"].index, df_stock["4. close"].values, "k", lw=3) + plt.xlim(df_stock["4. close"].index[0], df_stock["4. close"].index[-1]) + plt.xlabel("Time") + plt.ylabel(f"Share Price of {s_ticker} ($)") + axTa = axPrice.twinx() + plt.plot(df_ta.index, df_ta.values) + # Pandas series + if len(df_ta.shape) == 1: + l_legend = ["{ns_parser.n_length} EMA"] + # Pandas dataframe + else: + l_legend = df_ta.columns.tolist() + plt.legend(l_legend) + axTa.set_ylabel("{ns_parser.n_length} EMA", color="tab:blue") + axTa.spines["right"].set_color("tab:blue") + axTa.tick_params(axis="y", colors="tab:blue") + plt.grid(b=True, which="major", color="#666666", linestyle="-") + plt.minorticks_on() + plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) + plt.ion() + plt.show() + print("") except Exception as e: print(e) print("") -# ----------------------------------------------------- SMA ----------------------------------------------------- def sma(l_args, s_ticker, s_interval, df_stock): parser = argparse.ArgumentParser( prog="sma", @@ -113,55 +135,38 @@ def sma(l_args, s_ticker, s_interval, df_stock): ) try: - (ns_parser, l_unknown_args) = parser.parse_known_args(l_args) + ns_parser = parse_known_args_and_warn(parser, l_args) - if l_unknown_args: - print(f"The following args couldn't be interpreted: {l_unknown_args}\n") - return - - # Daily + plt.figure() if s_interval == "1440min": plt.plot(df_stock.index, df_stock["5. adjusted close"].values, color="k") - l_legend = list() - l_legend.append(s_ticker) - for length in ns_parser.l_length: + else: + plt.plot(df_stock.index, df_stock["4. close"].values, color="k") + l_legend = list() + l_legend.append(s_ticker) + for length in ns_parser.l_length: + if s_interval == "1440min": df_ta = ta.sma( df_stock["5. adjusted close"], length=length, offset=ns_parser.n_offset, ).dropna() - plt.plot(df_ta.index, df_ta.values) - l_legend.append(f"{length} SMA") - plt.title(f"SMA on {s_ticker}") - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.xlabel("Time") - plt.ylabel("Share Price ($)") - plt.legend(l_legend) - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.show() - - # Intraday - else: - plt.plot(df_stock.index, df_stock["4. close"].values, color="k") - l_legend = list() - l_legend.append(s_ticker) - for length in ns_parser.n_length: + else: df_ta = ta.sma( df_stock["4. close"], length=length, offset=ns_parser.n_offset ).dropna() - plt.plot(df_ta.index, df_ta.values) - l_legend.append(f"{length} SMA") - plt.title(f"SMA on {s_ticker}") - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.xlabel("Time") - plt.ylabel("Share Price ($)") - plt.legend(l_legend) - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.show() + plt.plot(df_ta.index, df_ta.values) + l_legend.append(f"{length} SMA") + plt.title(f"SMA on {s_ticker}") + plt.xlim(df_stock.index[0], df_stock.index[-1]) + plt.xlabel("Time") + plt.ylabel("Share Price ($)") + plt.legend(l_legend) + plt.grid(b=True, which="major", color="#666666", linestyle="-") + plt.minorticks_on() + plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) + plt.ion() + plt.show() print("") except Exception as e: @@ -169,7 +174,6 @@ def sma(l_args, s_ticker, s_interval, df_stock): print("") -# ----------------------------------------------------- VWAP ----------------------------------------------------- def vwap(l_args, s_ticker, s_interval, df_stock): parser = argparse.ArgumentParser( prog="vwap", @@ -190,11 +194,7 @@ def vwap(l_args, s_ticker, s_interval, df_stock): ) try: - (ns_parser, l_unknown_args) = parser.parse_known_args(l_args) - - if l_unknown_args: - print(f"The following args couldn't be interpreted: {l_unknown_args}\n") - return + ns_parser = parse_known_args_and_warn(parser, l_args) # Daily if s_interval == "1440min": @@ -206,30 +206,6 @@ def vwap(l_args, s_ticker, s_interval, df_stock): offset=ns_parser.n_offset, ) - _, axPrice = plt.subplots() - plt.plot(df_stock.index, df_stock["5. adjusted close"].values, color="k") - plt.plot(df_ta.index, df_ta.values) - plt.title(f"VWAP on {s_ticker}") - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.xlabel("Time") - plt.ylabel("Share Price ($)") - plt.legend([s_ticker, "VWAP"]) - # pylint: disable=unused-variable - axVolume = axPrice.twinx() - plt.bar( - df_stock.index, - df_stock["6. volume"].values, - color="k", - alpha=0.8, - width=0.3, - ) - plt.ylabel("Volume") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.show() - print("") - # Intraday else: df_ta = ta.vwap( @@ -240,15 +216,27 @@ def vwap(l_args, s_ticker, s_interval, df_stock): offset=ns_parser.n_offset, ) - _, axPrice = plt.subplots() + _, axPrice = plt.subplots() + if s_interval == "1440min": + plt.plot(df_stock.index, df_stock["5. adjusted close"].values, color="k") + else: plt.plot(df_stock.index, df_stock["4. close"].values, color="k") - plt.plot(df_ta.index, df_ta.values) - plt.title(f"VWAP on {s_ticker}") - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.xlabel("Time") - plt.ylabel("Share Price ($)") - plt.legend([s_ticker, "VWAP"]) - axVolume = axPrice.twinx() + plt.plot(df_ta.index, df_ta.values) + plt.title(f"VWAP on {s_ticker}") + plt.xlim(df_stock.index[0], df_stock.index[-1]) + plt.xlabel("Time") + plt.ylabel("Share Price ($)") + plt.legend([s_ticker, "VWAP"]) + _ = axPrice.twinx() + if s_interval == "1440min": + plt.bar( + df_stock.index, + df_stock["6. volume"].values, + color="k", + alpha=0.8, + width=0.3, + ) + else: plt.bar( df_stock.index, df_stock["5. volume"].values, @@ -256,12 +244,13 @@ def vwap(l_args, s_ticker, s_interval, df_stock): alpha=0.8, width=0.3, ) - plt.ylabel("Volume") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.show() - print("") + plt.ylabel("Volume") + plt.grid(b=True, which="major", color="#666666", linestyle="-") + plt.minorticks_on() + plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) + plt.ion() + plt.show() + print("") except Exception as e: print(e) diff --git a/gamestonk_terminal/technical_analysis/ta_menu.py b/gamestonk_terminal/technical_analysis/ta_menu.py index 288a4500a57..a78cc074793 100644 --- a/gamestonk_terminal/technical_analysis/ta_menu.py +++ b/gamestonk_terminal/technical_analysis/ta_menu.py @@ -5,9 +5,9 @@ from gamestonk_terminal.technical_analysis import momentum as ta_momentum from gamestonk_terminal.technical_analysis import trend as ta_trend from gamestonk_terminal.technical_analysis import volatility as ta_volatility from gamestonk_terminal.technical_analysis import volume as ta_volume +import matplotlib.pyplot as plt -# ----------------------------------------------------------------------------------------------------------------------- def print_technical_analysis(s_ticker, s_start, s_interval): """ Print help """ @@ -42,7 +42,6 @@ def print_technical_analysis(s_ticker, s_start, s_interval): print("") -# ---------------------------------------------------- MENU ---------------------------------------------------- def ta_menu(df_stock, s_ticker, s_start, s_interval): # Add list of arguments that the technical analysis parser accepts @@ -55,18 +54,18 @@ def ta_menu(df_stock, s_ticker, s_start, s_interval): "quit", "ema", "sma", - "vwap", # overlap + "vwap", "cci", "macd", "rsi", - "stoch", # momentum + "stoch", "adx", - "aroon", # trend - "bbands", # volatility + "aroon", + "bbands", "ad", "obv", ], - ) # volume + ) print_technical_analysis(s_ticker, s_start, s_interval) @@ -75,6 +74,9 @@ def ta_menu(df_stock, s_ticker, s_start, s_interval): # Get input command from user as_input = input("> ") + # Images are non blocking - allows to close them if we type other command + plt.close() + # Parse fundamental analysis command of the list of possible commands try: (ns_known_args, l_args) = ta_parser.parse_known_args(as_input.split()) @@ -94,7 +96,7 @@ def ta_menu(df_stock, s_ticker, s_start, s_interval): # Abandon the program return True - # -------------------------------------------------- OVERLAP -------------------------------------------------- + # OVERLAP elif ns_known_args.cmd == "ema": ta_overlap.ema(l_args, s_ticker, s_interval, df_stock) @@ -104,7 +106,7 @@ def ta_menu(df_stock, s_ticker, s_start, s_interval): elif ns_known_args.cmd == "vwap": ta_overlap.vwap(l_args, s_ticker, s_interval, df_stock) - # --------------------------------------------------- MOMENTUM --------------------------------------------------- + # MOMENTUM elif ns_known_args.cmd == "cci": ta_momentum.cci(l_args, s_ticker, s_interval, df_stock) @@ -117,24 +119,23 @@ def ta_menu(df_stock, s_ticker, s_start, s_interval): elif ns_known_args.cmd == "stoch": ta_momentum.stoch(l_args, s_ticker, s_interval, df_stock) - # ---------------------------------------------------- TREND ---------------------------------------------------- + # TREND elif ns_known_args.cmd == "adx": ta_trend.adx(l_args, s_ticker, s_interval, df_stock) elif ns_known_args.cmd == "aroon": ta_trend.aroon(l_args, s_ticker, s_interval, df_stock) - # -------------------------------------------------- VOLATILITY -------------------------------------------------- + # VOLATILITY elif ns_known_args.cmd == "bbands": ta_volatility.bbands(l_args, s_ticker, s_interval, df_stock) - # ---------------------------------------------------- VOLUME ---------------------------------------------------- + # VOLUME elif ns_known_args.cmd == "ad": ta_volume.ad(l_args, s_ticker, s_interval, df_stock) elif ns_known_args.cmd == "obv": ta_volume.obv(l_args, s_ticker, s_interval, df_stock) - # ------------------------------------------------------------------------------------------------------------ else: print("Command not recognized!") diff --git a/gamestonk_terminal/technical_analysis/trend.py b/gamestonk_terminal/technical_analysis/trend.py index 766247141e7..654e28e1d4a 100644 --- a/gamestonk_terminal/technical_analysis/trend.py +++ b/gamestonk_terminal/technical_analysis/trend.py @@ -2,11 +2,11 @@ import argparse import matplotlib.pyplot as plt import pandas_ta as ta from pandas.plotting import register_matplotlib_converters -from gamestonk_terminal.helper_funcs import check_positive +from gamestonk_terminal.helper_funcs import check_positive, parse_known_args_and_warn register_matplotlib_converters() -# ----------------------------------------------------- ADX ----------------------------------------------------- + def adx(l_args, s_ticker, s_interval, df_stock): parser = argparse.ArgumentParser( prog="adx", @@ -55,11 +55,7 @@ def adx(l_args, s_ticker, s_interval, df_stock): ) try: - (ns_parser, l_unknown_args) = parser.parse_known_args(l_args) - - if l_unknown_args: - print(f"The following args couldn't be interpreted: {l_unknown_args}\n") - return + ns_parser = parse_known_args_and_warn(parser, l_args) # Daily if s_interval == "1440min": @@ -73,34 +69,6 @@ def adx(l_args, s_ticker, s_interval, df_stock): offset=ns_parser.n_offset, ).dropna() - plt.subplot(211) - plt.plot(df_stock.index, df_stock["5. adjusted close"].values, "k", lw=2) - plt.title(f"Average Directional Movement Index (ADX) on {s_ticker}") - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.ylabel("Share Price ($)") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.subplot(212) - plt.plot(df_ta.index, df_ta.iloc[:, 0].values, "b", lw=2) - plt.plot(df_ta.index, df_ta.iloc[:, 1].values, "g", lw=1) - plt.plot(df_ta.index, df_ta.iloc[:, 2].values, "r", lw=1) - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.axhline(25, linewidth=3, color="k", ls="--") - plt.legend( - [ - f"ADX ({df_ta.columns[0]})", - f"+DI ({df_ta.columns[1]})", - f"- DI ({df_ta.columns[2]})", - ] - ) - plt.xlabel("Time") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.ylim([0, 100]) - plt.show() - # Intraday else: df_ta = ta.adx( @@ -113,33 +81,8 @@ def adx(l_args, s_ticker, s_interval, df_stock): offset=ns_parser.n_offset, ).dropna() - plt.subplot(211) - plt.plot(df_stock.index, df_stock["4. close"].values, "k", lw=2) - plt.title(f"Average Directional Movement Index (ADX) on {s_ticker}") - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.ylabel("Share Price ($)") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.subplot(212) - plt.plot(df_ta.index, df_ta.iloc[:, 0].values, "b", lw=2) - plt.plot(df_ta.index, df_ta.iloc[:, 1].values, "g", lw=1) - plt.plot(df_ta.index, df_ta.iloc[:, 2].values, "r", lw=1) - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.axhline(25, linewidth=3, color="k", ls="--") - plt.legend( - [ - f"ADX ({df_ta.columns[0]})", - f"+DI ({df_ta.columns[1]})", - f"- DI ({df_ta.columns[2]})", - ] - ) - plt.xlabel("Time") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.ylim([0, 100]) - plt.show() + plot_adx(df_stock, s_ticker, df_ta) + print("") except Exception as e: @@ -147,7 +90,38 @@ def adx(l_args, s_ticker, s_interval, df_stock): print("") -# ----------------------------------------------------- AROON ----------------------------------------------------- +def plot_adx(df_stock, s_ticker, df_ta): + plt.figure() + plt.subplot(211) + plt.plot(df_stock.index, df_stock["4. close"].values, "k", lw=2) + plt.title(f"Average Directional Movement Index (ADX) on {s_ticker}") + plt.xlim(df_stock.index[0], df_stock.index[-1]) + plt.ylabel("Share Price ($)") + plt.grid(b=True, which="major", color="#666666", linestyle="-") + plt.minorticks_on() + plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) + plt.subplot(212) + plt.plot(df_ta.index, df_ta.iloc[:, 0].values, "b", lw=2) + plt.plot(df_ta.index, df_ta.iloc[:, 1].values, "g", lw=1) + plt.plot(df_ta.index, df_ta.iloc[:, 2].values, "r", lw=1) + plt.xlim(df_stock.index[0], df_stock.index[-1]) + plt.axhline(25, linewidth=3, color="k", ls="--") + plt.legend( + [ + f"ADX ({df_ta.columns[0]})", + f"+DI ({df_ta.columns[1]})", + f"- DI ({df_ta.columns[2]})", + ] + ) + plt.xlabel("Time") + plt.grid(b=True, which="major", color="#666666", linestyle="-") + plt.minorticks_on() + plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) + plt.ylim([0, 100]) + plt.ion() + plt.show() + + def aroon(l_args, s_ticker, s_interval, df_stock): parser = argparse.ArgumentParser( prog="aroon", @@ -194,11 +168,7 @@ def aroon(l_args, s_ticker, s_interval, df_stock): ) try: - (ns_parser, l_unknown_args) = parser.parse_known_args(l_args) - - if l_unknown_args: - print(f"The following args couldn't be interpreted: {l_unknown_args}\n") - return + ns_parser = parse_known_args_and_warn(parser, l_args) df_ta = ta.aroon( high=df_stock["2. high"], @@ -208,21 +178,22 @@ def aroon(l_args, s_ticker, s_interval, df_stock): offset=ns_parser.n_offset, ).dropna() + plt.figure() plt.subplot(311) # Daily if s_interval == "1440min": - # plot_stock_and_ta(df_stock['5. adjusted close'], s_ticker, df_ta.iloc[:,-1], "AROON") plt.plot(df_stock.index, df_stock["5. adjusted close"].values, "k", lw=2) # Intraday else: - # plot_stock_and_ta(df_stock['4. close'], s_ticker, df_ta.iloc[:,-1], "AROON") plt.plot(df_stock.index, df_stock["4. close"].values, "k", lw=2) + plt.title(f"Aroon on {s_ticker}") plt.xlim(df_stock.index[0], df_stock.index[-1]) plt.ylabel("Share Price ($)") plt.grid(b=True, which="major", color="#666666", linestyle="-") plt.minorticks_on() plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) + plt.subplot(312) plt.plot(df_ta.index, df_ta.iloc[:, 0].values, "r", lw=2) plt.plot(df_ta.index, df_ta.iloc[:, 1].values, "g", lw=2) @@ -235,6 +206,7 @@ def aroon(l_args, s_ticker, s_interval, df_stock): plt.minorticks_on() plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) plt.ylim([0, 100]) + plt.subplot(313) plt.plot(df_ta.index, df_ta.iloc[:, 2].values, "b", lw=2) plt.xlabel("Time") @@ -243,6 +215,7 @@ def aroon(l_args, s_ticker, s_interval, df_stock): plt.minorticks_on() plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) plt.ylim([-100, 100]) + plt.ion() plt.show() print("") diff --git a/gamestonk_terminal/technical_analysis/volatility.py b/gamestonk_terminal/technical_analysis/volatility.py index a63b47e7c8d..c6ef28a0176 100644 --- a/gamestonk_terminal/technical_analysis/volatility.py +++ b/gamestonk_terminal/technical_analysis/volatility.py @@ -2,11 +2,11 @@ import argparse import matplotlib.pyplot as plt import pandas_ta as ta from pandas.plotting import register_matplotlib_converters -from gamestonk_terminal.helper_funcs import check_positive +from gamestonk_terminal.helper_funcs import check_positive, parse_known_args_and_warn register_matplotlib_converters() -# ----------------------------------------------------- BBANDS ----------------------------------------------------- + def bbands(l_args, s_ticker, s_interval, df_stock): parser = argparse.ArgumentParser( prog="bbands", @@ -14,13 +14,13 @@ def bbands(l_args, s_ticker, s_interval, df_stock): Bollinger Bands consist of three lines. The middle band is a simple moving average (generally 20 periods) of the typical price (TP). The upper and lower bands are F standard deviations (generally 2) above and below the middle band. - The bands widen and narrow when the volatility of the price is higher or lower, respectively. - \n \nBollinger Bands do not, in themselves, generate buy or sell signals; they are an - indicator of overbought or oversold conditions. When the price is near the upper or lower - band it indicates that a reversal may be imminent. The middle band becomes a support or - resistance level. The upper and lower bands can also be interpreted as price targets. - When the price bounces off of the lower band and crosses the middle band, then the - upper band becomes the price target. + The bands widen and narrow when the volatility of the price is higher or lower, + respectively. \n \nBollinger Bands do not, in themselves, generate buy or sell signals; + they are an indicator of overbought or oversold conditions. When the price is near the + upper or lower band it indicates that a reversal may be imminent. The middle band + becomes a support or resistance level. The upper and lower bands can also be + interpreted as price targets. When the price bounces off of the lower band and crosses + the middle band, then the upper band becomes the price target. """, ) @@ -56,11 +56,7 @@ def bbands(l_args, s_ticker, s_interval, df_stock): ) try: - (ns_parser, l_unknown_args) = parser.parse_known_args(l_args) - - if l_unknown_args: - print(f"The following args couldn't be interpreted: {l_unknown_args}\n") - return + ns_parser = parse_known_args_and_warn(parser, l_args) # Daily if s_interval == "1440min": @@ -71,30 +67,6 @@ def bbands(l_args, s_ticker, s_interval, df_stock): mamode=ns_parser.s_mamode, offset=ns_parser.n_offset, ).dropna() - # plot_stock_ta(df_stock['5. adjusted close'], s_ticker, df_ta, "BBANDS") - - plt.plot( - df_stock.index, df_stock["5. adjusted close"].values, color="k", lw=3 - ) - plt.plot(df_ta.index, df_ta.iloc[:, 0].values, "r", lw=2) - plt.plot(df_ta.index, df_ta.iloc[:, 1].values, "b", lw=1.5, ls="--") - plt.plot(df_ta.index, df_ta.iloc[:, 2].values, "g", lw=2) - plt.title(f"Bollinger Band (BBands) on {s_ticker}") - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.xlabel("Time") - plt.ylabel("Share Price ($)") - plt.legend([s_ticker, df_ta.columns[0], df_ta.columns[1], df_ta.columns[2]]) - plt.gca().fill_between( - df_ta.index, - df_ta.iloc[:, 0].values, - df_ta.iloc[:, 2].values, - alpha=0.1, - color="b", - ) - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.show() # Intraday else: @@ -105,28 +77,34 @@ def bbands(l_args, s_ticker, s_interval, df_stock): mamode=ns_parser.s_mamode, offset=ns_parser.n_offset, ).dropna() - # plot_stock_ta(df_stock['4. close'], s_ticker, df_ta, "BBANDS") - plt.plot(df_stock.index, df_stock["4. close"].values, color="k", lw=3) - plt.plot(df_ta.index, df_ta.iloc[:, 0].values, "r", lw=2) - plt.plot(df_ta.index, df_ta.iloc[:, 1].values, "b", lw=1.5, ls="--") - plt.plot(df_ta.index, df_ta.iloc[:, 2].values, "g", lw=2) - plt.title(f"Bollinger Band (BBands) on {s_ticker}") - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.xlabel("Time") - plt.ylabel("Share Price ($)") - plt.legend([s_ticker, df_ta.columns[0], df_ta.columns[1], df_ta.columns[2]]) - plt.gca().fill_between( - df_ta.index, - df_ta.iloc[:, 0].values, - df_ta.iloc[:, 2].values, - alpha=0.1, - color="b", + plt.figure() + if s_ticker == "1440min": + plt.plot( + df_stock.index, df_stock["5. adjusted close"].values, color="k", lw=3 ) - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.show() + else: + plt.plot(df_stock.index, df_stock["4. close"].values, color="k", lw=3) + plt.plot(df_ta.index, df_ta.iloc[:, 0].values, "r", lw=2) + plt.plot(df_ta.index, df_ta.iloc[:, 1].values, "b", lw=1.5, ls="--") + plt.plot(df_ta.index, df_ta.iloc[:, 2].values, "g", lw=2) + plt.title(f"Bollinger Band (BBands) on {s_ticker}") + plt.xlim(df_stock.index[0], df_stock.index[-1]) + plt.xlabel("Time") + plt.ylabel("Share Price ($)") + plt.legend([s_ticker, df_ta.columns[0], df_ta.columns[1], df_ta.columns[2]]) + plt.gca().fill_between( + df_ta.index, + df_ta.iloc[:, 0].values, + df_ta.iloc[:, 2].values, + alpha=0.1, + color="b", + ) + plt.grid(b=True, which="major", color="#666666", linestyle="-") + plt.minorticks_on() + plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) + plt.ion() + plt.show() print("") except Exception as e: diff --git a/gamestonk_terminal/technical_analysis/volume.py b/gamestonk_terminal/technical_analysis/volume.py index 63731605174..e8dc353e6ed 100644 --- a/gamestonk_terminal/technical_analysis/volume.py +++ b/gamestonk_terminal/technical_analysis/volume.py @@ -2,11 +2,11 @@ import argparse import matplotlib.pyplot as plt import pandas_ta as ta from pandas.plotting import register_matplotlib_converters -from gamestonk_terminal.helper_funcs import check_positive +from gamestonk_terminal.helper_funcs import check_positive, parse_known_args_and_warn register_matplotlib_converters() -# ------------------------------------------------------- AD ------------------------------------------------------- + def ad(l_args, s_ticker, s_interval, df_stock): parser = argparse.ArgumentParser( prog="ad", @@ -42,11 +42,7 @@ def ad(l_args, s_ticker, s_interval, df_stock): ) try: - (ns_parser, l_unknown_args) = parser.parse_known_args(l_args) - - if l_unknown_args: - print(f"The following args couldn't be interpreted: {l_unknown_args}\n") - return + ns_parser = parse_known_args_and_warn(parser, l_args) # Daily if s_interval == "1440min": @@ -70,34 +66,6 @@ def ad(l_args, s_ticker, s_interval, df_stock): offset=ns_parser.n_offset, ).dropna() - axPrice = plt.subplot(211) - plt.plot(df_stock.index, df_stock["5. adjusted close"].values, "k", lw=2) - plt.title(f"Accumulation/Distribution Line (AD) on {s_ticker}") - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.ylabel("Share Price ($)") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - # pylint: disable=unused-variable - axVolume = axPrice.twinx() - plt.bar( - df_stock.index, - df_stock["6. volume"].values, - color="k", - alpha=0.8, - width=0.3, - ) - plt.subplot(212) - plt.plot(df_ta.index, df_ta.values, "b", lw=1) - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.axhline(0, linewidth=2, color="k", ls="--") - plt.legend(["Chaikin Oscillator"]) - plt.xlabel("Time") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.show() - # Intraday else: # Use open stock values @@ -120,15 +88,28 @@ def ad(l_args, s_ticker, s_interval, df_stock): offset=ns_parser.n_offset, ).dropna() - axPrice = plt.subplot(211) + plt.figure() + axPrice = plt.subplot(211) + if s_interval == "1440min": + plt.plot(df_stock.index, df_stock["5. adjusted close"].values, "k", lw=2) + else: plt.plot(df_stock.index, df_stock["4. close"].values, "k", lw=2) - plt.title(f"Accumulation/Distribution Line (AD) on {s_ticker}") - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.ylabel("Share Price ($)") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - axVolume = axPrice.twinx() + plt.title(f"Accumulation/Distribution Line (AD) on {s_ticker}") + plt.xlim(df_stock.index[0], df_stock.index[-1]) + plt.ylabel("Share Price ($)") + plt.grid(b=True, which="major", color="#666666", linestyle="-") + plt.minorticks_on() + plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) + _ = axPrice.twinx() + if s_interval == "1440min": + plt.bar( + df_stock.index, + df_stock["6. volume"].values, + color="k", + alpha=0.8, + width=0.3, + ) + else: plt.bar( df_stock.index, df_stock["5. volume"].values, @@ -136,16 +117,17 @@ def ad(l_args, s_ticker, s_interval, df_stock): alpha=0.8, width=0.3, ) - plt.subplot(212) - plt.plot(df_ta.index, df_ta.values, "b", lw=1) - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.axhline(0, linewidth=2, color="k", ls="--") - plt.legend(["Chaikin Oscillator"]) - plt.xlabel("Time") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.show() + plt.subplot(212) + plt.plot(df_ta.index, df_ta.values, "b", lw=1) + plt.xlim(df_stock.index[0], df_stock.index[-1]) + plt.axhline(0, linewidth=2, color="k", ls="--") + plt.legend(["Chaikin Oscillator"]) + plt.xlabel("Time") + plt.grid(b=True, which="major", color="#666666", linestyle="-") + plt.minorticks_on() + plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) + plt.ion() + plt.show() print("") except Exception as e: @@ -154,7 +136,6 @@ def ad(l_args, s_ticker, s_interval, df_stock): return -# ------------------------------------------------------- OBV ------------------------------------------------------- def obv(l_args, s_ticker, s_interval, df_stock): parser = argparse.ArgumentParser( prog="obv", @@ -180,11 +161,7 @@ def obv(l_args, s_ticker, s_interval, df_stock): ) try: - (ns_parser, l_unknown_args) = parser.parse_known_args(l_args) - - if l_unknown_args: - print(f"The following args couldn't be interpreted: {l_unknown_args}\n") - return + ns_parser = parse_known_args_and_warn(parser, l_args) # Daily if s_interval == "1440min": @@ -194,33 +171,6 @@ def obv(l_args, s_ticker, s_interval, df_stock): offset=ns_parser.n_offset, ).dropna() - axPrice = plt.subplot(211) - plt.plot(df_stock.index, df_stock["5. adjusted close"].values, "k", lw=2) - plt.title(f"On-Balance Volume (OBV) on {s_ticker}") - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.ylabel("Share Price ($)") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - # pylint: disable=unused-variable - axVolume = axPrice.twinx() - plt.bar( - df_stock.index, - df_stock["6. volume"].values, - color="k", - alpha=0.8, - width=0.3, - ) - plt.subplot(212) - plt.plot(df_ta.index, df_ta.values, "b", lw=1) - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.legend(["OBV"]) - plt.xlabel("Time") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.show() - # Intraday else: df_ta = ta.obv( @@ -229,15 +179,29 @@ def obv(l_args, s_ticker, s_interval, df_stock): offset=ns_parser.n_offset, ).dropna() - axPrice = plt.subplot(211) + plt.figure() + axPrice = plt.subplot(211) + if s_interval == "1440min": plt.plot(df_stock.index, df_stock["5. adjusted close"].values, "k", lw=2) - plt.title(f"On-Balance Volume (OBV) on {s_ticker}") - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.ylabel("Share Price ($)") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - axVolume = axPrice.twinx() + else: + plt.plot(df_stock.index, df_stock["4. close"].values, "k", lw=2) + plt.title(f"On-Balance Volume (OBV) on {s_ticker}") + plt.xlim(df_stock.index[0], df_stock.index[-1]) + plt.ylabel("Share Price ($)") + plt.grid(b=True, which="major", color="#666666", linestyle="-") + plt.minorticks_on() + plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) + # pylint: disable=unused-variable + _ = axPrice.twinx() + if s_interval == "1440min": + plt.bar( + df_stock.index, + df_stock["6. volume"].values, + color="k", + alpha=0.8, + width=0.3, + ) + else: plt.bar( df_stock.index, df_stock["5. volume"].values, @@ -245,15 +209,16 @@ def obv(l_args, s_ticker, s_interval, df_stock): alpha=0.8, width=0.3, ) - plt.subplot(212) - plt.plot(df_ta.index, df_ta.values, "b", lw=1) - plt.xlim(df_stock.index[0], df_stock.index[-1]) - plt.legend(["OBV"]) - plt.xlabel("Time") - plt.grid(b=True, which="major", color="#666666", linestyle="-") - plt.minorticks_on() - plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) - plt.show() + plt.subplot(212) + plt.plot(df_ta.index, df_ta.values, "b", lw=1) + plt.xlim(df_stock.index[0], df_stock.index[-1]) + plt.legend(["OBV"]) + plt.xlabel("Time") + plt.grid(b=True, which="major", color="#666666", linestyle="-") + plt.minorticks_on() + plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2) + plt.ion() + plt.show() print("") From 557fe1089550b6fc91ed96c95526222548fae190 Mon Sep 17 00:00:00 2001 From: didier Date: Sat, 6 Mar 2021 11:46:13 +0000 Subject: [PATCH 2/8] Make lint happy --- gamestonk_terminal/helper_funcs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gamestonk_terminal/helper_funcs.py b/gamestonk_terminal/helper_funcs.py index 525616c0fe5..c3afb2477e9 100644 --- a/gamestonk_terminal/helper_funcs.py +++ b/gamestonk_terminal/helper_funcs.py @@ -6,9 +6,9 @@ import sys from pytz import timezone import iso8601 import matplotlib.pyplot as plt +from holidays import US as holidaysUS import pandas.io.formats.format from pandas._config.config import get_option -from holidays import US as holidaysUS from pandas.plotting import register_matplotlib_converters register_matplotlib_converters() From 355dcdd4233e7dded56270759053c54fd8db6444 Mon Sep 17 00:00:00 2001 From: DidierRLopes Date: Sat, 6 Mar 2021 14:44:12 +0000 Subject: [PATCH 3/8] Update gamestonk_terminal/fundamental_analysis/business_insider_api.py Co-authored-by: Christian Clauss --- .../fundamental_analysis/business_insider_api.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/gamestonk_terminal/fundamental_analysis/business_insider_api.py b/gamestonk_terminal/fundamental_analysis/business_insider_api.py index 4f52b474c94..c36043adc12 100644 --- a/gamestonk_terminal/fundamental_analysis/business_insider_api.py +++ b/gamestonk_terminal/fundamental_analysis/business_insider_api.py @@ -91,11 +91,9 @@ def management(l_args, s_ticker): for ind in df_management.index: s_name = f"{ind}{(max([len(x) for x in df_management.index])-len(ind))*' '}" - spacing = ( - max([len(x) for x in df_management["Title"]]) - - len(df_management["Title"][ind]) - ) * " " - s_title = f"{df_management['Title'][ind]}{spacing}" + df_mgmt_title = df_management["Title"] + spaces = max([len(x) for x in df_mgmt_title]) - len(df_mgmt_title[ind]) + s_title = f"{df_mgmt_title[ind]}{spaces * ' '}" s_management = f"""{s_name} {s_title} {df_management['Info'][ind]}""" print(s_management) if df_management["Insider Activity"][ind] not in "-": From 76cfe15102ca5060d845c5e3afaafe3df39d92ac Mon Sep 17 00:00:00 2001 From: didier Date: Sat, 6 Mar 2021 14:58:37 +0000 Subject: [PATCH 4/8] Improve pred files, and non-blocking plot --- .../prediction_techniques/arima.py | 16 +++++---- .../prediction_techniques/fbprophet.py | 14 ++++---- .../prediction_techniques/knn.py | 16 +++++---- .../prediction_techniques/neural_networks.py | 34 ++++++++----------- .../prediction_techniques/pred_menu.py | 6 +++- .../prediction_techniques/regression.py | 15 ++++---- .../prediction_techniques/sma.py | 14 ++++---- 7 files changed, 60 insertions(+), 55 deletions(-) diff --git a/gamestonk_terminal/prediction_techniques/arima.py b/gamestonk_terminal/prediction_techniques/arima.py index a66cbf847ae..6ce2736423a 100644 --- a/gamestonk_terminal/prediction_techniques/arima.py +++ b/gamestonk_terminal/prediction_techniques/arima.py @@ -4,11 +4,15 @@ import pandas as pd from pandas.plotting import register_matplotlib_converters import pmdarima from statsmodels.tsa.arima.model import ARIMA -from gamestonk_terminal.helper_funcs import check_positive, get_next_stock_market_days +from gamestonk_terminal.helper_funcs import ( + check_positive, + get_next_stock_market_days, + parse_known_args_and_warn, +) + register_matplotlib_converters() -# -------------------------------------------------- ARIMA -------------------------------------------------- # pylint: disable=unused-argument def arima(l_args, s_ticker, s_interval, df_stock): parser = argparse.ArgumentParser( @@ -71,11 +75,7 @@ def arima(l_args, s_ticker, s_interval, df_stock): ) try: - (ns_parser, l_unknown_args) = parser.parse_known_args(l_args) - - if l_unknown_args: - print(f"The following args couldn't be interpreted: {l_unknown_args}\n") - return + ns_parser = parse_known_args_and_warn(parser, l_args) # Machine Learning model if ns_parser.s_order: @@ -115,6 +115,7 @@ def arima(l_args, s_ticker, s_interval, df_stock): print("") # Plotting + plt.figure() plt.plot(df_stock.index, df_stock["5. adjusted close"], lw=2) if ns_parser.s_order: plt.title( @@ -147,6 +148,7 @@ def arima(l_args, s_ticker, s_interval, df_stock): plt.vlines( df_stock.index[-1], ymin, ymax, linewidth=1, linestyle="--", color="k" ) + plt.ion() plt.show() # Print prediction data diff --git a/gamestonk_terminal/prediction_techniques/fbprophet.py b/gamestonk_terminal/prediction_techniques/fbprophet.py index c92ae42f704..dee891ae9b8 100644 --- a/gamestonk_terminal/prediction_techniques/fbprophet.py +++ b/gamestonk_terminal/prediction_techniques/fbprophet.py @@ -4,13 +4,16 @@ import matplotlib.pyplot as plt import pandas as pd from pandas.plotting import register_matplotlib_converters from fbprophet import Prophet -from gamestonk_terminal.helper_funcs import check_positive, get_next_stock_market_days +from gamestonk_terminal.helper_funcs import ( + check_positive, + get_next_stock_market_days, + parse_known_args_and_warn, +) register_matplotlib_converters() warnings.simplefilter("ignore") -# ----------------------------------------------------- FBPROPHET ----------------------------------------------------- # pylint: disable=unused-argument def fbprophet(l_args, s_ticker, s_interval, df_stock): parser = argparse.ArgumentParser( @@ -33,11 +36,7 @@ def fbprophet(l_args, s_ticker, s_interval, df_stock): ) try: - (ns_parser, l_unknown_args) = parser.parse_known_args(l_args) - - if l_unknown_args: - print(f"The following args couldn't be interpreted: {l_unknown_args}\n") - return + ns_parser = parse_known_args_and_warn(parser, l_args) df_stock = df_stock.sort_index(ascending=True) df_stock.reset_index(level=0, inplace=True) @@ -77,6 +76,7 @@ def fbprophet(l_args, s_ticker, s_interval, df_stock): df_stock["ds"].values[0], get_next_stock_market_days(l_pred_days[-1], 1)[-1] ) plt.title(f"Fb Prophet on {s_ticker} - {ns_parser.n_days} days prediction") + plt.ion() plt.show() print("") diff --git a/gamestonk_terminal/prediction_techniques/knn.py b/gamestonk_terminal/prediction_techniques/knn.py index e1ae266a72a..8ea9a579158 100644 --- a/gamestonk_terminal/prediction_techniques/knn.py +++ b/gamestonk_terminal/prediction_techniques/knn.py @@ -4,11 +4,15 @@ import pandas as pd from pandas.plotting import register_matplotlib_converters from sklearn import neighbors from TimeSeriesCrossValidation import splitTrain -from gamestonk_terminal.helper_funcs import check_positive, get_next_stock_market_days +from gamestonk_terminal.helper_funcs import ( + check_positive, + get_next_stock_market_days, + parse_known_args_and_warn, +) register_matplotlib_converters() -# ----------------------------------------------------- kNN ----------------------------------------------------- + # pylint: disable=unused-argument def k_nearest_neighbors(l_args, s_ticker, s_interval, df_stock): parser = argparse.ArgumentParser( @@ -58,11 +62,7 @@ def k_nearest_neighbors(l_args, s_ticker, s_interval, df_stock): ) try: - (ns_parser, l_unknown_args) = parser.parse_known_args(l_args) - - if l_unknown_args: - print(f"The following args couldn't be interpreted: {l_unknown_args}\n") - return + ns_parser = parse_known_args_and_warn(parser, l_args) # Split training data stock_x, stock_y = splitTrain.split_train( @@ -87,6 +87,7 @@ def k_nearest_neighbors(l_args, s_ticker, s_interval, df_stock): df_pred = pd.Series(l_predictions, index=l_pred_days, name="Price") # Plotting + plt.figure() plt.plot(df_stock.index, df_stock["5. adjusted close"], lw=2) plt.title( f"{ns_parser.n_neighbors}-Nearest Neighbors on {s_ticker} - {ns_parser.n_days} days prediction" @@ -114,6 +115,7 @@ def k_nearest_neighbors(l_args, s_ticker, s_interval, df_stock): plt.vlines( df_stock.index[-1], ymin, ymax, linewidth=1, linestyle="--", color="k" ) + plt.ion() plt.show() # Print prediction data diff --git a/gamestonk_terminal/prediction_techniques/neural_networks.py b/gamestonk_terminal/prediction_techniques/neural_networks.py index 49b79bbb668..58e22f4df8e 100644 --- a/gamestonk_terminal/prediction_techniques/neural_networks.py +++ b/gamestonk_terminal/prediction_techniques/neural_networks.py @@ -18,7 +18,12 @@ from tensorflow.keras.layers import ( # TimeDistributed, ) -from gamestonk_terminal.helper_funcs import check_positive, get_next_stock_market_days +from gamestonk_terminal.helper_funcs import ( + check_positive, + get_next_stock_market_days, + parse_known_args_and_warn, +) + from gamestonk_terminal import config_neural_network_models as cfg_nn_models @@ -77,7 +82,6 @@ def build_neural_network_model(Recurrent_Neural_Network, n_inputs, n_days): return model -# -------------------------------------------------- MLP -------------------------------------------------- # pylint: disable=unused-argument def mlp(l_args, s_ticker, s_interval, df_stock): parser = argparse.ArgumentParser( @@ -159,11 +163,7 @@ def mlp(l_args, s_ticker, s_interval, df_stock): ) try: - (ns_parser, l_unknown_args) = parser.parse_known_args(l_args) - - if l_unknown_args: - print(f"The following args couldn't be interpreted: {l_unknown_args}\n") - return + ns_parser = parse_known_args_and_warn(parser, l_args) # Pre-process data if ns_parser.s_preprocessing == "standardization": @@ -227,6 +227,7 @@ def mlp(l_args, s_ticker, s_interval, df_stock): df_pred = pd.Series(y_pred_test_t[0].tolist(), index=l_pred_days, name="Price") # Plotting + plt.figure() plt.plot(df_stock.index, df_stock["5. adjusted close"], lw=3) plt.title(f"MLP on {s_ticker} - {ns_parser.n_days} days prediction") plt.xlim( @@ -258,6 +259,7 @@ def mlp(l_args, s_ticker, s_interval, df_stock): linestyle="--", color="k", ) + plt.ion() plt.show() # Print prediction data @@ -271,7 +273,6 @@ def mlp(l_args, s_ticker, s_interval, df_stock): print("") -# -------------------------------------------------- RNN -------------------------------------------------- # pylint: disable=unused-argument def rnn(l_args, s_ticker, s_interval, df_stock): parser = argparse.ArgumentParser( @@ -353,11 +354,7 @@ def rnn(l_args, s_ticker, s_interval, df_stock): ) try: - (ns_parser, l_unknown_args) = parser.parse_known_args(l_args) - - if l_unknown_args: - print(f"The following args couldn't be interpreted: {l_unknown_args}\n") - return + ns_parser = parse_known_args_and_warn(parser, l_args) # Pre-process data if ns_parser.s_preprocessing == "standardization": @@ -421,6 +418,7 @@ def rnn(l_args, s_ticker, s_interval, df_stock): df_pred = pd.Series(y_pred_test_t[0].tolist(), index=l_pred_days, name="Price") # Plotting + plt.figure() plt.plot(df_stock.index, df_stock["5. adjusted close"], lw=3) plt.title(f"RNN on {s_ticker} - {ns_parser.n_days} days prediction") plt.xlim( @@ -452,6 +450,7 @@ def rnn(l_args, s_ticker, s_interval, df_stock): linestyle="--", color="k", ) + plt.ion() plt.show() # Print prediction data @@ -465,7 +464,6 @@ def rnn(l_args, s_ticker, s_interval, df_stock): print("") -# -------------------------------------------------- LSTM -------------------------------------------------- # pylint: disable=unused-argument def lstm(l_args, s_ticker, s_interval, df_stock): parser = argparse.ArgumentParser( @@ -547,11 +545,7 @@ def lstm(l_args, s_ticker, s_interval, df_stock): ) try: - (ns_parser, l_unknown_args) = parser.parse_known_args(l_args) - - if l_unknown_args: - print(f"The following args couldn't be interpreted: {l_unknown_args}\n") - return + ns_parser = parse_known_args_and_warn(parser, l_args) # Pre-process data if ns_parser.s_preprocessing == "standardization": @@ -615,6 +609,7 @@ def lstm(l_args, s_ticker, s_interval, df_stock): df_pred = pd.Series(y_pred_test_t[0].tolist(), index=l_pred_days, name="Price") # Plotting + plt.figure() plt.plot(df_stock.index, df_stock["5. adjusted close"], lw=3) plt.title(f"LSTM on {s_ticker} - {ns_parser.n_days} days prediction") plt.xlim( @@ -646,6 +641,7 @@ def lstm(l_args, s_ticker, s_interval, df_stock): linestyle="--", color="k", ) + plt.ion() plt.show() # Print prediction data diff --git a/gamestonk_terminal/prediction_techniques/pred_menu.py b/gamestonk_terminal/prediction_techniques/pred_menu.py index c8d3ddb34c6..4a1918e439b 100644 --- a/gamestonk_terminal/prediction_techniques/pred_menu.py +++ b/gamestonk_terminal/prediction_techniques/pred_menu.py @@ -6,8 +6,9 @@ from gamestonk_terminal.prediction_techniques import regression from gamestonk_terminal.prediction_techniques import arima from gamestonk_terminal.prediction_techniques import fbprophet from gamestonk_terminal.prediction_techniques import neural_networks +import matplotlib.pyplot as plt + -# ----------------------------------------------------------------------------------------------------------------------- def print_prediction(s_ticker, s_start, s_interval): """ Print help """ @@ -69,6 +70,9 @@ def pred_menu(df_stock, s_ticker, s_start, s_interval): # Get input command from user as_input = input("> ") + # Images are non blocking - allows to close them if we type other command + plt.close() + # Parse prediction techniques command of the list of possible commands try: (ns_known_args, l_args) = pred_parser.parse_known_args(as_input.split()) diff --git a/gamestonk_terminal/prediction_techniques/regression.py b/gamestonk_terminal/prediction_techniques/regression.py index 8fa1cfb4d94..2af7272173c 100644 --- a/gamestonk_terminal/prediction_techniques/regression.py +++ b/gamestonk_terminal/prediction_techniques/regression.py @@ -7,7 +7,11 @@ from sklearn import linear_model from sklearn import pipeline from sklearn import preprocessing -from gamestonk_terminal.helper_funcs import check_positive, get_next_stock_market_days +from gamestonk_terminal.helper_funcs import ( + check_positive, + get_next_stock_market_days, + parse_known_args_and_warn, +) register_matplotlib_converters() @@ -16,7 +20,6 @@ LINEAR = 1 QUADRATIC = 2 CUBIC = 3 -# -------------------------------------------------- REGRESSION -------------------------------------------------- # pylint: disable=unused-argument def regression(l_args, s_ticker, s_interval, df_stock, polynomial): parser = argparse.ArgumentParser( @@ -69,11 +72,7 @@ def regression(l_args, s_ticker, s_interval, df_stock, polynomial): ) try: - (ns_parser, l_unknown_args) = parser.parse_known_args(l_args) - - if l_unknown_args: - print(f"The following args couldn't be interpreted: {l_unknown_args}\n") - return + ns_parser = parse_known_args_and_warn(parser, l_args) # Split training data stock_x, stock_y = splitTrain.split_train( @@ -106,6 +105,7 @@ def regression(l_args, s_ticker, s_interval, df_stock, polynomial): df_pred = pd.Series(l_predictions, index=l_pred_days, name="Price") # Plotting + plt.figure() plt.plot(df_stock.index, df_stock["5. adjusted close"], lw=2) plt.title( f"Regression (polynomial {polynomial}) on {s_ticker} - {ns_parser.n_days} days prediction" @@ -133,6 +133,7 @@ def regression(l_args, s_ticker, s_interval, df_stock, polynomial): plt.vlines( df_stock.index[-1], ymin, ymax, linewidth=1, linestyle="--", color="k" ) + plt.ion() plt.show() # Print prediction data diff --git a/gamestonk_terminal/prediction_techniques/sma.py b/gamestonk_terminal/prediction_techniques/sma.py index 834c61ce7cb..ad8fae16212 100644 --- a/gamestonk_terminal/prediction_techniques/sma.py +++ b/gamestonk_terminal/prediction_techniques/sma.py @@ -4,11 +4,14 @@ import matplotlib.pyplot as plt import pandas as pd from pandas.plotting import register_matplotlib_converters -from gamestonk_terminal.helper_funcs import check_positive, get_next_stock_market_days +from gamestonk_terminal.helper_funcs import ( + check_positive, + get_next_stock_market_days, + parse_known_args_and_warn, +) register_matplotlib_converters() -# ----------------------------------------------------- SMA ----------------------------------------------------- # pylint: disable=unused-argument def simple_moving_average(l_args, s_ticker, s_interval, df_stock): parser = argparse.ArgumentParser( @@ -44,11 +47,7 @@ def simple_moving_average(l_args, s_ticker, s_interval, df_stock): ) try: - (ns_parser, l_unknown_args) = parser.parse_known_args(l_args) - - if l_unknown_args: - print(f"The following args couldn't be interpreted: {l_unknown_args}\n") - return + ns_parser = parse_known_args_and_warn(parser, l_args) # Prediction data l_predictions = list() @@ -97,6 +96,7 @@ def simple_moving_average(l_args, s_ticker, s_interval, df_stock): plt.vlines( df_stock.index[-1], ymin, ymax, linewidth=1, linestyle="--", color="k" ) + plt.ion() plt.show() # Print prediction data From abf1475937caf5b0fb7f69357abf9381119b65b2 Mon Sep 17 00:00:00 2001 From: didier Date: Sat, 6 Mar 2021 15:53:11 +0000 Subject: [PATCH 5/8] Improve Pred menu overall --- gamestonk_terminal/helper_funcs.py | 17 +++++++++ .../prediction_techniques/arima.py | 10 ++--- .../prediction_techniques/fbprophet.py | 8 ++-- .../prediction_techniques/knn.py | 8 ++-- .../prediction_techniques/neural_networks.py | 22 ++++------- .../prediction_techniques/pred_menu.py | 37 ++++++------------- .../prediction_techniques/regression.py | 9 ++--- .../prediction_techniques/sma.py | 8 ++-- 8 files changed, 54 insertions(+), 65 deletions(-) diff --git a/gamestonk_terminal/helper_funcs.py b/gamestonk_terminal/helper_funcs.py index 7f9f21b0759..d21c8f55dda 100644 --- a/gamestonk_terminal/helper_funcs.py +++ b/gamestonk_terminal/helper_funcs.py @@ -6,9 +6,11 @@ import sys from pytz import timezone import iso8601 import matplotlib.pyplot as plt +import pandas as pd import pandas.io.formats.format from pandas._config.config import get_option from holidays import US as holidaysUS +from colorama import Fore, Style def check_non_negative(value) -> int: @@ -340,3 +342,18 @@ def parse_known_args_and_warn(parser, l_args): if l_unknown_args: print(f"The following args couldn't be interpreted: {l_unknown_args}") return ns_parser + + +def price_prediction_color(val: int, last_val: int) -> str: + if float(val) > last_val: + color = Fore.GREEN + else: + color = Fore.RED + return f"{color}{val:.2f} ${Style.RESET_ALL}" + + +def print_pretty_prediction(df_pred: pd.DataFrame, last_price: float): + print(f"Actual price: {Fore.YELLOW}{last_price:.2f} ${Style.RESET_ALL}\n") + + print("Prediction:") + print(df_pred.apply(price_prediction_color, last_val=last_price).to_string()) diff --git a/gamestonk_terminal/prediction_techniques/arima.py b/gamestonk_terminal/prediction_techniques/arima.py index 6ce2736423a..43bf91f01d7 100644 --- a/gamestonk_terminal/prediction_techniques/arima.py +++ b/gamestonk_terminal/prediction_techniques/arima.py @@ -8,13 +8,13 @@ from gamestonk_terminal.helper_funcs import ( check_positive, get_next_stock_market_days, parse_known_args_and_warn, + print_pretty_prediction, ) - register_matplotlib_converters() -# pylint: disable=unused-argument -def arima(l_args, s_ticker, s_interval, df_stock): + +def arima(l_args, s_ticker, df_stock): parser = argparse.ArgumentParser( prog="arima", description=""" @@ -152,9 +152,7 @@ def arima(l_args, s_ticker, s_interval, df_stock): plt.show() # Print prediction data - print("Predicted share price:") - df_pred = df_pred.apply(lambda x: f"{x:.2f} $") - print(df_pred.to_string()) + print_pretty_prediction(df_pred, df_stock["5. adjusted close"].values[-1]) print("") except Exception as e: diff --git a/gamestonk_terminal/prediction_techniques/fbprophet.py b/gamestonk_terminal/prediction_techniques/fbprophet.py index dee891ae9b8..3a93230555f 100644 --- a/gamestonk_terminal/prediction_techniques/fbprophet.py +++ b/gamestonk_terminal/prediction_techniques/fbprophet.py @@ -14,14 +14,14 @@ register_matplotlib_converters() warnings.simplefilter("ignore") -# pylint: disable=unused-argument -def fbprophet(l_args, s_ticker, s_interval, df_stock): +def fbprophet(l_args, s_ticker, df_stock): parser = argparse.ArgumentParser( prog="fbprophet", description=""" Facebook Prophet is a forecasting procedure that is fast and provides - completely automated forecasts that can be tuned by hand by data scientists and analysts. - It was developed by Facebook's data science team and is open source. + completely automated forecasts that can be tuned by hand by data scientists + and analysts. It was developed by Facebook's data science team and is open + source. """, ) diff --git a/gamestonk_terminal/prediction_techniques/knn.py b/gamestonk_terminal/prediction_techniques/knn.py index 8ea9a579158..1fc1cfa0417 100644 --- a/gamestonk_terminal/prediction_techniques/knn.py +++ b/gamestonk_terminal/prediction_techniques/knn.py @@ -8,13 +8,13 @@ from gamestonk_terminal.helper_funcs import ( check_positive, get_next_stock_market_days, parse_known_args_and_warn, + print_pretty_prediction, ) register_matplotlib_converters() -# pylint: disable=unused-argument -def k_nearest_neighbors(l_args, s_ticker, s_interval, df_stock): +def k_nearest_neighbors(l_args, s_ticker, df_stock): parser = argparse.ArgumentParser( prog="knn", description=""" @@ -119,9 +119,7 @@ def k_nearest_neighbors(l_args, s_ticker, s_interval, df_stock): plt.show() # Print prediction data - print("Predicted share price:") - df_pred = df_pred.apply(lambda x: f"{x:.2f} $") - print(df_pred.to_string()) + print_pretty_prediction(df_pred, df_stock["5. adjusted close"].values[-1]) print("") except Exception as e: diff --git a/gamestonk_terminal/prediction_techniques/neural_networks.py b/gamestonk_terminal/prediction_techniques/neural_networks.py index 58e22f4df8e..c062fd1ecf0 100644 --- a/gamestonk_terminal/prediction_techniques/neural_networks.py +++ b/gamestonk_terminal/prediction_techniques/neural_networks.py @@ -22,6 +22,7 @@ from gamestonk_terminal.helper_funcs import ( check_positive, get_next_stock_market_days, parse_known_args_and_warn, + print_pretty_prediction ) from gamestonk_terminal import config_neural_network_models as cfg_nn_models @@ -82,8 +83,7 @@ def build_neural_network_model(Recurrent_Neural_Network, n_inputs, n_days): return model -# pylint: disable=unused-argument -def mlp(l_args, s_ticker, s_interval, df_stock): +def mlp(l_args, s_ticker, df_stock): parser = argparse.ArgumentParser( prog="mlp", description="""Multilayer Perceptron. """ ) @@ -263,9 +263,7 @@ def mlp(l_args, s_ticker, s_interval, df_stock): plt.show() # Print prediction data - print("Predicted share price:") - df_pred = df_pred.apply(lambda x: f"{x:.2f} $") - print(df_pred.to_string()) + print_pretty_prediction(df_pred, df_stock["5. adjusted close"].values[-1]) print("") except Exception as e: @@ -273,8 +271,7 @@ def mlp(l_args, s_ticker, s_interval, df_stock): print("") -# pylint: disable=unused-argument -def rnn(l_args, s_ticker, s_interval, df_stock): +def rnn(l_args, s_ticker, df_stock): parser = argparse.ArgumentParser( prog="rnn", description="""Recurrent Neural Network. """ ) @@ -454,9 +451,7 @@ def rnn(l_args, s_ticker, s_interval, df_stock): plt.show() # Print prediction data - print("Predicted share price:") - df_pred = df_pred.apply(lambda x: f"{x:.2f} $") - print(df_pred.to_string()) + print_pretty_prediction(df_pred, df_stock["5. adjusted close"].values[-1]) print("") except Exception as e: @@ -464,8 +459,7 @@ def rnn(l_args, s_ticker, s_interval, df_stock): print("") -# pylint: disable=unused-argument -def lstm(l_args, s_ticker, s_interval, df_stock): +def lstm(l_args, s_ticker, df_stock): parser = argparse.ArgumentParser( prog="lstm", description="""Long-Short Term Memory. """ ) @@ -645,9 +639,7 @@ def lstm(l_args, s_ticker, s_interval, df_stock): plt.show() # Print prediction data - print("Predicted share price:") - df_pred = df_pred.apply(lambda x: f"{x:.2f} $") - print(df_pred.to_string()) + print_pretty_prediction(df_pred, df_stock["5. adjusted close"].values[-1]) print("") except Exception as e: diff --git a/gamestonk_terminal/prediction_techniques/pred_menu.py b/gamestonk_terminal/prediction_techniques/pred_menu.py index 4a1918e439b..8eeab413bee 100644 --- a/gamestonk_terminal/prediction_techniques/pred_menu.py +++ b/gamestonk_terminal/prediction_techniques/pred_menu.py @@ -92,53 +92,38 @@ def pred_menu(df_stock, s_ticker, s_start, s_interval): # Abandon the program return True - # ------------------------------------------ SIMPLE MOVING AVERAGE ------------------------------------------ elif ns_known_args.cmd == "sma": - sma.simple_moving_average(l_args, s_ticker, s_interval, df_stock) + sma.simple_moving_average(l_args, s_ticker, df_stock) - # ------------------------------------------- k NEAREST NEIGHBORS ------------------------------------------ elif ns_known_args.cmd == "knn": - knn.k_nearest_neighbors(l_args, s_ticker, s_interval, df_stock) + knn.k_nearest_neighbors(l_args, s_ticker, df_stock) - # ----------------------------------------------- REGRESSION ------------------------------------------------- elif ns_known_args.cmd == "linear": - regression.regression( - l_args, s_ticker, s_interval, df_stock, regression.LINEAR - ) + regression.regression(l_args, s_ticker, df_stock, regression.LINEAR) elif ns_known_args.cmd == "quadratic": - regression.regression( - l_args, s_ticker, s_interval, df_stock, regression.QUADRATIC - ) + regression.regression(l_args, s_ticker, df_stock, regression.QUADRATIC) elif ns_known_args.cmd == "cubic": - regression.regression( - l_args, s_ticker, s_interval, df_stock, regression.CUBIC - ) + regression.regression(l_args, s_ticker, df_stock, regression.CUBIC) elif ns_known_args.cmd == "regression": - regression.regression( - l_args, s_ticker, s_interval, df_stock, regression.USER_INPUT - ) + regression.regression(l_args, s_ticker, df_stock, regression.USER_INPUT) - # ------------------------------------------------- ARIMA ------------------------------------------------- elif ns_known_args.cmd == "arima": - arima.arima(l_args, s_ticker, s_interval, df_stock) + arima.arima(l_args, s_ticker, df_stock) - # ------------------------------------------------ FBPROPHET ------------------------------------------------ elif ns_known_args.cmd == "prophet": - fbprophet.fbprophet(l_args, s_ticker, s_interval, df_stock) + fbprophet.fbprophet(l_args, s_ticker, df_stock) - # ---------------------------------------------- NEURAL NETWORK ---------------------------------------------- elif ns_known_args.cmd == "mlp": - neural_networks.mlp(l_args, s_ticker, s_interval, df_stock) + neural_networks.mlp(l_args, s_ticker, df_stock) elif ns_known_args.cmd == "rnn": - neural_networks.rnn(l_args, s_ticker, s_interval, df_stock) + neural_networks.rnn(l_args, s_ticker, df_stock) elif ns_known_args.cmd == "lstm": - neural_networks.lstm(l_args, s_ticker, s_interval, df_stock) + neural_networks.lstm(l_args, s_ticker, df_stock) - # ------------------------------------------------------------------------------------------------------------ else: print("Command not recognized!") diff --git a/gamestonk_terminal/prediction_techniques/regression.py b/gamestonk_terminal/prediction_techniques/regression.py index 2af7272173c..841ff00371f 100644 --- a/gamestonk_terminal/prediction_techniques/regression.py +++ b/gamestonk_terminal/prediction_techniques/regression.py @@ -11,6 +11,7 @@ from gamestonk_terminal.helper_funcs import ( check_positive, get_next_stock_market_days, parse_known_args_and_warn, + print_pretty_prediction, ) register_matplotlib_converters() @@ -20,8 +21,8 @@ LINEAR = 1 QUADRATIC = 2 CUBIC = 3 -# pylint: disable=unused-argument -def regression(l_args, s_ticker, s_interval, df_stock, polynomial): + +def regression(l_args, s_ticker, df_stock, polynomial): parser = argparse.ArgumentParser( prog="regression", description=""" @@ -137,9 +138,7 @@ def regression(l_args, s_ticker, s_interval, df_stock, polynomial): plt.show() # Print prediction data - print("Predicted share price:") - df_pred = df_pred.apply(lambda x: f"{x:.2f} $") - print(df_pred.to_string()) + print_pretty_prediction(df_pred, df_stock["5. adjusted close"].values[-1]) print("") except Exception as e: diff --git a/gamestonk_terminal/prediction_techniques/sma.py b/gamestonk_terminal/prediction_techniques/sma.py index ad8fae16212..5755212614b 100644 --- a/gamestonk_terminal/prediction_techniques/sma.py +++ b/gamestonk_terminal/prediction_techniques/sma.py @@ -8,12 +8,14 @@ from gamestonk_terminal.helper_funcs import ( check_positive, get_next_stock_market_days, parse_known_args_and_warn, + print_pretty_prediction, ) register_matplotlib_converters() + # pylint: disable=unused-argument -def simple_moving_average(l_args, s_ticker, s_interval, df_stock): +def simple_moving_average(l_args, s_ticker, df_stock): parser = argparse.ArgumentParser( prog="sma", description=""" @@ -100,9 +102,7 @@ def simple_moving_average(l_args, s_ticker, s_interval, df_stock): plt.show() # Print prediction data - print("Predicted share price:") - df_pred = df_pred.apply(lambda x: f"{x:.2f} $") - print(df_pred.to_string()) + print_pretty_prediction(df_pred, df_stock["5. adjusted close"].values[-1]) print("") except Exception as e: From 1aa7d9627ed41d5952bc657d50c8774657aa2ff0 Mon Sep 17 00:00:00 2001 From: didier Date: Sat, 6 Mar 2021 18:20:27 +0000 Subject: [PATCH 6/8] Fix black failing test --- .../prediction_techniques/fbprophet.py | 1 + .../prediction_techniques/neural_networks.py | 12 ++---------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/gamestonk_terminal/prediction_techniques/fbprophet.py b/gamestonk_terminal/prediction_techniques/fbprophet.py index 3a93230555f..3f894feb7c9 100644 --- a/gamestonk_terminal/prediction_techniques/fbprophet.py +++ b/gamestonk_terminal/prediction_techniques/fbprophet.py @@ -14,6 +14,7 @@ register_matplotlib_converters() warnings.simplefilter("ignore") + def fbprophet(l_args, s_ticker, df_stock): parser = argparse.ArgumentParser( prog="fbprophet", diff --git a/gamestonk_terminal/prediction_techniques/neural_networks.py b/gamestonk_terminal/prediction_techniques/neural_networks.py index c062fd1ecf0..4fab5020788 100644 --- a/gamestonk_terminal/prediction_techniques/neural_networks.py +++ b/gamestonk_terminal/prediction_techniques/neural_networks.py @@ -8,21 +8,13 @@ from pandas.plotting import register_matplotlib_converters from TimeSeriesCrossValidation import splitTrain from sklearn.preprocessing import MinMaxScaler, StandardScaler from tensorflow.keras.models import Sequential -from tensorflow.keras.layers import ( - LSTM, - SimpleRNN, - Dense, - Dropout, - # Activation, - # RepeatVector, - # TimeDistributed, -) +from tensorflow.keras.layers import LSTM, SimpleRNN, Dense, Dropout from gamestonk_terminal.helper_funcs import ( check_positive, get_next_stock_market_days, parse_known_args_and_warn, - print_pretty_prediction + print_pretty_prediction, ) from gamestonk_terminal import config_neural_network_models as cfg_nn_models From 7b3d480f0ae23e15c20764b40493f80771607997 Mon Sep 17 00:00:00 2001 From: didier Date: Sat, 6 Mar 2021 18:27:17 +0000 Subject: [PATCH 7/8] Fix test by removing unused s_interval arg --- tests/test_pred_neural_networks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_pred_neural_networks.py b/tests/test_pred_neural_networks.py index a86d624f806..4784a100d27 100644 --- a/tests/test_pred_neural_networks.py +++ b/tests/test_pred_neural_networks.py @@ -11,4 +11,4 @@ from gamestonk_terminal.prediction_techniques.neural_networks import mlp class TestPredNeuralNetworks(unittest.TestCase): def test_mlp(self): # Fix: need to move loading of ticker data into a df somewhere - mlp([], "TLSA", None, None) + mlp([], "TLSA", None) From a5fd538307028b4bbfb5b52b5cb8f4620a9dec21 Mon Sep 17 00:00:00 2001 From: DidierRLopes Date: Sat, 6 Mar 2021 19:45:40 +0000 Subject: [PATCH 8/8] Update helper_funcs.py --- gamestonk_terminal/helper_funcs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gamestonk_terminal/helper_funcs.py b/gamestonk_terminal/helper_funcs.py index b1d4c88c645..250989fad1b 100644 --- a/gamestonk_terminal/helper_funcs.py +++ b/gamestonk_terminal/helper_funcs.py @@ -6,11 +6,11 @@ import sys from pytz import timezone import iso8601 import matplotlib.pyplot as plt +from holidays import US as holidaysUS +from colorama import Fore, Style import pandas as pd import pandas.io.formats.format from pandas._config.config import get_option -from holidays import US as holidaysUS -from colorama import Fore, Style from pandas.plotting import register_matplotlib_converters register_matplotlib_converters()