Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Odd output - Most basic algo

From the getting-started tutorial:

def initialize(context):  
    # Reference to AAPL  
    context.aapl = sid(24)

def handle_data(context, data):  
    # Position 100% of our portfolio to be long in AAPL  
    order_target_percent(context.aapl, 1.00)  

From 2008-03-03 to 2008-03-31 with $1,000,000 initial capital yields the following transaction history:
Only day with transactions, as expect (2008-03-03).

If someone can explain to me why there are 7 transactions.
4 Buys
2 Sells
1 Buy

Buys = $1.489M
Sells = $0.490M

What causes this? I would have expected it to buy roughly $1M worth of shares, and nothing over. It uses leverage when it never had to. Simply fill 100% of portfolio and do nothing. What am I missing?

Thanks,

M

4 responses

Try this:

if get_open_orders(): return  
order_target_percent(context.aapl, 1.00)  

Vladimir,

I added your code and instead of 7 transactions, I get 3.
2 Buys $1.006M; 1 Sell $6K.

Ok so I changed the initial capital to something more reasonable, i.e. $10k. Then it purchases $10.03k, and no sells.
So it seems that at large amounts, it becomes an issue with liquidity? Can someone elaborate on this?

My suspicion is that order_target_percent simply makes a market order for the amount of capital divided by the last price with no regard for slippage or the fill rate.