本文整理汇总了Python中zipline.finance.blotter.Blotter.hold方法的典型用法代码示例。如果您正苦于以下问题:Python Blotter.hold方法的具体用法?Python Blotter.hold怎么用?Python Blotter.hold使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zipline.finance.blotter.Blotter
的用法示例。
在下文中一共展示了Blotter.hold方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_order_hold
# 需要导入模块: from zipline.finance.blotter import Blotter [as 别名]
# 或者: from zipline.finance.blotter.Blotter import hold [as 别名]
def test_order_hold(self):
"""
Held orders act almost identically to open orders, except for the
status indication. When a fill happens, the order should switch
status to OPEN/FILLED as necessary
"""
blotter = Blotter(self.sim_params.data_frequency, self.env.asset_finder)
# Nothing happens on held of a non-existent order
blotter.hold(56)
self.assertEqual(blotter.new_orders, [])
asset_24 = blotter.asset_finder.retrieve_asset(24)
open_id = blotter.order(asset_24, 100, MarketOrder())
open_order = blotter.open_orders[asset_24][0]
self.assertEqual(open_order.id, open_id)
blotter.hold(open_id)
self.assertEqual(len(blotter.new_orders), 1)
self.assertEqual(len(blotter.open_orders[asset_24]), 1)
held_order = blotter.new_orders[0]
self.assertEqual(held_order.status, ORDER_STATUS.HELD)
self.assertEqual(held_order.reason, "")
blotter.cancel(held_order.id)
self.assertEqual(len(blotter.new_orders), 1)
self.assertEqual(len(blotter.open_orders[asset_24]), 0)
cancelled_order = blotter.new_orders[0]
self.assertEqual(cancelled_order.id, held_order.id)
self.assertEqual(cancelled_order.status, ORDER_STATUS.CANCELLED)
for data in ([100, self.sim_params.trading_days[0]], [400, self.sim_params.trading_days[1]]):
# Verify that incoming fills will change the order status.
trade_amt = data[0]
dt = data[1]
order_size = 100
expected_filled = int(trade_amt * DEFAULT_VOLUME_SLIPPAGE_BAR_LIMIT)
expected_open = order_size - expected_filled
expected_status = ORDER_STATUS.OPEN if expected_open else ORDER_STATUS.FILLED
blotter = Blotter(self.sim_params.data_frequency, self.env.asset_finder)
open_id = blotter.order(blotter.asset_finder.retrieve_asset(24), order_size, MarketOrder())
open_order = blotter.open_orders[asset_24][0]
self.assertEqual(open_id, open_order.id)
blotter.hold(open_id)
held_order = blotter.new_orders[0]
filled_order = None
blotter.current_dt = dt
bar_data = BarData(self.data_portal, lambda: dt, self.sim_params.data_frequency)
txns, _, _ = blotter.get_transactions(bar_data)
for txn in txns:
filled_order = blotter.orders[txn.order_id]
self.assertEqual(filled_order.id, held_order.id)
self.assertEqual(filled_order.status, expected_status)
self.assertEqual(filled_order.filled, expected_filled)
self.assertEqual(filled_order.open_amount, expected_open)
示例2: test_order_hold
# 需要导入模块: from zipline.finance.blotter import Blotter [as 别名]
# 或者: from zipline.finance.blotter.Blotter import hold [as 别名]
def test_order_hold(self):
"""
Held orders act almost identically to open orders, except for the
status indication. When a fill happens, the order should switch
status to OPEN/FILLED as necessary
"""
blotter = Blotter()
# Nothing happens on held of a non-existent order
blotter.hold(56)
self.assertEqual(blotter.new_orders, [])
open_id = blotter.order(24, 100, MarketOrder())
open_order = blotter.open_orders[24][0]
self.assertEqual(open_order.id, open_id)
blotter.hold(open_id)
self.assertEqual(len(blotter.new_orders), 1)
self.assertEqual(len(blotter.open_orders[24]), 1)
held_order = blotter.new_orders[0]
self.assertEqual(held_order.status, ORDER_STATUS.HELD)
self.assertEqual(held_order.reason, '')
blotter.cancel(held_order.id)
self.assertEqual(len(blotter.new_orders), 1)
self.assertEqual(len(blotter.open_orders[24]), 0)
cancelled_order = blotter.new_orders[0]
self.assertEqual(cancelled_order.id, held_order.id)
self.assertEqual(cancelled_order.status, ORDER_STATUS.CANCELLED)
for trade_amt in (100, 400):
# Verify that incoming fills will change the order status.
order_size = 100
expected_filled = trade_amt * 0.25
expected_open = order_size - expected_filled
expected_status = ORDER_STATUS.OPEN if expected_open else \
ORDER_STATUS.FILLED
blotter = Blotter()
blotter.current_dt = datetime.datetime.now()
open_id = blotter.order(24, order_size, MarketOrder())
open_order = blotter.open_orders[24][0]
self.assertEqual(open_id, open_order.id)
blotter.hold(open_id)
held_order = blotter.new_orders[0]
aapl_trade = create_trade(24, 50.0, trade_amt,
datetime.datetime.now())
filled_order = None
for txn, updated_order in blotter.process_trade(aapl_trade):
filled_order = updated_order
self.assertEqual(filled_order.id, held_order.id)
self.assertEqual(filled_order.status, expected_status)
self.assertEqual(filled_order.filled, expected_filled)
self.assertEqual(filled_order.open_amount, expected_open)