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

Method test_order_equity_targeted

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

Source from the content-addressed store, hash-verified

133 ('order_target_percent', 1), # 100% on a $10000 capital base.
134 ])
135 def test_order_equity_targeted(self, order_method, amount):
136 # Every day, place an order for a target of $10000 worth of sid(1).
137 # With no commissions or slippage, we should only place one order.
138 algotext = """
139import zipline.api as api
140
141def initialize(context):
142 api.set_slippage(api.slippage.FixedSlippage(spread=0.0))
143 api.set_commission(api.commission.PerShare(0))
144
145 context.equity = api.sid(1)
146
147 api.schedule_function(
148 func=do_order,
149 date_rule=api.date_rules.every_day(),
150 time_rule=api.time_rules.market_open(),
151 )
152
153def do_order(context, data):
154 context.ordered = True
155 api.{order_func}(context.equity, {arg})
156 """.format(order_func=order_method, arg=amount)
157
158 result = self.run_algorithm(script=algotext)
159
160 assert_equal([len(ords) for ords in result.orders], [1, 0, 0, 0])
161 order = result.orders.iloc[0][0]
162 assert_equal(order['amount'], 5000)
163 assert_equal(order['sid'], self.EQUITY)
164
165 for positions in result.positions.values:
166 assert_equal(len(positions), 1)
167 assert_equal(positions[0]['amount'], 5000.0)
168 assert_equal(positions[0]['sid'], self.EQUITY)
169
170 @parameterized.expand([
171 # These should all be orders for the same amount.

Callers

nothing calls this directly

Calls 2

assert_equalFunction · 0.90
run_algorithmMethod · 0.80

Tested by

no test coverage detected