Beispiel #1
0
def get_bid(index):
    if index in codes:
        return

    hist = ts.get_sina_dd(index, date=date, vol=500)
    if hist is not None:
        # print(index, hist['volume'].sum())

        hist = hist.iloc[::-1]
        r = redis.Redis(connection_pool=redis_pool)
        rise_stop = r.get('quant.{}.rise_stop'.format(index))
        rise_stop = float(rise_stop)
        super_dd = False
        for i in range(len(hist)):
            if hist['volume'][i] > 2000 * 100:
                super_dd = True

            if hist['price'][i] == rise_stop:  # 涨停
                if hist['preprice'][i] != 0:  # 开盘涨停
                    # if hist['preprice'][i] != hist['price'][i] or super_dd:  # 大单打到涨停
                    if hist['preprice'][i] != hist['price'][i]:  # 大单打到涨停
                        mu.acquire()
                        codes.append(index)
                        mu.release()
                        print(
                            'time: {}, rise stop: {}, preprice: {}, price: {}'.
                            format(hist['time'][i], rise_stop,
                                   hist['preprice'][i], hist['price'][i]))
                        print('https://xueqiu.com/S/{}{}'.format(
                            get_stock_type(index).upper(), index))
                        break
Beispiel #2
0
def history(stock_code, market=None, bundle_path='~/.rqalpha/bundle'):
    d = BaseDataSource(os.path.expanduser(bundle_path))

    instruments = d._instruments.get_all_instruments()

    stock_map = {i.order_book_id: i for i in instruments}
    if not market:
        market = easyutils.get_stock_type(stock_code)
    if market == 'sh':
        stock_code += '.XSHG'
    else:
        stock_code += '.XSHE'
    raw = d._all_day_bars_of(stock_map[stock_code])
    df = pd.DataFrame.from_dict(raw)
    df.set_index('datetime', inplace=True)
    return df
Beispiel #3
0
def history(stock_code, market=None, d=d, stock_map=stock_map):
    if not market:
        market = easyutils.get_stock_type(stock_code)
    if market == 'sh':
        stock_code += '.XSHG'
    else:
        stock_code += '.XSHE'
    raw = d._all_day_bars_of(stock_map[stock_code])
    df = pd.DataFrame.from_dict(raw)

    def f(x):
        return(str(int(x['datetime'] / 1000000))[:9])

    df['datetime'] = df.apply(f, axis=1)
    df.columns = ['Date', 'Open', 'Close', 'High', 'Low', 'Volume', 'total_turnover', 'limit_up', 'limit_down']
    df.set_index('Date', inplace=True)
    df.index = pd.to_datetime(df.index)

    return df
Beispiel #4
0
        end_time = datetime.datetime.now()
        print('round {}, curent time {}, elapsed time: {}'.format(
            i, end_time.time(), end_time - now))

    print('codes', codes)

    all = ts.get_today_all()
    all_index = list(all['code'])

    filterd = pd.DataFrame()
    for i in codes:
        index = all_index.index(i)
        row = all.loc[index]
        row['url'] = 'https://xueqiu.com/S/{}{}'.format(
            get_stock_type(i).upper(), i)
        filterd = filterd.append(row)

    now = pd.DataFrame({'code': filterd['code']})
    now['name'] = filterd['name']
    now['high'] = filterd['high']
    now['close'] = (100 +
                    filterd['changepercent']) * filterd['settlement'] / 100
    now['highpercent'] = ((now['close'] - filterd['high']) / filterd['high'] *
                          100).round(3)
    now['url'] = filterd['url']
    now = now.reset_index(drop=True)
    now = now.sort_values('highpercent')

    path = 'data/scan_big_bid'
    if not os.path.exists(path):
Beispiel #5
0
def get_xueqiu_url(index):
    return 'https://xueqiu.com/S/{}{}'.format(
        get_stock_type(index).upper(), index)
Beispiel #6
0
def explore_growth_form(code):
    # hist = ts.get_h_data(code)
    hist = ts.get_hist_data(code, start=start, end=end)
    if hist is None:
        return

    hist_len = len(hist)
    if hist_len == 0:
        return

    hist = hist.iloc[::-1]

    # pre_close = list(hist['close'])
    # pre_close.pop()
    # pre_close.insert(0, hist['high'][0] / 1.1)
    #
    # hist['pre_close'] = pre_close
    #
    # hist['rise_stop'] = np.round(hist['pre_close'] * 1.1, 2)
    # hist['fall_stop'] = np.round(hist['pre_close'] / 1.1, 2)

    # print(hist)

    average_volume = hist['volume'].mean()

    from_index = -1
    for i in range(1, hist_len):
        if i < from_index:
            continue
        if i + 4 >= hist_len:
            continue

        # if hist['p_change'][i] > 9:  # 涨停
        #     if hist['p_change'][i + 1] < -8:  # 跌停
        #         if hist['volume'][i + 1] < hist['volume'][i]:  # 缩量
        #             if (hist['open'][i + 2] - hist['close'][i + 1]) / hist['close'][i + 1] > -.05:  # 不跌破5个点

        # if hist['p_change'][i] > 5:  # 上涨5%
        #     if hist['p_change'][i + 1] > 5:  # 上涨5%
        #         if hist['p_change'][i + 2] > 5:  # 上涨5%
        #             if hist['high'][i + 3] != hist['low'][i + 3]:  # 能买得进

        # if hist['p_change'][i] > 4:  # 上涨4%
        #     if hist['p_change'][i + 1] > 4:  # 上涨4%
        #         if hist['high'][i + 2] != hist['low'][i + 2]:  # 能买得进
        #
        #             if hist['close'][i + 2] < hist['close'][i + 1]:  # 买入当天收盘比前一天底,第二天开盘卖出
        #                 j = i + 3
        #                 benefit = (hist['open'][j] - hist['open'][i + 2]) / hist['open'][i + 2]
        #             else:
        #                 for j in range(i + 3, hist_len):
        #                     if hist['close'][j] < hist['close'][j - 1]:  # 收盘比前一天的底,收盘卖出
        #                         break
        #                 benefit = (hist['close'][j] - hist['open'][i + 2]) / hist['open'][i + 2]

        # if hist['p_change'][i] < 3:  # 上涨4%
        #     if hist['p_change'][i + 1] < 3:  # 上涨4%
        #         if hist['ma5'][i + 1] > hist['ma5'][i]:
        #             if hist['high'][i + 2] != hist['low'][i + 2] and hist['high'][i + 2] > 9.5:  # 能买得进

        if i + 10 < hist_len:
            sum_volume = 0
            for k in range(8):
                sum_volume += hist['volume'][i + k]

            if sum_volume / 8 < average_volume:
                # if (hist['close'][i + 8] - hist['close'][i]) / hist['close'][i] < 0.1:  # 两周内上涨不超过10%
                if hist['high'][i + 9] != hist['low'][i + 9] and hist['high'][i + 9] > 9.5:  # 能买得进

                    benefit = (hist['close'][i + 10] - hist['high'][i + 9]) / hist['high'][i + 9]
                    benefit = round(benefit * 100, 2)

                    mu.acquire()
                    benefits.append(benefit)
                    mu.release()

                    print('https://xueqiu.com/S/{}{}'.format(get_stock_type(code), code), hist.index[i + 9],
                          # hist.index[j], j - (i + 2),
                          benefit)
Beispiel #7
0
def explore_second_rise(index):
    global start, end, p_change_array, mu

    hist = ts.get_h_data(index, start=start, end=end)

    if hist is None:
        return

    _len = len(hist)
    if _len < 5:  # 第一天用来计算第三天是否是二板,第四天计算收益
        return

    hist = hist.iloc[::-1]
    # print(hist)

    pChange = hist['p_change']
    ma5 = hist['ma5']
    ma10 = hist['ma10']
    ma20 = hist['ma20']

    for i in range(2, _len):  # 去掉次新股时期
        # 二板策略
        # 因为第一天要求不是涨停,所以肯定避开了次新股时期
        if pChange[i - 3] > 9.5:  # 第一天涨停,则第三天不是二板
            continue
        if pChange[i - 2] <= 9.5 or pChange[i - 1] <= 9.5:  # 第二天第三天得是板
            continue
        if hist['high'][i - 1] == hist['low'][i - 1]:  # 第三天不能是一字板
            continue
        if i >= _len - 1 - 1:
            continue

        # TODO 检查是否放量

        # 板后低开策略
        # if i < 100:  # 不考虑次新股
        #     continue
        # if not (ma5[i - 3] > ma10[i - 3] > ma20[i - 3]):  # 均线上行
        #     continue
        # if hist['open'][i - 3] < hist['close'][i - 3]:  # 板前面得是阳线
        #     continue
        # if pChange[i - 2] <= 9.5:  # 板
        #     continue
        # if hist['open'][i - 1] >= hist['close'][i - 2]:  # 低开
        # # if hist['open'][i - 1] < hist['close'][i - 2]:  # 高开
        #     continue

        # 连续三天上涨超过1%
        # if pChange[i - 3] < 1:
        #     continue
        # if pChange[i - 2] < 1:
        #     continue
        # if pChange[i - 1] < 1:
        #     continue

        # 大盘上行
        # mssh0 = sh.get_value(hist.index[i - 3], 'ma5')
        # mssh1 = sh.get_value(hist.index[i - 2], 'ma5')
        # if mssh0 >= mssh1:  # 大盘上行
        #     continue

        # 个股上行
        # if ma5[i - 1] > ma10[i - 1] > ma20[i - 1]:
        #     if ma5[i - 0] > ma10[i - 0] > ma20[i - 0]:
        #         if ma5[i - 1] > ma5[i - 0] and ma10[i - 1] > ma10[i - 0] and ma20[i - 1] > ma20[i - 0]:

        # if ma10[i - 3] >= ma10[i - 2]:  # 个股上行
        #     continue

        # 二板策略
        benefit = pChange[i]
        # benefit = round((hist['close'][i + 1] - hist['close'][i - 1]) / hist['close'][i - 1] * 100, 2)

        # 板后低开策略
        # benefit = round((hist['open'][i] - hist['open'][i - 1]) / hist['open'][i - 1] * 100, 2)  # 低开买入,开盘即抛
        # benefit = round((hist['close'][i] - hist['open'][i - 1]) / hist['open'][i - 1] * 100, 2)  # 低开买入,收盘抛出

        # 连续三天上涨超过1%
        # benefit = round((hist['open'][i] - hist['open'][i - 1]) / hist['open'][i - 1] * 100, 2)  # 开盘买入,开盘卖出
        # benefit = round((hist['open'][i] - hist['close'][i - 1]) / hist['close'][i - 1] * 100, 2)  # 尾盘买入,开盘卖出

        mu.acquire()
        p_change_array.append(benefit)
        code_date[index] = hist.index[i]
        # code_date[index] = hist.index[i + 1]
        mu.release()

        if benefit < -5:
            # if benefit > 5:
            print(
                'https://xueqiu.com/S/{}{}'.format(get_stock_type(index),
                                                   index), hist.index[i],
                benefit)