Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

context.portfolio.positions 无法使用类似字典一样的查询方法 #105

Closed
littleicgar opened this issue Apr 25, 2017 · 2 comments
Closed
Assignees

Comments

@littleicgar
Copy link

littleicgar commented Apr 25, 2017

在RiceQuant测试
判断某知股票是否是当前持仓股票时,使用order_book_id in context.portfolio.positions时,始终是False,即使order_book_id 的股票当前有持仓。

for stock in context.universe:
        #当可用资金不足以买入一手股票时,order_percent函数不返回order对象,而是返回一个空值
        #分钟级别回测时,应下单量超过当前bar的总交易量的25%,导致下单无法全部成交。
        if is_suspended(stock) or context.portfolio.cash<=100*bar_dict[stock].last:
            break
        if stock in context.portfolio.positions:
            target_percent = context.portfolio.positions.value_percent + 0.1
        else:
            target_percent = 0.1
            logger.info('%s, %s, %s' % (stock, context.portfolio.positions, stock in context.portfolio.positions))

日志输出:
2012-12-21 09:35:00.00 INFO 002594.XSHE, [], False
2012-12-24 09:35:00.00 INFO 002594.XSHE, ['002594.XSHE'], False
第二行应该返回True

@wh1100717
Copy link
Member

@littleicgar a2ec4b8 已经修复该问题,会在下一个版本发布时可用。

@wh1100717
Copy link
Member

2.1.3 版本已发布

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants