Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Anomalous EDV ordering behavior

In browsing the work of others I may have encountered a bug related to the ordering of EDV (issue 1)
The presence of a correlated anomaly (issue 2) suggests that a broader algo/backtester problem may exist.

Issue 1: observed anomalous ordering behavior
After years of apparently correct orders the following occurs
2013-05-02 No position in EDV
2013-05-03 Buy order for qty_A shares of EDV
2013-06-03 Sell order for qty_A shares of EDV
2013-06-04 Sell order for qty_B shares of EDV

Issue 2: The leverage may differ significantly from 1.0 at two specific times
June 2009 Leverage = 1.06 after selling EEM and buying IEV
October 2010 Leverage = 0.95 after selling EDV and buying EEM

This issue is observed in test cases in which Issue 1 is present

Conditions under which problems are/are not observed:
- common: $100000 initial cash, daily execution
- present with start date of
- 1/1/06
(qtyB=1239 on 6/3/13), (qtyB=1233 on 8/4/14)
leverage = 1.06 in June 2009, leverage = 0.95 in October 2010
- 1/1/07
(qtyB= 696 on 6/3/13), (qtyB= 396 on 8/4/14)
leverage = 1.06 in June 2009, leverage = 0.95 in October 2010
- 1/1/08
(qtyB =133 on 6/3/13)
leverage = 1.06 in June 2009, leverage = 0.95 in October 2010
- not present with start dates of
- 1/1/09, 1/1/10, 1/1/11, 1/1/12

Base algo:
- Ed Bartosh's "more pythonic" 12/28/2013 implemention of
https://www.quantopian.com/posts/global-market-rotation-strategy-buggy-implementation

Modifications made to base algo:
- added leverage tracking (handle_data)
- added 0.995 multiplier to cash to reduce tendency to be cash negative (handle_data)
- dropped ILF and EPP from stock list (initialize)

2 responses

Substituting TLT for EDV gives similar overall results, but neither issue is observed.

I suspected that the problem might be caused by the old batch method.
Updated code to use history and got the same results when using EDV vs TLT.

Changing from EDV to TLT again I was able to stimulate anomalies at other times
For example:
Start: 1/4/2011, Daily execution
9/13/2012: holding qty_A of IEV
9/14/2012: sell order for qty_A of IEV
9/17/2012: sell order for qty_B of IEV
The above is seen with initial cash of $900k, $1M, $1.5M
It is not seen for initial cash of $100k, $300k, $600k, $800k