def handle_data(self, data):
if not self.ordered:
for s in self.sids:
self.order(self.sid(s), 1)
self.ordered = True
if not self.exited:
amounts = [pos.amount for pos
in itervalues(self.portfolio.positions)]
if (
len(amounts) > 0 and
all([(amount == 1) for amount in amounts])
):
for stock in self.portfolio.positions:
self.order(self.sid(stock), -1)
self.exited = True
# Should be 0 when all positions are exited.
self.record(num_positions=len(self.portfolio.positions))
评论列表
文章目录