def verify_train_NN(self): # Load parameters used during model training and if trend different than current param re-create model and train and save param with open(os.getcwd()+self.ML_dataset_parameters_path, 'r') as json_file: ML_Parameters = json.load(json_file) # Verify if the dataset has to be redone if ML_Parameters['ML_trend_length'] != self.ML_trend_length or self.parameters['Crypto?'] != ML_Parameters['Crypto?']: # Hist loading and dataset creation my_hist = Dataset(Parameters) my_hist.load() ML_dataset = my_hist.new_format(len(my_hist.hist)) # Create the dataset ML_dataset = my_hist.create_ML_dataset(ML_dataset) # Save dataset parameters with open(os.getcwd()+self.parameters['ML_path']['ML_dataset_parameters_path'], 'w') as json_file: json.dump(self.parameters, json_file) else: ML_dataset = pd.read_csv(os.getcwd()+Parameters['ML_path']['ML_dataset_path']) if not(os.path.exists(os.getcwd()+self.NN_model_path+str(self.ML_trend_length))): # Train the dataset self.train_NN(ML_dataset)
def verify_train_LSTM(self): # Load parameters used during model training and if trend different than current param re-create model and train and save param with open(os.getcwd()+self.ML_dataset_parameters_path, 'r') as json_file: ML_Parameters = json.load(json_file) full_hist = Dataset(Parameters) full_hist.load() if full_hist.date_name != '1m': full_hist.hist[full_hist.date_name] = full_hist.hist[full_hist.date_name].astype('datetime64[ns]') else: full_hist.hist[full_hist.date_name] = full_hist.hist[full_hist.date_name].dt.floor('min') dataset = full_hist.new_format(len(full_hist.hist)) companies_to_train = [] for company in self.companies_list: if not(os.path.exists(os.getcwd()+self.LSTM_model_path+'_'+str(company))): companies_to_train.append(company) self.train_LSTM(dataset, companies_to_train)
# -------------------- with open(os.getcwd()+'\\parameters\\Parameters.json', 'r') as json_file: Parameters = json.load(json_file) # Overwrite mesh Parameters['Mesh'] = '1m' # -------------------- # MAIN # -------------------- # ------- LOAD ------- # Loading history csv full_hist = Dataset(Parameters) full_hist.load() # Setting back the timestamp format if full_hist.date_name != '1m': full_hist.hist[full_hist.date_name] = full_hist.hist[full_hist.date_name].astype('datetime64[ns]') else: full_hist.hist[full_hist.date_name] = full_hist.hist[full_hist.date_name].dt.floor('min') # Create the porfolio Portfolio = Portfolio_class(Parameters) Portfolio.create() # ------ UPDATE ------ # Fetching Data to complete history if Parameters['Update_Values'] == True:
print('##### Crypto #####') else: sys.stdout = open( os.getcwd() + '\\models\\logs\\NASDAQ\\Model_Eval_' + str(Parameters['trend_length']) + '-' + str(Parameters['ML_trend_length']) + '-' + str(Parameters['study_length']) + '.txt', 'w') print('##### NASDAQ #####') # -------------------- # MAIN # -------------------- # ------- LOAD ------- # Loading history csv full_hist = Dataset(Parameters) full_hist.load() # Setting back the timestamp format if full_hist.date_name != '1m': full_hist.hist[full_hist.date_name] = full_hist.hist[ full_hist.date_name].astype('datetime64[ns]') else: full_hist.hist[full_hist.date_name] = full_hist.hist[ full_hist.date_name].dt.floor('min') # Load the porfolio Portfolio = Portfolio_class(Parameters).reset() # ------ UPDATE ------ # Update Companies list if needed
else: BS_dict[company] = "Hold" # Specific rules if add_specific_rules: # Sell after a high rise if prediction_dict[company] > sell_after_high_rise_ratio * last_values.loc[company]: BS_dict[company] = "Sell" # Sell after a high loss if prediction_dict[company] < last_values.loc[company] / sell_after_high_loss_ratio: BS_dict[company] = "Sell" return(BS_dict, prediction_dict, next_variation_dict) if __name__ == "__main__": study_length = 10 # Loading history csv full_hist = pd.read_csv(os.getcwd() + '\\resources\\full_NASDAQ_history.csv', usecols=['Close', 'Company', 'Date', 'Dividends', 'High', 'Low', 'Open', 'Stock Splits', 'Volume']) # Setting back the timestamp format full_hist['Date'] = full_hist['Date'].astype('datetime64[ns]') dataset = Dataset(full_hist).new_format(study_length) BS_dict, Trend_dict = BuySell(dataset, Parameters).trend() print(BS_dict, Trend_dict)
from functions.Plot_Class import Plot # -------------------- # PARAMETERS # -------------------- with open(os.getcwd() + '\\parameters\\Parameters.json', 'r') as json_file: Parameters = json.load(json_file) # -------------------- # MAIN # -------------------- # ------- LOAD ------- # Loading history csv full_hist = Dataset(Parameters) full_hist.load() # Setting back the timestamp format if full_hist.date_name != '1m': full_hist.hist[full_hist.date_name] = full_hist.hist[ full_hist.date_name].astype('datetime64[ns]') else: full_hist.hist[full_hist.date_name] = full_hist.hist[ full_hist.date_name].dt.floor('min') # Load the porfolio Portfolio = Portfolio_class(Parameters).reset() # ------ UPDATE ------ # Update Companies list if needed