MCPcopy
hub / github.com/quantopian/zipline / test_order_future_targeted

Method test_order_future_targeted

tests/test_ordering.py:217–252  ·  view source on GitHub ↗
(self, order_method, amount)

Source from the content-addressed store, hash-verified

215 ('order_target_percent', 1), # 100% on a $10000 capital base.
216 ])
217 def test_order_future_targeted(self, order_method, amount):
218 # Every day, place an order for a target of $10000 worth of sid(2).
219 # With no commissions or slippage, we should only place one order.
220 algotext = """
221import zipline.api as api
222
223def initialize(context):
224 api.set_slippage(us_futures=api.slippage.FixedSlippage(spread=0.0))
225 api.set_commission(us_futures=api.commission.PerTrade(0.0))
226
227 context.future = api.sid(2)
228
229 api.schedule_function(
230 func=do_order,
231 date_rule=api.date_rules.every_day(),
232 time_rule=api.time_rules.market_open(),
233 )
234
235def do_order(context, data):
236 context.ordered = True
237 api.{order_func}(context.future, {arg})
238 """.format(order_func=order_method, arg=amount)
239
240 result = self.run_algorithm(script=algotext)
241
242 # We should get one order on the first day.
243 assert_equal([len(ords) for ords in result.orders], [1, 0, 0, 0])
244 order = result.orders.iloc[0][0]
245 assert_equal(order['amount'], 500)
246 assert_equal(order['sid'], self.FUTURE)
247
248 # Our position at the end of each day should be worth $10,000.
249 for positions in result.positions.values:
250 assert_equal(len(positions), 1)
251 assert_equal(positions[0]['amount'], 500.0)
252 assert_equal(positions[0]['sid'], self.FUTURE)
253
254 @parameterized.expand([
255 (api.order, 5000),

Callers

nothing calls this directly

Calls 2

assert_equalFunction · 0.90
run_algorithmMethod · 0.80

Tested by

no test coverage detected