diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..e52f2952 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +machine-learning/stock-prediction/.ipynb_checkpoints/stock_prediction-checkpoint.ipynb diff --git a/machine-learning/stock-prediction/stock_prediction.ipynb b/machine-learning/stock-prediction/stock_prediction.ipynb index 792accf3..8fd4f933 100644 --- a/machine-learning/stock-prediction/stock_prediction.ipynb +++ b/machine-learning/stock-prediction/stock_prediction.ipynb @@ -346,10 +346,10 @@ " \"\"\"\n", " # if predicted future price is higher than the current, \n", " # then calculate the true future price minus the current price, to get the buy profit\n", - " buy_profit = lambda current, true_future, pred_future: true_future - current if pred_future > current else 0\n", + " buy_profit = lambda current, pred_future, true_future: true_future - current if pred_future > current else 0\n", " # if the predicted future price is lower than the current price,\n", " # then subtract the true future price from the current price\n", - " sell_profit = lambda current, true_future, pred_future: current - true_future if pred_future < current else 0\n", + " sell_profit = lambda current, pred_future, true_future: current - true_future if pred_future < current else 0\n", " X_test = data[\"X_test\"]\n", " y_test = data[\"y_test\"]\n", " # perform prediction and get prices\n", @@ -528,9 +528,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3.6.6 64-bit", + "display_name": "Python 3", "language": "python", - "name": "python36664bitea6884f10f474b21a2a2f022451e0d09" + "name": "python3" }, "language_info": { "codemirror_mode": { @@ -542,9 +542,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.6" + "version": "3.8.0" } }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/machine-learning/stock-prediction/test.py b/machine-learning/stock-prediction/test.py index 3659d71f..9aa9dc44 100644 --- a/machine-learning/stock-prediction/test.py +++ b/machine-learning/stock-prediction/test.py @@ -21,16 +21,16 @@ def plot_graph(test_df): def get_final_df(model, data): """ - This function takes the `model` and `data` dict to - construct a final dataframe that includes the features along + This function takes the `model` and `data` dict to + construct a final dataframe that includes the features along with true and predicted prices of the testing dataset """ - # if predicted future price is higher than the current, + # if predicted future price is higher than the current, # then calculate the true future price minus the current price, to get the buy profit - buy_profit = lambda current, true_future, pred_future: true_future - current if pred_future > current else 0 + buy_profit = lambda current, pred_future, true_future: true_future - current if pred_future > current else 0 # if the predicted future price is lower than the current price, # then subtract the true future price from the current price - sell_profit = lambda current, true_future, pred_future: current - true_future if pred_future < current else 0 + sell_profit = lambda current, pred_future, true_future: current - true_future if pred_future < current else 0 X_test = data["X_test"] y_test = data["y_test"] # perform prediction and get prices @@ -47,16 +47,16 @@ def get_final_df(model, data): test_df.sort_index(inplace=True) final_df = test_df # add the buy profit column - final_df["buy_profit"] = list(map(buy_profit, - final_df["adjclose"], - final_df[f"adjclose_{LOOKUP_STEP}"], + final_df["buy_profit"] = list(map(buy_profit, + final_df["adjclose"], + final_df[f"adjclose_{LOOKUP_STEP}"], final_df[f"true_adjclose_{LOOKUP_STEP}"]) # since we don't have profit for last sequence, add 0's ) # add the sell profit column - final_df["sell_profit"] = list(map(sell_profit, - final_df["adjclose"], - final_df[f"adjclose_{LOOKUP_STEP}"], + final_df["sell_profit"] = list(map(sell_profit, + final_df["adjclose"], + final_df[f"adjclose_{LOOKUP_STEP}"], final_df[f"true_adjclose_{LOOKUP_STEP}"]) # since we don't have profit for last sequence, add 0's ) @@ -79,8 +79,8 @@ def predict(model, data): # load the data -data = load_data(ticker, N_STEPS, scale=SCALE, split_by_date=SPLIT_BY_DATE, - shuffle=SHUFFLE, lookup_step=LOOKUP_STEP, test_size=TEST_SIZE, +data = load_data(ticker, N_STEPS, scale=SCALE, split_by_date=SPLIT_BY_DATE, + shuffle=SHUFFLE, lookup_step=LOOKUP_STEP, test_size=TEST_SIZE, feature_columns=FEATURE_COLUMNS) # construct the model @@ -129,4 +129,4 @@ def predict(model, data): if not os.path.isdir(csv_results_folder): os.mkdir(csv_results_folder) csv_filename = os.path.join(csv_results_folder, model_name + ".csv") -final_df.to_csv(csv_filename) \ No newline at end of file +final_df.to_csv(csv_filename)