示例#1
0
def select_2():
    stock_list = []
    #stock_list += StockFilter.find_kdj_jx('sha', kline_type=StockConfig.kline_type_day, x_position=-1, k_max=50)
    stock_list += StockFilter.find_kdj_jx(
        'sha', kline_type=StockConfig.kline_type_day, x_position=-2, k_max=50)
    stock_list = StockFilter.sma_close(stock_list,
                                       kline_type=StockConfig.kline_type_week)
    return stock_list
示例#2
0
def select_1():
    """
    周线即将jx, 收于5日均线之上
    :return:
    """
    stock_list = StockFilter.find_kdj_jx(
        'sha', kline_type=StockConfig.kline_type_week, x_position=-1, k_max=50)
    stock_list += StockFilter.find_kdj_jx(
        'sza', kline_type=StockConfig.kline_type_week, x_position=-1, k_max=50)
    stock_list = StockFilter.sma_close(stock_list,
                                       kline_type=StockConfig.kline_type_week)
    stock_list = StockFilter.sma_close(stock_list,
                                       kline_type=StockConfig.kline_type_day)
    return stock_list
示例#3
0
def select_6():
    """
    jx后的微调
    :return:
    """
    stock_list = StockFilter.find_kdj_jx(
        'sha',
        kline_type=StockConfig.kline_type_week,
        x_position=-3,
        about=False)
    stock_list = StockFilter.updown(stock_list,
                                    kline_type=StockConfig.kline_type_week,
                                    x_position=-2)
    return stock_list
示例#4
0
def select_3():

    stock_list = []
    stock_list += StockFilter.find_kdj_jx(
        'sha',
        kline_type=StockConfig.kline_type_week,
        x_position=-3,
        about=True)
    stock_list = StockFilter.sma_close(stock_list,
                                       kline_type=StockConfig.kline_type_week,
                                       x_position=-3)
    stock_list = StockFilter.sma_close(stock_list,
                                       kline_type=StockConfig.kline_type_week,
                                       x_position=-2,
                                       reverse=True)
    return stock_list
示例#5
0
def select_7(date):
    """
    还有about=False等
    :return:
    """
    filter_date = date
    fileter_x_position = None
    stock_list = StockFilter.find_kdj_jx('sza',
                                         kline_type=StockConfig.kline_type_day,
                                         x_position=fileter_x_position,
                                         date=filter_date,
                                         about=False)
    result = []
    hit = False
    for stock in stock_list:
        x_position = StockIndicator.position(
            filter_date, stock.stock_code, StockConfig.kline_type_day
        ) if filter_date is not None else fileter_x_position
        kline = StockIO.get_kline(stock.stock_code,
                                  kline_type=StockConfig.kline_type_day)
        open = kline[:, 1].astype(np.float)
        close = kline[:, 2].astype(np.float)
        vol = kline[:, 5].astype(np.float)
        sma5 = StockIndicator.sma(kline, 5)[0]
        if sma5.shape[0] < 5 + abs(x_position):
            continue
        if sma5[x_position] < open[x_position] < close[x_position]  \
            and sma5[x_position - 2] > close[x_position - 2] \
            and sma5[x_position - 3] > close[x_position - 3] \
                and sma5[x_position - 4] > close[x_position - 4] \
                and sma5[x_position - 5] < close[x_position - 5] :

            result.append(stock)
    return result
def report(p, Rf, Rm):
    res = pd.DataFrame()
    for i in p:
        Rf = Rf.loc[getR(i).index]
        Rm = Rm.loc[getR(i).index]
        result = dict()
        result['Sharpe Ratio'] = round(getSharpe(getR(i), Rf), 3)
        result['Treynor Ratio'] = round(sf.Treynor(getR(i), Rm), 5)
        result['Alpha_CAPM'] = round(
            sf.Factor_AB(pd.DataFrame(Rm - Rf), getR(i) - Rf, get='a'), 5)
        result['M2'] = round(sf.M2(getR(i), Rm, Rf), 3)
        result['Information Ratio'] = round(sf.InfoR(getR(i), Rf), 3)
        result['Sortino Ratio'] = round(sf.Sortino(getR(i), Rf), 3)
        result = pd.DataFrame((result), index=[0])
        res = pd.concat([res, result])
    res = res.T
    res.columns = ['Benchmark', 'Stocks', 'Portfolio', 'S&P']
    return res
示例#7
0
 def f_wrapper(stock_list):
     stock_list = func(stock_list)
     return [
         stock for stock in stock_list
         if StockFilter.kdj_is_in(stock,
                                  kline_type,
                                  position=position,
                                  k_min=k_min,
                                  k_max=k_max)
     ]
示例#8
0
def select_4():
    """
    downdown
    :return:
    """
    stock_list = StockIO.get_stock('sha')
    stock_list = StockFilter.downdown(stock_list,
                                      kline_type=StockConfig.kline_type_week,
                                      count=5)
    return stock_list
示例#9
0
def select_5():
    """
    upup
    :return:
    """
    stock_list = StockIO.get_stock('sha')
    stock_list = StockFilter.upup(stock_list,
                                  kline_type=StockConfig.kline_type_week,
                                  count=1,
                                  x_position=-1)
    return stock_list
示例#10
0
def select_5_1():
    """
    upup
    :return:
    """
    x_position = -1
    kline_type = StockConfig.kline_type_week
    stock_list = StockIO.get_stock('sza')
    stock_list = StockFilter.upup(stock_list,
                                  kline_type=kline_type,
                                  count=1,
                                  x_position=x_position)
    result = []
    for stock in stock_list:
        k, d = StockIndicator.kd(
            StockIO.get_kline(stock.stock_code,
                              kline_type=StockConfig.kline_type_day), 9)
        if StockFilter.is_jx(k, d, x_position=-3, about=True):
            if StockFilter.between(k[x_position], 0, 100):
                result.append(stock)
    return result
def select(stock_list,
           kline_type=StockConfig.kline_type_week,
           x_position=-1,
           period=4,
           count_limit=3,
           min_vb=0,
           max_vb=100,
           min_item=120):
    """
    通过统计一段时间内振幅较大出现的次数, 然后对支撑价与压力价进行监测
    :param stock_list:
    :param kline_type:
    :param x_position:
    :param min_vb:
    :param max_vb:
    :param min_item:
    :return:
    """
    result = []
    for stock in stock_list:
        try:
            kline = StockIO.get_kline(stock.stock_code, kline_type=kline_type)
            close = kline[:, 2].astype(np.float)
        except Exception as e:
            print(e)
            continue
        if kline.shape[0] < min_item:
            continue

        vb = StockIndicator.vibration(kline)
        count = 0
        for vb_value in vb[x_position - period:x_position]:
            if StockFilter.between(vb_value, min_vb, max_vb):
                count += 1
        if count > count_limit:
            print(stock)
            result.append(stock)
    return result