diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 00000000..447a1e9c --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,17 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 00000000..105ce2da --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..3e210f59 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/stockPredict.iml b/.idea/stockPredict.iml new file mode 100644 index 00000000..aad402c4 --- /dev/null +++ b/.idea/stockPredict.iml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..228f533a --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/stock_prediction.py b/stock_prediction.py index 14a0e689..76daf358 100644 --- a/stock_prediction.py +++ b/stock_prediction.py @@ -4,10 +4,23 @@ # The percentage by which a stock has to beat the S&P500 to be considered a 'buy' -OUTPERFORMANCE = 10 +#OUTPERFORMANCE = 90 +def get_outer_performance(): + while True: + try: + x = int(input("Enter min outer performance: ")) + except ValueError: + print("Not an integer!") + continue + else: + if (x < 0 or x >100): + print("Valuse must be >=0 and <=100") + continue + else: + return (x) -def build_data_set(): +def build_data_set(outer_performance): """ Reads the keystats.csv file and prepares it for scikit-learn :return: X_train and y_train numpy arrays @@ -22,7 +35,7 @@ def build_data_set(): status_calc( training_data["stock_p_change"], training_data["SP500_p_change"], - OUTPERFORMANCE, + outer_performance, ) ) @@ -30,7 +43,9 @@ def build_data_set(): def predict_stocks(): - X_train, y_train = build_data_set() + outer_performance = get_outer_performance() + + X_train, y_train = build_data_set(outer_performance) # Remove the random_state parameter to generate actual predictions clf = RandomForestClassifier(n_estimators=100, random_state=0) clf.fit(X_train, y_train) @@ -49,7 +64,7 @@ def predict_stocks(): else: invest_list = z[y_pred].tolist() print( - f"{len(invest_list)} stocks predicted to outperform the S&P500 by more than {OUTPERFORMANCE}%:" + f"{len(invest_list)} stocks predicted to outperform the S&P500 by more than {outer_performance}%:" ) print(" ".join(invest_list)) return invest_list