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 process1(stock_no): records = datafile.load_raw_records(stock_no) count = len(records) # print 'trade_date,close,peak5,peak10' for i in range(0,count): stock_no_infos = stock_no.split('.') records[i].stock_no = stock_no #stock_no_infos[0] records[i].stock_pycode = stock_no_infos[1] #5日内波峰波谷 records[i].peak_trough_5 = comm.get_peak_trough(records,count,i,3) ##records[i].peak_trough_10 = comm.get_peak_trough(records,count,i,5) #和5得出的结论基本吻合 #100天内,最高值high,最低值low分布, 日期&具体的值 rows = sorted(records[i:i+100], cmp=lambda x,y : cmp(x.close, y.close)) records[i].days100_low_close = rows[0].close records[i].days100_low_date = rows[0].trade_date records[i].days100_high_close = rows[-1].close records[i].days100_high_date = rows[-1].trade_date #成交量 r10 = records[i:i+10] l = [r.volume for r in r10] volume_avg_10 = reduce(lambda x, y: x + y, l) / len(l) volume_p = float(records[i].volume) / volume_avg_10 if volume_avg_10 else 0 records[i].volume_avg_10 = volume_avg_10 records[i].volume_level = comm.get_volume_level(volume_p) #移动平均线 MAs = comm.get_ma(records,i) # print MAs ma_5 = records[i].ma_5 = MAs['ma_5'] ma_10 = records[i].ma_10 = MAs['ma_10'] records[i].ma_20 = MAs['ma_20'] records[i].ma_50 = MAs['ma_50'] records[i].ma_100 = MAs['ma_100'] records[i].ma_200 = MAs['ma_200'] records[i].ma_p_2 = MAs['ma_p_2'] records[i].ma_p_3 = MAs['ma_p_3'] records[i].ma_p_4 = MAs['ma_p_4'] records[i].ma_p_5 = MAs['ma_p_5'] records[i].close_ma_5 = records[i].close > MAs['ma_5'] records[i].close_ma_10 = records[i].close > MAs['ma_10'] records[i].close_ma_20 = records[i].close > MAs['ma_20'] records[i].close_ma_50 = records[i].close > MAs['ma_50'] records[i].close_ma_100 = records[i].close > MAs['ma_100'] records[i].close_ma_200 = records[i].close > MAs['ma_200'] # for i in range(2,6): # key = 'ma_p_%s' % (i) # records[i][key] = MAs[key] #几条移动平均线的上下关系 ma_5_10 = 0 if ma_5<>0 and ma_10<>0: ma_5_10 = 2 if ma_5>ma_10 else 1 records[i].ma_5_10 = ma_5_10 records[i].volume_cos_10 = comm.cos_dist( [r.volume for r in records[i:i+5]]) #蜡烛图形态 candles = comm.get_candle_2(records[i].open,records[i].close,records[i].high,records[i].low) records[i].range_1 = candles[0] records[i].range_2 = candles[1] records[i].range_3 = candles[2] records[i].candle_sort = candles[4] records[i].up_or_down = 2 if candles[1]>0 else 1 records[i].high_low = records[i].high - records[i].low records[i].close_open = records[i].close - records[i].open records[i].jump_level = 0 if (count-i) > 1: records[i].last_close = records[i+1].close records[i].last_acp = records[i+1].acp records[i].open_lastclose = records[i].open - records[i].last_close records[i].jump_rate = records[i].open_lastclose / records[i].last_close records[i].jump_level = comm.get_jump_level(records[i].jump_rate) records[i].price_rate = (records[i].close - records[i].last_close) / records[i].last_close records[i].high_rate = (records[i].high - records[i].last_close) / records[i].last_close records[i].low_rate = (records[i].low - records[i].last_close) / records[i].last_close records[i].hig_low_rate = records[i].high_rate - records[i].low_rate # current_record = records[i] # print '%s,%s,%s,%s' %(current_record.trade_date,current_record.close,records[i].peak_trough_5,records[i].peak_trough_10) records[i].trend_3 = comm.get_trend(records[i:i+3]) if count-i>2 else 0 records[i].trend_5 = comm.get_trend(records[i:i+5]) if count-i>4 else 0 records[i].future1_prate = 0 records[i].future1_range = 0 if i>1: prate = (records[i-2].close - records[i-1].close) / records[i-1].close frange = comm.getFutureRange(prate) records[i].future1_prate = prate records[i].future1_range = frange records[i].future2_prate = 0 records[i].future2_range = 0 if i>2: prate = (records[i-3].close - records[i-1].close) / records[i-1].close frange = comm.getFutureRange(prate) records[i].future2_prate = prate records[i].future2_range = frange records[i].future3_prate = 0 records[i].future3_range = 0 if i>3: prate = (records[i-4].close - records[i-1].close) / records[i-1].close frange = comm.getFutureRange(prate) records[i].future3_prate = prate records[i].future3_range = frange #print records[i] # comm.get_test(records,i) # datafile.gen_date_file(records[i]) datafile.save_stocks(stock_no,records) return records
def process1(stock_no): records = datafile.load_raw_records(stock_no) count = len(records) # print 'trade_date,close,peak5,peak10' for i in range(0, count): stock_no_infos = stock_no.split('.') records[i].stock_no = stock_no #stock_no_infos[0] records[i].stock_pycode = stock_no_infos[1] #5日内波峰波谷 records[i].peak_trough_5 = comm.get_peak_trough(records, count, i, 3) ##records[i].peak_trough_10 = comm.get_peak_trough(records,count,i,5) #和5得出的结论基本吻合 #100天内,最高值high,最低值low分布, 日期&具体的值 rows = sorted(records[i:i + 100], cmp=lambda x, y: cmp(x.close, y.close)) records[i].days100_low_close = rows[0].close records[i].days100_low_date = rows[0].trade_date records[i].days100_high_close = rows[-1].close records[i].days100_high_date = rows[-1].trade_date #成交量 r10 = records[i:i + 10] l = [r.volume for r in r10] volume_avg_10 = reduce(lambda x, y: x + y, l) / len(l) volume_p = float( records[i].volume) / volume_avg_10 if volume_avg_10 else 0 records[i].volume_avg_10 = volume_avg_10 records[i].volume_level = comm.get_volume_level(volume_p) #移动平均线 MAs = comm.get_ma(records, i) # print MAs ma_5 = records[i].ma_5 = MAs['ma_5'] ma_10 = records[i].ma_10 = MAs['ma_10'] records[i].ma_20 = MAs['ma_20'] records[i].ma_50 = MAs['ma_50'] records[i].ma_100 = MAs['ma_100'] records[i].ma_200 = MAs['ma_200'] records[i].ma_p_2 = MAs['ma_p_2'] records[i].ma_p_3 = MAs['ma_p_3'] records[i].ma_p_4 = MAs['ma_p_4'] records[i].ma_p_5 = MAs['ma_p_5'] records[i].close_ma_5 = records[i].close > MAs['ma_5'] records[i].close_ma_10 = records[i].close > MAs['ma_10'] records[i].close_ma_20 = records[i].close > MAs['ma_20'] records[i].close_ma_50 = records[i].close > MAs['ma_50'] records[i].close_ma_100 = records[i].close > MAs['ma_100'] records[i].close_ma_200 = records[i].close > MAs['ma_200'] # for i in range(2,6): # key = 'ma_p_%s' % (i) # records[i][key] = MAs[key] #几条移动平均线的上下关系 ma_5_10 = 0 if ma_5 <> 0 and ma_10 <> 0: ma_5_10 = 2 if ma_5 > ma_10 else 1 records[i].ma_5_10 = ma_5_10 records[i].volume_cos_10 = comm.cos_dist( [r.volume for r in records[i:i + 5]]) #蜡烛图形态 candles = comm.get_candle_2(records[i].open, records[i].close, records[i].high, records[i].low) records[i].range_1 = candles[0] records[i].range_2 = candles[1] records[i].range_3 = candles[2] records[i].candle_sort = candles[4] records[i].up_or_down = 2 if candles[1] > 0 else 1 records[i].high_low = records[i].high - records[i].low records[i].close_open = records[i].close - records[i].open records[i].jump_level = 0 if (count - i) > 1: records[i].last_close = records[i + 1].close records[i].last_acp = records[i + 1].acp records[i].open_lastclose = records[i].open - records[i].last_close records[i].jump_rate = records[i].open_lastclose / records[ i].last_close records[i].jump_level = comm.get_jump_level(records[i].jump_rate) records[i].price_rate = (records[i].close - records[i].last_close ) / records[i].last_close records[i].high_rate = (records[i].high - records[i].last_close ) / records[i].last_close records[i].low_rate = ( records[i].low - records[i].last_close) / records[i].last_close records[ i].hig_low_rate = records[i].high_rate - records[i].low_rate # current_record = records[i] # print '%s,%s,%s,%s' %(current_record.trade_date,current_record.close,records[i].peak_trough_5,records[i].peak_trough_10) records[i].trend_3 = comm.get_trend(records[i:i + 3]) if count - i > 2 else 0 records[i].trend_5 = comm.get_trend(records[i:i + 5]) if count - i > 4 else 0 records[i].future1_prate = 0 records[i].future1_range = 0 if i > 1: prate = (records[i - 2].close - records[i - 1].close) / records[i - 1].close frange = comm.getFutureRange(prate) records[i].future1_prate = prate records[i].future1_range = frange records[i].future2_prate = 0 records[i].future2_range = 0 if i > 2: prate = (records[i - 3].close - records[i - 1].close) / records[i - 1].close frange = comm.getFutureRange(prate) records[i].future2_prate = prate records[i].future2_range = frange records[i].future3_prate = 0 records[i].future3_range = 0 if i > 3: prate = (records[i - 4].close - records[i - 1].close) / records[i - 1].close frange = comm.getFutureRange(prate) records[i].future3_prate = prate records[i].future3_range = frange #print records[i] # comm.get_test(records,i) # datafile.gen_date_file(records[i]) datafile.save_stocks(stock_no, records) return records