def save_all(self): filename = os.path.join(mydir(), "data", time.strftime("%Y%m%d", time.localtime())+".pkl") try: logging.info("dump all the data to file %s" % filename) with open(filename, "w") as f: cPickle.dump(self.data, f) return os.path.basename(filename) except: trace_log() return None
def __init__(self, close_data_file, predict_file): Stock.__init__(self) self.reload_all(close_data_file) with open(os.path.join(mydir(), "data", predict_file), "r") as f: code_list = f.read().split('\n') self.up_code = [] for code in code_list: if " " in code: c = code.split(" ") self.up_code.append(c[0]) else: self.up_code.append(code)
def reload_all(self, name=time.strftime("%Y%m%d", time.localtime())+".pkl"): filename = os.path.join(mydir(), "data", name) if not os.path.exists(filename): self.fast_refresh_all() self.save_all() else: try: logging.info("load all the data from file %s" % filename) with open(filename, "r") as f: self.data = cPickle.load(f) except: trace_log() self.fast_refresh_all() self.save_all() return self.data
jumped = False for i in range(-1, -10, -1): if high_array[i] < close_array[i - 1]: jumped = True break if jumped and chg_p_array[-1] > 3.0: down_number = 0 for c in chg_p_array[-10:]: if c < 0.0: down_number += 1 result[code] = down_number except: trace_log() pass sorted_result = sorted(result.iteritems(), key=operator.itemgetter(1), reverse=True) return sorted_result if __name__ == '__main__': k = bottom() r = k.predict() with open( os.path.join( mydir(), "data", time.strftime("bottom_%Y%m%d", time.localtime()) + ".txt"), "w") as f: for code, down_number in r[0:10]: f.write(code + "\n")
def usage(): print "hdfs_put.py [options] src dest" print " -f encoding: src file's encoding, supported codecs '%s'" % ' '.join( supported_codecs) print " -t encoding: dest file's encoding, supported codecs '%s'" % ' '.join( supported_codecs) print " -r 'regex patten': regex to be applied on the src file, like '/\\x1E/\\x01/;/\\x0C//;/\\x0D//;/\\x00//'" if __name__ == '__main__': reload(sys) sys.setdefaultencoding("utf-8") logging.basicConfig(level=logging.DEBUG, format="%(message)s", filename=os.path.join(mydir(), "hdfs_put.log"), filemode="w") console = logging.StreamHandler() console.setLevel(logging.INFO) console.setFormatter(logging.Formatter("%(message)s")) logging.getLogger('').addHandler(console) parser = OptionParser() parser.add_option("-f", action="store", type="string", dest="from_encoding", help="-f encoding: src file's encoding") parser.add_option("-t", action="store", type="string",
data_array = np.array(self.data[code]) try: close_array, chg_p_array = np.float32(data_array[:,close]), np.float32(data_array[:,chg_p]) def gold_predict(close_array): close_array = close_array[-10:] max_close = max(close_array) min_close = min(close_array) if close_array[-1] < max_close and max_close == close_array[-2]: if (max_close - min_close)/min_close > 0.1 : ratio = (max_close - close_array[-1]) / (max_close - min_close) if ratio < (0.382+0.010) and ratio > (0.382-0.010): result[code] = 2*max_close-close_array[-1] return True return False top_5_close_array = close_array[-5:] if not gold_predict(top_5_close_array): top_10_close_array = close_array[-10:] gold_predict(top_10_close_array) except: trace_log() pass return result.items() if __name__ == '__main__': k = gold() r = k.predict() with open(os.path.join(mydir(), "data", time.strftime("gold_%Y%m%d", time.localtime())+".txt"), "w") as f: for code, price in r[0:10]: f.write("%s %.2f\n"%(code, price))
def usage(): print "hdfs_find_tree.py" print " --ctime n: File status was last changed n*24 hours ago" print " --path: Path to walk through" print " --action: Action to do for the found files, 'print' or 'delete', default is 'print'" print " --empty: Remove empty folder" if __name__ == '__main__': reload(sys) sys.setdefaultencoding("utf-8") logging.basicConfig(level=logging.DEBUG, format="%(message)s", filename=os.path.join(mydir(), "hdfs_find_tree.log"), filemode="w") console = logging.StreamHandler() console.setLevel(logging.ERROR) console.setFormatter(logging.Formatter("%(message)s")) logging.getLogger('').addHandler(console) parser = OptionParser() parser.add_option( "--ctime", action="store", type="string", dest="ctime", help="--ctime n: File status was last changed n*24 hours ago") parser.add_option("--path", action="store",