예제 #1
0
    def __make_factors(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'),
        )

        last_price = USEquityPricing.close.latest >= 1.0  # 大于1元
        universe = universe & last_price

        # market cap and book-to-price data gets fed in here
        outstanding = Fundamental().outstanding
        outstanding.window_safe = True
        market_cap = Latest([outstanding])

        book_to_price = SimpleBookToPrice()
        momentum = SimpleMomentum(mask=universe)

        alpha5 = Alpha5(mask=universe)
        alpha8 = Alpha8(mask=universe)
        alpha9 = Alpha9(mask=universe)

        all_factors = {
            'market_cap': market_cap.downsample('month_start'),
            'book_to_price': book_to_price.downsample('month_start'),
            'momentum': momentum,
            'alpha5': alpha5,
            'alpha8': alpha8,
            'alpha9': alpha9,
        }
        return all_factors, universe
예제 #2
0
def make_pipeline(asset_finder):
    h2o = USEquityPricing.high.latest / USEquityPricing.open.latest
    l2o = USEquityPricing.low.latest / USEquityPricing.open.latest
    c2o = USEquityPricing.close.latest / USEquityPricing.open.latest
    h2c = USEquityPricing.high.latest / USEquityPricing.close.latest
    l2c = USEquityPricing.low.latest / USEquityPricing.close.latest
    h2l = USEquityPricing.high.latest / USEquityPricing.low.latest

    vol = USEquityPricing.volume.latest
    outstanding = Fundamental(asset_finder).outstanding
    outstanding.window_safe = True
    turnover_rate = vol / Latest([outstanding])
    returns = Returns(inputs=[USEquityPricing.close], window_length=5)  # 预测一周数据

    pipe_columns = {
        'h2o': h2o.log1p().zscore(),
        'l2o': l2o.log1p().zscore(),
        'c2o': c2o.log1p().zscore(),
        'h2c': h2c.log1p().zscore(),
        'l2c': l2c.log1p().zscore(),
        'h2l': h2l.log1p().zscore(),
        'vol': vol.zscore(),
        'turnover_rate': turnover_rate.log1p().zscore(),
        'return': returns.log1p(),
    }
    # pipe_screen = (low_returns | high_returns)
    pipe = Pipeline(columns=pipe_columns)
    return pipe