Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Why so much available cash after using order_target_percent(stock, 1.0)?

Hi,

I wrote a simple algo that (attempts to) rotate to the ETF that performed the best over the last 3 months. The strategy is very simple, but I have some questions about how Quantopian is behaving:

  1. I'm using daily mode and schedule_function(date_rules.month_end(), time_rules.market_close(hours=1, minutes=30)) and my function seems to run on the proper day, but when I look at Transaction Details, it shows trades for that day. For example, in the log output, order_target_percent() is called on 2003-07-31, but Transaction Details shows a trade on 2003-07-31. I thought that the order is supposed to execute on the next day? Also, in the log output, order_target_percent() is called on 2003-11-28, but the Transaction Details shows a trade on 2003-11-30 which is a Sunday.

  2. To rotate out of existing positions, I use order_target(stock, 0) and to rotate into the selection, I use order_target_percent(stock, 1.0), but I notice that this doesn’t seem to be using all the available cash. For example, on 2003-12-01, there is $587.72 available. Some days such as 2007-09-04 have $10,454.28 available which is a lot.

So my questions are: Why does this occur? What is the recommended way to deal with this?

Thanks.

6 responses

I accidentally posted this as a new post elsewhere. Intended as a reply. Anyways, I upgraded this to Quantopian 2 and added an additional "cancel open orders" for "stuck open orders". I imagine if pipeline was used for selection of the basket of stocks, it would do even better.

I disabled the "Don't do anything this month if we don't have all the data". I also added some stocks to the mix. Thought I'd share, because the results are pretty good. Props to the original poster above (Fizz Buzz). 95 something percent of the code is still what you did.

Added automatic spontaneous rebalance at start of algorithm, in case you start on a different day than the monthly rebalance day.

I added profit taking and auto rebalance when that happens.

Added minimally impacting Take Profit and Stop Loss triggers. Added numerous safeguards against going negative cash. Did some more clean up of the code, to my liking anyways. Added limits to buy and sell orders.

Thought I'd share this much longer backtest. I am currently using this version for live trading.