Added scaling to arima, ets, fbprophet, knn, nn, regression, sma and historical yahoo_finance_api

This commit is contained in:
buzzCraft
2021-03-17 10:51:45 +01:00
parent ce872197be
commit 05065ec540
8 changed files with 35 additions and 25 deletions

View File

@@ -6,11 +6,11 @@ import matplotlib.pyplot as plt
import yfinance as yf
import seaborn as sns
from gamestonk_terminal.helper_funcs import parse_known_args_and_warn
from gamestonk_terminal.helper_funcs import parse_known_args_and_warn, plot_autoscale
from gamestonk_terminal.config_plot import PLOT_DPI
register_matplotlib_converters()
d_candle_types = {
"o": "Open",
"h": "High",
@@ -79,7 +79,7 @@ def historical(l_args, df_stock, s_ticker, s_start, s_interval, similar):
similar += ns_parser.l_also
plt.figure()
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
plt.title(f"Similar companies to {s_ticker}")
df_stock = yf.download(s_ticker, start=s_start, progress=False)
plt.plot(

View File

@@ -11,6 +11,7 @@ from gamestonk_terminal.helper_funcs import (
valid_date,
patch_pandas_text_adjustment,
get_next_stock_market_days,
plot_autoscale,
)
from gamestonk_terminal.prediction_techniques.pred_helper import (
print_pretty_prediction,
@@ -18,6 +19,7 @@ from gamestonk_terminal.prediction_techniques.pred_helper import (
print_prediction_kpis,
)
from gamestonk_terminal.config_plot import PLOT_DPI
from gamestonk_terminal import feature_flags as gtff
register_matplotlib_converters()
@@ -168,7 +170,7 @@ def arima(l_args, s_ticker, df_stock):
print("")
# Plotting
plt.figure()
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
plt.plot(df_stock.index, df_stock["5. adjusted close"], lw=2)
if ns_parser.s_order:
# BACKTESTING
@@ -241,7 +243,7 @@ def arima(l_args, s_ticker, df_stock):
# BACKTESTING
if ns_parser.s_end_date:
plt.figure()
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
plt.subplot(211)
plt.plot(
df_future.index,

View File

@@ -11,6 +11,7 @@ from gamestonk_terminal.helper_funcs import (
valid_date,
patch_pandas_text_adjustment,
get_next_stock_market_days,
plot_autoscale,
)
from gamestonk_terminal.prediction_techniques.pred_helper import (
print_pretty_prediction,
@@ -18,6 +19,7 @@ from gamestonk_terminal.prediction_techniques.pred_helper import (
print_prediction_kpis,
)
from gamestonk_terminal.config_plot import PLOT_DPI
from gamestonk_terminal import feature_flags as gtff
register_matplotlib_converters()
@@ -179,7 +181,7 @@ def exponential_smoothing(l_args, s_ticker, df_stock):
print(f"SSE: {round(model.sse, 2)}\n")
# Plotting
plt.figure()
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
plt.plot(df_stock.index, df_stock["5. adjusted close"], lw=2)
# BACKTESTING
if ns_parser.s_end_date:
@@ -249,7 +251,7 @@ def exponential_smoothing(l_args, s_ticker, df_stock):
# BACKTESTING
if ns_parser.s_end_date:
plt.figure()
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
plt.subplot(211)
plt.plot(
df_future.index,

View File

@@ -11,12 +11,14 @@ from gamestonk_terminal.helper_funcs import (
parse_known_args_and_warn,
valid_date,
patch_pandas_text_adjustment,
plot_autoscale,
)
from gamestonk_terminal.prediction_techniques.pred_helper import (
price_prediction_backtesting_color,
print_prediction_kpis,
)
from gamestonk_terminal.config_plot import PLOT_DPI
from gamestonk_terminal import feature_flags as gtff
register_matplotlib_converters()
@@ -114,7 +116,7 @@ def fbprophet(l_args, s_ticker, df_stock):
] # .apply(lambda x: f"{x:.2f} $")
df_pred.index = l_pred_days
_, ax = plt.subplots()
_, ax = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
model.plot(
forecast[: -ns_parser.n_days],
ax=ax,
@@ -177,7 +179,7 @@ def fbprophet(l_args, s_ticker, df_stock):
# BACKTESTING
if ns_parser.s_end_date:
plt.figure()
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
plt.subplot(211)
plt.plot(
df_future.index,

View File

@@ -11,6 +11,7 @@ from gamestonk_terminal.helper_funcs import (
valid_date,
patch_pandas_text_adjustment,
get_next_stock_market_days,
plot_autoscale,
)
from gamestonk_terminal.prediction_techniques.pred_helper import (
print_pretty_prediction,
@@ -18,7 +19,7 @@ from gamestonk_terminal.prediction_techniques.pred_helper import (
print_prediction_kpis,
)
from gamestonk_terminal.config_plot import PLOT_DPI
from gamestonk_terminal import feature_flags as gtff
register_matplotlib_converters()
@@ -143,7 +144,7 @@ def k_nearest_neighbors(l_args, s_ticker, df_stock):
df_pred = pd.Series(l_predictions, index=l_pred_days, name="Price")
# Plotting
plt.figure()
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
plt.plot(df_stock.index, df_stock["5. adjusted close"], lw=2)
# BACKTESTING
if ns_parser.s_end_date:
@@ -202,7 +203,7 @@ def k_nearest_neighbors(l_args, s_ticker, df_stock):
# BACKTESTING
if ns_parser.s_end_date:
plt.figure()
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
plt.subplot(211)
plt.plot(
df_future.index,

View File

@@ -17,6 +17,7 @@ from gamestonk_terminal.helper_funcs import (
valid_date,
patch_pandas_text_adjustment,
get_next_stock_market_days,
plot_autoscale,
)
from gamestonk_terminal.prediction_techniques.pred_helper import (
@@ -25,7 +26,7 @@ from gamestonk_terminal.prediction_techniques.pred_helper import (
print_prediction_kpis,
)
from gamestonk_terminal.config_plot import PLOT_DPI
from gamestonk_terminal import feature_flags as gtff
from gamestonk_terminal import config_neural_network_models as cfg_nn_models
@@ -275,7 +276,7 @@ def mlp(l_args, s_ticker, df_stock):
df_pred = pd.Series(y_pred_test_t[0].tolist(), index=l_pred_days, name="Price")
# Plotting
plt.figure()
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
plt.plot(df_stock.index, df_stock["5. adjusted close"], lw=3)
# BACKTESTING
if ns_parser.s_end_date:
@@ -341,7 +342,7 @@ def mlp(l_args, s_ticker, df_stock):
# BACKTESTING
if ns_parser.s_end_date:
plt.figure()
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
plt.subplot(211)
plt.plot(
df_future.index,
@@ -654,7 +655,7 @@ def rnn(l_args, s_ticker, df_stock):
df_pred = pd.Series(y_pred_test_t[0].tolist(), index=l_pred_days, name="Price")
# Plotting
plt.figure()
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
plt.plot(df_stock.index, df_stock["5. adjusted close"], lw=3)
# BACKTESTING
if ns_parser.s_end_date:
@@ -720,7 +721,7 @@ def rnn(l_args, s_ticker, df_stock):
# BACKTESTING
if ns_parser.s_end_date:
plt.figure()
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
plt.subplot(211)
plt.plot(
df_future.index,
@@ -1033,7 +1034,7 @@ def lstm(l_args, s_ticker, df_stock):
df_pred = pd.Series(y_pred_test_t[0].tolist(), index=l_pred_days, name="Price")
# Plotting
plt.figure()
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
plt.plot(df_stock.index, df_stock["5. adjusted close"], lw=3)
# BACKTESTING
if ns_parser.s_end_date:
@@ -1099,7 +1100,7 @@ def lstm(l_args, s_ticker, df_stock):
# BACKTESTING
if ns_parser.s_end_date:
plt.figure()
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
plt.subplot(211)
plt.plot(
df_future.index,

View File

@@ -14,6 +14,7 @@ from gamestonk_terminal.helper_funcs import (
valid_date,
patch_pandas_text_adjustment,
get_next_stock_market_days,
plot_autoscale,
)
from gamestonk_terminal.prediction_techniques.pred_helper import (
@@ -22,7 +23,7 @@ from gamestonk_terminal.prediction_techniques.pred_helper import (
print_prediction_kpis,
)
from gamestonk_terminal.config_plot import PLOT_DPI
from gamestonk_terminal import feature_flags as gtff
register_matplotlib_converters()
@@ -163,7 +164,7 @@ def regression(l_args, s_ticker, df_stock, polynomial):
df_pred = pd.Series(l_predictions, index=l_pred_days, name="Price")
# Plotting
plt.figure()
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
plt.plot(df_stock.index, df_stock["5. adjusted close"], lw=2)
# BACKTESTING
if ns_parser.s_end_date:
@@ -225,7 +226,7 @@ def regression(l_args, s_ticker, df_stock, polynomial):
# BACKTESTING
if ns_parser.s_end_date:
plt.figure()
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
plt.subplot(211)
plt.plot(
df_future.index,

View File

@@ -11,6 +11,7 @@ from gamestonk_terminal.helper_funcs import (
valid_date,
patch_pandas_text_adjustment,
get_next_stock_market_days,
plot_autoscale,
)
from gamestonk_terminal.prediction_techniques.pred_helper import (
@@ -19,7 +20,7 @@ from gamestonk_terminal.prediction_techniques.pred_helper import (
print_prediction_kpis,
)
from gamestonk_terminal.config_plot import PLOT_DPI
from gamestonk_terminal import feature_flags as gtff
register_matplotlib_converters()
@@ -125,7 +126,7 @@ def simple_moving_average(l_args, s_ticker, df_stock):
df_pred = pd.Series(l_predictions, index=l_pred_days, name="Price")
# Plotting
plt.figure()
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
plt.plot(df_stock.index, df_stock["5. adjusted close"], lw=2)
# BACKTESTING
if ns_parser.s_end_date:
@@ -189,7 +190,7 @@ def simple_moving_average(l_args, s_ticker, df_stock):
# BACKTESTING
if ns_parser.s_end_date:
plt.figure()
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
plt.subplot(211)
plt.plot(
df_future.index,