예제 #1
0
 def predict2csv(self, code, startd, endd, csvpath):
     tfl = TfLearning(meigaras=[code], restore_first=False)
     (restored, ver, accuracy) = tfl.restore(code)
     if restored == False:
         return False
     (dates, ximage) = tfl.get_meigara_xs(code, startd, endd)
     result = tfl.predict(ximage)
     data = []
     for i in range(len(dates)):
         if dates[i] <= ver:
             continue
         row = [code, dates[i], ver, accuracy]
         row.extend(result[i].tolist())
         data.append(row)
     cf.arr2csv(csvpath, data)
예제 #2
0
def do_test(startd, endd, meigaras=[]):
    interval = 20

    if len(meigaras) == 0:
        meigaras = kf.get_meigaras()

    f.log("Start making reports")
    
    report = []
    for code in meigaras:
        f.log("Processing meigara:%s" % (code))
        kl = KabukaLines(code, startd, endd)
        lt = LineTrader(kl)
            
        kabuka = kl.get_kabuka()
        if len(kabuka) == 7:
            (indexes, dates, open, high, low, close, volume) = kabuka
        else:
            continue
        
        tmp_endd = dates[-1]
        i = 60
        old_from_date = ""
        while i < len(dates)-interval:
            if lt.judge_trade_goodness(i) == False:
                i += interval
                continue

            tmp_startd = dates[i]
            tmp_next_startd = dates[i+interval]
            (trade_mode_str, interest, from_date, to_date, spent, start_price, end_price, endi) \
                = lt.test(tmp_startd, tmp_endd, tmp_next_startd)
            if old_from_date != from_date:
                if trade_mode_str != "":
                    report.append([code, trade_mode_str, interest, from_date, to_date, spent, start_price, end_price])
                old_from_date = from_date
            if endi > i:
                i = endi
            else:
                i += interval
    
    
    f.arr2csv("%s/report.csv" % (TMP_DIR), report)
    
    f.log("Finished making reports:%s/report.csv" % (TMP_DIR))
예제 #3
0
 def save(self):
     path = "%s/%s" % (CSV_DIR, self.cluster_centers_csv)
     labels = np.matrix(self.km.predict(self.km.cluster_centers_)).T
     labels = np.array(labels)
     centers = self.km.cluster_centers_
     f.arr2csv(path, np.c_[labels, centers], "w")
예제 #4
0
 def save(self):
     path = "%s/%s" % (CSV_DIR, self.cluster_centers_csv)
     coef = self.sgdcls.coef_
     intercept = self.sgdcls.intercept_
     f.arr2csv(self.coef_csv, coef, "w")
     f.arr2csv(self.intercept_csv, intercept, "w")
예제 #5
0
def save(km, cluster_centers_csv):
    path = "%s/%s" % (CSV_DIR, cluster_centers_csv)
    f.arr2csv(path, km.cluster_centers_, "w")