Repository: kaneelgit/Trading-strategy- Branch: main Commit: 89233b84bad9 Files: 33 Total size: 110.0 KB Directory structure: gitextract_uysqdcle/ ├── .ipynb_checkpoints/ │ └── crypto-checkpoint.ipynb ├── .vscode/ │ └── settings.json ├── README.md ├── backtester.py ├── backtester_ape.py ├── companies.csv ├── data_science/ │ ├── create_figures.py │ └── stats.py ├── models/ │ ├── lr_inference.py │ └── lr_run_training.py ├── results/ │ ├── LR_v1_predict_0.7_3/ │ │ ├── history_df.csv │ │ ├── params │ │ ├── results_summary │ │ └── running_gains_df.csv │ ├── LR_v1_predict_0.95_21/ │ │ ├── history_df.csv │ │ ├── params │ │ ├── results_summary │ │ └── running_gains_df.csv │ ├── LR_v1_predict_0.9_10/ │ │ ├── history_df.csv │ │ ├── params │ │ ├── results_summary │ │ └── running_gains_df.csv │ ├── LR_v1_predict_1_1/ │ │ ├── history_df.csv │ │ ├── params │ │ ├── results_summary │ │ └── running_gains_df.csv │ └── model_result_summary.csv ├── saved_models/ │ ├── lr_v1.sav │ ├── lr_v2.sav │ ├── scaler_v1.sav │ └── scaler_v2.sav └── stock_utils/ ├── simulator.py └── stock_utils.py ================================================ FILE CONTENTS ================================================ ================================================ FILE: .ipynb_checkpoints/crypto-checkpoint.ipynb ================================================ { "cells": [ { "cell_type": "code", "execution_count": 2, "id": "84309d53", "metadata": {}, "outputs": [], "source": [ "from td.client import TDClient\n", "import requests, time, re, os\n", "import matplotlib.pyplot as plt\n", "import pandas as pd\n", "import pickle as pkl\n", "import numpy as np\n", "import datetime\n", "plt.style.use('grayscale')\n", "\n", "from scipy import linalg\n", "import math\n", "from datetime import datetime\n", "import warnings\n", "warnings.filterwarnings(\"ignore\")\n", "\n", "import time\n", "from datetime import datetime\n", "import yfinance as yf" ] }, { "cell_type": "code", "execution_count": 36, "id": "48b0cba2", "metadata": {}, "outputs": [], "source": [ "bit = yf.Ticker('ETH-USD')" ] }, { "cell_type": "code", "execution_count": 42, "id": "b7128fa8", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
OpenHighLowCloseVolumeDividendsStock Splits
Date
2021-11-134699.2822274700.363774585.6738284681.8388671493733376000
\n", "
" ], "text/plain": [ " Open High Low Close Volume \\\n", "Date \n", "2021-11-13 4699.282227 4700.36377 4585.673828 4681.838867 14937333760 \n", "\n", " Dividends Stock Splits \n", "Date \n", "2021-11-13 0 0 " ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "bit.history(period = '1m')" ] }, { "cell_type": "code", "execution_count": null, "id": "5db65814", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.8" } }, "nbformat": 4, "nbformat_minor": 5 } ================================================ FILE: .vscode/settings.json ================================================ { "jupyter.jupyterServerType": "local" } ================================================ FILE: README.md ================================================ # Trading-strategy- Here I test a simple ML trading strategy ## Please note - I have commented out the paths in the code. If you use code you'd have to correct them accordingly. - You will need to create a TDA developer account (https://developer.tdameritrade.com/apis) and get the API key in order to download the data. I have left this blank in the code where I used to download data. The blog article with results --> (https://medium.com/analytics-vidhya/how-im-using-machine-learning-to-trade-in-the-stock-market-3ba981a2ffc2) Some results - Predicted buying opportunities ![1_2rdETRDZHCg4NqnIaXDWDA](https://user-images.githubusercontent.com/85404022/156928802-094d90c1-8ae6-491c-aea3-0672c3b032de.png) Model comparison with the S&P 500 gains in 2021 ![1_ZjoDR8c7fDGqMKXyRIbfpw](https://user-images.githubusercontent.com/85404022/156928807-9e94e6b8-0ce4-4ea1-8aad-bf1771ca1b3b.png) ================================================ FILE: backtester.py ================================================ """ stock backtester to test the model given a dataset. author - Kaneel Senevirathne date - 1/13/2022 """ import numpy as np from stock_utils.simulator import simulator from stock_utils.stock_utils import get_stock_price from models import lr_inference from datetime import datetime from datetime import timedelta from td.client import TDClient import pandas as pd from models.lr_inference import LR_v1_predict, LR_v1_sell import warnings from collections import OrderedDict warnings.filterwarnings("ignore") import os import pickle from tqdm import tqdm class backtester(simulator): def __init__(self, stocks_list, model, capital, start_date, end_date, threshold = 0.99, sell_perc = 0.04, hold_till = 5,\ stop_perc = 0.005): super().__init__(capital) #initialize simulator self.stocks = stocks_list self.model = model self.start_date = start_date self.day = start_date self.end_date = end_date self.status = 'buy' #the status says if the backtester is in buy mode or sell mode self.threshold = threshold self.sell_perc = sell_perc self.hold_till = hold_till self.stop_perc = stop_perc #current directory current_dir = os.getcwd() results_dir = os.path.join(current_dir, 'results') folder_name = f'{str(self.model.__name__)}_{self.threshold}_{self.hold_till}' self.folder_dir = os.path.join(results_dir, folder_name) if not os.path.exists(self.folder_dir): #create a new folder os.makedirs(self.folder_dir) def backtest(self): """ start backtesting """ delta = timedelta(days = 1) #progress bar to track progress total_days = (self.end_date - self.start_date).days d = 0 pbar = tqdm(desc = 'Progress', total = total_days) while self.day <= self.end_date: #daily scanner dict self.daily_scanner = {} if self.status == 'buy': #scan stocks for the day self.scanner() if list(self.daily_scanner.keys()) != []: recommended_stock = list(self.daily_scanner.keys())[0] recommended_price = list(self.daily_scanner.values())[0][2] self.buy(recommended_stock, recommended_price, self.day) #buy stock # print(f'Bought {recommended_stock} for {recommended_price} on the {self.day}') self.status = 'sell' #change the status to sell else: # print('No recommendations') pass else: #if the status is sell #get stock price on the day stocks = [key for key in self.buy_orders.keys()] for s in stocks: recommended_action, current_price = LR_v1_sell(s, self.buy_orders[s][3], self.buy_orders[s][0], self.day, \ self.sell_perc, self.hold_till, self.stop_perc) if recommended_action == "SELL": # print(f'Sold {s} for {current_price} on {self.day}') self.sell(s, current_price, self.buy_orders[s][1], self.day) self.status = 'buy' #go to next day self.day += delta d += 1 pbar.update(1) pbar.close() #sell the final stock and print final capital also print stock history self.print_bag() self.print_summary() self.save_results() return def get_stock_data(self, stock, back_to = 40): """ this function queries to td database and get data of a particular stock on a given day back to certain amount of days (default is 30). """ #get start and end dates end = self.day start = self.day - timedelta(days = back_to) # prediction, prediction_thresholded, close_price = LR_v1_predict(stock, start, end, threshold = 0.5) prediction, prediction_thresholded, close_price = self.model(stock, start, end, self.threshold) return prediction[0], prediction_thresholded, close_price def scanner(self): """ scan the stocks to find good stocks """ for stock in self.stocks: try:#to ignore the stock if no data is available. #for staturdays or sundays etc prediction, prediction_thresholded, close_price = self.get_stock_data(stock) #if prediction greater than if prediction_thresholded < 1: #if prediction is zero self.daily_scanner[stock] = (prediction, prediction_thresholded, close_price) except: pass def take_first(elem): return elem[1] self.daily_scanner = OrderedDict(sorted(self.daily_scanner.items(), key = take_first, reverse = True)) def save_results(self): """ save history dataframe create figures and save """ #save csv file results_df_path = os.path.join(self.folder_dir, 'history_df.csv') self.history_df.to_csv(results_df_path, index = False) #save params and results summary results_summary_path = os.path.join(self.folder_dir, 'results_summary') results_summary = [self.initial_capital, self.total_gain] params_path = os.path.join(self.folder_dir, 'params') params = [self.threshold, self.hold_till, self.sell_perc, self.stop_perc, self.start_date, self.end_date] with open(results_summary_path, 'wb') as fp: pickle.dump(results_summary, fp) with open(params_path, 'wb') as fp: pickle.dump(params, fp) if __name__ == "__main__": #stocks list dow = ['AXP', 'AMGN', 'AAPL', 'BA', 'CAT', 'CSCO', 'CVX', 'GS', 'HD', 'HON', 'IBM', 'INTC',\ 'JNJ', 'KO', 'JPM', 'MCD', 'MMM', 'MRK', 'MSFT', 'NKE', 'PG', 'TRV', 'UNH',\ 'CRM', 'VZ', 'V', 'WBA', 'WMT', 'DIS'] other = ['AMD', 'MU', 'ABT', 'AAL', 'UAL', 'DAL', 'ANTM', 'ATVI', 'BAC', 'PNC', 'C', 'EBAY', 'AMZN', 'GOOG', 'FB', 'SNAP', 'TWTR'\ 'FDX', 'MCD', 'PEP', ] stocks = list(np.unique(dow + other)) back = backtester(dow, LR_v1_predict, 3000, datetime(2021, 1, 1), datetime(2021, 12, 31), threshold = 0.9, sell_perc = 0.03, hold_till = 10,\ stop_perc = 0.03) back.backtest() ================================================ FILE: backtester_ape.py ================================================ """ stock backtester to test the model given a dataset. author - Kaneel Senevirathne date - 1/13/2022 """ import numpy as np from stock_utils.simulator import simulator from stock_utils.stock_utils import get_stock_price from models import lr_inference from datetime import datetime from datetime import timedelta from td.client import TDClient import pandas as pd from models.lr_inference import LR_v1_predict, LR_v1_sell import warnings from collections import OrderedDict warnings.filterwarnings("ignore") import os import pickle from tqdm import tqdm class backtester(simulator): def __init__(self, stocks_list, model, capital, start_date, end_date, threshold = 0.99, sell_perc = 0.04, hold_till = 5,\ stop_perc = 0.005): super().__init__(capital) #initialize simulator self.stocks = stocks_list self.model = model self.start_date = start_date self.day = start_date self.end_date = end_date self.status = 'buy' #the status says if the backtester is in buy mode or sell mode self.threshold = threshold self.sell_perc = sell_perc self.hold_till = hold_till self.stop_perc = stop_perc #current directory current_dir = os.getcwd() results_dir = os.path.join(current_dir, 'results') folder_name = f'{str(self.model.__name__)}_{self.threshold}_{self.hold_till}' self.folder_dir = os.path.join(results_dir, folder_name) if not os.path.exists(self.folder_dir): #create a new folder os.makedirs(self.folder_dir) def backtest(self): """ start backtesting """ delta = timedelta(days = 1) #progress bar to track progress total_days = (self.end_date - self.start_date).days d = 0 pbar = tqdm(desc = 'Progress', total = total_days) while self.day <= self.end_date: #daily scanner dict self.daily_scanner = {} if self.status == 'buy': #scan stocks for the day self.scanner() if list(self.daily_scanner.keys()) != []: recommended_stock = list(self.daily_scanner.keys())[0] recommended_price = list(self.daily_scanner.values())[0][2] self.buy(recommended_stock, recommended_price, self.day) #buy stock # print(f'Bought {recommended_stock} for {recommended_price} on the {self.day}') self.status = 'sell' #change the status to sell else: # print('No recommendations') pass else: #if the status is sell #get stock price on the day stocks = [key for key in self.buy_orders.keys()] for s in stocks: recommended_action, current_price = LR_v1_sell(s, self.buy_orders[s][3], self.buy_orders[s][0], self.day, \ self.sell_perc, self.hold_till, self.stop_perc) if np.random.choice([0, 1]) == 1: #randomly sell # print(f'Sold {s} for {current_price} on {self.day}') self.sell(s, current_price, self.buy_orders[s][1], self.day) self.status = 'buy' #go to next day self.day += delta d += 1 pbar.update(1) pbar.close() #sell the final stock and print final capital also print stock history self.print_bag() self.print_summary() self.save_results() return def get_stock_data(self, stock, back_to = 40): """ this function queries to td database and get data of a particular stock on a given day back to certain amount of days (default is 30). """ #get start and end dates end = self.day start = self.day - timedelta(days = back_to) # prediction, prediction_thresholded, close_price = LR_v1_predict(stock, start, end, threshold = 0.5) prediction, prediction_thresholded, close_price = self.model(stock, start, end, self.threshold) return prediction[0], prediction_thresholded, close_price def scanner(self): """ scan the stocks to find good stocks """ stock = np.random.choice(self.stocks) prediction, prediction_thresholded, close_price = self.get_stock_data(stock) self.daily_scanner[stock] = (prediction, prediction_thresholded, close_price) def save_results(self): """ save history dataframe create figures and save """ #save csv file results_df_path = os.path.join(self.folder_dir, 'history_df.csv') self.history_df.to_csv(results_df_path, index = False) #save params and results summary results_summary_path = os.path.join(self.folder_dir, 'results_summary') results_summary = [self.initial_capital, self.total_gain] params_path = os.path.join(self.folder_dir, 'params') params = [self.threshold, self.hold_till, self.sell_perc, self.stop_perc, self.start_date, self.end_date] with open(results_summary_path, 'wb') as fp: pickle.dump(results_summary, fp) with open(params_path, 'wb') as fp: pickle.dump(params, fp) if __name__ == "__main__": #stocks list dow = ['AXP', 'AMGN', 'AAPL', 'BA', 'CAT', 'CSCO', 'CVX', 'GS', 'HD', 'HON', 'IBM', 'INTC',\ 'JNJ', 'KO', 'JPM', 'MCD', 'MMM', 'MRK', 'MSFT', 'NKE', 'PG', 'TRV', 'UNH',\ 'CRM', 'VZ', 'V', 'WBA', 'WMT', 'DIS'] other = ['AMD', 'MU', 'ABT', 'AAL', 'UAL', 'DAL', 'ANTM', 'ATVI', 'BAC', 'PNC', 'C', 'EBAY', 'AMZN', 'GOOG', 'FB', 'SNAP', 'TWTR'\ 'FDX', 'MCD', 'PEP', ] stocks = list(np.unique(dow + other)) back = backtester(dow, LR_v1_predict, 3000, datetime(2021, 1, 1), datetime(2021, 12, 31), threshold = 1, sell_perc = 0.03, hold_till = 1,\ stop_perc = 0.03) back.backtest() ================================================ FILE: companies.csv ================================================ Ticker AAPL MSFT GOOG AMZN TSLA BRK-A NVDA FB V JPM UNH JNJ WMT PG BAC MA HD XOM DIS KO PFE ABBV CVX AVGO CSCO PEP LLY VZ COST NKE WFC CMCSA TMO ABT ADBE ORCL CRM MRK AMD DHR MCD QCOM INTC UPS NFLX T MS PM SCHW UNP TMUS TXN AXP BMY NEE LOW RTX INTU CVS C HON AMGN PYPL BA AMAT GS COP BLK IBM NOW DE SBUX EL ANTM PLD ABNB LMT AMT GE BKNG CHTR CAT MU ISRG SYK TGT MO SPGI MDLZ ZTS BX USB CME PNC MMM ADI ADP SNOW TFC LRCX DUK MMC GILD CSX BDX HCA CI TJX CCI F ICE GM SHW SO REGN ITW EW CL UBER PSA EOG D COF ATVI EQIX PGR FISV NSC BSX FCX NOC GD MCO SNAP VRTX WM MRNA FIS FDX MRVL MET MAR RIVN SLB EMR PXD WDAY KDP SQ KLAC HUM NEM APD SPG SCCO LBSI ECL ================================================ FILE: data_science/create_figures.py ================================================ import pickle import numpy as np import pandas as pd import matplotlib.pyplot as plt import os from datetime import timedelta import seaborn as sns class create_figures: def __init__(self, model_name, threshold, hold_till): self.model = model_name self.threshold = threshold self.hold_till = hold_till results_dir = ## '\\results' folder directory self.folder_name = f'{str(self.model)}_{self.threshold}_{self.hold_till}' self.folder_dir = os.path.join(results_dir, self.folder_name) history_df_path = os.path.join(self.folder_dir, 'history_df.csv') self.history_df = pd.read_csv(history_df_path) self.history_df['buy_date'] = pd.to_datetime(self.history_df['buy_date']) self.history_df['sell_date'] = pd.to_datetime(self.history_df['sell_date']) params_path = os.path.join(self.folder_dir, 'params') with open(params_path, 'rb') as fp: self.params = pickle.load(fp) results_summary_path = os.path.join(self.folder_dir, 'results_summary') with open(results_summary_path, 'rb') as fp: self.results_summary = pickle.load(fp) #get params from stored files self.initial_capital = self.results_summary[0] self.total_gain = self.results_summary[1] self.start_date = self.params[4] self.end_date = self.params[5] self.create_history_df() self.create_history_figure() self.gain_loss_plot() self.hold_hist() def create_history_df(self): """ this function creates a dataframe from start date to end date """ cols = ['Date', 'Stock', 'Gain', 'Total'] self.running_gains_df = pd.DataFrame(columns = cols) #create a row with the start date - 1 with the starting balance self.running_gains_df = self.running_gains_df.append({'Date': self.start_date - timedelta(days = 1), 'Stock': np.nan, 'Gain': \ np.nan, 'Total': self.initial_capital}, ignore_index = True) values_total = self.initial_capital #start balance #create date range def date_range(start, end): delta = end - start # as timedelta days = [start + timedelta(days=i) for i in range(delta.days + 1)] return days days = date_range(self.start_date, self.end_date) for day in days: #find if data is available. 1 if available 0 if not available = self.history_df[self.history_df['buy_date'] == day].values.shape[0] if available > 0: values = self.history_df.loc[self.history_df['buy_date'] == day].reset_index(drop = True) values_date = day values_stock = values['stock'][0] values_gain = values['net_gain'][0] values_total = values_total + values_gain #dict to append dict_ = {'Date': values_date, 'Stock': values_stock, 'Gain': values_gain, 'Total': values_total} self.running_gains_df = self.running_gains_df.append(dict_, ignore_index = True) else: dict_ = {'Date': day, 'Stock': np.nan, 'Gain': np.nan, 'Total': values_total} self.running_gains_df = self.running_gains_df.append(dict_, ignore_index = True) #save the running gains df self.running_gains_df.to_csv(f'{self.folder_dir}/running_gains_df.csv', index = False) def create_history_figure(self): """ plot the running gains """ plt.figure(figsize = (10, 6)) plt.plot(self.running_gains_df['Date'], self.running_gains_df['Total']) plt.xlabel('Time (days)', fontsize = '6') plt.ylabel('Total Balance ($)') plt.xticks(rotation = 45) # plt.show() fig_path = os.path.join(self.folder_dir, 'total_balance_history.jpg') plt.savefig(fig_path) def gain_loss_plot(self): """ a bar plot with gains and losses on the day """ positives = self.running_gains_df[self.running_gains_df['Gain'] > 0] negatives = self.running_gains_df[self.running_gains_df['Gain'] < 0] plt.figure(figsize = (10, 6)) plt.bar(positives['Date'], positives['Gain'], color = 'g', width = 1.5, label = 'wins') plt.bar(negatives['Date'], negatives['Gain'], color = 'r', width = 1.5, label = 'losses') plt.axhline(linewidth = 1, color = 'k') plt.legend() plt.xlabel('Time (days)', fontsize = '6') plt.ylabel('Gain ($)') plt.xticks(rotation = 45) # plt.show() fig_path = os.path.join(self.folder_dir, 'gain_loss.jpg') plt.savefig(fig_path) def hold_hist(self): """ This function creates a histogram with buy times and color code it with winner or loser """ #create columns df = self.history_df df['winner_bool'] = ['win' if x > 0 else 'loss' for x in df.net_gain] df['held_time'] = [(t2 - t1).days for t2, t1 in zip(df['sell_date'], df['buy_date'])] plt.figure(figsize = (10, 6)) sns.histplot(x = 'held_time', data = df, hue = 'winner_bool', bins = 100) plt.xticks(rotation = 45) plt.xlabel('Held time (days)') # plt.show() fig_path = os.path.join(self.folder_dir, 'held_time_histogram.jpg') plt.savefig(fig_path) if __name__ == '__main__': create_figures('LR_v1_predict', 1, 1) ================================================ FILE: data_science/stats.py ================================================ import pickle import numpy as np import pandas as pd import matplotlib.pyplot as plt import os from datetime import timedelta import seaborn as sns class create_stats: def __init__(self, model_name, threshold, hold_till): self.model = model_name self.threshold = threshold self.hold_till = hold_till results_dir = #add results directory self.folder_name = f'{str(self.model)}_{self.threshold}_{self.hold_till}' self.folder_dir = os.path.join(results_dir, self.folder_name) history_df_path = os.path.join(self.folder_dir, 'history_df.csv') self.history_df = pd.read_csv(history_df_path) self.history_df['buy_date'] = pd.to_datetime(self.history_df['buy_date']) self.history_df['sell_date'] = pd.to_datetime(self.history_df['sell_date']) params_path = os.path.join(self.folder_dir, 'params') with open(params_path, 'rb') as fp: self.params = pickle.load(fp) results_summary_path = os.path.join(self.folder_dir, 'results_summary') with open(results_summary_path, 'rb') as fp: self.results_summary = pickle.load(fp) #get params from stored files self.initial_capital = self.results_summary[0] self.total_gain = self.results_summary[1] self.start_date = self.params[4] self.end_date = self.params[5] self.calculate_stats() self.save_stats() def calculate_stats(self): #calculate total percentage win self.total_percentage = np.round(self.total_gain/self.initial_capital * 100, 2) #total gains self.total_gains = np.round(self.history_df[self.history_df['net_gain'] > 0]['net_gain'].sum(), 2) self.maximum_gain = np.round(self.history_df[self.history_df['net_gain'] > 0]['net_gain'].max(), 2) #total losses self.total_losses = np.round(self.history_df[self.history_df['net_gain'] < 0]['net_gain'].sum(), 2) self.maximum_loss = np.round(self.history_df[self.history_df['net_gain'] < 0]['net_gain'].min()) def save_stats(self): df = pd.read_csv(## add results/model_result_summary.csv path) results_dict = {'Model': f'{self.model}_{self.threshold}_{self.hold_till}',\ 'Gains': self.total_gains, 'Losses': self.total_losses, 'Profit': np.round(self.total_gain, 2), 'Profit Percentage': self.total_percentage, 'Maximum Gain': self.maximum_gain, 'Maximum Loss': self.maximum_loss} df = df.append(results_dict, ignore_index = True) df.to_csv(## add path results/model_result_summary.csv') if __name__ == "__main__": cs = create_stats('LR_v1_predict', 1, 1) ================================================ FILE: models/lr_inference.py ================================================ """ stock backtester to test the model given a dataset. author - Kaneel Senevirathne date - 1/13/2022 """ from doctest import OutputChecker import numpy as np import pickle from sklearn.linear_model import LogisticRegression from stock_utils.stock_utils import timestamp, create_train_data, get_data, create_test_data_lr, get_stock_price from datetime import timedelta import time def load_LR(model_version): file = #add path to the saved models folder and then model version 'eg: f'//saved_models//lr_{model_version}.sav' loaded_model = pickle.load(open(file, 'rb')) return loaded_model def load_scaler(model_version): file = ## add path to //saved_models//scaler_{model_version}.sav' loaded_model = pickle.load(open(file, 'rb')) return loaded_model def _threshold(probs, threshold): """ Inputs the probability and returns 1 or 0 based on the threshold """ prob_thresholded = [0 if x > threshold else 1 for x in probs[:, 0]] return np.array(prob_thresholded) def LR_v1_predict(stock, start_date, end_date, threshold = 0.98): """ this function predict given the data """ #create model and scaler instances scaler = load_scaler('v2') lr = load_LR('v2') #create input data = create_test_data_lr(stock, start_date, end_date) #get close price of final date close_price = data['close'].values[-1] #get input data to model input_data = data[['volume', 'normalized_value', '3_reg', '5_reg', '10_reg', '20_reg']] input_data = input_data.to_numpy()[-1].reshape(1, -1) #scale input data input_data_scaled = scaler.transform(input_data) prediction = lr._predict_proba_lr(input_data_scaled) prediction_thresholded = _threshold(prediction, threshold) return prediction[:, 0], prediction_thresholded[0], close_price def LR_v1_sell(stock, buy_date, buy_price, todays_date, sell_perc = 0.1, hold_till = 3, stop_perc = 0.05): """ gets stock price. recommnd to sell if the stock price is higher sell_perc * buy_price + buy_price stock - stock ticker symbol buy_date - the date the stock was bought todays_date - date today sell_perc - sell percentage hold_till - how many days to hold from today """ current_price = get_stock_price(stock, todays_date) #current stock value sell_price = buy_price + buy_price * sell_perc stop_price = buy_price - buy_price * stop_perc sell_date = buy_date + timedelta(days = hold_till) #the day to sell time.sleep(1) #to make sure the requested transactions per seconds is not exeeded. #some times it returns current price as none if (current_price is not None) and ((current_price < stop_price) or (current_price >= sell_price) or (todays_date >= sell_date)): return "SELL", current_price #if criteria is met recommend to sell else: return "HOLD", current_price #if crieteria is not met hold the stock ================================================ FILE: models/lr_run_training.py ================================================ """ LR training author - Kaneel Senevirathne date - 1/13/2022 """ from td.client import TDClient import requests, time, re, os import matplotlib.pyplot as plt import pandas as pd import pickle as pkl import numpy as np import datetime plt.style.use('grayscale') from scipy import linalg import math from datetime import datetime import warnings warnings.filterwarnings("ignore") import time from datetime import datetime import os import sys import pickle #append path current_dir = os.getcwd() sys.path.append(current_dir) from stock_utils import stock_utils import sklearn from sklearn.model_selection import train_test_split from sklearn.preprocessing import MinMaxScaler, StandardScaler from sklearn.linear_model import LogisticRegression from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay import seaborn as sns class LR_training: def __init__(self, model_version, threshold = 0.98, start_date = None, end_date = None): self.model_version = model_version self.threshold = threshold if start_date: self.start_date = start_date if end_date: self.end_date = end_date #get stock ticker symbols dow = ['AXP', 'AMGN', 'AAPL', 'BA', 'CAT', 'CSCO', 'CVX', 'GS', 'HD', 'HON', 'IBM', 'INTC',\ 'JNJ', 'KO', 'JPM', 'MCD', 'MMM', 'MRK', 'MSFT', 'NKE', 'PG', 'TRV', 'UNH',\ 'CRM', 'VZ', 'V', 'WBA', 'WMT', 'DIS'] sp500 = #use pandas to open the companies csv sp = list(sp500['Ticker']) stocks = dow + sp[:20] self.stocks = list(np.unique(stocks)) #main dataframe self.main_df = pd.DataFrame(columns = ['volume', 'normalized_value', '3_reg', '5_reg', '10_reg', '20_reg', 'target']) #init models self.scaler = MinMaxScaler() self.lr = LogisticRegression() #run logistic regresion self.fetch_data() self.create_train_test() self.fit_model() self.confusion_matrix() self.save_model() def fetch_data(self): """ get train and test data """ for stock in self.stocks: try: df = stock_utils.create_train_data(stock, n = 10) self.main_df = self.main_df.append(df) except: pass print(f'{len(self.main_df)} samples were fetched from the database..') def create_train_test(self): """ create train and test data """ self.main_df = self.main_df.sample(frac = 1, random_state = 3). reset_index(drop = True) self.main_df['target'] = self.main_df['target'].astype('category') y = self.main_df.pop('target').to_numpy() y = y.reshape(y.shape[0], 1) x = self.scaler.fit_transform(self.main_df) #test train split self.train_x, self.test_x, self.train_y, self.test_y = train_test_split(x, y, \ test_size = 0.05, random_state = 50, shuffle = True) print('Created test and train data...') def fit_model(self): print('Training model...') self.lr.fit(self.train_x, self.train_y) #predict the test data self.predictions = self.lr.predict(self.test_x) self.score = self.lr.score(self.test_x, self.test_y) print(f'Logistic regression model score: {self.score}') #preds with threshold self.predictions_proba = self.lr._predict_proba_lr(self.test_x) self.predictions_proba_thresholded = self._threshold(self.predictions_proba, self.threshold) def confusion_matrix(self): cm = confusion_matrix(self.test_y, self.predictions) self.cmd = ConfusionMatrixDisplay(cm) cm_thresholded = confusion_matrix(self.test_y, self.predictions_proba_thresholded) self.cmd_thresholded = ConfusionMatrixDisplay(cm_thresholded) def _threshold(self, predictions, threshold): prob_thresholded = [0 if x > threshold else 1 for x in predictions[:, 0]] return np.array(prob_thresholded) def save_model(self): #save models saved_models_dir = os.path.join(os.getcwd(), 'saved_models') model_file = f'lr_{self.model_version}.sav' model_dir = os.path.join(saved_models_dir, model_file) pickle.dump(self.lr, open(model_dir, 'wb')) scaler_file = f'scaler_{self.model_version}.sav' scaler_dir = os.path.join(saved_models_dir, scaler_file) pickle.dump(self.scaler, open(scaler_dir, 'wb')) print(f'Saved the model and scaler in {saved_models_dir}') cm_path = os.path.join(os.getcwd(), 'results\Confusion Matrices') #save cms plt.figure() self.cmd.plot() plt.savefig(f'{cm_path}\\cm_{self.model_version}.jpg') plt.figure() self.cmd_thresholded.plot() plt.savefig(f'{cm_path}\\cm_thresholded_{self.model_version}.jpg') print(f'Figures saved in {cm_path}') import argparse if __name__ == "__main__": run_lr = LR_training('v2') ================================================ FILE: results/LR_v1_predict_0.7_3/history_df.csv ================================================ stock,buy_price,n_shares,sell_price,net_gain,buy_date,sell_date BA,214.06,14,214.06,0.0,2021-01-01,2021-01-04 BA,202.72,14,211.63,124.73999999999995,2021-01-05,2021-01-06 MSFT,212.25,14,218.29,84.55999999999989,2021-01-07,2021-01-08 JNJ,160.04,20,159.37,-13.39999999999975,2021-01-09,2021-01-12 INTC,56.95,56,59.25,128.79999999999984,2021-01-14,2021-01-15 CRM,213.14,15,213.14,0.0,2021-01-16,2021-01-19 PG,133.6,24,131.93,-40.0799999999997,2021-01-20,2021-01-21 HON,205.23,16,202.25,-47.679999999999836,2021-01-22,2021-01-23 V,202.02,16,200.98,-16.640000000000327,2021-01-24,2021-01-26 HON,201.06,16,199.38,-26.88000000000011,2021-01-27,2021-01-28 V,198.22,16,193.25,-79.51999999999998,2021-01-29,2021-01-30 V,193.25,16,198.36,81.76000000000022,2021-01-31,2021-02-02 PG,128.79,24,129.17,9.11999999999989,2021-02-03,2021-02-09 HD,276.77,11,278.69,21.120000000000175,2021-02-10,2021-02-11 PG,128.33,25,127.62,-17.7500000000002,2021-02-12,2021-02-13 VZ,54.2,59,54.15,-2.9500000000002515,2021-02-14,2021-02-17 AXP,128.56,24,135.95,177.35999999999967,2021-02-18,2021-02-23 JNJ,160.44,21,162.59,45.15000000000012,2021-02-24,2021-02-25 HD,255.25,13,258.34,40.169999999999675,2021-02-26,2021-02-27 AAPL,121.26,28,127.79,182.84000000000003,2021-02-28,2021-03-02 CRM,213.47,17,211.96,-25.669999999999845,2021-03-03,2021-03-11 VZ,55.51,65,55.63,7.800000000000296,2021-03-12,2021-03-15 WMT,133.43,27,132.28,-31.050000000000153,2021-03-16,2021-03-18 WMT,130.01,27,131.74,46.71000000000049,2021-03-19,2021-03-20 V,206.9,17,213.53,112.70999999999992,2021-03-21,2021-03-27 GS,327.39,11,325.73,-18.25999999999965,2021-03-28,2021-03-30 MRK,76.96,48,77.09,6.240000000000464,2021-03-31,2021-04-03 KO,52.51,71,52.81,21.300000000000303,2021-04-04,2021-04-06 CVX,103.58,36,102.92,-23.759999999999877,2021-04-07,2021-04-11 WBA,54.18,69,54.7,35.880000000000216,2021-04-12,2021-04-13 NKE,133.54,28,132.26,-35.84000000000003,2021-04-14,2021-04-15 JNJ,160.39,23,162.24,42.55000000000052,2021-04-16,2021-04-17 WBA,53.3,71,53.02,-19.879999999999576,2021-04-18,2021-04-25 PG,133.94,28,131.26,-75.04000000000019,2021-04-26,2021-04-27 CSCO,51.37,71,51.11,-18.45999999999986,2021-04-28,2021-04-29 AAPL,133.48,27,131.46,-54.53999999999951,2021-04-30,2021-05-01 CVX,103.07,35,106.11,106.40000000000022,2021-05-02,2021-05-05 CRM,215.4,17,218.05,45.0500000000001,2021-05-06,2021-05-07 CRM,216.5,17,213.89,-44.37000000000023,2021-05-08,2021-05-11 TRV,156.69,23,153.75,-67.61999999999995,2021-05-12,2021-05-13 CRM,211.86,17,221.34,161.15999999999983,2021-05-14,2021-05-20 VZ,56.79,67,56.91,8.039999999999829,2021-05-21,2021-05-24 HD,314.84,12,316.75,22.9200000000003,2021-05-25,2021-05-26 AMGN,238.55,16,235.31,-51.840000000000146,2021-05-27,2021-05-28 HD,318.91,11,311.01,-86.90000000000038,2021-05-29,2021-06-05 JNJ,165.97,22,164.84,-24.8599999999999,2021-06-06,2021-06-08 WMT,139.83,26,139.08,-19.5,2021-06-09,2021-06-10 CAT,225.73,16,220.7,-80.48000000000002,2021-06-11,2021-06-12 CAT,220.7,16,208.86,-189.4399999999996,2021-06-13,2021-06-21 CAT,213.21,15,219.34,91.94999999999993,2021-06-22,2021-06-25 MCD,232.42,15,231.09,-19.94999999999976,2021-06-26,2021-06-29 BA,235.76,14,239.56,53.20000000000016,2021-06-30,2021-07-01 CAT,216.71,16,217.76,16.799999999999727,2021-07-02,2021-07-06 AMGN,243.65,14,243.22,-6.0200000000000955,2021-07-07,2021-07-08 TRV,148.52,23,153.33,110.63000000000005,2021-07-09,2021-07-10 MRK,77.99,46,77.55,-20.239999999999895,2021-07-11,2021-07-13 BA,228.2,15,222.54,-84.89999999999995,2021-07-14,2021-07-22 MMM,199.07,17,200.49,24.14000000000027,2021-07-23,2021-07-24 AXP,173.18,20,172.61,-11.399999999999864,2021-07-25,2021-07-27 WBA,46.82,75,47.11,21.749999999999936,2021-07-28,2021-07-29 AMGN,242.46,14,233.99,-118.57999999999998,2021-07-30,2021-08-06 VZ,55.22,62,55.12,-6.200000000000088,2021-08-07,2021-08-10 MCD,233.45,14,235.55,29.40000000000032,2021-08-11,2021-08-12 V,231.79,15,232.65,12.900000000000205,2021-08-13,2021-08-16 DIS,175.83,19,174.74,-20.710000000000065,2021-08-18,2021-08-19 BA,212.16,16,212.67,8.159999999999854,2021-08-20,2021-08-23 VZ,55.42,62,55.01,-25.42000000000023,2021-08-24,2021-08-25 AMGN,221.59,15,222.78,17.849999999999966,2021-08-26,2021-08-28 HON,231.14,15,231.91,11.550000000000153,2021-08-29,2021-09-01 BA,218.12,15,220.83,40.65000000000012,2021-09-02,2021-09-03 WBA,51.29,68,51.29,0.0,2021-09-04,2021-09-07 MMM,185.58,18,187.89,41.57999999999953,2021-09-08,2021-09-09 AMGN,215.58,16,218.13,40.79999999999973,2021-09-10,2021-09-16 BA,213.36,16,213.36,0.0,2021-09-17,2021-09-20 AMGN,215.11,16,213.64,-23.520000000000437,2021-09-21,2021-09-23 UNH,408.03,8,407.08,-7.599999999999909,2021-09-24,2021-09-25 KO,53.89,66,53.02,-57.41999999999983,2021-09-26,2021-10-02 MRK,81.4,43,83.1,73.09999999999951,2021-10-03,2021-10-05 V,224.28,16,226.51,35.679999999999836,2021-10-06,2021-10-07 MMM,177.8,20,176.95,-17.000000000000455,2021-10-08,2021-10-09 VZ,53.24,67,52.27,-64.98999999999992,2021-10-10,2021-10-18 MRK,77.15,45,79.49,105.29999999999951,2021-10-19,2021-10-20 V,231.42,15,230.24,-17.699999999999676,2021-10-21,2021-10-22 BA,212.97,17,212.87,-1.6999999999999034,2021-10-23,2021-10-26 MCD,236.42,15,250.58,212.40000000000038,2021-10-27,2021-11-02 TRV,158.82,24,160.25,34.320000000000164,2021-11-03,2021-11-04 V,208.78,18,216.67,142.01999999999975,2021-11-05,2021-11-06 GS,407.08,9,405.35,-15.569999999999652,2021-11-07,2021-11-10 AAPL,147.92,27,153.49,150.39000000000058,2021-11-11,2021-11-18 TRV,156.03,26,152.53,-91.0,2021-11-19,2021-11-20 TRV,152.53,26,156.87,112.84000000000009,2021-11-21,2021-11-23 DIS,151.03,27,148.11,-78.83999999999966,2021-11-24,2021-11-27 AMGN,201.09,20,201.17,1.5999999999996817,2021-11-28,2021-12-03 CRM,258.32,15,258.75,6.450000000000102,2021-12-04,2021-12-07 INTC,52.57,78,51.75,-63.96000000000002,2021-12-08,2021-12-09 NKE,168.1,24,169.06,23.04000000000019,2021-12-10,2021-12-11 CRM,266.03,15,252.93,-196.4999999999995,2021-12-12,2021-12-19 HD,387.98,9,390.47,22.410000000000082,2021-12-20,2021-12-22 TRV,154.69,25,154.65,-0.999999999999801,2021-12-23,2021-12-26 JPM,157.26,24,158.16,21.600000000000136,2021-12-27,2021-12-28 ================================================ FILE: results/LR_v1_predict_0.7_3/running_gains_df.csv ================================================ Date,Stock,Gain,Total 2020-12-31,,,3000 2021-01-01,BA,0.0,3000.0 2021-01-02,,,3000.0 2021-01-03,,,3000.0 2021-01-04,,,3000.0 2021-01-05,BA,124.73999999999997,3124.74 2021-01-06,,,3124.74 2021-01-07,MSFT,84.55999999999989,3209.2999999999997 2021-01-08,,,3209.2999999999997 2021-01-09,JNJ,-13.39999999999975,3195.9 2021-01-10,,,3195.9 2021-01-11,,,3195.9 2021-01-12,,,3195.9 2021-01-13,,,3195.9 2021-01-14,INTC,128.79999999999984,3324.7 2021-01-15,,,3324.7 2021-01-16,CRM,0.0,3324.7 2021-01-17,,,3324.7 2021-01-18,,,3324.7 2021-01-19,,,3324.7 2021-01-20,PG,-40.0799999999997,3284.62 2021-01-21,,,3284.62 2021-01-22,HON,-47.67999999999984,3236.94 2021-01-23,,,3236.94 2021-01-24,V,-16.640000000000327,3220.2999999999997 2021-01-25,,,3220.2999999999997 2021-01-26,,,3220.2999999999997 2021-01-27,HON,-26.88000000000011,3193.4199999999996 2021-01-28,,,3193.4199999999996 2021-01-29,V,-79.51999999999998,3113.8999999999996 2021-01-30,,,3113.8999999999996 2021-01-31,V,81.76000000000022,3195.66 2021-02-01,,,3195.66 2021-02-02,,,3195.66 2021-02-03,PG,9.11999999999989,3204.7799999999997 2021-02-04,,,3204.7799999999997 2021-02-05,,,3204.7799999999997 2021-02-06,,,3204.7799999999997 2021-02-07,,,3204.7799999999997 2021-02-08,,,3204.7799999999997 2021-02-09,,,3204.7799999999997 2021-02-10,HD,21.12000000000017,3225.9 2021-02-11,,,3225.9 2021-02-12,PG,-17.7500000000002,3208.15 2021-02-13,,,3208.15 2021-02-14,VZ,-2.9500000000002515,3205.2 2021-02-15,,,3205.2 2021-02-16,,,3205.2 2021-02-17,,,3205.2 2021-02-18,AXP,177.35999999999967,3382.5599999999995 2021-02-19,,,3382.5599999999995 2021-02-20,,,3382.5599999999995 2021-02-21,,,3382.5599999999995 2021-02-22,,,3382.5599999999995 2021-02-23,,,3382.5599999999995 2021-02-24,JNJ,45.15000000000012,3427.7099999999996 2021-02-25,,,3427.7099999999996 2021-02-26,HD,40.16999999999968,3467.879999999999 2021-02-27,,,3467.879999999999 2021-02-28,AAPL,182.84000000000003,3650.7199999999993 2021-03-01,,,3650.7199999999993 2021-03-02,,,3650.7199999999993 2021-03-03,CRM,-25.669999999999845,3625.0499999999993 2021-03-04,,,3625.0499999999993 2021-03-05,,,3625.0499999999993 2021-03-06,,,3625.0499999999993 2021-03-07,,,3625.0499999999993 2021-03-08,,,3625.0499999999993 2021-03-09,,,3625.0499999999993 2021-03-10,,,3625.0499999999993 2021-03-11,,,3625.0499999999993 2021-03-12,VZ,7.800000000000296,3632.8499999999995 2021-03-13,,,3632.8499999999995 2021-03-14,,,3632.8499999999995 2021-03-15,,,3632.8499999999995 2021-03-16,WMT,-31.050000000000157,3601.7999999999993 2021-03-17,,,3601.7999999999993 2021-03-18,,,3601.7999999999993 2021-03-19,WMT,46.71000000000049,3648.5099999999998 2021-03-20,,,3648.5099999999998 2021-03-21,V,112.70999999999992,3761.22 2021-03-22,,,3761.22 2021-03-23,,,3761.22 2021-03-24,,,3761.22 2021-03-25,,,3761.22 2021-03-26,,,3761.22 2021-03-27,,,3761.22 2021-03-28,GS,-18.25999999999965,3742.96 2021-03-29,,,3742.96 2021-03-30,,,3742.96 2021-03-31,MRK,6.240000000000464,3749.2000000000007 2021-04-01,,,3749.2000000000007 2021-04-02,,,3749.2000000000007 2021-04-03,,,3749.2000000000007 2021-04-04,KO,21.300000000000303,3770.500000000001 2021-04-05,,,3770.500000000001 2021-04-06,,,3770.500000000001 2021-04-07,CVX,-23.75999999999988,3746.740000000001 2021-04-08,,,3746.740000000001 2021-04-09,,,3746.740000000001 2021-04-10,,,3746.740000000001 2021-04-11,,,3746.740000000001 2021-04-12,WBA,35.880000000000216,3782.6200000000013 2021-04-13,,,3782.6200000000013 2021-04-14,NKE,-35.84000000000003,3746.780000000001 2021-04-15,,,3746.780000000001 2021-04-16,JNJ,42.55000000000052,3789.3300000000017 2021-04-17,,,3789.3300000000017 2021-04-18,WBA,-19.879999999999576,3769.450000000002 2021-04-19,,,3769.450000000002 2021-04-20,,,3769.450000000002 2021-04-21,,,3769.450000000002 2021-04-22,,,3769.450000000002 2021-04-23,,,3769.450000000002 2021-04-24,,,3769.450000000002 2021-04-25,,,3769.450000000002 2021-04-26,PG,-75.04000000000019,3694.4100000000017 2021-04-27,,,3694.4100000000017 2021-04-28,CSCO,-18.45999999999986,3675.9500000000016 2021-04-29,,,3675.9500000000016 2021-04-30,AAPL,-54.53999999999951,3621.410000000002 2021-05-01,,,3621.410000000002 2021-05-02,CVX,106.40000000000022,3727.810000000002 2021-05-03,,,3727.810000000002 2021-05-04,,,3727.810000000002 2021-05-05,,,3727.810000000002 2021-05-06,CRM,45.0500000000001,3772.8600000000024 2021-05-07,,,3772.8600000000024 2021-05-08,CRM,-44.37000000000023,3728.490000000002 2021-05-09,,,3728.490000000002 2021-05-10,,,3728.490000000002 2021-05-11,,,3728.490000000002 2021-05-12,TRV,-67.61999999999995,3660.870000000002 2021-05-13,,,3660.870000000002 2021-05-14,CRM,161.15999999999983,3822.030000000002 2021-05-15,,,3822.030000000002 2021-05-16,,,3822.030000000002 2021-05-17,,,3822.030000000002 2021-05-18,,,3822.030000000002 2021-05-19,,,3822.030000000002 2021-05-20,,,3822.030000000002 2021-05-21,VZ,8.039999999999829,3830.070000000002 2021-05-22,,,3830.070000000002 2021-05-23,,,3830.070000000002 2021-05-24,,,3830.070000000002 2021-05-25,HD,22.9200000000003,3852.9900000000025 2021-05-26,,,3852.9900000000025 2021-05-27,AMGN,-51.84000000000015,3801.1500000000024 2021-05-28,,,3801.1500000000024 2021-05-29,HD,-86.90000000000038,3714.250000000002 2021-05-30,,,3714.250000000002 2021-05-31,,,3714.250000000002 2021-06-01,,,3714.250000000002 2021-06-02,,,3714.250000000002 2021-06-03,,,3714.250000000002 2021-06-04,,,3714.250000000002 2021-06-05,,,3714.250000000002 2021-06-06,JNJ,-24.8599999999999,3689.390000000002 2021-06-07,,,3689.390000000002 2021-06-08,,,3689.390000000002 2021-06-09,WMT,-19.5,3669.890000000002 2021-06-10,,,3669.890000000002 2021-06-11,CAT,-80.48000000000002,3589.410000000002 2021-06-12,,,3589.410000000002 2021-06-13,CAT,-189.4399999999996,3399.9700000000025 2021-06-14,,,3399.9700000000025 2021-06-15,,,3399.9700000000025 2021-06-16,,,3399.9700000000025 2021-06-17,,,3399.9700000000025 2021-06-18,,,3399.9700000000025 2021-06-19,,,3399.9700000000025 2021-06-20,,,3399.9700000000025 2021-06-21,,,3399.9700000000025 2021-06-22,CAT,91.94999999999992,3491.9200000000023 2021-06-23,,,3491.9200000000023 2021-06-24,,,3491.9200000000023 2021-06-25,,,3491.9200000000023 2021-06-26,MCD,-19.94999999999976,3471.9700000000025 2021-06-27,,,3471.9700000000025 2021-06-28,,,3471.9700000000025 2021-06-29,,,3471.9700000000025 2021-06-30,BA,53.20000000000016,3525.170000000003 2021-07-01,,,3525.170000000003 2021-07-02,CAT,16.799999999999727,3541.9700000000025 2021-07-03,,,3541.9700000000025 2021-07-04,,,3541.9700000000025 2021-07-05,,,3541.9700000000025 2021-07-06,,,3541.9700000000025 2021-07-07,AMGN,-6.020000000000096,3535.9500000000025 2021-07-08,,,3535.9500000000025 2021-07-09,TRV,110.63000000000004,3646.5800000000027 2021-07-10,,,3646.5800000000027 2021-07-11,MRK,-20.239999999999892,3626.340000000003 2021-07-12,,,3626.340000000003 2021-07-13,,,3626.340000000003 2021-07-14,BA,-84.89999999999995,3541.440000000003 2021-07-15,,,3541.440000000003 2021-07-16,,,3541.440000000003 2021-07-17,,,3541.440000000003 2021-07-18,,,3541.440000000003 2021-07-19,,,3541.440000000003 2021-07-20,,,3541.440000000003 2021-07-21,,,3541.440000000003 2021-07-22,,,3541.440000000003 2021-07-23,MMM,24.14000000000027,3565.580000000003 2021-07-24,,,3565.580000000003 2021-07-25,AXP,-11.399999999999864,3554.180000000003 2021-07-26,,,3554.180000000003 2021-07-27,,,3554.180000000003 2021-07-28,WBA,21.749999999999936,3575.930000000003 2021-07-29,,,3575.930000000003 2021-07-30,AMGN,-118.57999999999998,3457.350000000003 2021-07-31,,,3457.350000000003 2021-08-01,,,3457.350000000003 2021-08-02,,,3457.350000000003 2021-08-03,,,3457.350000000003 2021-08-04,,,3457.350000000003 2021-08-05,,,3457.350000000003 2021-08-06,,,3457.350000000003 2021-08-07,VZ,-6.200000000000088,3451.150000000003 2021-08-08,,,3451.150000000003 2021-08-09,,,3451.150000000003 2021-08-10,,,3451.150000000003 2021-08-11,MCD,29.40000000000032,3480.550000000003 2021-08-12,,,3480.550000000003 2021-08-13,V,12.900000000000205,3493.450000000003 2021-08-14,,,3493.450000000003 2021-08-15,,,3493.450000000003 2021-08-16,,,3493.450000000003 2021-08-17,,,3493.450000000003 2021-08-18,DIS,-20.710000000000065,3472.740000000003 2021-08-19,,,3472.740000000003 2021-08-20,BA,8.159999999999854,3480.900000000003 2021-08-21,,,3480.900000000003 2021-08-22,,,3480.900000000003 2021-08-23,,,3480.900000000003 2021-08-24,VZ,-25.42000000000023,3455.4800000000027 2021-08-25,,,3455.4800000000027 2021-08-26,AMGN,17.849999999999966,3473.3300000000027 2021-08-27,,,3473.3300000000027 2021-08-28,,,3473.3300000000027 2021-08-29,HON,11.550000000000152,3484.880000000003 2021-08-30,,,3484.880000000003 2021-08-31,,,3484.880000000003 2021-09-01,,,3484.880000000003 2021-09-02,BA,40.65000000000012,3525.530000000003 2021-09-03,,,3525.530000000003 2021-09-04,WBA,0.0,3525.530000000003 2021-09-05,,,3525.530000000003 2021-09-06,,,3525.530000000003 2021-09-07,,,3525.530000000003 2021-09-08,MMM,41.57999999999953,3567.1100000000024 2021-09-09,,,3567.1100000000024 2021-09-10,AMGN,40.79999999999973,3607.910000000002 2021-09-11,,,3607.910000000002 2021-09-12,,,3607.910000000002 2021-09-13,,,3607.910000000002 2021-09-14,,,3607.910000000002 2021-09-15,,,3607.910000000002 2021-09-16,,,3607.910000000002 2021-09-17,BA,0.0,3607.910000000002 2021-09-18,,,3607.910000000002 2021-09-19,,,3607.910000000002 2021-09-20,,,3607.910000000002 2021-09-21,AMGN,-23.52000000000044,3584.3900000000017 2021-09-22,,,3584.3900000000017 2021-09-23,,,3584.3900000000017 2021-09-24,UNH,-7.599999999999909,3576.790000000002 2021-09-25,,,3576.790000000002 2021-09-26,KO,-57.41999999999983,3519.370000000002 2021-09-27,,,3519.370000000002 2021-09-28,,,3519.370000000002 2021-09-29,,,3519.370000000002 2021-09-30,,,3519.370000000002 2021-10-01,,,3519.370000000002 2021-10-02,,,3519.370000000002 2021-10-03,MRK,73.09999999999951,3592.4700000000016 2021-10-04,,,3592.4700000000016 2021-10-05,,,3592.4700000000016 2021-10-06,V,35.67999999999984,3628.1500000000015 2021-10-07,,,3628.1500000000015 2021-10-08,MMM,-17.000000000000455,3611.150000000001 2021-10-09,,,3611.150000000001 2021-10-10,VZ,-64.98999999999992,3546.160000000001 2021-10-11,,,3546.160000000001 2021-10-12,,,3546.160000000001 2021-10-13,,,3546.160000000001 2021-10-14,,,3546.160000000001 2021-10-15,,,3546.160000000001 2021-10-16,,,3546.160000000001 2021-10-17,,,3546.160000000001 2021-10-18,,,3546.160000000001 2021-10-19,MRK,105.29999999999951,3651.460000000001 2021-10-20,,,3651.460000000001 2021-10-21,V,-17.699999999999676,3633.760000000001 2021-10-22,,,3633.760000000001 2021-10-23,BA,-1.6999999999999034,3632.0600000000013 2021-10-24,,,3632.0600000000013 2021-10-25,,,3632.0600000000013 2021-10-26,,,3632.0600000000013 2021-10-27,MCD,212.4000000000004,3844.460000000002 2021-10-28,,,3844.460000000002 2021-10-29,,,3844.460000000002 2021-10-30,,,3844.460000000002 2021-10-31,,,3844.460000000002 2021-11-01,,,3844.460000000002 2021-11-02,,,3844.460000000002 2021-11-03,TRV,34.320000000000164,3878.780000000002 2021-11-04,,,3878.780000000002 2021-11-05,V,142.01999999999975,4020.800000000002 2021-11-06,,,4020.800000000002 2021-11-07,GS,-15.569999999999652,4005.2300000000023 2021-11-08,,,4005.2300000000023 2021-11-09,,,4005.2300000000023 2021-11-10,,,4005.2300000000023 2021-11-11,AAPL,150.39000000000058,4155.620000000003 2021-11-12,,,4155.620000000003 2021-11-13,,,4155.620000000003 2021-11-14,,,4155.620000000003 2021-11-15,,,4155.620000000003 2021-11-16,,,4155.620000000003 2021-11-17,,,4155.620000000003 2021-11-18,,,4155.620000000003 2021-11-19,TRV,-91.0,4064.6200000000026 2021-11-20,,,4064.6200000000026 2021-11-21,TRV,112.84000000000007,4177.460000000003 2021-11-22,,,4177.460000000003 2021-11-23,,,4177.460000000003 2021-11-24,DIS,-78.83999999999966,4098.6200000000035 2021-11-25,,,4098.6200000000035 2021-11-26,,,4098.6200000000035 2021-11-27,,,4098.6200000000035 2021-11-28,AMGN,1.5999999999996817,4100.220000000003 2021-11-29,,,4100.220000000003 2021-11-30,,,4100.220000000003 2021-12-01,,,4100.220000000003 2021-12-02,,,4100.220000000003 2021-12-03,,,4100.220000000003 2021-12-04,CRM,6.450000000000102,4106.670000000003 2021-12-05,,,4106.670000000003 2021-12-06,,,4106.670000000003 2021-12-07,,,4106.670000000003 2021-12-08,INTC,-63.96000000000002,4042.7100000000028 2021-12-09,,,4042.7100000000028 2021-12-10,NKE,23.04000000000019,4065.7500000000027 2021-12-11,,,4065.7500000000027 2021-12-12,CRM,-196.4999999999995,3869.250000000003 2021-12-13,,,3869.250000000003 2021-12-14,,,3869.250000000003 2021-12-15,,,3869.250000000003 2021-12-16,,,3869.250000000003 2021-12-17,,,3869.250000000003 2021-12-18,,,3869.250000000003 2021-12-19,,,3869.250000000003 2021-12-20,HD,22.41000000000008,3891.660000000003 2021-12-21,,,3891.660000000003 2021-12-22,,,3891.660000000003 2021-12-23,TRV,-0.999999999999801,3890.660000000003 2021-12-24,,,3890.660000000003 2021-12-25,,,3890.660000000003 2021-12-26,,,3890.660000000003 2021-12-27,JPM,21.600000000000136,3912.260000000003 2021-12-28,,,3912.260000000003 2021-12-29,,,3912.260000000003 2021-12-30,,,3912.260000000003 2021-12-31,,,3912.260000000003 ================================================ FILE: results/LR_v1_predict_0.95_21/history_df.csv ================================================ stock,buy_price,n_shares,sell_price,net_gain,buy_date,sell_date BA,202.72,14,211.45,122.21999999999986,2021-01-05,2021-01-21 HON,205.23,15,202.25,-44.69999999999985,2021-01-22,2021-01-23 PG,130.0,23,128.38,-37.260000000000105,2021-01-24,2021-01-28 V,198.22,15,193.25,-74.54999999999998,2021-01-29,2021-01-30 GS,271.17,10,293.5,223.29999999999984,2021-01-31,2021-02-06 UNH,324.51,9,332.22,69.39000000000033,2021-02-07,2021-02-28 AAPL,121.26,26,127.79,169.78000000000003,2021-03-01,2021-03-02 CRM,213.47,16,206.0,-119.51999999999998,2021-03-03,2021-03-04 CRM,211.53,15,209.48,-30.75000000000017,2021-03-10,2021-03-19 V,206.9,15,216.86,149.40000000000012,2021-03-20,2021-04-02 GS,323.54,10,338.55,150.0999999999999,2021-04-06,2021-04-16 WBA,53.3,67,52.58,-48.239999999999924,2021-04-17,2021-04-23 PG,131.26,26,137.67,166.6599999999999,2021-04-27,2021-05-11 BA,220.78,16,234.82,224.63999999999987,2021-05-13,2021-05-22 V,226.77,17,234.96,139.22999999999996,2021-05-23,2021-06-13 CAT,220.7,18,219.01,-30.41999999999996,2021-06-14,2021-06-15 JNJ,164.49,24,161.98,-60.240000000000464,2021-06-16,2021-06-19 GS,348.83,11,368.75,219.12000000000018,2021-06-20,2021-06-25 MCD,232.42,18,230.37,-36.89999999999969,2021-06-26,2021-06-30 V,233.82,17,245.99,206.89000000000027,2021-07-01,2021-07-15 BA,217.74,20,206.99,-215.0,2021-07-17,2021-07-20 VZ,55.58,74,55.37,-15.540000000000063,2021-07-21,2021-08-05 VZ,55.22,74,55.01,-15.540000000000063,2021-08-07,2021-08-25 AMGN,221.59,18,220.87,-12.95999999999998,2021-08-26,2021-09-09 AMGN,215.58,19,213.75,-34.77000000000024,2021-09-10,2021-09-11 MMM,184.55,22,182.42,-46.860000000000525,2021-09-12,2021-09-15 BA,213.36,18,209.5,-69.48000000000025,2021-09-17,2021-09-21 GS,375.84,10,391.86,160.2000000000004,2021-09-22,2021-09-24 KO,53.89,76,53.61,-21.280000000000086,2021-09-26,2021-09-28 NKE,145.3,28,151.85,183.39999999999952,2021-09-29,2021-10-08 VZ,53.24,80,52.18,-84.80000000000018,2021-10-09,2021-10-12 KO,54.23,77,53.94,-22.329999999999934,2021-10-13,2021-10-19 IBM,122.57619612,33,122.14637232,-14.184185400000274,2021-10-22,2021-10-23 BA,212.97,19,207.03,-112.85999999999996,2021-10-24,2021-11-01 TRV,158.82,25,156.5,-57.99999999999983,2021-11-03,2021-11-05 AAPL,147.92,26,157.87,258.70000000000044,2021-11-11,2021-11-19 TRV,152.53,27,160.26,208.70999999999972,2021-11-20,2021-11-24 MMM,177.63,25,175.52,-52.74999999999963,2021-11-25,2021-11-28 AMGN,201.09,21,198.88,-46.41000000000017,2021-11-29,2021-12-01 GS,376.48,11,400.11,259.92999999999995,2021-12-02,2021-12-08 NKE,168.1,27,165.4,-72.8999999999997,2021-12-10,2021-12-15 CRM,253.12,17,247.21,-100.46999999999994,2021-12-17,2021-12-21 ================================================ FILE: results/LR_v1_predict_0.95_21/running_gains_df.csv ================================================ Date,Stock,Gain,Total 2020-12-31,,,3000 2021-01-01,,,3000 2021-01-02,,,3000 2021-01-03,,,3000 2021-01-04,,,3000 2021-01-05,BA,122.21999999999986,3122.22 2021-01-06,,,3122.22 2021-01-07,,,3122.22 2021-01-08,,,3122.22 2021-01-09,,,3122.22 2021-01-10,,,3122.22 2021-01-11,,,3122.22 2021-01-12,,,3122.22 2021-01-13,,,3122.22 2021-01-14,,,3122.22 2021-01-15,,,3122.22 2021-01-16,,,3122.22 2021-01-17,,,3122.22 2021-01-18,,,3122.22 2021-01-19,,,3122.22 2021-01-20,,,3122.22 2021-01-21,,,3122.22 2021-01-22,HON,-44.69999999999985,3077.52 2021-01-23,,,3077.52 2021-01-24,PG,-37.260000000000105,3040.2599999999998 2021-01-25,,,3040.2599999999998 2021-01-26,,,3040.2599999999998 2021-01-27,,,3040.2599999999998 2021-01-28,,,3040.2599999999998 2021-01-29,V,-74.54999999999998,2965.7099999999996 2021-01-30,,,2965.7099999999996 2021-01-31,GS,223.29999999999984,3189.0099999999993 2021-02-01,,,3189.0099999999993 2021-02-02,,,3189.0099999999993 2021-02-03,,,3189.0099999999993 2021-02-04,,,3189.0099999999993 2021-02-05,,,3189.0099999999993 2021-02-06,,,3189.0099999999993 2021-02-07,UNH,69.39000000000033,3258.3999999999996 2021-02-08,,,3258.3999999999996 2021-02-09,,,3258.3999999999996 2021-02-10,,,3258.3999999999996 2021-02-11,,,3258.3999999999996 2021-02-12,,,3258.3999999999996 2021-02-13,,,3258.3999999999996 2021-02-14,,,3258.3999999999996 2021-02-15,,,3258.3999999999996 2021-02-16,,,3258.3999999999996 2021-02-17,,,3258.3999999999996 2021-02-18,,,3258.3999999999996 2021-02-19,,,3258.3999999999996 2021-02-20,,,3258.3999999999996 2021-02-21,,,3258.3999999999996 2021-02-22,,,3258.3999999999996 2021-02-23,,,3258.3999999999996 2021-02-24,,,3258.3999999999996 2021-02-25,,,3258.3999999999996 2021-02-26,,,3258.3999999999996 2021-02-27,,,3258.3999999999996 2021-02-28,,,3258.3999999999996 2021-03-01,AAPL,169.78000000000003,3428.18 2021-03-02,,,3428.18 2021-03-03,CRM,-119.51999999999998,3308.66 2021-03-04,,,3308.66 2021-03-05,,,3308.66 2021-03-06,,,3308.66 2021-03-07,,,3308.66 2021-03-08,,,3308.66 2021-03-09,,,3308.66 2021-03-10,CRM,-30.75000000000017,3277.91 2021-03-11,,,3277.91 2021-03-12,,,3277.91 2021-03-13,,,3277.91 2021-03-14,,,3277.91 2021-03-15,,,3277.91 2021-03-16,,,3277.91 2021-03-17,,,3277.91 2021-03-18,,,3277.91 2021-03-19,,,3277.91 2021-03-20,V,149.40000000000012,3427.31 2021-03-21,,,3427.31 2021-03-22,,,3427.31 2021-03-23,,,3427.31 2021-03-24,,,3427.31 2021-03-25,,,3427.31 2021-03-26,,,3427.31 2021-03-27,,,3427.31 2021-03-28,,,3427.31 2021-03-29,,,3427.31 2021-03-30,,,3427.31 2021-03-31,,,3427.31 2021-04-01,,,3427.31 2021-04-02,,,3427.31 2021-04-03,,,3427.31 2021-04-04,,,3427.31 2021-04-05,,,3427.31 2021-04-06,GS,150.0999999999999,3577.41 2021-04-07,,,3577.41 2021-04-08,,,3577.41 2021-04-09,,,3577.41 2021-04-10,,,3577.41 2021-04-11,,,3577.41 2021-04-12,,,3577.41 2021-04-13,,,3577.41 2021-04-14,,,3577.41 2021-04-15,,,3577.41 2021-04-16,,,3577.41 2021-04-17,WBA,-48.23999999999992,3529.17 2021-04-18,,,3529.17 2021-04-19,,,3529.17 2021-04-20,,,3529.17 2021-04-21,,,3529.17 2021-04-22,,,3529.17 2021-04-23,,,3529.17 2021-04-24,,,3529.17 2021-04-25,,,3529.17 2021-04-26,,,3529.17 2021-04-27,PG,166.6599999999999,3695.83 2021-04-28,,,3695.83 2021-04-29,,,3695.83 2021-04-30,,,3695.83 2021-05-01,,,3695.83 2021-05-02,,,3695.83 2021-05-03,,,3695.83 2021-05-04,,,3695.83 2021-05-05,,,3695.83 2021-05-06,,,3695.83 2021-05-07,,,3695.83 2021-05-08,,,3695.83 2021-05-09,,,3695.83 2021-05-10,,,3695.83 2021-05-11,,,3695.83 2021-05-12,,,3695.83 2021-05-13,BA,224.63999999999987,3920.47 2021-05-14,,,3920.47 2021-05-15,,,3920.47 2021-05-16,,,3920.47 2021-05-17,,,3920.47 2021-05-18,,,3920.47 2021-05-19,,,3920.47 2021-05-20,,,3920.47 2021-05-21,,,3920.47 2021-05-22,,,3920.47 2021-05-23,V,139.22999999999996,4059.7 2021-05-24,,,4059.7 2021-05-25,,,4059.7 2021-05-26,,,4059.7 2021-05-27,,,4059.7 2021-05-28,,,4059.7 2021-05-29,,,4059.7 2021-05-30,,,4059.7 2021-05-31,,,4059.7 2021-06-01,,,4059.7 2021-06-02,,,4059.7 2021-06-03,,,4059.7 2021-06-04,,,4059.7 2021-06-05,,,4059.7 2021-06-06,,,4059.7 2021-06-07,,,4059.7 2021-06-08,,,4059.7 2021-06-09,,,4059.7 2021-06-10,,,4059.7 2021-06-11,,,4059.7 2021-06-12,,,4059.7 2021-06-13,,,4059.7 2021-06-14,CAT,-30.41999999999996,4029.2799999999997 2021-06-15,,,4029.2799999999997 2021-06-16,JNJ,-60.240000000000464,3969.039999999999 2021-06-17,,,3969.039999999999 2021-06-18,,,3969.039999999999 2021-06-19,,,3969.039999999999 2021-06-20,GS,219.12000000000015,4188.159999999999 2021-06-21,,,4188.159999999999 2021-06-22,,,4188.159999999999 2021-06-23,,,4188.159999999999 2021-06-24,,,4188.159999999999 2021-06-25,,,4188.159999999999 2021-06-26,MCD,-36.89999999999969,4151.259999999999 2021-06-27,,,4151.259999999999 2021-06-28,,,4151.259999999999 2021-06-29,,,4151.259999999999 2021-06-30,,,4151.259999999999 2021-07-01,V,206.89000000000027,4358.15 2021-07-02,,,4358.15 2021-07-03,,,4358.15 2021-07-04,,,4358.15 2021-07-05,,,4358.15 2021-07-06,,,4358.15 2021-07-07,,,4358.15 2021-07-08,,,4358.15 2021-07-09,,,4358.15 2021-07-10,,,4358.15 2021-07-11,,,4358.15 2021-07-12,,,4358.15 2021-07-13,,,4358.15 2021-07-14,,,4358.15 2021-07-15,,,4358.15 2021-07-16,,,4358.15 2021-07-17,BA,-215.0,4143.15 2021-07-18,,,4143.15 2021-07-19,,,4143.15 2021-07-20,,,4143.15 2021-07-21,VZ,-15.540000000000065,4127.61 2021-07-22,,,4127.61 2021-07-23,,,4127.61 2021-07-24,,,4127.61 2021-07-25,,,4127.61 2021-07-26,,,4127.61 2021-07-27,,,4127.61 2021-07-28,,,4127.61 2021-07-29,,,4127.61 2021-07-30,,,4127.61 2021-07-31,,,4127.61 2021-08-01,,,4127.61 2021-08-02,,,4127.61 2021-08-03,,,4127.61 2021-08-04,,,4127.61 2021-08-05,,,4127.61 2021-08-06,,,4127.61 2021-08-07,VZ,-15.540000000000065,4112.07 2021-08-08,,,4112.07 2021-08-09,,,4112.07 2021-08-10,,,4112.07 2021-08-11,,,4112.07 2021-08-12,,,4112.07 2021-08-13,,,4112.07 2021-08-14,,,4112.07 2021-08-15,,,4112.07 2021-08-16,,,4112.07 2021-08-17,,,4112.07 2021-08-18,,,4112.07 2021-08-19,,,4112.07 2021-08-20,,,4112.07 2021-08-21,,,4112.07 2021-08-22,,,4112.07 2021-08-23,,,4112.07 2021-08-24,,,4112.07 2021-08-25,,,4112.07 2021-08-26,AMGN,-12.95999999999998,4099.11 2021-08-27,,,4099.11 2021-08-28,,,4099.11 2021-08-29,,,4099.11 2021-08-30,,,4099.11 2021-08-31,,,4099.11 2021-09-01,,,4099.11 2021-09-02,,,4099.11 2021-09-03,,,4099.11 2021-09-04,,,4099.11 2021-09-05,,,4099.11 2021-09-06,,,4099.11 2021-09-07,,,4099.11 2021-09-08,,,4099.11 2021-09-09,,,4099.11 2021-09-10,AMGN,-34.77000000000024,4064.3399999999992 2021-09-11,,,4064.3399999999992 2021-09-12,MMM,-46.860000000000525,4017.4799999999987 2021-09-13,,,4017.4799999999987 2021-09-14,,,4017.4799999999987 2021-09-15,,,4017.4799999999987 2021-09-16,,,4017.4799999999987 2021-09-17,BA,-69.48000000000025,3947.999999999998 2021-09-18,,,3947.999999999998 2021-09-19,,,3947.999999999998 2021-09-20,,,3947.999999999998 2021-09-21,,,3947.999999999998 2021-09-22,GS,160.2000000000004,4108.199999999999 2021-09-23,,,4108.199999999999 2021-09-24,,,4108.199999999999 2021-09-25,,,4108.199999999999 2021-09-26,KO,-21.280000000000086,4086.9199999999987 2021-09-27,,,4086.9199999999987 2021-09-28,,,4086.9199999999987 2021-09-29,NKE,183.39999999999952,4270.319999999998 2021-09-30,,,4270.319999999998 2021-10-01,,,4270.319999999998 2021-10-02,,,4270.319999999998 2021-10-03,,,4270.319999999998 2021-10-04,,,4270.319999999998 2021-10-05,,,4270.319999999998 2021-10-06,,,4270.319999999998 2021-10-07,,,4270.319999999998 2021-10-08,,,4270.319999999998 2021-10-09,VZ,-84.80000000000018,4185.519999999998 2021-10-10,,,4185.519999999998 2021-10-11,,,4185.519999999998 2021-10-12,,,4185.519999999998 2021-10-13,KO,-22.32999999999993,4163.189999999998 2021-10-14,,,4163.189999999998 2021-10-15,,,4163.189999999998 2021-10-16,,,4163.189999999998 2021-10-17,,,4163.189999999998 2021-10-18,,,4163.189999999998 2021-10-19,,,4163.189999999998 2021-10-20,,,4163.189999999998 2021-10-21,,,4163.189999999998 2021-10-22,IBM,-14.184185400000274,4149.005814599997 2021-10-23,,,4149.005814599997 2021-10-24,BA,-112.85999999999996,4036.1458145999973 2021-10-25,,,4036.1458145999973 2021-10-26,,,4036.1458145999973 2021-10-27,,,4036.1458145999973 2021-10-28,,,4036.1458145999973 2021-10-29,,,4036.1458145999973 2021-10-30,,,4036.1458145999973 2021-10-31,,,4036.1458145999973 2021-11-01,,,4036.1458145999973 2021-11-02,,,4036.1458145999973 2021-11-03,TRV,-57.99999999999983,3978.1458145999973 2021-11-04,,,3978.1458145999973 2021-11-05,,,3978.1458145999973 2021-11-06,,,3978.1458145999973 2021-11-07,,,3978.1458145999973 2021-11-08,,,3978.1458145999973 2021-11-09,,,3978.1458145999973 2021-11-10,,,3978.1458145999973 2021-11-11,AAPL,258.70000000000044,4236.8458145999975 2021-11-12,,,4236.8458145999975 2021-11-13,,,4236.8458145999975 2021-11-14,,,4236.8458145999975 2021-11-15,,,4236.8458145999975 2021-11-16,,,4236.8458145999975 2021-11-17,,,4236.8458145999975 2021-11-18,,,4236.8458145999975 2021-11-19,,,4236.8458145999975 2021-11-20,TRV,208.70999999999967,4445.555814599998 2021-11-21,,,4445.555814599998 2021-11-22,,,4445.555814599998 2021-11-23,,,4445.555814599998 2021-11-24,,,4445.555814599998 2021-11-25,MMM,-52.74999999999963,4392.805814599998 2021-11-26,,,4392.805814599998 2021-11-27,,,4392.805814599998 2021-11-28,,,4392.805814599998 2021-11-29,AMGN,-46.41000000000017,4346.395814599998 2021-11-30,,,4346.395814599998 2021-12-01,,,4346.395814599998 2021-12-02,GS,259.92999999999995,4606.325814599998 2021-12-03,,,4606.325814599998 2021-12-04,,,4606.325814599998 2021-12-05,,,4606.325814599998 2021-12-06,,,4606.325814599998 2021-12-07,,,4606.325814599998 2021-12-08,,,4606.325814599998 2021-12-09,,,4606.325814599998 2021-12-10,NKE,-72.8999999999997,4533.425814599998 2021-12-11,,,4533.425814599998 2021-12-12,,,4533.425814599998 2021-12-13,,,4533.425814599998 2021-12-14,,,4533.425814599998 2021-12-15,,,4533.425814599998 2021-12-16,,,4533.425814599998 2021-12-17,CRM,-100.46999999999994,4432.955814599998 2021-12-18,,,4432.955814599998 2021-12-19,,,4432.955814599998 2021-12-20,,,4432.955814599998 2021-12-21,,,4432.955814599998 2021-12-22,,,4432.955814599998 2021-12-23,,,4432.955814599998 2021-12-24,,,4432.955814599998 2021-12-25,,,4432.955814599998 2021-12-26,,,4432.955814599998 2021-12-27,,,4432.955814599998 2021-12-28,,,4432.955814599998 2021-12-29,,,4432.955814599998 2021-12-30,,,4432.955814599998 2021-12-31,,,4432.955814599998 ================================================ FILE: results/LR_v1_predict_0.9_10/history_df.csv ================================================ stock,buy_price,n_shares,sell_price,net_gain,buy_date,sell_date BA,202.72,14,211.63,124.73999999999995,2021-01-05,2021-01-06 MSFT,212.25,14,219.62,103.18000000000006,2021-01-07,2021-01-09 MMM,165.2,19,170.22,95.3800000000002,2021-01-12,2021-01-21 HON,205.23,16,195.37,-157.75999999999976,2021-01-22,2021-01-30 V,193.25,16,202.61,149.76000000000022,2021-01-31,2021-02-03 MRK,77.32,42,74.89,-102.05999999999969,2021-02-04,2021-02-11 PG,128.33,25,127.12,-30.2500000000002,2021-02-12,2021-02-22 AAPL,126.0,25,120.99,-125.25000000000013,2021-02-23,2021-02-26 AAPL,121.26,25,127.79,163.25000000000003,2021-02-27,2021-03-02 CRM,213.47,15,206.0,-112.04999999999998,2021-03-03,2021-03-04 AMGN,221.91,14,228.99,99.12000000000018,2021-03-05,2021-03-10 INTC,62.25,51,64.78,129.03000000000006,2021-03-11,2021-03-17 PG,128.42,25,132.6,104.50000000000017,2021-03-18,2021-03-24 GS,328.65,10,327.64,-10.099999999999909,2021-03-25,2021-04-04 KO,52.51,65,53.08,37.05000000000002,2021-04-05,2021-04-15 JNJ,160.39,21,166.48,127.89000000000007,2021-04-16,2021-04-21 VZ,58.14,61,56.32,-111.02000000000001,2021-04-22,2021-04-28 WMT,137.89,25,142.12,105.75000000000045,2021-04-29,2021-05-04 CRM,215.4,16,217.66,36.159999999999854,2021-05-06,2021-05-16 VZ,58.69,61,56.92,-107.96999999999976,2021-05-17,2021-05-20 VZ,56.79,61,56.49,-18.299999999999827,2021-05-21,2021-05-31 HD,318.91,10,307.34,-115.7000000000005,2021-06-01,2021-06-10 CAT,225.73,14,217.16,-119.9799999999999,2021-06-11,2021-06-17 CAT,209.45,15,219.34,148.35000000000022,2021-06-18,2021-06-25 MCD,232.42,14,233.63,16.94000000000011,2021-06-26,2021-07-06 BA,231.78,14,239.59,109.34000000000003,2021-07-08,2021-07-10 MRK,77.99,45,76.17,-81.8999999999997,2021-07-11,2021-07-21 VZ,55.95,61,55.78,-10.370000000000104,2021-07-22,2021-08-01 VZ,55.78,61,55.57,-12.810000000000052,2021-08-02,2021-08-12 V,231.79,14,231.36,-6.019999999999698,2021-08-13,2021-08-23 VZ,55.42,61,55.29,-7.930000000000156,2021-08-24,2021-09-03 WBA,51.29,66,49.45,-121.43999999999976,2021-09-04,2021-09-11 MMM,184.55,17,178.42,-104.2100000000004,2021-09-12,2021-09-22 CAT,191.35,16,200.0,138.4000000000001,2021-09-23,2021-09-28 NKE,145.3,22,151.85,144.09999999999962,2021-09-29,2021-10-08 VZ,53.24,65,51.33,-124.15000000000023,2021-10-09,2021-10-13 JPM,161.0,20,166.61,112.20000000000027,2021-10-14,2021-10-16 TRV,155.64,22,162.37,148.0600000000004,2021-10-17,2021-10-23 BA,212.97,16,212.77,-3.199999999999818,2021-10-24,2021-11-03 V,208.78,17,216.67,134.12999999999977,2021-11-05,2021-11-06 GS,407.08,9,403.09,-35.91000000000008,2021-11-07,2021-11-17 GS,391.55,9,406.34,133.10999999999967,2021-11-18,2021-11-24 MMM,177.63,21,170.04,-159.39000000000007,2021-11-25,2021-12-01 GS,376.48,9,389.3,115.37999999999994,2021-12-02,2021-12-07 INTC,52.57,72,50.48,-150.48000000000025,2021-12-08,2021-12-10 CRM,266.03,13,255.59,-135.7199999999996,2021-12-11,2021-12-15 VZ,50.55,69,52.75,151.80000000000018,2021-12-16,2021-12-17 HD,387.98,9,404.09,144.9899999999996,2021-12-18,2021-12-28 ================================================ FILE: results/LR_v1_predict_0.9_10/running_gains_df.csv ================================================ Date,Stock,Gain,Total 2020-12-31,,,3000 2021-01-01,,,3000 2021-01-02,,,3000 2021-01-03,,,3000 2021-01-04,,,3000 2021-01-05,BA,124.73999999999997,3124.74 2021-01-06,,,3124.74 2021-01-07,MSFT,103.18000000000006,3227.92 2021-01-08,,,3227.92 2021-01-09,,,3227.92 2021-01-10,,,3227.92 2021-01-11,,,3227.92 2021-01-12,MMM,95.3800000000002,3323.3 2021-01-13,,,3323.3 2021-01-14,,,3323.3 2021-01-15,,,3323.3 2021-01-16,,,3323.3 2021-01-17,,,3323.3 2021-01-18,,,3323.3 2021-01-19,,,3323.3 2021-01-20,,,3323.3 2021-01-21,,,3323.3 2021-01-22,HON,-157.75999999999976,3165.5400000000004 2021-01-23,,,3165.5400000000004 2021-01-24,,,3165.5400000000004 2021-01-25,,,3165.5400000000004 2021-01-26,,,3165.5400000000004 2021-01-27,,,3165.5400000000004 2021-01-28,,,3165.5400000000004 2021-01-29,,,3165.5400000000004 2021-01-30,,,3165.5400000000004 2021-01-31,V,149.76000000000022,3315.3000000000006 2021-02-01,,,3315.3000000000006 2021-02-02,,,3315.3000000000006 2021-02-03,,,3315.3000000000006 2021-02-04,MRK,-102.05999999999968,3213.240000000001 2021-02-05,,,3213.240000000001 2021-02-06,,,3213.240000000001 2021-02-07,,,3213.240000000001 2021-02-08,,,3213.240000000001 2021-02-09,,,3213.240000000001 2021-02-10,,,3213.240000000001 2021-02-11,,,3213.240000000001 2021-02-12,PG,-30.2500000000002,3182.990000000001 2021-02-13,,,3182.990000000001 2021-02-14,,,3182.990000000001 2021-02-15,,,3182.990000000001 2021-02-16,,,3182.990000000001 2021-02-17,,,3182.990000000001 2021-02-18,,,3182.990000000001 2021-02-19,,,3182.990000000001 2021-02-20,,,3182.990000000001 2021-02-21,,,3182.990000000001 2021-02-22,,,3182.990000000001 2021-02-23,AAPL,-125.25000000000011,3057.740000000001 2021-02-24,,,3057.740000000001 2021-02-25,,,3057.740000000001 2021-02-26,,,3057.740000000001 2021-02-27,AAPL,163.25000000000003,3220.990000000001 2021-02-28,,,3220.990000000001 2021-03-01,,,3220.990000000001 2021-03-02,,,3220.990000000001 2021-03-03,CRM,-112.04999999999998,3108.940000000001 2021-03-04,,,3108.940000000001 2021-03-05,AMGN,99.12000000000018,3208.0600000000013 2021-03-06,,,3208.0600000000013 2021-03-07,,,3208.0600000000013 2021-03-08,,,3208.0600000000013 2021-03-09,,,3208.0600000000013 2021-03-10,,,3208.0600000000013 2021-03-11,INTC,129.03000000000006,3337.0900000000015 2021-03-12,,,3337.0900000000015 2021-03-13,,,3337.0900000000015 2021-03-14,,,3337.0900000000015 2021-03-15,,,3337.0900000000015 2021-03-16,,,3337.0900000000015 2021-03-17,,,3337.0900000000015 2021-03-18,PG,104.50000000000016,3441.5900000000015 2021-03-19,,,3441.5900000000015 2021-03-20,,,3441.5900000000015 2021-03-21,,,3441.5900000000015 2021-03-22,,,3441.5900000000015 2021-03-23,,,3441.5900000000015 2021-03-24,,,3441.5900000000015 2021-03-25,GS,-10.099999999999907,3431.4900000000016 2021-03-26,,,3431.4900000000016 2021-03-27,,,3431.4900000000016 2021-03-28,,,3431.4900000000016 2021-03-29,,,3431.4900000000016 2021-03-30,,,3431.4900000000016 2021-03-31,,,3431.4900000000016 2021-04-01,,,3431.4900000000016 2021-04-02,,,3431.4900000000016 2021-04-03,,,3431.4900000000016 2021-04-04,,,3431.4900000000016 2021-04-05,KO,37.05000000000002,3468.540000000002 2021-04-06,,,3468.540000000002 2021-04-07,,,3468.540000000002 2021-04-08,,,3468.540000000002 2021-04-09,,,3468.540000000002 2021-04-10,,,3468.540000000002 2021-04-11,,,3468.540000000002 2021-04-12,,,3468.540000000002 2021-04-13,,,3468.540000000002 2021-04-14,,,3468.540000000002 2021-04-15,,,3468.540000000002 2021-04-16,JNJ,127.89000000000009,3596.4300000000017 2021-04-17,,,3596.4300000000017 2021-04-18,,,3596.4300000000017 2021-04-19,,,3596.4300000000017 2021-04-20,,,3596.4300000000017 2021-04-21,,,3596.4300000000017 2021-04-22,VZ,-111.02,3485.4100000000017 2021-04-23,,,3485.4100000000017 2021-04-24,,,3485.4100000000017 2021-04-25,,,3485.4100000000017 2021-04-26,,,3485.4100000000017 2021-04-27,,,3485.4100000000017 2021-04-28,,,3485.4100000000017 2021-04-29,WMT,105.75000000000044,3591.160000000002 2021-04-30,,,3591.160000000002 2021-05-01,,,3591.160000000002 2021-05-02,,,3591.160000000002 2021-05-03,,,3591.160000000002 2021-05-04,,,3591.160000000002 2021-05-05,,,3591.160000000002 2021-05-06,CRM,36.159999999999854,3627.320000000002 2021-05-07,,,3627.320000000002 2021-05-08,,,3627.320000000002 2021-05-09,,,3627.320000000002 2021-05-10,,,3627.320000000002 2021-05-11,,,3627.320000000002 2021-05-12,,,3627.320000000002 2021-05-13,,,3627.320000000002 2021-05-14,,,3627.320000000002 2021-05-15,,,3627.320000000002 2021-05-16,,,3627.320000000002 2021-05-17,VZ,-107.96999999999976,3519.350000000002 2021-05-18,,,3519.350000000002 2021-05-19,,,3519.350000000002 2021-05-20,,,3519.350000000002 2021-05-21,VZ,-18.299999999999827,3501.0500000000025 2021-05-22,,,3501.0500000000025 2021-05-23,,,3501.0500000000025 2021-05-24,,,3501.0500000000025 2021-05-25,,,3501.0500000000025 2021-05-26,,,3501.0500000000025 2021-05-27,,,3501.0500000000025 2021-05-28,,,3501.0500000000025 2021-05-29,,,3501.0500000000025 2021-05-30,,,3501.0500000000025 2021-05-31,,,3501.0500000000025 2021-06-01,HD,-115.7000000000005,3385.350000000002 2021-06-02,,,3385.350000000002 2021-06-03,,,3385.350000000002 2021-06-04,,,3385.350000000002 2021-06-05,,,3385.350000000002 2021-06-06,,,3385.350000000002 2021-06-07,,,3385.350000000002 2021-06-08,,,3385.350000000002 2021-06-09,,,3385.350000000002 2021-06-10,,,3385.350000000002 2021-06-11,CAT,-119.9799999999999,3265.370000000002 2021-06-12,,,3265.370000000002 2021-06-13,,,3265.370000000002 2021-06-14,,,3265.370000000002 2021-06-15,,,3265.370000000002 2021-06-16,,,3265.370000000002 2021-06-17,,,3265.370000000002 2021-06-18,CAT,148.35000000000022,3413.7200000000025 2021-06-19,,,3413.7200000000025 2021-06-20,,,3413.7200000000025 2021-06-21,,,3413.7200000000025 2021-06-22,,,3413.7200000000025 2021-06-23,,,3413.7200000000025 2021-06-24,,,3413.7200000000025 2021-06-25,,,3413.7200000000025 2021-06-26,MCD,16.94000000000011,3430.6600000000026 2021-06-27,,,3430.6600000000026 2021-06-28,,,3430.6600000000026 2021-06-29,,,3430.6600000000026 2021-06-30,,,3430.6600000000026 2021-07-01,,,3430.6600000000026 2021-07-02,,,3430.6600000000026 2021-07-03,,,3430.6600000000026 2021-07-04,,,3430.6600000000026 2021-07-05,,,3430.6600000000026 2021-07-06,,,3430.6600000000026 2021-07-07,,,3430.6600000000026 2021-07-08,BA,109.34000000000005,3540.0000000000027 2021-07-09,,,3540.0000000000027 2021-07-10,,,3540.0000000000027 2021-07-11,MRK,-81.8999999999997,3458.100000000003 2021-07-12,,,3458.100000000003 2021-07-13,,,3458.100000000003 2021-07-14,,,3458.100000000003 2021-07-15,,,3458.100000000003 2021-07-16,,,3458.100000000003 2021-07-17,,,3458.100000000003 2021-07-18,,,3458.100000000003 2021-07-19,,,3458.100000000003 2021-07-20,,,3458.100000000003 2021-07-21,,,3458.100000000003 2021-07-22,VZ,-10.370000000000104,3447.730000000003 2021-07-23,,,3447.730000000003 2021-07-24,,,3447.730000000003 2021-07-25,,,3447.730000000003 2021-07-26,,,3447.730000000003 2021-07-27,,,3447.730000000003 2021-07-28,,,3447.730000000003 2021-07-29,,,3447.730000000003 2021-07-30,,,3447.730000000003 2021-07-31,,,3447.730000000003 2021-08-01,,,3447.730000000003 2021-08-02,VZ,-12.810000000000052,3434.9200000000033 2021-08-03,,,3434.9200000000033 2021-08-04,,,3434.9200000000033 2021-08-05,,,3434.9200000000033 2021-08-06,,,3434.9200000000033 2021-08-07,,,3434.9200000000033 2021-08-08,,,3434.9200000000033 2021-08-09,,,3434.9200000000033 2021-08-10,,,3434.9200000000033 2021-08-11,,,3434.9200000000033 2021-08-12,,,3434.9200000000033 2021-08-13,V,-6.019999999999698,3428.9000000000037 2021-08-14,,,3428.9000000000037 2021-08-15,,,3428.9000000000037 2021-08-16,,,3428.9000000000037 2021-08-17,,,3428.9000000000037 2021-08-18,,,3428.9000000000037 2021-08-19,,,3428.9000000000037 2021-08-20,,,3428.9000000000037 2021-08-21,,,3428.9000000000037 2021-08-22,,,3428.9000000000037 2021-08-23,,,3428.9000000000037 2021-08-24,VZ,-7.930000000000156,3420.9700000000034 2021-08-25,,,3420.9700000000034 2021-08-26,,,3420.9700000000034 2021-08-27,,,3420.9700000000034 2021-08-28,,,3420.9700000000034 2021-08-29,,,3420.9700000000034 2021-08-30,,,3420.9700000000034 2021-08-31,,,3420.9700000000034 2021-09-01,,,3420.9700000000034 2021-09-02,,,3420.9700000000034 2021-09-03,,,3420.9700000000034 2021-09-04,WBA,-121.43999999999976,3299.530000000004 2021-09-05,,,3299.530000000004 2021-09-06,,,3299.530000000004 2021-09-07,,,3299.530000000004 2021-09-08,,,3299.530000000004 2021-09-09,,,3299.530000000004 2021-09-10,,,3299.530000000004 2021-09-11,,,3299.530000000004 2021-09-12,MMM,-104.2100000000004,3195.3200000000033 2021-09-13,,,3195.3200000000033 2021-09-14,,,3195.3200000000033 2021-09-15,,,3195.3200000000033 2021-09-16,,,3195.3200000000033 2021-09-17,,,3195.3200000000033 2021-09-18,,,3195.3200000000033 2021-09-19,,,3195.3200000000033 2021-09-20,,,3195.3200000000033 2021-09-21,,,3195.3200000000033 2021-09-22,,,3195.3200000000033 2021-09-23,CAT,138.4000000000001,3333.7200000000034 2021-09-24,,,3333.7200000000034 2021-09-25,,,3333.7200000000034 2021-09-26,,,3333.7200000000034 2021-09-27,,,3333.7200000000034 2021-09-28,,,3333.7200000000034 2021-09-29,NKE,144.09999999999962,3477.820000000003 2021-09-30,,,3477.820000000003 2021-10-01,,,3477.820000000003 2021-10-02,,,3477.820000000003 2021-10-03,,,3477.820000000003 2021-10-04,,,3477.820000000003 2021-10-05,,,3477.820000000003 2021-10-06,,,3477.820000000003 2021-10-07,,,3477.820000000003 2021-10-08,,,3477.820000000003 2021-10-09,VZ,-124.15000000000023,3353.670000000003 2021-10-10,,,3353.670000000003 2021-10-11,,,3353.670000000003 2021-10-12,,,3353.670000000003 2021-10-13,,,3353.670000000003 2021-10-14,JPM,112.20000000000029,3465.870000000003 2021-10-15,,,3465.870000000003 2021-10-16,,,3465.870000000003 2021-10-17,TRV,148.0600000000004,3613.9300000000035 2021-10-18,,,3613.9300000000035 2021-10-19,,,3613.9300000000035 2021-10-20,,,3613.9300000000035 2021-10-21,,,3613.9300000000035 2021-10-22,,,3613.9300000000035 2021-10-23,,,3613.9300000000035 2021-10-24,BA,-3.199999999999818,3610.7300000000037 2021-10-25,,,3610.7300000000037 2021-10-26,,,3610.7300000000037 2021-10-27,,,3610.7300000000037 2021-10-28,,,3610.7300000000037 2021-10-29,,,3610.7300000000037 2021-10-30,,,3610.7300000000037 2021-10-31,,,3610.7300000000037 2021-11-01,,,3610.7300000000037 2021-11-02,,,3610.7300000000037 2021-11-03,,,3610.7300000000037 2021-11-04,,,3610.7300000000037 2021-11-05,V,134.12999999999977,3744.8600000000033 2021-11-06,,,3744.8600000000033 2021-11-07,GS,-35.91000000000008,3708.9500000000035 2021-11-08,,,3708.9500000000035 2021-11-09,,,3708.9500000000035 2021-11-10,,,3708.9500000000035 2021-11-11,,,3708.9500000000035 2021-11-12,,,3708.9500000000035 2021-11-13,,,3708.9500000000035 2021-11-14,,,3708.9500000000035 2021-11-15,,,3708.9500000000035 2021-11-16,,,3708.9500000000035 2021-11-17,,,3708.9500000000035 2021-11-18,GS,133.10999999999967,3842.060000000003 2021-11-19,,,3842.060000000003 2021-11-20,,,3842.060000000003 2021-11-21,,,3842.060000000003 2021-11-22,,,3842.060000000003 2021-11-23,,,3842.060000000003 2021-11-24,,,3842.060000000003 2021-11-25,MMM,-159.39000000000007,3682.6700000000033 2021-11-26,,,3682.6700000000033 2021-11-27,,,3682.6700000000033 2021-11-28,,,3682.6700000000033 2021-11-29,,,3682.6700000000033 2021-11-30,,,3682.6700000000033 2021-12-01,,,3682.6700000000033 2021-12-02,GS,115.37999999999994,3798.0500000000034 2021-12-03,,,3798.0500000000034 2021-12-04,,,3798.0500000000034 2021-12-05,,,3798.0500000000034 2021-12-06,,,3798.0500000000034 2021-12-07,,,3798.0500000000034 2021-12-08,INTC,-150.48000000000025,3647.5700000000033 2021-12-09,,,3647.5700000000033 2021-12-10,,,3647.5700000000033 2021-12-11,CRM,-135.7199999999996,3511.8500000000035 2021-12-12,,,3511.8500000000035 2021-12-13,,,3511.8500000000035 2021-12-14,,,3511.8500000000035 2021-12-15,,,3511.8500000000035 2021-12-16,VZ,151.80000000000018,3663.6500000000037 2021-12-17,,,3663.6500000000037 2021-12-18,HD,144.9899999999996,3808.6400000000035 2021-12-19,,,3808.6400000000035 2021-12-20,,,3808.6400000000035 2021-12-21,,,3808.6400000000035 2021-12-22,,,3808.6400000000035 2021-12-23,,,3808.6400000000035 2021-12-24,,,3808.6400000000035 2021-12-25,,,3808.6400000000035 2021-12-26,,,3808.6400000000035 2021-12-27,,,3808.6400000000035 2021-12-28,,,3808.6400000000035 2021-12-29,,,3808.6400000000035 2021-12-30,,,3808.6400000000035 2021-12-31,,,3808.6400000000035 ================================================ FILE: results/LR_v1_predict_1_1/history_df.csv ================================================ stock,buy_price,n_shares,sell_price,net_gain,buy_date,sell_date WBA,39.88,75,39.88,0.0,2021-01-01,2021-01-02 VZ,58.75,51,58.53,-11.219999999999942,2021-01-03,2021-01-08 JPM,136.02,21,136.02,0.0,2021-01-09,2021-01-10 CRM,222.04,13,218.25,-49.2699999999999,2021-01-11,2021-01-12 CVX,93.34,31,93.25,-2.7900000000001057,2021-01-13,2021-01-14 WMT,146.97,19,144.64,-44.27000000000024,2021-01-15,2021-01-17 MSFT,212.65,13,224.97,160.1599999999999,2021-01-18,2021-01-22 HON,202.25,15,202.25,0.0,2021-01-23,2021-01-24 CRM,225.77,13,226.26,6.369999999999749,2021-01-25,2021-01-27 WMT,143.84,21,140.49,-70.34999999999988,2021-01-28,2021-01-31 GS,271.17,11,274.73,39.160000000000025,2021-02-01,2021-02-02 AXP,120.7,25,120.44,-6.500000000000128,2021-02-03,2021-02-04 AMGN,237.22,12,236.32,-10.800000000000068,2021-02-05,2021-02-06 NKE,145.11,20,145.11,0.0,2021-02-07,2021-02-08 UNH,324.34,9,329.63,47.610000000000184,2021-02-09,2021-02-10 CSCO,47.24,64,47.29,3.199999999999818,2021-02-11,2021-02-14 KO,50.69,60,50.69,0.0,2021-02-15,2021-02-16 VZ,54.15,56,56.99,159.0400000000002,2021-02-17,2021-02-18 KO,50.77,63,50.11,-41.58000000000023,2021-02-19,2021-02-20 CSCO,45.68,69,45.68,0.0,2021-02-21,2021-02-22 PG,126.58,25,127.66,26.999999999999957,2021-02-23,2021-02-25 INTC,60.4,53,60.78,20.140000000000136,2021-02-26,2021-02-28 CSCO,44.87,71,45.515,45.79500000000022,2021-03-01,2021-03-03 WBA,47.63,68,46.86,-52.36000000000021,2021-03-04,2021-03-05 BA,223.22,14,223.22,0.0,2021-03-06,2021-03-08 CVX,109.75,29,109.5,-7.25,2021-03-09,2021-03-10 UNH,349.6,9,353.1,31.5,2021-03-11,2021-03-12 DIS,197.16,16,197.16,0.0,2021-03-13,2021-03-14 PG,128.14,25,128.56,10.500000000000398,2021-03-15,2021-03-16 MCD,219.86,14,224.11,59.5,2021-03-17,2021-03-18 TRV,156.83,21,149.3,-158.13000000000002,2021-03-19,2021-03-22 MMM,189.47,16,188.33,-18.23999999999978,2021-03-23,2021-03-24 JNJ,161.91,19,164.93,57.380000000000194,2021-03-25,2021-03-27 MRK,77.39,41,77.39,0.0,2021-03-28,2021-03-29 WBA,52.85,60,55.58,163.7999999999998,2021-03-30,2021-04-08 CAT,230.48,14,230.75,3.7800000000001432,2021-04-09,2021-04-11 MSFT,255.85,13,259.5,47.450000000000074,2021-04-12,2021-04-16 CRM,231.91,14,231.91,0.0,2021-04-17,2021-04-18 MCD,233.08,14,233.01,-0.9800000000003024,2021-04-19,2021-04-21 WMT,141.2,24,139.67,-36.72000000000003,2021-04-22,2021-04-23 UNH,400.31,8,400.31,0.0,2021-04-24,2021-04-25 CSCO,51.91,64,51.11,-51.19999999999982,2021-04-26,2021-04-29 JPM,155.19,21,153.81,-28.979999999999905,2021-04-30,2021-05-01 CRM,230.32,14,230.32,0.0,2021-05-02,2021-05-03 CSCO,51.17,64,50.71,-29.440000000000055,2021-05-04,2021-05-05 WMT,140.05,23,140.2,3.449999999999477,2021-05-06,2021-05-08 HD,339.25,9,341.12,16.83000000000004,2021-05-09,2021-05-11 MSFT,246.23,13,243.03,-41.59999999999985,2021-05-12,2021-05-14 MRK,78.29,41,78.29,0.0,2021-05-15,2021-05-16 HON,227.36,14,222.32,-70.56000000000029,2021-05-17,2021-05-19 WBA,54.81,57,54.6,-11.970000000000049,2021-05-20,2021-05-21 AMGN,251.01,12,251.01,0.0,2021-05-22,2021-05-23 TRV,159.08,19,160.89,34.3899999999995,2021-05-24,2021-06-02 HD,313.23,10,311.01,-22.200000000000273,2021-06-03,2021-06-07 MSFT,253.81,12,253.59,-2.6399999999999864,2021-06-08,2021-06-10 UNH,401.49,7,397.89,-25.20000000000016,2021-06-11,2021-06-12 MRK,76.27,41,76.27,0.0,2021-06-13,2021-06-14 HON,223.17,14,222.5,-9.379999999999825,2021-06-15,2021-06-16 HD,302.78,10,302.61,-1.6999999999995907,2021-06-17,2021-06-20 MSFT,259.43,12,266.69,87.11999999999989,2021-06-21,2021-06-25 MCD,232.42,13,232.42,0.0,2021-06-26,2021-06-27 JNJ,164.21,19,168.98,90.62999999999965,2021-06-28,2021-07-03 MCD,233.63,14,233.63,0.0,2021-07-04,2021-07-06 MSFT,277.66,11,277.94,3.0799999999997,2021-07-07,2021-07-11 BA,239.59,13,222.76,-218.79000000000016,2021-07-12,2021-07-16 MRK,78.02,39,77.05,-37.829999999999956,2021-07-17,2021-07-20 MSFT,279.32,10,281.4,20.79999999999984,2021-07-21,2021-07-22 VZ,55.95,54,55.88,-3.7800000000000153,2021-07-23,2021-07-24 CSCO,55.23,55,54.77,-25.299999999999656,2021-07-25,2021-07-29 AMGN,242.46,12,241.54,-11.040000000000191,2021-07-30,2021-07-31 INTC,53.72,56,53.68,-2.2399999999999523,2021-08-01,2021-08-03 MMM,201.03,15,197.53,-52.5,2021-08-04,2021-08-05 WBA,46.93,63,48.43,94.5,2021-08-06,2021-08-11 MRK,75.21,40,76.04,33.2000000000005,2021-08-12,2021-08-13 BA,234.46,13,229.06,-70.20000000000007,2021-08-14,2021-08-17 TRV,158.9,19,158.72,-3.4200000000001296,2021-08-18,2021-08-19 CSCO,57.27,53,58.22,50.349999999999774,2021-08-20,2021-08-22 KO,56.64,54,56.44,-10.800000000000153,2021-08-23,2021-08-24 HD,324.9,9,321.48,-30.77999999999963,2021-08-25,2021-08-27 KO,55.65,54,55.65,0.0,2021-08-28,2021-08-29 CAT,212.83,14,211.45,-19.320000000000334,2021-08-30,2021-08-31 GS,413.51,7,413.66,1.0500000000002387,2021-09-01,2021-09-02 AMGN,225.96,13,226.37,5.329999999999956,2021-09-03,2021-09-04 UNH,422.86,7,422.86,0.0,2021-09-05,2021-09-06 MMM,194.39,15,185.58,-132.1499999999996,2021-09-07,2021-09-08 JNJ,171.9,16,166.97,-78.88000000000011,2021-09-09,2021-09-13 BA,214.48,13,213.36,-14.55999999999969,2021-09-14,2021-09-17 AAPL,146.06,19,146.92,16.33999999999972,2021-09-18,2021-09-25 TRV,156.46,18,156.46,0.0,2021-09-26,2021-09-27 AMGN,213.11,13,214.9,23.269999999999897,2021-09-28,2021-09-30 WBA,47.05,60,46.8,-15.0,2021-10-01,2021-10-02 IBM,136.89410448,20,136.7317266,-3.247557600000164,2021-10-03,2021-10-06 VZ,54.53,51,53.9,-32.13000000000013,2021-10-07,2021-10-08 WMT,139.66,20,139.66,0.0,2021-10-09,2021-10-10 MMM,176.95,15,175.53,-21.299999999999812,2021-10-11,2021-10-13 CRM,284.41,9,291.66,65.25,2021-10-14,2021-10-18 HD,355.01,7,358.23,22.54000000000019,2021-10-19,2021-10-21 CAT,202.14,14,200.65,-20.85999999999973,2021-10-22,2021-10-23 MSFT,309.16,9,309.16,0.0,2021-10-24,2021-10-25 CAT,202.21,14,204.09,26.319999999999936,2021-10-26,2021-10-29 MRK,88.05,32,88.05,0.0,2021-10-30,2021-10-31 BA,207.03,13,214.58,98.15000000000015,2021-11-01,2021-11-02 MSFT,333.13,8,336.44,26.480000000000018,2021-11-03,2021-11-05 CRM,307.25,9,309.96,24.389999999999816,2021-11-06,2021-11-09 PG,145.39,20,146.56,23.40000000000032,2021-11-10,2021-11-14 PG,146.56,20,147.1,10.79999999999984,2021-11-15,2021-11-18 AAPL,157.87,19,160.55,50.92000000000013,2021-11-19,2021-11-20 CVX,111.91,27,113.91,54.0,2021-11-21,2021-11-23 AAPL,161.41,19,161.94,10.070000000000022,2021-11-24,2021-11-25 HD,412.11,7,406.82,-37.03000000000014,2021-11-26,2021-11-30 UNH,444.22,7,444.34,0.8399999999996339,2021-12-01,2021-12-02 VZ,50.73,61,51.42,42.090000000000295,2021-12-03,2021-12-04 V,196.32,16,208.99,202.72000000000025,2021-12-05,2021-12-09 CRM,264.32,12,266.03,20.519999999999754,2021-12-10,2021-12-11 HD,415.4,8,405.24,-81.27999999999975,2021-12-12,2021-12-14 HON,206.68,16,209.76,49.279999999999745,2021-12-15,2021-12-16 MMM,178.31,18,174.75,-64.08000000000004,2021-12-17,2021-12-19 HD,387.98,8,395.64,61.279999999999745,2021-12-20,2021-12-23 MRK,75.73,44,76.57,36.959999999999525,2021-12-24,2021-12-28 MMM,177.64,19,178.41,14.630000000000194,2021-12-29,2021-12-30 ================================================ FILE: results/LR_v1_predict_1_1/running_gains_df.csv ================================================ Date,Stock,Gain,Total 2020-12-31,,,3000 2021-01-01,WBA,0.0,3000.0 2021-01-02,,,3000.0 2021-01-03,VZ,-11.219999999999942,2988.78 2021-01-04,,,2988.78 2021-01-05,,,2988.78 2021-01-06,,,2988.78 2021-01-07,,,2988.78 2021-01-08,,,2988.78 2021-01-09,JPM,0.0,2988.78 2021-01-10,,,2988.78 2021-01-11,CRM,-49.2699999999999,2939.51 2021-01-12,,,2939.51 2021-01-13,CVX,-2.7900000000001057,2936.7200000000003 2021-01-14,,,2936.7200000000003 2021-01-15,WMT,-44.27000000000024,2892.45 2021-01-16,,,2892.45 2021-01-17,,,2892.45 2021-01-18,MSFT,160.1599999999999,3052.6099999999997 2021-01-19,,,3052.6099999999997 2021-01-20,,,3052.6099999999997 2021-01-21,,,3052.6099999999997 2021-01-22,,,3052.6099999999997 2021-01-23,HON,0.0,3052.6099999999997 2021-01-24,,,3052.6099999999997 2021-01-25,CRM,6.369999999999749,3058.9799999999996 2021-01-26,,,3058.9799999999996 2021-01-27,,,3058.9799999999996 2021-01-28,WMT,-70.34999999999988,2988.6299999999997 2021-01-29,,,2988.6299999999997 2021-01-30,,,2988.6299999999997 2021-01-31,,,2988.6299999999997 2021-02-01,GS,39.160000000000025,3027.7899999999995 2021-02-02,,,3027.7899999999995 2021-02-03,AXP,-6.500000000000128,3021.2899999999995 2021-02-04,,,3021.2899999999995 2021-02-05,AMGN,-10.800000000000068,3010.4899999999993 2021-02-06,,,3010.4899999999993 2021-02-07,NKE,0.0,3010.4899999999993 2021-02-08,,,3010.4899999999993 2021-02-09,UNH,47.61000000000018,3058.0999999999995 2021-02-10,,,3058.0999999999995 2021-02-11,CSCO,3.199999999999818,3061.2999999999993 2021-02-12,,,3061.2999999999993 2021-02-13,,,3061.2999999999993 2021-02-14,,,3061.2999999999993 2021-02-15,KO,0.0,3061.2999999999993 2021-02-16,,,3061.2999999999993 2021-02-17,VZ,159.0400000000002,3220.3399999999992 2021-02-18,,,3220.3399999999992 2021-02-19,KO,-41.58000000000023,3178.759999999999 2021-02-20,,,3178.759999999999 2021-02-21,CSCO,0.0,3178.759999999999 2021-02-22,,,3178.759999999999 2021-02-23,PG,26.99999999999996,3205.759999999999 2021-02-24,,,3205.759999999999 2021-02-25,,,3205.759999999999 2021-02-26,INTC,20.140000000000136,3225.899999999999 2021-02-27,,,3225.899999999999 2021-02-28,,,3225.899999999999 2021-03-01,CSCO,45.79500000000022,3271.6949999999993 2021-03-02,,,3271.6949999999993 2021-03-03,,,3271.6949999999993 2021-03-04,WBA,-52.36000000000021,3219.334999999999 2021-03-05,,,3219.334999999999 2021-03-06,BA,0.0,3219.334999999999 2021-03-07,,,3219.334999999999 2021-03-08,,,3219.334999999999 2021-03-09,CVX,-7.25,3212.084999999999 2021-03-10,,,3212.084999999999 2021-03-11,UNH,31.5,3243.584999999999 2021-03-12,,,3243.584999999999 2021-03-13,DIS,0.0,3243.584999999999 2021-03-14,,,3243.584999999999 2021-03-15,PG,10.500000000000398,3254.0849999999996 2021-03-16,,,3254.0849999999996 2021-03-17,MCD,59.5,3313.5849999999996 2021-03-18,,,3313.5849999999996 2021-03-19,TRV,-158.13000000000002,3155.4549999999995 2021-03-20,,,3155.4549999999995 2021-03-21,,,3155.4549999999995 2021-03-22,,,3155.4549999999995 2021-03-23,MMM,-18.23999999999978,3137.2149999999997 2021-03-24,,,3137.2149999999997 2021-03-25,JNJ,57.380000000000194,3194.595 2021-03-26,,,3194.595 2021-03-27,,,3194.595 2021-03-28,MRK,0.0,3194.595 2021-03-29,,,3194.595 2021-03-30,WBA,163.7999999999998,3358.3949999999995 2021-03-31,,,3358.3949999999995 2021-04-01,,,3358.3949999999995 2021-04-02,,,3358.3949999999995 2021-04-03,,,3358.3949999999995 2021-04-04,,,3358.3949999999995 2021-04-05,,,3358.3949999999995 2021-04-06,,,3358.3949999999995 2021-04-07,,,3358.3949999999995 2021-04-08,,,3358.3949999999995 2021-04-09,CAT,3.7800000000001432,3362.1749999999997 2021-04-10,,,3362.1749999999997 2021-04-11,,,3362.1749999999997 2021-04-12,MSFT,47.45000000000008,3409.625 2021-04-13,,,3409.625 2021-04-14,,,3409.625 2021-04-15,,,3409.625 2021-04-16,,,3409.625 2021-04-17,CRM,0.0,3409.625 2021-04-18,,,3409.625 2021-04-19,MCD,-0.9800000000003024,3408.6449999999995 2021-04-20,,,3408.6449999999995 2021-04-21,,,3408.6449999999995 2021-04-22,WMT,-36.72000000000003,3371.9249999999993 2021-04-23,,,3371.9249999999993 2021-04-24,UNH,0.0,3371.9249999999993 2021-04-25,,,3371.9249999999993 2021-04-26,CSCO,-51.19999999999982,3320.7249999999995 2021-04-27,,,3320.7249999999995 2021-04-28,,,3320.7249999999995 2021-04-29,,,3320.7249999999995 2021-04-30,JPM,-28.979999999999905,3291.7449999999994 2021-05-01,,,3291.7449999999994 2021-05-02,CRM,0.0,3291.7449999999994 2021-05-03,,,3291.7449999999994 2021-05-04,CSCO,-29.44000000000005,3262.3049999999994 2021-05-05,,,3262.3049999999994 2021-05-06,WMT,3.449999999999477,3265.7549999999987 2021-05-07,,,3265.7549999999987 2021-05-08,,,3265.7549999999987 2021-05-09,HD,16.83000000000004,3282.5849999999987 2021-05-10,,,3282.5849999999987 2021-05-11,,,3282.5849999999987 2021-05-12,MSFT,-41.59999999999985,3240.9849999999988 2021-05-13,,,3240.9849999999988 2021-05-14,,,3240.9849999999988 2021-05-15,MRK,0.0,3240.9849999999988 2021-05-16,,,3240.9849999999988 2021-05-17,HON,-70.56000000000029,3170.4249999999984 2021-05-18,,,3170.4249999999984 2021-05-19,,,3170.4249999999984 2021-05-20,WBA,-11.970000000000049,3158.454999999998 2021-05-21,,,3158.454999999998 2021-05-22,AMGN,0.0,3158.454999999998 2021-05-23,,,3158.454999999998 2021-05-24,TRV,34.3899999999995,3192.8449999999975 2021-05-25,,,3192.8449999999975 2021-05-26,,,3192.8449999999975 2021-05-27,,,3192.8449999999975 2021-05-28,,,3192.8449999999975 2021-05-29,,,3192.8449999999975 2021-05-30,,,3192.8449999999975 2021-05-31,,,3192.8449999999975 2021-06-01,,,3192.8449999999975 2021-06-02,,,3192.8449999999975 2021-06-03,HD,-22.200000000000276,3170.6449999999973 2021-06-04,,,3170.6449999999973 2021-06-05,,,3170.6449999999973 2021-06-06,,,3170.6449999999973 2021-06-07,,,3170.6449999999973 2021-06-08,MSFT,-2.6399999999999864,3168.0049999999974 2021-06-09,,,3168.0049999999974 2021-06-10,,,3168.0049999999974 2021-06-11,UNH,-25.20000000000016,3142.804999999997 2021-06-12,,,3142.804999999997 2021-06-13,MRK,0.0,3142.804999999997 2021-06-14,,,3142.804999999997 2021-06-15,HON,-9.379999999999823,3133.4249999999975 2021-06-16,,,3133.4249999999975 2021-06-17,HD,-1.6999999999995907,3131.7249999999976 2021-06-18,,,3131.7249999999976 2021-06-19,,,3131.7249999999976 2021-06-20,,,3131.7249999999976 2021-06-21,MSFT,87.11999999999989,3218.8449999999975 2021-06-22,,,3218.8449999999975 2021-06-23,,,3218.8449999999975 2021-06-24,,,3218.8449999999975 2021-06-25,,,3218.8449999999975 2021-06-26,MCD,0.0,3218.8449999999975 2021-06-27,,,3218.8449999999975 2021-06-28,JNJ,90.62999999999964,3309.474999999997 2021-06-29,,,3309.474999999997 2021-06-30,,,3309.474999999997 2021-07-01,,,3309.474999999997 2021-07-02,,,3309.474999999997 2021-07-03,,,3309.474999999997 2021-07-04,MCD,0.0,3309.474999999997 2021-07-05,,,3309.474999999997 2021-07-06,,,3309.474999999997 2021-07-07,MSFT,3.0799999999997,3312.5549999999967 2021-07-08,,,3312.5549999999967 2021-07-09,,,3312.5549999999967 2021-07-10,,,3312.5549999999967 2021-07-11,,,3312.5549999999967 2021-07-12,BA,-218.79000000000016,3093.7649999999967 2021-07-13,,,3093.7649999999967 2021-07-14,,,3093.7649999999967 2021-07-15,,,3093.7649999999967 2021-07-16,,,3093.7649999999967 2021-07-17,MRK,-37.82999999999996,3055.9349999999968 2021-07-18,,,3055.9349999999968 2021-07-19,,,3055.9349999999968 2021-07-20,,,3055.9349999999968 2021-07-21,MSFT,20.79999999999984,3076.7349999999965 2021-07-22,,,3076.7349999999965 2021-07-23,VZ,-3.7800000000000153,3072.9549999999963 2021-07-24,,,3072.9549999999963 2021-07-25,CSCO,-25.299999999999656,3047.6549999999966 2021-07-26,,,3047.6549999999966 2021-07-27,,,3047.6549999999966 2021-07-28,,,3047.6549999999966 2021-07-29,,,3047.6549999999966 2021-07-30,AMGN,-11.040000000000193,3036.614999999996 2021-07-31,,,3036.614999999996 2021-08-01,INTC,-2.2399999999999523,3034.3749999999964 2021-08-02,,,3034.3749999999964 2021-08-03,,,3034.3749999999964 2021-08-04,MMM,-52.5,2981.8749999999964 2021-08-05,,,2981.8749999999964 2021-08-06,WBA,94.5,3076.3749999999964 2021-08-07,,,3076.3749999999964 2021-08-08,,,3076.3749999999964 2021-08-09,,,3076.3749999999964 2021-08-10,,,3076.3749999999964 2021-08-11,,,3076.3749999999964 2021-08-12,MRK,33.2000000000005,3109.574999999997 2021-08-13,,,3109.574999999997 2021-08-14,BA,-70.20000000000007,3039.374999999997 2021-08-15,,,3039.374999999997 2021-08-16,,,3039.374999999997 2021-08-17,,,3039.374999999997 2021-08-18,TRV,-3.4200000000001296,3035.9549999999967 2021-08-19,,,3035.9549999999967 2021-08-20,CSCO,50.349999999999774,3086.3049999999967 2021-08-21,,,3086.3049999999967 2021-08-22,,,3086.3049999999967 2021-08-23,KO,-10.800000000000152,3075.5049999999965 2021-08-24,,,3075.5049999999965 2021-08-25,HD,-30.77999999999963,3044.7249999999967 2021-08-26,,,3044.7249999999967 2021-08-27,,,3044.7249999999967 2021-08-28,KO,0.0,3044.7249999999967 2021-08-29,,,3044.7249999999967 2021-08-30,CAT,-19.32000000000033,3025.4049999999966 2021-08-31,,,3025.4049999999966 2021-09-01,GS,1.0500000000002387,3026.4549999999967 2021-09-02,,,3026.4549999999967 2021-09-03,AMGN,5.329999999999956,3031.7849999999967 2021-09-04,,,3031.7849999999967 2021-09-05,UNH,0.0,3031.7849999999967 2021-09-06,,,3031.7849999999967 2021-09-07,MMM,-132.1499999999996,2899.634999999997 2021-09-08,,,2899.634999999997 2021-09-09,JNJ,-78.88000000000011,2820.754999999997 2021-09-10,,,2820.754999999997 2021-09-11,,,2820.754999999997 2021-09-12,,,2820.754999999997 2021-09-13,,,2820.754999999997 2021-09-14,BA,-14.55999999999969,2806.1949999999974 2021-09-15,,,2806.1949999999974 2021-09-16,,,2806.1949999999974 2021-09-17,,,2806.1949999999974 2021-09-18,AAPL,16.33999999999972,2822.534999999997 2021-09-19,,,2822.534999999997 2021-09-20,,,2822.534999999997 2021-09-21,,,2822.534999999997 2021-09-22,,,2822.534999999997 2021-09-23,,,2822.534999999997 2021-09-24,,,2822.534999999997 2021-09-25,,,2822.534999999997 2021-09-26,TRV,0.0,2822.534999999997 2021-09-27,,,2822.534999999997 2021-09-28,AMGN,23.269999999999897,2845.804999999997 2021-09-29,,,2845.804999999997 2021-09-30,,,2845.804999999997 2021-10-01,WBA,-15.0,2830.804999999997 2021-10-02,,,2830.804999999997 2021-10-03,IBM,-3.247557600000164,2827.557442399997 2021-10-04,,,2827.557442399997 2021-10-05,,,2827.557442399997 2021-10-06,,,2827.557442399997 2021-10-07,VZ,-32.13000000000013,2795.427442399997 2021-10-08,,,2795.427442399997 2021-10-09,WMT,0.0,2795.427442399997 2021-10-10,,,2795.427442399997 2021-10-11,MMM,-21.29999999999981,2774.127442399997 2021-10-12,,,2774.127442399997 2021-10-13,,,2774.127442399997 2021-10-14,CRM,65.25,2839.377442399997 2021-10-15,,,2839.377442399997 2021-10-16,,,2839.377442399997 2021-10-17,,,2839.377442399997 2021-10-18,,,2839.377442399997 2021-10-19,HD,22.54000000000019,2861.9174423999975 2021-10-20,,,2861.9174423999975 2021-10-21,,,2861.9174423999975 2021-10-22,CAT,-20.85999999999973,2841.057442399998 2021-10-23,,,2841.057442399998 2021-10-24,MSFT,0.0,2841.057442399998 2021-10-25,,,2841.057442399998 2021-10-26,CAT,26.319999999999936,2867.3774423999976 2021-10-27,,,2867.3774423999976 2021-10-28,,,2867.3774423999976 2021-10-29,,,2867.3774423999976 2021-10-30,MRK,0.0,2867.3774423999976 2021-10-31,,,2867.3774423999976 2021-11-01,BA,98.15000000000016,2965.5274423999977 2021-11-02,,,2965.5274423999977 2021-11-03,MSFT,26.480000000000015,2992.0074423999977 2021-11-04,,,2992.0074423999977 2021-11-05,,,2992.0074423999977 2021-11-06,CRM,24.389999999999816,3016.3974423999975 2021-11-07,,,3016.3974423999975 2021-11-08,,,3016.3974423999975 2021-11-09,,,3016.3974423999975 2021-11-10,PG,23.40000000000032,3039.7974423999976 2021-11-11,,,3039.7974423999976 2021-11-12,,,3039.7974423999976 2021-11-13,,,3039.7974423999976 2021-11-14,,,3039.7974423999976 2021-11-15,PG,10.79999999999984,3050.5974423999974 2021-11-16,,,3050.5974423999974 2021-11-17,,,3050.5974423999974 2021-11-18,,,3050.5974423999974 2021-11-19,AAPL,50.92000000000013,3101.5174423999974 2021-11-20,,,3101.5174423999974 2021-11-21,CVX,54.0,3155.5174423999974 2021-11-22,,,3155.5174423999974 2021-11-23,,,3155.5174423999974 2021-11-24,AAPL,10.070000000000022,3165.5874423999976 2021-11-25,,,3165.5874423999976 2021-11-26,HD,-37.03000000000014,3128.5574423999974 2021-11-27,,,3128.5574423999974 2021-11-28,,,3128.5574423999974 2021-11-29,,,3128.5574423999974 2021-11-30,,,3128.5574423999974 2021-12-01,UNH,0.8399999999996339,3129.397442399997 2021-12-02,,,3129.397442399997 2021-12-03,VZ,42.090000000000295,3171.4874423999972 2021-12-04,,,3171.4874423999972 2021-12-05,V,202.72000000000023,3374.2074423999975 2021-12-06,,,3374.2074423999975 2021-12-07,,,3374.2074423999975 2021-12-08,,,3374.2074423999975 2021-12-09,,,3374.2074423999975 2021-12-10,CRM,20.519999999999754,3394.727442399997 2021-12-11,,,3394.727442399997 2021-12-12,HD,-81.27999999999975,3313.4474423999973 2021-12-13,,,3313.4474423999973 2021-12-14,,,3313.4474423999973 2021-12-15,HON,49.27999999999975,3362.727442399997 2021-12-16,,,3362.727442399997 2021-12-17,MMM,-64.08000000000004,3298.647442399997 2021-12-18,,,3298.647442399997 2021-12-19,,,3298.647442399997 2021-12-20,HD,61.27999999999975,3359.927442399997 2021-12-21,,,3359.927442399997 2021-12-22,,,3359.927442399997 2021-12-23,,,3359.927442399997 2021-12-24,MRK,36.959999999999525,3396.8874423999964 2021-12-25,,,3396.8874423999964 2021-12-26,,,3396.8874423999964 2021-12-27,,,3396.8874423999964 2021-12-28,,,3396.8874423999964 2021-12-29,MMM,14.630000000000194,3411.5174423999965 2021-12-30,,,3411.5174423999965 2021-12-31,,,3411.5174423999965 ================================================ FILE: results/model_result_summary.csv ================================================ Model,Gains,Losses,Profit,Profit Percentage,Maximum Gain,Maximum Loss LR_v1_predict_0.7_3,2974.89,-2062.63,912.26,30.41,212.4,-196 LR_v1_predict_0.9_10,2772.61,-1963.97,808.64,26.95,163.25,-159 LR_v1_predict_0.95_21,2911.67,-1478.71,1432.96,47.77,259.93,-215 LR_v1_predict_1_1,2203.36,-1791.85,411.52,13.72,202.72,-219 ================================================ FILE: stock_utils/simulator.py ================================================ import numpy as np import math import pandas as pd """ stock simulator to trade in real time. author - Kaneel Senevirathne date - 1/4/2022 """ class simulator: def __init__(self, capital): self.capital = capital self.initial_capital = capital #keep a copy of the initial capital self.total_gain = 0 self.buy_orders = {} self.history = [] #create a pandas df to save history cols = ['stock', 'buy_price', 'n_shares', 'sell_price', 'net_gain', 'buy_date', 'sell_date'] self.history_df = pd.DataFrame(columns = cols) def buy(self, stock, buy_price, buy_date): """ function takes buy price and the number of shares and buy the stock """ #calculate the procedure n_shares = self.buy_percentage(buy_price) self.capital = self.capital - buy_price * n_shares self.buy_orders[stock] = [buy_price, n_shares, buy_price * n_shares, buy_date] def sell(self, stock, sell_price, n_shares_sell, sell_date): """ function to sell stock given the stock name and number of shares """ buy_price, n_shares, _, buy_date = self.buy_orders[stock] sell_amount = sell_price * (n_shares_sell) self.capital = self.capital + sell_amount if (n_shares - n_shares_sell) == 0: #if sold all self.history.append([stock, buy_price, n_shares, sell_price, buy_date, sell_date]) del self.buy_orders[stock] else: n_shares = n_shares - n_shares_sell self.buy_orders[stock][1] = n_shares self.buy_orders[stock][2] = buy_price * n_shares def buy_percentage(self, buy_price, buy_perc = 1): """ this function determines how much capital to spend on the stock and returns the number of shares """ stock_expenditure = self.capital * buy_perc n_shares = math.floor(stock_expenditure / buy_price) return n_shares def trailing_stop_loss(self): """ activates a trailing stop loss """ pass def print_bag(self): """ print current stocks holding """ print ("{:<10} {:<10} {:<10} {:<10}".format('STOCK', 'BUY PRICE', 'SHARES', 'TOTAL VALUE')) for key, value in self.buy_orders.items(): print("{:<10} {:<10} {:<10} {:<10}".format(key, value[0], value[1], value[2])) print('\n') def create_summary(self, print_results = False): """ create summary """ if print_results: print ("{:<10} {:<10} {:<10} {:<10} {:<10}".format('STOCK', 'BUY PRICE', 'SHARES', 'SELL PRICE', 'NET GAIN')) for values in self.history: net_gain = (values[3] - values[1]) * values[2] self.total_gain += net_gain self.history_df = self.history_df.append({'stock': values[0], 'buy_price': values[1], 'n_shares': values[2], 'sell_price': values[3]\ ,'net_gain': net_gain, 'buy_date': values[4], 'sell_date': values[5]}, ignore_index = True) if print_results: print("{:<10} {:<10} {:<10} {:<10} {:<10}".format(values[0], values[1], values[2], values[3], np.round(net_gain, 2))) def print_summary(self): """ prints the summary of results """ self.create_summary(print_results = True) print('\n') print(f'Initial Balance: {self.initial_capital:.2f}') print(f'Final Balance: {(self.initial_capital + self.total_gain):.2f}') print(f'Total gain: {self.total_gain:.2f}') print(f'P/L : {(self.total_gain/self.initial_capital)*100:.2f} %') print('\n') ================================================ FILE: stock_utils/stock_utils.py ================================================ from td.client import TDClient import requests, time, re, os import matplotlib.pyplot as plt import pandas as pd import numpy as np from datetime import datetime, timedelta from scipy.signal import argrelextrema from sklearn.linear_model import LinearRegression from sklearn.preprocessing import MinMaxScaler from datetime import datetime """ author - Kaneel Senevirathne date - 1/8/2022 stock utils for preparing training data. """ #TD API - TD_API = 'XXXXX' ### your TD ameritrade api key def timestamp(dt): epoch = datetime.utcfromtimestamp(0) return int((dt - epoch).total_seconds() * 1000) def linear_regression(x, y): """ performs linear regression given x and y. outputs regression coefficient """ #fit linear regression lr = LinearRegression() lr.fit(x, y) return lr.coef_[0][0] def n_day_regression(n, df, idxs): """ n day regression. """ #variable _varname_ = f'{n}_reg' df[_varname_] = np.nan for idx in idxs: if idx > n: y = df['close'][idx - n: idx].to_numpy() x = np.arange(0, n) #reshape y = y.reshape(y.shape[0], 1) x = x.reshape(x.shape[0], 1) #calculate regression coefficient coef = linear_regression(x, y) df.loc[idx, _varname_] = coef #add the new value return df def normalized_values(high, low, close): """ normalize the price between 0 and 1. """ #epsilon to avoid deletion by 0 epsilon = 10e-10 #subtract the lows high = high - low close = close - low return close/(high + epsilon) def get_stock_price(stock, date): """ returns the stock price given a date """ start_date = date - timedelta(days = 10) end_date = date #enter url of database url = f'https://api.tdameritrade.com/v1/marketdata/{stock}/pricehistory' query = {'apikey': str(TD_API), 'startDate': timestamp(start_date), \ 'endDate': timestamp(end_date), 'periodType': 'year', 'frequencyType': \ 'daily', 'frequency': '1', 'needExtendedHoursData': 'False'} #request results = requests.get(url, params = query) data = results.json() try: #change the data from ms to datetime format data = pd.DataFrame(data['candles']) data['date'] = pd.to_datetime(data['datetime'], unit = 'ms') return data['close'].values[-1] except: pass def get_data(sym, start_date = None, end_date = None, n = 10): #enter url url = f'https://api.tdameritrade.com/v1/marketdata/{sym}/pricehistory' if start_date: payload = {'apikey': str(TD_API), 'startDate': timestamp(start_date), \ 'endDate': timestamp(end_date), 'periodType': 'year', 'frequencyType': \ 'daily', 'frequency': '1', 'needExtendedHoursData': 'False'} else: payload = {'apikey': str(TD_API), 'startDate': timestamp(datetime(2007, 1, 1)), \ 'endDate': timestamp(datetime(2020, 12, 31)), 'periodType': 'year', 'frequencyType': \ 'daily', 'frequency': '1', 'needExtendedHoursData': 'False'} #request results = requests.get(url, params = payload) data = results.json() #change the data from ms to datetime format data = pd.DataFrame(data['candles']) data['date'] = pd.to_datetime(data['datetime'], unit = 'ms') #add the noramlzied value function and create a new column data['normalized_value'] = data.apply(lambda x: normalized_values(x.high, x.low, x.close), axis = 1) #column with local minima and maxima data['loc_min'] = data.iloc[argrelextrema(data.close.values, np.less_equal, order = n)[0]]['close'] data['loc_max'] = data.iloc[argrelextrema(data.close.values, np.greater_equal, order = n)[0]]['close'] #idx with mins and max idx_with_mins = np.where(data['loc_min'] > 0)[0] idx_with_maxs = np.where(data['loc_max'] > 0)[0] return data, idx_with_mins, idx_with_maxs def create_train_data(stock, start_date = None, end_date = None, n = 10): #get data to a dataframe data, idxs_with_mins, idxs_with_maxs = get_data(stock, start_date, end_date, n) #create regressions for 3, 5 and 10 days data = n_day_regression(3, data, list(idxs_with_mins) + list(idxs_with_maxs)) data = n_day_regression(5, data, list(idxs_with_mins) + list(idxs_with_maxs)) data = n_day_regression(10, data, list(idxs_with_mins) + list(idxs_with_maxs)) data = n_day_regression(20, data, list(idxs_with_mins) + list(idxs_with_maxs)) _data_ = data[(data['loc_min'] > 0) | (data['loc_max'] > 0)].reset_index(drop = True) #create a dummy variable for local_min (0) and max (1) _data_['target'] = [1 if x > 0 else 0 for x in _data_.loc_max] #columns of interest cols_of_interest = ['volume', 'normalized_value', '3_reg', '5_reg', '10_reg', '20_reg', 'target'] _data_ = _data_[cols_of_interest] return _data_.dropna(axis = 0) def create_test_data_lr(stock, start_date = None, end_date = None, n = 10): """ this function create test data sample for logistic regression model """ #get data to a dataframe data, _, _ = get_data(stock, start_date, end_date, n) idxs = np.arange(0, len(data)) #create regressions for 3, 5 and 10 days data = n_day_regression(3, data, idxs) data = n_day_regression(5, data, idxs) data = n_day_regression(10, data, idxs) data = n_day_regression(20, data, idxs) cols = ['close', 'volume', 'normalized_value', '3_reg', '5_reg', '10_reg', '20_reg'] data = data[cols] return data.dropna(axis = 0) def predict_trend(stock, _model_, start_date = None, end_date = None, n = 10): #get data to a dataframe data, _, _ = get_data(stock, start_date, end_date, n) idxs = np.arange(0, len(data)) #create regressions for 3, 5 and 10 days data = n_day_regression(3, data, idxs) data = n_day_regression(5, data, idxs) data = n_day_regression(10, data, idxs) data = n_day_regression(20, data, idxs) #create a column for predicted value data['pred'] = np.nan #get data cols = ['volume', 'normalized_value', '3_reg', '5_reg', '10_reg', '20_reg'] x = data[cols] #scale the x data scaler = MinMaxScaler() x = scaler.fit_transform(x) for i in range(x.shape[0]): try: data['pred'][i] = _model_.predict(x[i, :]) except: data['pred'][i] = np.nan return data