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

Method test_order_future_non_targeted

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

Source from the content-addressed store, hash-verified

175 ('order_percent', 1), # 100% on a $10000 capital base.
176 ])
177 def test_order_future_non_targeted(self, order_method, amount):
178 # Every day, place an order for $10000 worth of sid(2)
179 algotext = """
180import zipline.api as api
181
182def initialize(context):
183 api.set_slippage(us_futures=api.slippage.FixedSlippage(spread=0.0))
184 api.set_commission(us_futures=api.commission.PerTrade(0.0))
185
186 context.future = api.sid(2)
187
188 api.schedule_function(
189 func=do_order,
190 date_rule=api.date_rules.every_day(),
191 time_rule=api.time_rules.market_open(),
192 )
193
194def do_order(context, data):
195 context.ordered = True
196 api.{order_func}(context.future, {arg})
197 """.format(order_func=order_method, arg=amount)
198 result = self.run_algorithm(script=algotext)
199
200 for orders in result.orders.values:
201 assert_equal(len(orders), 1)
202 assert_equal(orders[0]['amount'], 500)
203 assert_equal(orders[0]['sid'], self.FUTURE)
204
205 for i, positions in enumerate(result.positions.values, start=1):
206 assert_equal(len(positions), 1)
207 assert_equal(positions[0]['amount'], 500.0 * i)
208 assert_equal(positions[0]['sid'], self.FUTURE)
209
210 @parameterized.expand([
211 # These should all be orders targeting the same amount.

Callers

nothing calls this directly

Calls 2

assert_equalFunction · 0.90
run_algorithmMethod · 0.80

Tested by

no test coverage detected