예제 #1
0
def computeTrend(records):
    count = len(records)
    for i in range(0,count):        
        if count-i>2:
            t3 = comm.get_trend(records[i:i+3])
            sql = 'update stock_daily set trend_3=%s where pk_id=%s' % (t3,records[i].pk_id) 
            dbw.query(sql)
        if count-i>4:
            t5 = comm.get_trend(records[i:i+5])
            sql = 'update stock_daily set trend_5=%s where pk_id=%s' % (t5,records[i].pk_id) 
            dbw.query(sql) 
예제 #2
0
def computeTrend(records):
    count = len(records)
    for i in range(0, count):
        if count - i > 2:
            t3 = comm.get_trend(records[i:i + 3])
            sql = 'update stock_daily set trend_3=%s where pk_id=%s' % (
                t3, records[i].pk_id)
            dbw.query(sql)
        if count - i > 4:
            t5 = comm.get_trend(records[i:i + 5])
            sql = 'update stock_daily set trend_5=%s where pk_id=%s' % (
                t5, records[i].pk_id)
            dbw.query(sql)
예제 #3
0
def run():
    dates = da.stockdaily_cud.load_trade_dates()
    today = dates[0].trade_date    
    date_3 = dates[2].trade_date      

    date_3_rows = da.stockdaily_cud.load_by_beginDate(date_3)

    stocks = da.stockbaseinfos.load_all_stocks() #[web.storage(stock_no='000001',pk_id=332)] #test
    for s in stocks:
        rows = [r for r in date_3_rows if r.stock_no==s.stock_no]
        if not rows:
            continue
        print s.stock_no,comm.get_trend(rows)
        da.stockdaily_cud.update_trend3(today,s.stock_no,comm.get_trend(rows)) 

    send_report(today)    
예제 #4
0
def run():
    dates = da.stockdaily_cud.load_trade_dates()
    today = dates[0].trade_date
    date_3 = dates[2].trade_date

    date_3_rows = da.stockdaily_cud.load_by_beginDate(date_3)

    stocks = da.stockbaseinfos.load_all_stocks(
    )  #[web.storage(stock_no='000001',pk_id=332)] #test
    for s in stocks:
        rows = [r for r in date_3_rows if r.stock_no == s.stock_no]
        if not rows:
            continue
        print s.stock_no, comm.get_trend(rows)
        da.stockdaily_cud.update_trend3(today, s.stock_no,
                                        comm.get_trend(rows))

    send_report(today)
예제 #5
0
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
예제 #6
0
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