polyfactor.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:silverstrategy 作者: silverhandy 项目源码 文件源码
def handle_bar(context, bar_dict):
    # ?????????????

    # bar_dict[order_book_id] ?????????bar??
    # context.portfolio ???????????????

    # ??order_shares(id_or_ins, amount)??????

    # TODO: ??????????

    stocks = set(context.to_buy)
    holdings = set(get_holdings(context))
    to_buy = stocks - holdings
    holdings = set(get_holdings(context))
    to_sell = holdings - stocks
    for stock in to_sell:
        if bar_dict[stock].is_trading:
            order_target_percent(stock , 0)
    to_buy = get_trading_stocks(to_buy, context, bar_dict)
    buy_rsi = []
    for stock in to_buy:
        prices = history(context.SMAPERIOD+1,'1d','close')[stock].values
        avg = talib.SMA(prices,context.SMAPERIOD)
        if avg[-1] < prices[-1]:
            buy_rsi.append(stock)
    if len(buy_rsi) >0:
        #cash = context.portfolio.cash
        #average_value = 0.98 * cash / len(buy_rsi)
        for stock in buy_rsi:
            if bar_dict[stock].is_trading:
                #order_value(stock ,average_value)
                order_target_percent(stock,0.08)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号