def one_work(cls, taName, label, date_range, th): df = base.get_merged(base.dir_ta(taName)) df = get_range(df, date_range[0], date_range[1]) m = joblib.load( os.path.join(root, 'data', 'models', "model_" + cls + ".pkl")) s = joblib.load( os.path.join(root, 'data', 'models', "scaler_" + cls + ".pkl")) feat_names = base.get_feat_names(df) npFeat = df.loc[:, feat_names].values #npPred = cls.predict_proba(npFeat)[:,1] #prent npPred res = "" for i, npPred in enumerate(m.staged_predict_proba(s.transform(npFeat))): #if i % 1 != 0: # continue re = "%s\t%s\t%s\t%s\t%s\t%f\t" % (cls, taName, label, date_range[0], date_range[1], th) df["pred"] = npPred[:, 1] dacc = accu(df, label, th) re += "%d\t%d\t%d\t" % (i, dacc["trueInPos"], dacc["pos"]) if dacc["pos"] > 0: re += "%f" % (dacc["trueInPos"] * 1.0 / dacc["pos"]) else: re += "0.0" re += "\n" print re res += re return re
def one_work(cls, taName, label, date_range, th): df = base.get_merged(base.dir_ta(taName)) df = get_range(df, date_range[0], date_range[1]) m = joblib.load(os.path.join(root, 'data', 'models',"model_" + cls + ".pkl")) s = joblib.load(os.path.join(root, 'data', 'models',"scaler_" + cls + ".pkl")) feat_names = base.get_feat_names(df) npFeat = df.loc[:,feat_names].values #npPred = cls.predict_proba(npFeat)[:,1] #prent npPred res = "" for i, npPred in enumerate(m.staged_predict_proba(s.transform(npFeat))): #if i % 1 != 0: # continue re = "%s\t%s\t%s\t%s\t%s\t%f\t" % (cls, taName, label, date_range[0], date_range[1],th) df["pred"] = npPred[:,1] dacc = accu(df, label, th) re += "%d\t%d\t%d\t" % (i, dacc["trueInPos"], dacc["pos"]) if dacc["pos"] > 0: re += "%f" % (dacc["trueInPos"]*1.0 / dacc["pos"]) else : re += "0.0" re += "\n" print re res += re return re
def _one_work2(sym, tafunc): exec "import main.pandas_talib.sig_%s as conf" % tafunc df = pd.read_csv(os.path.join(base.dir_eod(), sym + ".csv")) if df is None: print sym return df = judge(df) if 'ta_index_hdiff_close_1' in df.columns: df = judge2(df) df["sym"] = sym df = conf.main(df) df.to_pickle(os.path.join(base.dir_ta(conf.__name__), sym + ".pkl"))
def _one_work(sym, taname): impstr = "import ta_%s as conf" % taname exec impstr df = pd.read_csv(os.path.join(base.dir_eod(), sym + ".csv")) if df is None: print sym return df = judge(df) if 'ta_index_hdiff_close_1' in df.columns: df = judge2(df) df["sym"] = sym df = conf.main(df) df.to_pickle(os.path.join(base.dir_ta(taname), sym + ".pkl"))
def _one_work(sym, ta, confer): try: df = pd.read_csv(os.path.join(base.dir_eod(), sym + ".csv")) df = df[["date", "open", "high", "low", "close", "volume"]] df[["volume"]] = df[["volume"]].astype(float) if df is None: print(sym) return df["sym"] = sym if TEST: print("TEST") df = df[df.date >= "2000-01-01"] df = ta.get_ta(df, confer) df.to_pickle(os.path.join(base.dir_ta(ta.get_name()), sym + ".pkl")) return df except: traceback.print_exc() assert False
def one_work(clsName, taName, labelName, start, end, top): df = base.get_merged(base.dir_ta(taName)) df = get_range(df, start, end) m = joblib.load(os.path.join(root, 'data', 'models',"model_" + clsName + ".pkl")) if isscaler: s = joblib.load(os.path.join(root, 'data', 'models',"scaler_" + clsName + ".pkl")) feat_names = base.get_feat_names(df) npFeat = df.loc[:,feat_names].values res = "" if isscaler : npFeat = s.transform(npFeat) topscore = None l = [] for i, npPred in enumerate(m.staged_predict_proba(npFeat)): df.loc[:,"pred"] = npPred[:,1] dacc = accu(df, labelName, top) acc = 0.0 if dacc["pos"] > 0: acc = (dacc["trueInPos"]*1.0 / dacc["pos"]) print i, acc l.append([i, acc]) return pd.DataFrame(np.asarray(l), columns=["idx", "acc"])