def compute_probability_one_stock(probabilities,stock_no): trade_records = datafile.load_stocks(stock_no) count = len(trade_records) print 'trade_date,c1,c2,c3,close,acp,future1_prate' for i in range(0,count): c1 = 0.194520338846 c2 = 0.604818399782 c3 = 0.199873024089 for fk in featureFieldssss: fv = trade_records[i][fk] ps = [p for p in probabilities if p.fk==fk and p.fv==str(fv)] c1_p = [p.p for p in ps if p.cv=='1'][0] c1 = c1 * float(c1_p) c2_p = [p.p for p in ps if p.cv=='2'][0] c2 = c2 * float(c2_p) c3_p = [p.p for p in ps if p.cv=='3'][0] c3 = c3 * float(c3_p) #print fk,fv,float(c1_p),float(c2_p) future1_range = trade_records[i]['future1_range'] if 'future1_range' in trade_records[i] else 0 future1_prate = trade_records[i]['future1_prate'] if 'future1_prate' in trade_records[i] else 0 print '%s,%s,%s,%s,%s,%s,%s' %(trade_records[i]['trade_date'],c1,c2,c3,trade_records[i]['close'],trade_records[i]['acp'],future1_prate)
def compute_probability_one_stock(probabilities, stock_no): trade_records = datafile.load_stocks(stock_no) count = len(trade_records) print 'trade_date,c1,c2,c3,close,acp,future1_prate' for i in range(0, count): c1 = 0.194520338846 c2 = 0.604818399782 c3 = 0.199873024089 for fk in featureFieldssss: fv = trade_records[i][fk] ps = [p for p in probabilities if p.fk == fk and p.fv == str(fv)] c1_p = [p.p for p in ps if p.cv == '1'][0] c1 = c1 * float(c1_p) c2_p = [p.p for p in ps if p.cv == '2'][0] c2 = c2 * float(c2_p) c3_p = [p.p for p in ps if p.cv == '3'][0] c3 = c3 * float(c3_p) #print fk,fv,float(c1_p),float(c2_p) future1_range = trade_records[i][ 'future1_range'] if 'future1_range' in trade_records[i] else 0 future1_prate = trade_records[i][ 'future1_prate'] if 'future1_prate' in trade_records[i] else 0 print '%s,%s,%s,%s,%s,%s,%s' % (trade_records[i]['trade_date'], c1, c2, c3, trade_records[i]['close'], trade_records[i]['acp'], future1_prate)
def process2(stock_no): records = datafile.load_stocks(stock_no) count = len(records) for i in range(0, count): peaks = [r for r in records[i:] if r.peak_trough_5 == 2] #peak波峰 troughs = [r for r in records[i:] if r.peak_trough_5 == 1] #trough波谷 if troughs and peaks: records[i].peak_trough_range = 'up' if troughs[ 0].trade_date > peaks[0].trade_date else 'down' records[i].zuli_price = peaks[0].high records[i].zhicheng_price = troughs[0].low else: records[i].peak_trough_range = '--' records[i].zuli_price = '-1' records[i].zhicheng_price = '-1' records[i].ma5_trend_3 = comm.get_trend_2( records[i:i + 3], 'ma_5') if count - i > 2 else 0 records[i].ma5_trend_5 = comm.get_trend_2( records[i:i + 5], 'ma_5') if count - i > 4 else 0 # print '%s,%s,%s' %(records[i].ma5_trend_3,records[i].ma5_trend_5,records[i].future2_range) datafile.save_stocks(stock_no, records) datafile.write_reports(stock_no, [ 'trade_date', 'close', 'peak_trough_5', 'peak_trough_range', 'zuli_price', 'zhicheng_price' ]) return records
def process2(stock_no): records = datafile.load_stocks(stock_no) count = len(records) for i in range(0,count): peaks = [r for r in records[i:] if r.peak_trough_5==2] #peak波峰 troughs = [r for r in records[i:] if r.peak_trough_5==1] #trough波谷 if troughs and peaks: records[i].peak_trough_range = 'up' if troughs[0].trade_date > peaks[0].trade_date else 'down' records[i].zuli_price = peaks[0].high records[i].zhicheng_price = troughs[0].low else: records[i].peak_trough_range='--' records[i].zuli_price = '-1' records[i].zhicheng_price = '-1' records[i].ma5_trend_3 = comm.get_trend_2(records[i:i+3],'ma_5') if count-i>2 else 0 records[i].ma5_trend_5 = comm.get_trend_2(records[i:i+5],'ma_5') if count-i>4 else 0 # print '%s,%s,%s' %(records[i].ma5_trend_3,records[i].ma5_trend_5,records[i].future2_range) datafile.save_stocks(stock_no,records) datafile.write_reports(stock_no,['trade_date','close','peak_trough_5','peak_trough_range','zuli_price','zhicheng_price']) return records
def tmp(stock_no): records = datafile.load_stocks(stock_no) for r in records: print r.trade_date,r.close,r.volume,r.volume_cos_10
def tmp(stock_no): records = datafile.load_stocks(stock_no) for r in records: print r.trade_date, r.close, r.volume, r.volume_cos_10