From 2602e9ca64bf795995b3661417e9fe53aad5fcbf Mon Sep 17 00:00:00 2001 From: didier Date: Sat, 13 Mar 2021 23:11:08 +0000 Subject: [PATCH] Fix black knn file --- .../prediction_techniques/knn.py | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/gamestonk_terminal/prediction_techniques/knn.py b/gamestonk_terminal/prediction_techniques/knn.py index 2137d9c4017..584c6f73d80 100644 --- a/gamestonk_terminal/prediction_techniques/knn.py +++ b/gamestonk_terminal/prediction_techniques/knn.py @@ -88,19 +88,16 @@ def k_nearest_neighbors(l_args, s_ticker, df_stock): # BACKTESTING if ns_parser.s_end_date: - if ns_parser.s_end_date < df_stock.index[0]: print( "Backtesting not allowed, since End Date is older than Start Date of historical data\n" ) return - if ( - ns_parser.s_end_date - < get_next_stock_market_days( - last_stock_day=df_stock.index[0], n_next_days=ns_parser.n_inputs + ns_parser.n_days - )[-1] - ): + if ns_parser.s_end_date < get_next_stock_market_days( + last_stock_day=df_stock.index[0], + n_next_days=ns_parser.n_inputs + ns_parser.n_days, + )[-1]: print( "Backtesting not allowed, since End Date is too close to Start Date to train model\n" ) @@ -150,13 +147,10 @@ def k_nearest_neighbors(l_args, s_ticker, df_stock): plt.plot(df_stock.index, df_stock["5. adjusted close"], lw=2) # BACKTESTING if ns_parser.s_end_date: - plt.title( - f"BACKTESTING: {ns_parser.n_neighbors}-Nearest Neighbors on {s_ticker} - {ns_parser.n_days} days prediction" - ) + s_knn = f"{ns_parser.n_neighbors}-Nearest Neighbors on {s_ticker}" + plt.title(f"BACKTESTING: {s_knn} - {ns_parser.n_days} days prediction") else: - plt.title( - f"{ns_parser.n_neighbors}-Nearest Neighbors on {s_ticker} - {ns_parser.n_days} days prediction" - ) + plt.title(f"{s_knn} - {ns_parser.n_days} days prediction") plt.xlim( df_stock.index[0], get_next_stock_market_days(df_pred.index[-1], 1)[-1] ) @@ -241,7 +235,9 @@ def k_nearest_neighbors(l_args, s_ticker, df_stock): ) plt.title("BACKTESTING: Real data price versus Prediction") plt.xlim(df_stock.index[-1], df_pred.index[-1] + datetime.timedelta(days=1)) - plt.xticks([df_stock.index[-1], df_pred.index[-1]+datetime.timedelta(days=1)], visible=True) + plt.xticks( + [df_stock.index[-1], df_pred.index[-1] + datetime.timedelta(days=1)] + ) plt.ylabel("Share Price ($)") plt.grid(b=True, which="major", color="#666666", linestyle="-") plt.minorticks_on() @@ -281,7 +277,9 @@ def k_nearest_neighbors(l_args, s_ticker, df_stock): c="red", ) plt.xlim(df_stock.index[-1], df_pred.index[-1] + datetime.timedelta(days=1)) - plt.xticks([df_stock.index[-1], df_pred.index[-1]+datetime.timedelta(days=1)], visible=True) + plt.xticks( + [df_stock.index[-1], df_pred.index[-1] + datetime.timedelta(days=1)] + ) plt.xlabel("Time") plt.ylabel("Prediction Error (%)") plt.grid(b=True, which="major", color="#666666", linestyle="-") @@ -300,7 +298,6 @@ def k_nearest_neighbors(l_args, s_ticker, df_stock): df_pred["Real"] = df_future["5. adjusted close"] if gtff.USE_COLOR: - patch_pandas_text_adjustment() print("Time Real [$] x Prediction [$]")