Hi,
I started working with quantopian 1 week ago. I wrote my first 'trading algos' to see what happens if... and so on. But I guess I still do not understand how quantopian is handling the trades during the backtest. Lets assume we have only one stock 'AAPL' and start with 1000$ over one year.
def initialize(context):
schedule_function(bb_trade,date_rules.every_day(),time_rules.market_close(minutes=1))
context.aapl = sid(24)
def bb_trade(context, data):
cur_price = data.current(context.jj,'price')
if some_condition:
order_target_percent(context.aapl,0)
elif some_other_condition:
order_target_percent(context.aapl,1)
What I don't get is: if I do 'order_target_percent(context.aapl,1)' ,my 1000$ should be invested in AAPL stock (at least in the amount I could buy for 1000$). What happens is, that I do 'order_target_percent(context.aapl,1)' two or more times in a row. But how can I buy Stock again with 100% of my portfolio if I already invested almost everything. Shouldn't the position be closed to do that again? Same Question for -1.
And 'order_target_percent(context.aapl,0)' means that I sell all the AAPL stock I have?
I'm looking forward to be enlightened:)
Best,
Robin