Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
please ignore

code attached - no long or short activity

3 responses

The problem is that you are buying SPY and then immediately selling the same number of shares of SPY. The net result is you will hold zero.

What you probably are trying to do is go long and short at the same time. Q doesn’t allow that. If one tries to go short, any existing shares will be sold first. This is also true in real trading. Most brokers (eg IB) won’t allow long and short positions of the same security.

Thanks Dan,
to clarify I am long Apple, short Microsoft
context.spy = sid(24) #apple 24 -
context.spy2 = sid(5061) #bmiscrosoft

not sure why its not working.

update this
def market_open(context, data):
# Put all my money in SPY.
if context.start == True:
order_target_percent(context.spy,1.0)

    order_target_percent(context.spy,-1.0)    '<---- to SPY2 = microsoft

but still no luck - no long or short