def handle_data(context, data): # Take a 100% long position in AAPL order_target_percent(context.aapl, 1.00)
What I was expecting it to do is buy the Apple stock for all the money that I have but instead I see some selling of the Apple stock as well. Why does this happen? Thanks!
You must be logged in to post. Please login or register an account.
The order_target_percent function is a very blunt instrument and can often not do what you expect. If you have pending orders, it'll still order, then you'll wind up with more positions then you wanted, then you'll sell some next time.
Any time you want to order_target_percent, you really want to check to see if you already have some:
open_orders = get_open_orders() if context.aapl not in open_orders: order_target_percent(context.aapl, 1.0)
Same with selling. Make sure you don't already have a position trying to sell, or you'll quickly find yourself with some pending sells that account for all of your shares, then you go and short another 100% of your portfolio.
-Harrison 8 years ago
You must be logged in to post. Please login or register an account.