Пример #1
0
def insert_date_sum(trade_date,rows):
    dbw.delete("date_sums",where="trade_date=$trade_date",vars=locals())
    for r in rows:
        dbw.insert('date_sums',trade_date=trade_date,stock_plate=r.stock_plate,
        stock_count=r.stock_count,avg_open=r.open,avg_close=r.close,
        avg_high=r.high,avg_low=r.low,avg_volume=r.volume,
        avg_amount=r.amount,create_date=datetime.datetime.now())
Пример #2
0
def compute_3or5(stock_no):
    date_infos = da.dailyrecords.load_by_stockno(stock_no)
    date_len = len(date_infos)

    rows = []
    for i in range(0, date_len):
        print i
        stock_date = date_infos[i]
        d = stock_date.date
        dh5 = __compute_trend(date_infos, i, 5, 'high_price')
        dh3 = __compute_trend(date_infos, i, 3, 'high_price')

        dl5 = __compute_trend(date_infos, i, 5, 'low_price')
        dl3 = __compute_trend(date_infos, i, 3, 'low_price')

        #未来n天内,收盘价 与 明天开盘价对比
        prates = {}
        tommorrow_open_price = date_infos[i - 1].open_price
        for day in range(2, 6):
            prates[day] = None
            if i < day: continue
            prates[day] = (date_infos[i - day].close_price -
                           tommorrow_open_price) / tommorrow_open_price

        if i > 6:
            p = date_infos[i - 6].close_price - date_infos[i - 1].open_price
            prate = p / date_infos[i - 1].open_price
            print stock_date.date, dh5, dh3, dl5, dl3, p, prate

        if date_len > (i + 5):
            history_prate_3 = (
                stock_date.close_price -
                date_infos[i + 3].close_price) / date_infos[i + 3].close_price
            history_prate_5 = (
                stock_date.close_price -
                date_infos[i + 5].close_price) / date_infos[i + 5].close_price

        rows.append(
            web.storage(pk_id=stock_date.pk_id,
                        date=stock_date.date,
                        stock_no=stock_date.stock_no,
                        high5=dh5,
                        high3=dh3,
                        low5=dl5,
                        low3=dl3,
                        tmrow_open_price=tommorrow_open_price,
                        price_rate_2=prates[2],
                        price_rate_3=prates[3],
                        price_rate_4=prates[4],
                        price_rate_5=prates[5],
                        history_prate_3=history_prate_3,
                        history_prate_5=history_prate_5))

        i = i + 1

    dbw.delete('trend_daily', where="stock_no=$stock_no", vars=locals())
    dbw.supports_multiple_insert = True
    dbw.multiple_insert('trend_daily', rows)
Пример #3
0
def update_v2(l):
    dbw.delete('stock_daily_records_tmp', where="pk_id>0", vars=locals())
    dbw.supports_multiple_insert = True
    dbw.multiple_insert('stock_daily_records_tmp', l)
    dbw.query('''update stock_daily_records a,stock_daily_records_tmp t set
        a.raise_drop=t.raise_drop,
        a.raise_drop_rate=t.raise_drop_rate,
        a.volume_updown=t.volume_updown,
        a.volume_updown_rate=t.volume_updown_rate,
        a.last_update = t.last_update
        where a.pk_id=t.pk_id''')
Пример #4
0
def update_v2(l):
    dbw.delete('stock_daily_records_tmp',where="pk_id>0",vars=locals())
    dbw.supports_multiple_insert = True
    dbw.multiple_insert('stock_daily_records_tmp',l)
    dbw.query('''update stock_daily_records a,stock_daily_records_tmp t set
        a.raise_drop=t.raise_drop,
        a.raise_drop_rate=t.raise_drop_rate,
        a.volume_updown=t.volume_updown,
        a.volume_updown_rate=t.volume_updown_rate,
        a.last_update = t.last_update
        where a.pk_id=t.pk_id''')
Пример #5
0
def compute_3or5(stock_no):
    date_infos = da.dailyrecords.load_by_stockno(stock_no)
    date_len = len(date_infos)

    rows = []
    for i in range(0,date_len):
        print i
        stock_date = date_infos[i]
        d = stock_date.date
        dh5 = __compute_trend(date_infos,i,5,'high_price')
        dh3 = __compute_trend(date_infos,i,3,'high_price')

        dl5 = __compute_trend(date_infos,i,5,'low_price')
        dl3 = __compute_trend(date_infos,i,3,'low_price')

        #未来n天内,收盘价 与 明天开盘价对比
        prates = {}
        tommorrow_open_price = date_infos[i-1].open_price
        for day in range(2,6):
            prates[day] = None
            if i < day : continue
            prates[day] = (date_infos[i-day].close_price - tommorrow_open_price) / tommorrow_open_price

        if i > 6:
           p = date_infos[i-6].close_price - date_infos[i-1].open_price
           prate = p/date_infos[i-1].open_price
           print stock_date.date,dh5,dh3,dl5,dl3,p,prate

        if date_len > (i+5):
            history_prate_3 = (stock_date.close_price - date_infos[i+3].close_price) / date_infos[i+3].close_price
            history_prate_5 = (stock_date.close_price - date_infos[i+5].close_price) / date_infos[i+5].close_price

        rows.append(web.storage(pk_id=stock_date.pk_id,date=stock_date.date,stock_no=stock_date.stock_no,
             high5=dh5,high3=dh3,low5=dl5,low3=dl3,tmrow_open_price=tommorrow_open_price,
             price_rate_2=prates[2],price_rate_3=prates[3],price_rate_4=prates[4],price_rate_5=prates[5],
             history_prate_3=history_prate_3,history_prate_5=history_prate_5))

        i = i + 1

    dbw.delete('trend_daily',where="stock_no=$stock_no",vars=locals())
    dbw.supports_multiple_insert = True
    dbw.multiple_insert('trend_daily',rows)
Пример #6
0
def delete_daily_record(pk_id):
    dbw.delete("stock_daily_records", where="pk_id=$pk_id", vars=locals())
Пример #7
0
def backup_tradingrecords(strategy_id):
    table_name = 'trading_records'
    os.system('mysqldump -uroot -proot forecast %s > %s/db/%s_%s.sql'% (table_name,const_root_local,table_name,strategy_id) )
    dbw.delete('trading_records',where="pk_id>0")
Пример #8
0
def delete_daily_record(pk_id):
    dbw.delete('stock_daily_records', where='pk_id=$pk_id', vars=locals())