Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Trouble making a program that buys an equal amount of two etfs

I am trying to make a program that spends 1/2 of my cash on VOO and the other half on RGI. However, the RGI is not getting filled. Also it is saying that negative number of shares cannot be filed. What am I doing wrong?

Can you please help me figure this out.

7 responses

so the

own = []  
own.append(stock)  

doesn't do anything. the own is reinitialized every time you run the func, stock is never in own because you've just set own = []

that said,

order_target_percent(sid(32836), .5)  

needs another look, i suspect it's corrupt data. try using spy and voo.

ps. i'm going to put up a bug post to see if Q notices.

@toan

There definitely seems to be a data issue.

I ran

order_target_percent(sid(32836), 1)  

and the graph does not look anything like this compared to the benchmark:
https://www.google.com/finance?chdnp=1&chdd=1&chds=1&chdv=1&chvs=maximized&chdeh=0&chfdeh=0&chdet=1465105413209&chddm=541535&chls=IntervalBasedLine&cmpto=NYSEARCA:SPY&cmptdms=0&q=NYSEARCA:RSP&ntsp=0&ei=8btTV6iZD4qmebv7jcgD

This is just an equally waited S&P 500 etf. It should not look like the back test.

Should I email quantopian?

The a similar issue happens to EWRI, hte EW Russell 1000

in the bug posting i did, one of the guys says it's not a bug, but i still think it is.

the order_target_percent will place an order and if it's not filled in the same minute, will place another order. if it is not a liquid etf, you will stack up a bunch of orders and they slowly get filled. I think that's a really buggy way to implement that function. the correct way, i think, is check portfolio and unfilled orders, and only place a new one if amount is insufficient to target.

toan tran,

It is not a bug in prices it is a good illustration how badly Quantopian unrealistic default slippage model controlling any algo.
If you disable it, the results will be much better or as expected.

Vald, here are the results of not setting slippage and commission. I'm not saying that the models are anywhere accurate, but in this case, the broken function is the order_target_percent.

toan,

To my mind the order_target_percent function working properly if you use it the right way.

Why does this under perform the benchmark?

The SPY should do the same as the benchmark and the RGI does better than the benchmark so together they should do slightly better than the benchmark.

Am I buying 50% of each improperly?