(self, order_method, amount)
| 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 = """ |
| 221 | import zipline.api as api |
| 222 | |
| 223 | def 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 | |
| 235 | def 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), |
nothing calls this directly
no test coverage detected