예제 #1
0
    def pipeline_columns_and_mask(self):
        factors, universe = self.__make_factors()
        from collections import OrderedDict
        factors_pipe = OrderedDict()
        # Create returns over last n days.
        factors_pipe['Returns'] = Returns(inputs=[USEquityPricing.close],
                                          mask=universe,
                                          window_length=5)
        # Instantiate ranked factors
        for name, f in factors.items():
            f.window_safe = True
            factors_pipe[name] = f.rank(
                mask=universe)  #rank 使用相对顺序,而不是绝对值,避免自相似性

        predict = BasicFactorRegress(inputs=factors_pipe.values(),
                                     window_length=42,
                                     mask=universe)  #进行预测,5天后价格
        risk_beta = 0.66 * RollingLinearRegressionOfReturns(
            target=symbol(risk_benchmark),  # sid(8554),
            returns_length=6,
            regression_length=21,
            # mask=long_short_screen
            mask=(universe),
        ).beta + 0.33 * 1.0
        sector = get_sector()

        columns = {
            'market_beta': risk_beta,
            'sector': sector,
            'predict': predict,
        }
        return columns, universe
예제 #2
0
def make_pipeline(asset_finder):

    private_universe = private_universe_mask( hs300.tolist(),asset_finder=asset_finder)
    #print private_universe_mask(['000001','000002','000005'],asset_finder=asset_finder)
    ######################################################################################################
    returns = Returns(inputs=[USEquityPricing.close], window_length=5)  # 预测一周数据
    ######################################################################################################
    ep = 1/Fundamental(mask = private_universe,asset_finder=asset_finder).pe
    bp = 1/Fundamental(mask = private_universe,asset_finder=asset_finder).pb
    bvps = Fundamental(mask = private_universe,asset_finder=asset_finder).bvps
    market = Fundamental(mask = private_universe,asset_finder=asset_finder).outstanding

    rev20 = Returns(inputs=[USEquityPricing.close], window_length=20,mask = private_universe)
    vol20 = AverageDollarVolume(window_length=20,mask = private_universe)

    illiq = ILLIQ(window_length=22,mask = private_universe)
    rsi = RSI(window_length=22,mask = private_universe)
    mom = Momentum(window_length=252,mask = private_universe)

    sector = get_sector(asset_finder=asset_finder,mask=private_universe)
    ONEHOTCLASS,sector_indict_keys = get_sector_by_onehot(asset_finder=asset_finder,mask=private_universe)


    pipe_columns = {

        'ep':ep.zscore(groupby=sector).downsample('month_start'),
        'bp':bp.zscore(groupby=sector).downsample('month_start'),
        'bvps':bvps.zscore(groupby=sector).downsample('month_start'),
        'market_cap': market.zscore(groupby=sector).downsample('month_start'),

        'vol20':vol20.zscore(groupby=sector),
        'rev20':rev20.zscore(groupby=sector),

        'ILLIQ':illiq.zscore(groupby=sector,mask=illiq.percentile_between(1, 99)),
        'mom'  :mom.zscore(groupby=sector,mask=mom.percentile_between(1, 99)),
        'rsi'  :rsi.zscore(groupby=sector,mask=rsi.percentile_between(1, 99)),
        #'sector':sector,
        #'returns':returns.quantiles(100),
        'returns': returns.zscore(),
    }
    # pipe_screen = (low_returns | high_returns)
    pipe = Pipeline(columns=pipe_columns,
           screen=private_universe,
           )
    i = 0
    for c in ONEHOTCLASS:
        pipe.add(c,sector_indict_keys[i])
        i +=1
    return pipe
    def pipeline_columns_and_mask(self):
        universe = make_china_equity_universe(
            target_size=2000,
            mask=default_china_equity_universe_mask([risk_benchmark]),
            max_group_weight=0.01,
            smoothing_func=lambda f: f.downsample('month_start'),
        )
        private_universe = private_universe_mask(
            self.portfolio.index)  #把当前组合的stock 包含在universe中

        last_price = USEquityPricing.close.latest >= 1.0  #大于1元
        universe = universe & last_price | private_universe
        hurst = HurstExp(window_length=int(252 * 0.25),
                         mask=universe)  #判断动量或反转特性指标
        sector = get_sector()
        #combined_rank = (
        #    hurst.rank(mask=universe)
        #)
        pct_slope = Slope(window_length=21, mask=(universe))  #量和价格加速度
        risk_beta = 0.66 * RollingLinearRegressionOfReturns(
            target=symbol(risk_benchmark),
            returns_length=5,
            regression_length=21,
            mask=(universe),
        ).beta + 0.33 * 1.0
        returns = Returns(inputs=[USEquityPricing.close],
                          mask=universe,
                          window_length=2)
        #returns.window_safe = True
        #risk_beta.window_safe = True
        #m = Markowitz(inputs=[returns,risk_beta],window_length=6,mask=universe)
        columns = {
            'hurst': hurst.downsample('week_start'),
            'price_pct_slope': pct_slope.pslope,
            'volume_pct_slope': pct_slope.vslope,
            'sector': sector.downsample('month_start'),
            'market_beta': risk_beta,
            'returns': returns,
        }
        return columns, universe
예제 #4
0
def universe_filter(smoothing_func=None, asset_finder=None):
    """
    Create a Pipeline producing Filters implementing common acceptance criteria.
    Returns
    -------
    zipline.Filter
        Filter to control tradeablility
    """
    factors = {
        'MarketCap': Fundamental(asset_finder=asset_finder).outstanding,
        'ADV_adj': ADV_adj(),
        'Sector': get_sector(asset_finder=asset_finder),
    }

    #func = lambda f: f.downsample('month_start')
    if smoothing_func != None:
        factors = {id: smoothing_func(factors[id]) for id in factors.keys()}
    #print factors
    factors['MarketCap'] = factors['MarketCap'] > MARKET_CAP_DOWNLIMIT
    factors['ADV_adj'] = factors['ADV_adj'] > ADV_ADJ_DOWNLIMIT
    factors['Sector'] = factors['Sector'].notnull()

    filters = None
    for value in factors.values():
        if filters == None:
            filters = value
        else:
            filters = (filters & value)

    #print filters

    #mySymbolsListfiter = default_china_equity_universe_mask()
    # Equities with an average daily volume greater than 5000000.
    #high_volume = (AverageDollarVolume(window_length=252) > 5000000)
    #liquid = ADV_adj().downsample('month_start') > 2500000
    #market_cap_filter = MarketCap().downsample('month_start') > market_cap_limit
    #universe_filter = (mySymbolsListfiter & market_cap_filter & liquid & high_volume )
    #universe_filter = ( maket_cap_filter & liquid )

    return filters
    def pipeline_columns_and_mask(self):
        '''
        universe = make_china_equity_universe(
            target_size=3000,
            mask=default_china_equity_universe_mask([RISK_BENCHMARK]),
            max_group_weight=0.01,
            smoothing_func=lambda f: f.downsample('month_start'),

        )
        private_universe = private_universe_mask(self.portfolio.index)  # 把当前组合的stock 包含在universe中
        '''
        last_price = USEquityPricing.close.latest >= 1.0  # 大于1元
        sector = get_sector()
        sector_filter = sector != 0.0
        universe = last_price & sector_filter
        # print "universe:",universe
        # Instantiate ranked factors
        returns = Returns(inputs=[USEquityPricing.close],
                          mask=universe,
                          window_length=2)
        risk_beta = 0.66 * RollingLinearRegressionOfReturns(
            target=symbol(RISK_BENCHMARK),
            returns_length=5,
            regression_length=21,
            # mask=long_short_screen
            mask=(universe),
        ).beta + 0.33 * 1.0
        returns.window_safe = True
        risk_beta.window_safe = True
        predict = RNNPredict(universe,
                             source='predict.csv',
                             trigger_date=self.predict_time)  # 进行回顾
        columns = {
            'predict': predict,
            'market_beta': risk_beta,
            'sector': sector,
        }
        return columns, universe
예제 #6
0
def make_pipeline(asset_finder, algo_mode):

    private_universe = private_universe_mask(hs300.tolist(),
                                             asset_finder=asset_finder)
    #private_universe = private_universe_mask( ['000005'],asset_finder=asset_finder)
    ###private_universe = private_universe_mask( ['000002','000005'],asset_finder=asset_finder)
    #private_universe = private_universe_mask( ['000001','000002','000005'],asset_finder=asset_finder)
    #private_universe = private_universe_mask( ['000001'],asset_finder=asset_finder)

    #print private_universe_mask(['000001','000002','000005'],asset_finder=asset_finder)
    ######################################################################################################
    returns = Returns(inputs=[USEquityPricing.close],
                      window_length=5,
                      mask=private_universe)  # 预测一周数据
    ######################################################################################################
    pe = Fundamental(mask=private_universe, asset_finder=asset_finder).pe
    pb = Fundamental(mask=private_universe, asset_finder=asset_finder).pb
    bvps = Fundamental(mask=private_universe, asset_finder=asset_finder).bvps
    market = Fundamental(mask=private_universe,
                         asset_finder=asset_finder).outstanding
    totals = Fundamental(mask=private_universe,
                         asset_finder=asset_finder).totals
    totalAssets = Fundamental(mask=private_universe,
                              asset_finder=asset_finder).totalAssets
    fixedAssets = Fundamental(mask=private_universe,
                              asset_finder=asset_finder).fixedAssets
    esp = Fundamental(mask=private_universe, asset_finder=asset_finder).esp
    rev = Fundamental(mask=private_universe, asset_finder=asset_finder).rev
    profit = Fundamental(mask=private_universe,
                         asset_finder=asset_finder).profit
    gpr = Fundamental(mask=private_universe, asset_finder=asset_finder).gpr
    npr = Fundamental(mask=private_universe, asset_finder=asset_finder).npr

    rev10 = Returns(inputs=[USEquityPricing.close],
                    window_length=10,
                    mask=private_universe)
    vol10 = AverageDollarVolume(window_length=20, mask=private_universe)
    rev20 = Returns(inputs=[USEquityPricing.close],
                    window_length=20,
                    mask=private_universe)
    vol20 = AverageDollarVolume(window_length=20, mask=private_universe)
    rev30 = Returns(inputs=[USEquityPricing.close],
                    window_length=30,
                    mask=private_universe)
    vol30 = AverageDollarVolume(window_length=20, mask=private_universe)

    illiq22 = ILLIQ(window_length=22, mask=private_universe)
    illiq5 = ILLIQ(window_length=5, mask=private_universe)

    rsi5 = RSI(window_length=5, mask=private_universe)
    rsi22 = RSI(window_length=22, mask=private_universe)

    mom5 = Momentum(window_length=5, mask=private_universe)
    mom22 = Momentum(window_length=22, mask=private_universe)

    sector = get_sector(asset_finder=asset_finder, mask=private_universe)
    ONEHOTCLASS, sector_indict_keys = get_sector_by_onehot(
        asset_finder=asset_finder, mask=private_universe)

    pipe_columns = {
        'pe': pe.zscore(groupby=sector).downsample('month_start'),
        'pb': pb.zscore(groupby=sector).downsample('month_start'),
        'bvps': bvps.zscore(groupby=sector).downsample('month_start'),
        'market_cap': market.zscore(groupby=sector).downsample('month_start'),
        'totals': totals.zscore(groupby=sector).downsample('month_start'),
        'totalAssets':
        totalAssets.zscore(groupby=sector).downsample('month_start'),
        'fixedAssets':
        fixedAssets.zscore(groupby=sector).downsample('month_start'),
        'esp': esp.zscore(groupby=sector).downsample('month_start'),
        'rev': rev.zscore(groupby=sector).downsample('month_start'),
        'profit': profit.zscore(groupby=sector).downsample('month_start'),
        'gpr': gpr.zscore(groupby=sector).downsample('month_start'),
        'npr': npr.zscore(groupby=sector).downsample('month_start'),
        'vol10': vol10.zscore(groupby=sector).downsample('week_start'),
        'rev10': rev10.zscore(groupby=sector).downsample('week_start'),
        'vol20': vol20.zscore(groupby=sector).downsample('week_start'),
        'rev20': rev20.zscore(groupby=sector).downsample('week_start'),
        'vol30': vol30.zscore(groupby=sector).downsample('week_start'),
        'rev30': rev30.zscore(groupby=sector).downsample('week_start'),
        'ILLIQ5': illiq5.zscore(groupby=sector).downsample('week_start'),
        'ILLIQ22': illiq22.zscore(groupby=sector).downsample('week_start'),
        'mom5': mom5.zscore(groupby=sector).downsample('week_start'),
        'mom22': mom22.zscore(groupby=sector).downsample('week_start'),
        'rsi5': rsi5.zscore(groupby=sector).downsample('week_start'),
        'rsi22': rsi22.zscore(groupby=sector).downsample('week_start'),
    }

    from collections import OrderedDict
    factors_pipe = OrderedDict()

    factors_pipe['Returns'] = returns
    factors_pipe['Returns'].window_safe = True
    idx = 0

    sort_keys = sorted(pipe_columns)
    for key in sort_keys:
        #print(key)
        factors_pipe[key] = pipe_columns[key]
        factors_pipe[key].window_safe = True
        idx += 1
        if idx == 100:
            break

    #for name, f in pipe_columns.items():
    #    f.window_safe = True
    #    factors_pipe[name] = f
    #    print (name,f)
    #    idx += 1
    #    if idx == 1:
    #       break

    i = 0
    for c in ONEHOTCLASS:
        c.window_safe = True
        factors_pipe[sector_indict_keys[i]] = c
        #print (c,sector_indict_keys[i])
        i += 1

    predict = BasicFactorRegress(inputs=factors_pipe.values(),
                                 window_length=252,
                                 mask=private_universe,
                                 n_fwd_days=5,
                                 algo_mode=algo_mode,
                                 cross=False)
    predict_rank = predict.rank(mask=private_universe)

    longs = predict_rank.top(NUM_LONG_POSITIONS)
    shorts = predict_rank.bottom(NUM_SHORT_POSITIONS)
    long_short_screen = (longs | shorts)
    #TODO sector onehot
    pipe_final_columns = {
        'Predict Factor': predict.downsample('week_start'),
        'longs': longs.downsample('week_start'),
        'shorts': shorts.downsample('week_start'),
        'predict_rank': predict_rank.downsample('week_start'),
    }
    pipe = Pipeline(
        columns=pipe_final_columns,
        screen=long_short_screen,
    )
    return pipe
예제 #7
0
def make_pipeline(asset_finder):
    hs300 = ts.get_hs300s()['code']
    private_universe = private_universe_mask(hs300.tolist(),
                                             asset_finder=asset_finder)
    #private_universe =  private_universe_mask(['000001','000002','000005'],asset_finder=asset_finder)
    ######################################################################################################
    returns = Returns(inputs=[USEquityPricing.close],
                      window_length=5,
                      mask=private_universe)  # 预测一周数据
    ######################################################################################################
    ep = 1 / Fundamental(mask=private_universe, asset_finder=asset_finder).pe
    bp = 1 / Fundamental(mask=private_universe, asset_finder=asset_finder).pb
    bvps = Fundamental(mask=private_universe, asset_finder=asset_finder).bvps
    market = Fundamental(mask=private_universe,
                         asset_finder=asset_finder).outstanding
    totals = Fundamental(mask=private_universe,
                         asset_finder=asset_finder).totals
    totalAssets = Fundamental(mask=private_universe,
                              asset_finder=asset_finder).totalAssets
    fixedAssets = Fundamental(mask=private_universe,
                              asset_finder=asset_finder).fixedAssets
    esp = Fundamental(mask=private_universe, asset_finder=asset_finder).esp
    rev = Fundamental(mask=private_universe, asset_finder=asset_finder).rev
    profit = Fundamental(mask=private_universe,
                         asset_finder=asset_finder).profit
    gpr = Fundamental(mask=private_universe, asset_finder=asset_finder).gpr
    npr = Fundamental(mask=private_universe, asset_finder=asset_finder).npr

    rev10 = Returns(inputs=[USEquityPricing.close],
                    window_length=10,
                    mask=private_universe)
    vol10 = AverageDollarVolume(window_length=20, mask=private_universe)
    rev20 = Returns(inputs=[USEquityPricing.close],
                    window_length=20,
                    mask=private_universe)
    vol20 = AverageDollarVolume(window_length=20, mask=private_universe)
    rev30 = Returns(inputs=[USEquityPricing.close],
                    window_length=30,
                    mask=private_universe)
    vol30 = AverageDollarVolume(window_length=20, mask=private_universe)

    illiq22 = ILLIQ(window_length=22, mask=private_universe)
    illiq5 = ILLIQ(window_length=5, mask=private_universe)

    rsi5 = RSI(window_length=5, mask=private_universe)
    rsi22 = RSI(window_length=22, mask=private_universe)

    mom5 = Momentum(window_length=5, mask=private_universe)
    mom22 = Momentum(window_length=22, mask=private_universe)

    sector = get_sector(asset_finder=asset_finder, mask=private_universe)
    ONEHOTCLASS, sector_indict_keys = get_sector_by_onehot(
        asset_finder=asset_finder, mask=private_universe)

    pipe_columns = {
        'ep': ep.zscore(groupby=sector).downsample('month_start'),
        'bp': bp.zscore(groupby=sector).downsample('month_start'),
        'bvps': bvps.zscore(groupby=sector).downsample('month_start'),
        'market_cap': market.zscore(groupby=sector).downsample('month_start'),
        'totals': totals.zscore(groupby=sector).downsample('month_start'),
        'totalAssets':
        totalAssets.zscore(groupby=sector).downsample('month_start'),
        'fixedAssets':
        fixedAssets.zscore(groupby=sector).downsample('month_start'),
        'esp': esp.zscore(groupby=sector).downsample('month_start'),
        'rev': rev.zscore(groupby=sector).downsample('month_start'),
        'profit': profit.zscore(groupby=sector).downsample('month_start'),
        'gpr': gpr.zscore(groupby=sector).downsample('month_start'),
        'npr': npr.zscore(groupby=sector).downsample('month_start'),
        'vol10': vol10.zscore(groupby=sector).downsample('week_start'),
        'rev10': rev10.zscore(groupby=sector).downsample('week_start'),
        'vol20': vol20.zscore(groupby=sector).downsample('week_start'),
        'rev20': rev20.zscore(groupby=sector).downsample('week_start'),
        'vol30': vol30.zscore(groupby=sector).downsample('week_start'),
        'rev30': rev30.zscore(groupby=sector).downsample('week_start'),
        'ILLIQ5': illiq5.zscore(groupby=sector).downsample('week_start'),
        'ILLIQ22': illiq22.zscore(groupby=sector).downsample('week_start'),
        'mom5': mom5.zscore(groupby=sector).downsample('week_start'),
        'mom22': mom22.zscore(groupby=sector).downsample('week_start'),
        'rsi5': rsi5.zscore(groupby=sector).downsample('week_start'),
        'rsi22': rsi22.zscore(groupby=sector).downsample('week_start'),
        #'rsi22': rsi22.zscore(groupby=sector, mask=rsi22.percentile_between(1, 99)),

        #######################################################################################################################
        # 'ILLIQ5-2' : illiq5.zscore(groupby=quantiles([illiq5],bins = 10,mask = private_universe)).downsample('week_start'),
        # 'ILLIQ22-2': illiq22.zscore(groupby=quantiles([illiq22],bins = 10,mask = private_universe)).downsample('week_start'),
        # 'ILLIQ5-2': illiq5.zscore(groupby=market.quantiles(bins=10, mask=private_universe)).downsample('week_start'),
        # 'ILLIQ22-2': illiq22.zscore(groupby=market.quantiles(bins=10, mask=private_universe)).downsample('week_start'),
        #############################################################################################################################
        'returns': returns.downsample('week_start'),
    }
    pipe = Pipeline(
        columns=pipe_columns,
        screen=private_universe,
    )
    i = 0
    for c in ONEHOTCLASS:
        pipe.add(c, sector_indict_keys[i])
        i += 1
    return pipe
예제 #8
0
def sector_filter(tradeable_count,
                  sector_exposure_limit,
                  smoothing_func=None,
                  asset_finder=None):
    """
    Mask for Pipeline in create_tradeable. Limits each sector so as not to be over-exposed

    Parameters
    ----------
    tradeable_count : int
        Target number of constituent securities in universe
    sector_exposure_limit: float
        Target threshold for any particular sector
    Returns
    -------
    zipline.Filter
        Filter to control sector exposure
    """

    industry_class, _ = get_sector_class()
    #print("g_inds",g_inds)
    sector_factor = get_sector(industry_class, asset_finder=asset_finder)
    # set thresholds
    sector_size = len(industry_class)
    if sector_exposure_limit < ((1. / sector_size)):
        threshold = int(math.ceil((1. / sector_size) * tradeable_count))
    elif sector_exposure_limit > 1.:
        threshold = tradeable_count
    else:
        threshold = int(math.ceil(sector_exposure_limit * tradeable_count))

    #print ("tradeable_count %s , get_sector_size %s , industry threashold %s:" % (tradeable_count,sector_size,threshold))
    filters = None
    for industry, ino in industry_class.items():
        #print industry,ino,industry_class[industry]
        mask = sector_factor.eq(industry_class[industry])
        if smoothing_func != None:
            value = smoothing_func(AverageDollarVolume(window_length=21)).top(
                threshold, mask)
        else:
            value = AverageDollarVolume(window_length=21).top(threshold, mask)
        #print value
        #print filters
        if filters == None:
            filters = value
        else:
            filters = (filters | value)
    '''
    transport_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['交通运输'.decode("UTF-8")]))             #
    instrument_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['仪器仪表'.decode("UTF-8")]))
    media_entertainment_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['传媒娱乐'.decode("UTF-8")]))   #
    water_supply_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['供水供气'.decode("UTF-8")]))          #
    highway_bridge_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['公路桥梁'.decode("UTF-8")]))        #
    other_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['其它行业'.decode("UTF-8")]))
    animal_husbandry_fishery_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['农林牧渔'.decode("UTF-8")]))  #
    pesticide_fertilizer_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['农药化肥'.decode("UTF-8")]))
    chemical_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['化工行业'.decode("UTF-8")]))                  #
    chemical_fiber_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['化纤行业'.decode("UTF-8")]))
    medical_device_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['医疗器械'.decode("UTF-8")]))
    printing_packaging_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['印刷包装'.decode("UTF-8")]))
    power_plant_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['发电设备'.decode("UTF-8")]))
    business_department_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['商业百货'.decode("UTF-8")]))       #
    plastics_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['塑料制品'.decode("UTF-8")]))
    furniture_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['家具行业'.decode("UTF-8")]))                 #
    appliance_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['家电行业'.decode("UTF-8")]))                 #
    building_materials_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['建筑建材'.decode("UTF-8")]))        #
    development_zone_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['开发区'.decode("UTF-8")]))
    real_estate_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['房地产'.decode("UTF-8")]))                #
    motorcycle_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['摩托车'.decode("UTF-8")]))
    nonferrous_metals_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['有色金属'.decode("UTF-8")]))         #
    clothing_footwear_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['服装鞋类'.decode("UTF-8")]))         #
    machinery_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['机械行业'.decode("UTF-8")]))                 #
    time_shares_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['次新股'.decode("UTF-8")]))
    cement_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['水泥行业'.decode("UTF-8")]))
    automobile_manufacturing_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['汽车制造'.decode("UTF-8")]))  #
    coal_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['煤炭行业'.decode("UTF-8")]))                      #
    material_trade_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['物资外贸'.decode("UTF-8")]))
    environmental_protection_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['环保行业'.decode("UTF-8")]))   #
    glass_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['玻璃行业'.decode("UTF-8")]))
    biopharmaceuticals_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['生物制药'.decode("UTF-8")]))         #
    power_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['电力行业'.decode("UTF-8")]))                     
    electronic_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['电器行业'.decode("UTF-8")]))
    electronic_information_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['电子信息'.decode("UTF-8")]))     #
    electronic_device_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['电子器件'.decode("UTF-8")]))            
    oil_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['石油行业'.decode("UTF-8")]))                     
    textile_machinery_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['纺织机械'.decode("UTF-8")]))
    textile_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['纺织行业'.decode("UTF-8")]))
    integrated_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['综合行业'.decode("UTF-8")]))
    ship_manufacturing_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['船舶制造'.decode("UTF-8")]))
    paper_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['造纸行业'.decode("UTF-8")]))
    hotel_tour_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['酒店旅游'.decode("UTF-8")]))                #
    wine_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['酿酒行业'.decode("UTF-8")]))
    financial_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['金融行业'.decode("UTF-8")]))                 #
    steel_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['钢铁行业'.decode("UTF-8")]))                     #      
    ceramics_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['陶瓷行业'.decode("UTF-8")]))           
    aircraft_manufacturing_trim = AverageDollarVolume(window_length=21).top(threshold, mask=sector_factor.eq(industry_class['飞机制造'.decode("UTF-8")]))
    food_industry_trim = AverageDollarVolume(window_length=21).downsample('month_start').top(threshold, mask=sector_factor.eq(industry_class['食品行业'.decode("UTF-8")]))             #

    return transport_trim|media_entertainment_trim|\
           chemical_trim|medical_device_trim|\
           power_plant_trim|business_department_trim|appliance_trim|\
           building_materials_trim|real_estate_trim|nonferrous_metals_trim|\
           clothing_footwear_trim|machinery_trim|automobile_manufacturing_trim|\
           coal_trim|environmental_protection_trim|biopharmaceuticals_trim|\
           power_trim|electronic_information_trim|electronic_device_trim|\
           oil_trim|textile_trim|hotel_tour_trim|\
           wine_trim|financial_trim|steel_trim|\
           aircraft_manufacturing_trim|food_industry_trim
    '''
    return filters