def show_chart(): strategy = settings["Strategy"] deltaDays = settings['deltaDays'] filename = settings['configFilename'] configjs = Settings.get_configjs(filename) watch = settings["watch"] dateset = gekkoWrapper.getAvailableDataset(watch) daterange = coreFunctions.getRandomDateRange(dateset, deltaDays=deltaDays) res = evolution_bayes.EvaluateRaw(watch, daterange, configjs[strategy], strategy) #res = gekkoWrapper.httpPost(URL, gekkoConfig) show_candles(res, configjs[strategy])
def show_chart(): strategy = settings["Strategy"] deltaDays = settings['deltaDays'] filename = settings['configFilename'] configjs = Settings.get_configjs(filename) watch = settings["watch"] dateset = gekkoWrapper.getAvailableDataset(watch) daterange = resultInterface.getRandomDateRange(dateset, deltaDays=deltaDays) res = evolution_bayes.EvaluateRaw(watch, daterange, configjs[strategy], strategy) #res = gekkoWrapper.httpPost(URL, gekkoConfig) show_candles(res, configjs[strategy])
def gekko_bayesian(indicator=None): print("") global Strategy Strategy = indicator watch = settings["watch"] global DatasetRange DatasetRange = gekkoWrapper.getAvailableDataset(watch) if indicator == None: Strategy = settings['Strategy'] print("Starting search %s parameters" % Strategy) bo = BayesianOptimization(gekko_search, copy.deepcopy(StratConfig)) # 1st Evaluate print("") print("Step 1: BayesianOptimization parameter search") bo.maximize(init_points=settings['init_points'], n_iter=settings['num_iter']) max_val = bo.res['max']['max_val'] index = all_val.index(max_val) s1 = stats[index] # 2nd Evaluate print("") print("Step 2: testing searched parameters on random date") chosenRange = gekkoWrapper.getAvailableDataset() DateRange = gekkoWrapper.getDateRange(chosenRange, deltaDays=settings['testDays']) max_params = bo.res['max']['max_params'].copy() #max_params["persistence"] = 1 print("Starting Second Evaluation") gekko_search(**max_params) s2 = stats[-1] # 3rd Evaluate print("") print("Step 3: testing searched parameters on recent date") watch = settings["watch"] result = EvaluateRaw(watch, DateRange, max_params, Strategy) if type(result['report']) == bool: s3 = 0. else: s3 = result['report']['relativeProfit'] resultjson = expandGekkoStrategyParameters(max_params, Strategy)[Strategy] # config.js like output percentiles = np.array([0.25, 0.5, 0.75]) formatted_percentiles = [ str(int(round(x * 100))) + "%" for x in percentiles ] stats_index = (['count', 'mean', 'std', 'min'] + formatted_percentiles + ['max']) print("") print("// " + '-' * 50) print("// " + Strategy + ' Settings') print("// " + '-' * 50) print("// 1st Evaluate: %.3f" % s1[1]) for i in range(len(s1)): print('// %s: %.3f' % (stats_index[i], s1[i])) print("// " + '-' * 50) print("// 2nd Evaluate: %.3f" % s2[1]) for i in range(len(s2)): print('// %s: %.3f' % (stats_index[i], s2[i])) print("// " + '-' * 50) print("// 3rd Evaluate nearest date: %s to %s" % (DateRange['from'], DateRange['to'])) print("// Evaluted Score: %f" % s3) print("// " + '-' * 50) print("config.%s = {%s};" % (Strategy, json.dumps(resultjson, indent=2)[1:-1])) print("// " + '-' * 50) if settings["save"]: paramsdf = pd.DataFrame.from_dict(bo.res["all"]["params"]) valuesdf = pd.DataFrame.from_dict(bo.res["all"]["values"]) paramsdf["target"] = valuesdf watch = settings["watch"] filename = "_".join([ watch["exchange"], watch["currency"], watch["asset"], Strategy, datetime.datetime.now().strftime('%Y%m%d_%H%M%S'), str(max_val) ]) save_dir = gsettings["save_dir"] csv_filename = os.path.join(save_dir, filename) + "_bayes.csv" json_filename = os.path.join(save_dir, filename) + "_config.json" json2_filename = os.path.join(save_dir, filename) + "_response.json" config = expandGekkoStrategyParameters(max_params, Strategy) config["watch"] = watch gekko_config = gekkoWrapper.createConfig(config, DateRange) if not os.path.exists(save_dir): os.mkdir(save_dir) paramsdf.to_csv(csv_filename, index=False) print("Saved: " + csv_filename) f = open(json_filename, "w") f.write(json.dumps(gekko_config, indent=2)) f.close() print("Saved: " + json_filename) f = open(json2_filename, "w") f.write(json.dumps(result, indent=2)) f.close() print("Saved: " + json2_filename) if settings["show_chart"]: chart.show_candles(result, max_params) return max_params
dict_merge = lambda a, b: a.update(b) or a gsettings = getSettings()['Global'] settings = getSettings()['bayesian'] Strategy = settings["Strategy"] StratConfig = getSettings()["strategies"][Strategy] percentiles = np.array([0.25, 0.5, 0.75]) all_val = [] stats = [] candleSize = 0 historySize = 0 watch = settings["watch"] watch, DatasetRange = gekkoWrapper.getAvailableDataset(watch) def expandGekkoStrategyParameters(IND, Strategy): config = {} IND = promoterz.utils.expandNestedParameters(IND) config[Strategy] = IND return config def Evaluate(Strategy, parameters): DateRange = gekkoWrapper.getRandomDateRange( DatasetRange, deltaDays=settings['deltaDays'])
# Fix the shit below! settings = getSettings()['bayesian'] bayesSettings = getSettings('bayesian') Strategy = settings["Strategy"] StratConfig = getSettings()["strategies"][Strategy] percentiles = np.array([0.25, 0.5, 0.75]) all_val = [] stats = [] candleSize = 0 historySize = 0 watch = settings["watch"] watch, DatasetRange = gekkoWrapper.getAvailableDataset(watch) def expandGekkoStrategyParameters(IND, Strategy): config = {} IND = promoterz.utils.expandNestedParameters(IND) config[Strategy] = IND return config def Evaluate(Strategy, parameters): DateRange = gekkoWrapper.getRandomDateRange(DatasetRange, deltaDays=settings['deltaDays']) params = expandGekkoStrategyParameters(parameters, Strategy)