Esempio n. 1
0
def new_test(rate=0.003, amount=100, symbols=[], stock_names=[]):
    record = []
    for symbol_idx in range(len(symbols)):
        symbol = symbols[symbol_idx]
        stock_name = stock_names[symbol_idx]
        date_price = get_tick_price(symbol, '5')

        try:
            start_price = date_price[0][1][0]
            # start_price = 68.7
            init_money = start_price * 900
            start_own = 900
            stock = {
                '初始资金': init_money + start_price * start_own,
                '当前资金': init_money + start_price * start_own,
                '可用余额': init_money,
                '持有股份': start_own,
                '可用股份': start_own,
                '冻结股份': 0,
                '初始价格': start_price,
                '当前成本': start_price,
                '最新价格': start_price,
                '买卖总手数': 0,
                '总资金增长率': 0,
                '股价波动率': 0
            }

        except KeyError as e:
            print(e)
        buy_rate = rate
        sell_rate = rate
        sell = 0
        buy = 0
        lock = 5
        # operate_price = 68.7
        # operate_price = date_price[0][1][0]
        record = []
        re_log = []
        sell_times = cal_rate_times(record, 0)
        buy_times = cal_rate_times(record, 1)
        operate_price = 0
        for day in date_price:
            price = day[1]
            if operate_price == 0:
                operate_price = price[0]
            for now_price in price[1:]:
                if now_price > operate_price * 1.003:
                    if sell - buy > lock:
                        # if sell - buy > lock and now_price < operate_price * (randint(lock, 2 * lock) * sell_rate + 1):
                        continue
                    if not can_I_go(record, now_price, 0):
                        continue
                    sell += 1
                    operate(stock, now_price, amount * ((sell_times + 1) // 2),
                            's', re_log)
                    operate_price = now_price
                    record.append({
                        'Type': 0,
                        'price': now_price,
                        'amount': amount * ((sell_times + 1) // 2)
                    })
                if now_price * 1.003 < operate_price:
                    if buy - sell > lock:
                        # if buy - sell > lock and now_price * (1 + randint(lock, 2 * lock) * buy_rate) > operate_price:
                        continue
                    if not can_I_go(record, now_price, 1):
                        continue
                    buy += 1
                    operate(stock, now_price, amount, 'b', re_log)
                    operate_price = now_price
                    record.append({
                        'Type': 1,
                        'price': now_price,
                        'amount': amount * ((buy_times + 1) // 2)
                    })
            stock['最新价格'] = price[-1]
            kaishi = len(re_log)
            skip_oneday(stock, price[-1], re_log)
            if len(re_log) - kaishi == 1:
                # print(price)
                pass
        # print(stock_name, ":", stock, '\n')
    return stock, re_log
Esempio n. 2
0
def JiZhunCeLue(rate=0.002, amount=100, k_type='15'):
    record = []
    symbol = '000759'
    stock_name = '中百集团'
    date_price = get_tick_price(symbol, k_type)

    try:
        start_price = date_price[0][1][0]
        # start_price = 68.7
        start_own = 1600
        init_money = start_price * start_own * 2
        stock = {
            '初始资金': init_money + start_price * start_own,
            '当前资金': init_money + start_price * start_own,
            '可用余额': init_money,
            '持有股份': start_own,
            '可用股份': start_own,
            '冻结股份': 0,
            '初始价格': start_price,
            '当前成本': start_price,
            '最新价格': start_price,
            '买卖总手数': 0,
            '总资金增长率': 0,
            '股价波动率': 0
        }

    except KeyError as e:
        print(e)

    smallest_rate = 0.01
    buy_amount = [100]
    for i in range(10):
        buy_amount.append(buy_amount[-1] + 100)
    sell_rate = [0.5] * 10

    operate_price = 0
    cost_price = start_price
    for day in date_price:
        buy_record = [0] * 10
        sell_record = [0] * 10
        price = day[1]
        if operate_price == 0:
            operate_price = price[0]
        operate_price = price[0]
        operate_price = max(cost_price, operate_price)
        for now_price in price[1:]:
            if now_price > operate_price:
                times = int((now_price - operate_price) / operate_price //
                            smallest_rate)
                if times >= 10:
                    times = 9
                sell_amount = int(
                    (sell_rate[times - 1] * stock['可用股份']) // 100 * 100)
                if sell_record[times] != 0 or times == 0 or sell_amount == 0:
                    continue
                else:
                    if stock['持有股份'] <= sell_amount - 100:
                        sell_amount = stock['持有股份'] - 100
                    if sell_amount == 0:
                        continue
                    operate(stock, now_price, sell_amount, 's', record)
                    sell_record[times] = 1
            if now_price < operate_price:
                times = int((operate_price - now_price) / operate_price //
                            smallest_rate)
                if times >= 10:
                    times = 9
                b_amount = buy_amount[times]
                if buy_record[times] != 0 or b_amount < 100 or times == 0:
                    continue
                operate(stock, now_price, b_amount, 'b', record)
                buy_record[times] = 1
        cost_price = stock['当前成本']
        stock['最新价格'] = price[-1]
        kaishi = len(record)
        skip_oneday(stock, price[-1], record, day[0])
        if len(record) - kaishi == 1:
            # print(price)
            pass
        # print(stock_name, ":", stock, '\n')
    return stock, record
Esempio n. 3
0
def ZhongBai(rate=0.002, amount=100, k_type='5'):
    record = []
    symbol = '000759'
    stock_name = '中百集团'
    date_price = get_tick_price(symbol, k_type)

    try:
        start_price = date_price[0][1][0]
        # start_price = 68.7
        start_own = 900
        init_money = start_price * start_own
        stock = {
            '初始资金': init_money + start_price * start_own,
            '当前资金': init_money + start_price * start_own,
            '可用余额': init_money,
            '持有股份': start_own,
            '可用股份': start_own,
            '冻结股份': 0,
            '初始价格': start_price,
            '当前成本': start_price,
            '最新价格': start_price,
            '买卖总手数': 0,
            '总资金增长率': 0,
            '股价波动率': 0
        }

    except KeyError as e:
        print(e)

    buy_times = 1
    sell_times = 1
    buy_rate = rate * buy_times
    sell_rate = rate * sell_times
    sell = 0
    buy = 0
    lock = 5
    # operate_price = 68.7
    operate_price = 0
    sell_record = []
    buy_record = []
    count = 0
    for day in date_price:
        count += 1
        price = day[1]
        if operate_price == 0:
            operate_price = price[0]
        # operate_price = price[0]
        for now_price in price[1:]:
            buy_record.sort()
            buy_record.reverse()
            sell_record.sort()
            sell_record.reverse()
            if now_price > operate_price * (sell_rate + 1):
                # if sell - buy > lock :
                if sell - buy > lock and now_price < operate_price * (
                        randint(lock, 2 * lock) * sell_rate + 1):
                    continue
                operate(stock, now_price, amount * (sell_times), 's', record)
                sell += sell_times
                sell_times += 1
                buy_times -= 1
                if buy_times < 1:
                    buy_times = 1
                operate_price = now_price
                sell_rate = sell_times * rate

            if now_price * (1 + buy_rate) < operate_price:
                # if buy - sell > lock :
                if buy - sell > lock and now_price * (1 + randint(
                        lock, 2 * lock) * buy_rate) > operate_price:
                    continue
                if len(sell_record) > 0 and now_price > sell_record[0]:
                    continue
                operate(stock, now_price, amount * (buy_times), 'b', record)
                buy += buy_times
                buy_times += 1
                sell_times -= 1
                if sell_times < 1:
                    sell_times = 1
                operate_price = now_price
                buy_rate = rate * buy_times
        stock['最新价格'] = price[-1]
        kaishi = len(record)
        skip_oneday(stock, price[-1], record, day[0])
        if len(record) - kaishi == 1:
            # print(price)
            pass
        # print(stock_name, ":", stock, '\n')
    return stock, record
Esempio n. 4
0
def base_line(rate=0.002, amount=100, k_type='5'):
    record = []
    symbol = '000759' \
             ''
    stock_name = '中百集团'
    date_price = get_tick_price(symbol, k_type)

    try:
        start_price = date_price[0][1][0]
        # start_price = 68.7
        start_own = 900
        init_money = start_price * start_own
        stock = {
            '初始资金': init_money + start_price * start_own,
            '当前资金': init_money + start_price * start_own,
            '可用余额': init_money,
            '持有股份': start_own,
            '可用股份': start_own,
            '冻结股份': 0,
            '初始价格': start_price,
            '当前成本': start_price,
            '最新价格': start_price,
            '买卖总手数': 0,
            '总资金增长率': 0,
            '股价波动率': 0
        }

    except KeyError as e:
        print(e)

    buy_times = 1
    sell_times = 1
    buy_rate = rate * buy_times
    sell_rate = rate * sell_times
    sell = 0
    buy = 0
    lock = 5
    # operate_price = 68.7
    operate_price = 0
    sell_record = []
    buy_record = []
    count = 0
    buy = 0
    sell_price = 0
    buy_price = 0
    for day in date_price:
        count += 1
        price = day[1]
        if operate_price == 0:
            operate_price = price[0]
        operate_price = price[0]
        for now_price in price[1:]:
            if now_price > operate_price * (sell_rate + 1):
                # if sell - buy > lock :
                if buy >= 0:
                    if now_price < buy_price:
                        continue
                    operate(stock, now_price, 400, 's', record)
                    sell_price = now_price
                    buy -= 1

            if now_price * (1 + buy_rate) < operate_price:
                if buy <= 0:
                    if now_price > sell_price:
                        continue
                    operate(stock, now_price, amount * (buy_times), 'b',
                            record)
                    buy += 1
                    buy_price = now_price

        stock['最新价格'] = price[-1]
        kaishi = len(record)
        skip_oneday(stock, price[-1], record, day[0])
        if len(record) - kaishi == 1:
            # print(price)
            pass
        # print(stock_name, ":", stock, '\n')
    return stock, record
Esempio n. 5
0
def test(rate=0.003, amount=200, symbols=[], stock_names=[]):
    record = []
    for symbol_idx in range(len(symbols)):
        symbol = symbols[symbol_idx]
        stock_name = stock_names[symbol_idx]
        date_price = get_tick_price(symbol, '5')

        try:
            start_price = date_price[0][1][0]
            # start_price = 68.7
            start_own = 2000
            init_money = start_price * start_own
            stock = {
                '初始资金': init_money + start_price * start_own,
                '当前资金': init_money + start_price * start_own,
                '可用余额': init_money,
                '持有股份': start_own,
                '可用股份': start_own,
                '冻结股份': 0,
                '初始价格': start_price,
                '当前成本': start_price,
                '最新价格': start_price,
                '买卖总手数': 0,
                '总资金增长率': 0,
                '股价波动率': 0
            }

        except KeyError as e:
            print(e)
        buy_rate = rate
        sell_rate = rate
        sell = 0
        buy = 0
        lock = 5
        # operate_price = 68.7
        operate_price = date_price[0][1][0]
        sell_record = []
        buy_record = []
        for day in date_price:
            price = day[1]
            operate_price = price[0]
            for now_price in price[1:]:
                min_count = min(sell, buy)
                if now_price > operate_price * (sell_rate + 1):
                    if sell - buy > lock:
                        # if sell - buy > lock and now_price < operate_price * (randint(lock, 2 * lock) * sell_rate + 1):
                        continue
                    if len(buy_record) > 0:
                        if now_price > buy_record[-1]:
                            buy_record.pop()
                        else:
                            continue
                    sell += 1
                    operate(stock, now_price, amount, 's', record)
                    operate_price = now_price
                    if sell - min_count == 0:
                        sell_rate = rate
                        continue
                    sell_rate = rate * (sell - min_count)
                    sell_record.append(now_price)
                if now_price * (1 + buy_rate) < operate_price:
                    if buy - sell > lock:
                        # if buy - sell > lock and now_price * (1 + randint(lock, 2 * lock) * buy_rate) > operate_price:
                        continue
                    if len(sell_record) > 0:
                        if now_price < sell_record[-1]:
                            sell_record.pop()
                        else:
                            continue
                    buy += 1
                    operate(stock, now_price, amount, 'b', record)
                    operate_price = now_price
                    if (buy - min_count) == 0:
                        buy_rate = rate
                        continue
                    buy_rate = rate * (buy - min_count)
                    buy_record.append(now_price)
            stock['最新价格'] = price[-1]
            kaishi = len(record)
            skip_oneday(stock, price[-1], record)
            if len(record) - kaishi == 1:
                # print(price)
                pass
        # print(stock_name, ":", stock, '\n')
    return stock, record