Skip to content

Develop #47

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/stockPredict.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 20 additions & 5 deletions stock_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,15 +35,17 @@ def build_data_set():
status_calc(
training_data["stock_p_change"],
training_data["SP500_p_change"],
OUTPERFORMANCE,
outer_performance,
)
)

return X_train, y_train


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)
Expand All @@ -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
Expand Down