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.

Clone Algorithm
5
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5750cda4fd4b490f8a477c0b
There was a runtime error.
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

Clone Algorithm
1
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5753bb86bb6be50f8553be19
There was a runtime error.

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.

Clone Algorithm
4
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5753d64a3213500f8d6782f8
There was a runtime error.

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.

Clone Algorithm
2
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5753dec3f5d8fd0f95a6803b
There was a runtime error.

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?

Clone Algorithm
2
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 57547defb9a0b00f9c40b7d9
There was a runtime error.