Пример #1
0
def scan(stock):
    # pot1 = get_stock_history_by_date(stock, '2015-10-08')
    # pot2 = get_stock_history_by_date(stock, '2015-10-09')
    pot3 = get_stock_history_by_date(stock, '2015-10-12')
    pot4 = get_stock_history_by_date(stock, '2015-10-13')
    pot5 = get_stock_history_by_date(stock, '2015-10-14')
    pot6 = get_stock_history_by_date(stock, '2015-10-15')

    if pot3 and pot4 and pot5 and pot6:
        if 'rong_all_balance' in pot6 and pot6['close'] != 0.0:
            if i(pot3['rong_all_balance']) > i(pot4['rong_all_balance']) > i(pot5['rong_all_balance']) > i(pot6['rong_all_balance']):
                r = str(rate(i(pot3['rong_all_balance']), i(pot6['rong_all_balance'])))[:5]
                print '{} {}'.format(stock, r)
Пример #2
0
def find_rate():
    rank = []

    for stock in stocks:
        try:
            first_open = get_stock_history_by_date(stock, '2015-07-09')['low']
            last_close = get_stock_history_by_date(stock, '2015-07-24')['close']

            r = rate(last_close, first_open)
            rank.append((stock, r))
        except:
            continue

    ranked = sorted(rank, key=lambda r: r[1])
    for rn, rr in ranked:
        name = get_stock_name_from_mongo(rn)
        print u'{} {} {}'.format(name, rn, rr)
Пример #3
0
def test():
    for stock in stocks:
        day = get_stock_history_by_date(stock, '2015-07-24')

        rate = (day['close'] - day['open']) / day['open'] * 100
        if abs(rate) > 9:
            name = get_stock_name_from_mongo(stock)
            print u'{} {} {}'.format(name, stock, rate)
Пример #4
0
def find_last_week_up_most():
    rank = []
    for stock in stocks:
        if not stock.startswith('002'):
            continue

        try:
            first_open = get_stock_history_by_date(stock, '2015-09-30')['close']
            last_close = get_stock_history_by_date(stock, '2015-11-06')['close']

            r = rate(last_close, first_open)
            rank.append((stock, r))
        except:
            continue

    ranked = sorted(rank, key=lambda r: r[1])
    for rn, rr in ranked:
        print u'{} {}'.format(rn, rr)
Пример #5
0
def get_history(pre, where, a, date_from, date_to, con=False):
    stock_code = base_stock.format(pre, a) + '.' + where

    if con:
        is_saved = get_stock_history_by_date(stock_code, date_to)
        if is_saved:
            return

    if not is_exist(where, base_stock.format(pre, a)):
        return

    date_from_parts = date_from.split('-')
    date_to_parts = date_to.split('-')
    stock_api = base_api.format(stock_code,
                                tran_date_month(date_from_parts[1]), date_from_parts[2], date_from_parts[0],
                                tran_date_month(date_to_parts[1]), date_to_parts[2], date_to_parts[0])

    try:
        print 'start load {} {}'.format(stock_code, str(datetime.now()))
        r = requests.get(stock_api)
        result = r.text

        lines = result.split('\n')
        for line in lines[1:]:
            if line:
                parts = line.split(',')
                if len(parts) >= 7 and float(parts[5]) > 0.0:
                    c.history.update({
                        'date': parts[0],
                        'stock': stock_code
                    }, {
                        '$set': {
                            'date': parts[0],
                            'open': float(parts[1]),
                            'high': float(parts[2]),
                            'low': float(parts[3]),
                            'close': float(parts[4]),
                            'volume': float(parts[5]),
                            'adj': float(parts[6]),
                            'stock': stock_code
                        }
                    }, upsert=True)
        r.close()
    except Exception, e:
        print e
Пример #6
0
def calc_rong_svg(stock_code):
    x = []
    y1 = []
    y2 = []
    y3 = []
    y4 = []

    for i in range(30):
        day = datetime.now()+timedelta(days=-i)
        date = day.strftime('%Y-%m-%d')

        result = get_rong_sz(stock_code, date)
        if result:
            price = get_stock_history_by_date(stock_code+'.SZ', date)
            if not price:
                price = {
                    'volume': 0,
                    'close': 0
                }

            print '{}\t{}\t{}\t{}\t{}'.format(date, result[2], result[3], price['volume'], price['close'])

            x.append(date[6:])
            y1.append(int(result[2].replace(',', '')))
            y2.append(int(result[3].replace(',', '')))
            y3.append(float(price['volume']))
            y4.append(float(price['close']))

    x.reverse()
    y1.reverse()
    y2.reverse()
    y3.reverse()
    y4.reverse()

    line_chart = pygal.Line(width=1600, height=800)
    line_chart.title = 'rongzi'
    line_chart.x_labels = x
    line_chart.add('rongzi', data_standard(y1))
    # line_chart.add('rongzi_balance', data_standard(y2))
    # line_chart.add('volume', data_standard(y3))
    # line_chart.add('close', data_standard(y4), secondary=True)
    line_chart.render_to_file(stock_code+'.svg')
Пример #7
0
def test():
    x = []
    y1 = []
    y2 = []
    y3 = []
    y4 = []
    y5 = []
    y6 = []
    y7 = []
    y8 = []

    last_rongzi_balance = 0
    for line in data.split('\n')[:30]:
        if not line.strip():
            continue

        date, rongzi_buy, rongzi_balance, rongquan_sell_liang, rongquan_balance_liang, rongquan_balance, rong_all_balance = line.split('\t')

        price = get_stock_history_by_date('399001.SZ', date)
        if not price:
            price_close = 0
        else:
            price_close = price['close']

            return_today = last_rongzi_balance + int(rongzi_buy.replace(',', '')) - int(rongzi_balance.replace(',', ''))

            x.append(date[-2:])
            y1.append(int(rongzi_buy.replace(',', '')))
            y2.append(int(rongzi_balance.replace(',', '')))
            y3.append(int(rongquan_sell_liang.replace(',', '')))
            y4.append(int(rongquan_balance_liang.replace(',', '')))
            y5.append(int(rongquan_balance.replace(',', '')))
            y6.append(int(rong_all_balance.replace(',', '')))
            y7.append(float(price_close))
            y8.append(return_today)

        last_rongzi_balance = int(rongzi_balance.replace(',', ''))

    x.reverse()
    y1.reverse()
    y2.reverse()
    y3.reverse()
    y4.reverse()
    y5.reverse()
    y6.reverse()
    y7.reverse()
    y8.reverse()

    line_chart = pygal.Line(width=1600, height=800)
    line_chart.title = 'rong'
    line_chart.x_labels = x
    line_chart.add('rongzi_buy', y1)
    # line_chart.add('rongzi_return', y8)
    line_chart.add('rongzi_balance', data_standard(y2), secondary=True)
    # line_chart.add('rongquan_sell_liang', data_standard(y3))
    # line_chart.add('rongquan_balance_liang', data_standard(y4))
    # line_chart.add('rongquan_balance', data_standard(y5))
    # line_chart.add('rong_all_balance', data_standard(y6))
    # line_chart.add('rong_all_balance', data_standard(y6))

    # line_chart.add('399001', data_standard(y7), secondary=True)

    line_chart.render_to_file('all.svg')
Пример #8
0
002547.SZ
002563.SZ
002568.SZ
002617.SZ
002640.SZ
002650.SZ
002651.SZ
002697.SZ
002707.SZ
002329.SZ
'''

if __name__ == '__main__':
    for stock in get_all_stock():
        if stock.startswith('000') or stock.startswith('002'):
            r1 = get_stock_history_by_date(stock, '2015-10-08')
            r2 = get_stock_history_by_date(stock, '2015-10-09')
            r3 = get_stock_history_by_date(stock, '2015-10-12')
            r4 = get_stock_history_by_date(stock, '2015-10-13')
            r5 = get_stock_history_by_date(stock, '2015-10-14')
            r6 = get_stock_history_by_date(stock, '2015-10-15')
            r7 = get_stock_history_by_date(stock, '2015-10-16')

            if not r7:
                continue

            if r7['close'] == 0.0 or r7['volume'] == 0:
                continue

            if 'dn' not in r7:
                continue