As a newbie in quantopian, I wrote a simple test in handle_data() function,
def handle_data(context,data):
print("********the timestamp is",get_datetime(),"*******")
print("the cash before ordering is",context.portfolio.cash)
order_target(sid(270),100)
for item in context.portfolio.positions:
print("item is ", item,)
for position in context.portfolio.positions.itervalues():
print("position amount is",position.amount)
return
As a position.amount result for the stock sid(270), it's varying at each time instead of being a constant 100, can anyone help me to understand why is that? Thanks!
As a reference, below is the output:
2011-01-04 09:31 PRINT ('********the timestamp is', Timestamp('2011-01-04 14:31:00+0000', tz='UTC'), '****')
2011-01-04 09:31 PRINT ('the cash before ordering is', 100000.0)
2011-01-04 09:32 PRINT ('*****the timestamp is', Timestamp('2011-01-04 14:32:00+0000', tz='UTC'), '****')
2011-01-04 09:32 PRINT ('the cash before ordering is', 100000.0)
2011-01-04 09:33 PRINT ('*****the timestamp is', Timestamp('2011-01-04 14:33:00+0000', tz='UTC'), '*****')
2011-01-04 09:33 PRINT ('the cash before ordering is', 99988.4375376)
2011-01-04 09:33 PRINT ('item is ', Equity(270 [AKRX]))
2011-01-04 09:33 PRINT ('position amount is', **2)
2011-01-04 09:34 PRINT ('********the timestamp is', Timestamp('2011-01-04 14:34:00+0000', tz='UTC'), '*****')
2011-01-04 09:34 PRINT ('the cash before ordering is', 99675.70408650559)
2011-01-04 09:34 PRINT ('item is ', Equity(270 [AKRX]))
2011-01-04 09:34 PRINT ('position amount is', **56)
2011-01-04 09:35 PRINT ('********the timestamp is', Timestamp('2011-01-04 14:35:00+0000', tz='UTC'), '*****')
2011-01-04 09:35 PRINT ('the cash before ordering is', 99664.12162330559)
2011-01-04 09:35 PRINT ('item is ', Equity(270 [AKRX]))
2011-01-04 09:35 PRINT ('position amount is', **58)
.............