Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
[Bug Fix] Anomalous dividends in long-running backtests

Hey folks!

We've fixed a bug in Zipline, our backtesting engine, that was causing dividends to pay out repeatedly in long-running backtests. Some members noticed that, when they ran very long backtests, they began to see anomalous cash flows entering their results. The root of the issue was that, when an asset was removed from the algorithm's universe, the dividend information was being left behind. If the algorithm then re-added the asset to the tradeable universe, the dividend information would be added a second time. This could happen repeatedly, stacking identical dividends on top of each other and causing an anomalous pay-out when the dividend's pay_date actually arrived.

Your algo would have been affected if:
1. Your algo frequently adds/subtracts assets from its universe
2. Those assets pay dividends
3. You run long backtests (long enough to add/subtract repeatedly)

An analysis run using our internal testing harness suggests that only ~1% of backtests were impacted by this issue, and most of those were minorly impacted. The bug was caught because some members' algos traded symbols with very large dividends, and the duplication of these divdends was very noticeable. Thanks are due to Simon Thornington, Mingran Wang, and others for noticing these anomalies and sharing their findings with us.

We've fixed how Zipline handles the removal of an asset from the universe, and this issue should no longer be present in newly-generated backtests.

I was a little bit bummed when I figured out this bug - I hated that we'd had a bug like this for so long and not noticed it. But talking about it with other people here at Quantopian, I was cheered up. They reminded me that the backtester is very good, and every time we find a bug like this, it gets better. We're finding these bugs because the backtester is being used and scrutinized by thousands of people. We've got more than 4 million years of backtesting already done. So yes, I hate this bug, but on the other hand, we're making a great backtester even better. It's good improvement.

Separately, I've dug into a number of underlying data issues that were causing problems with splits and dividends. We have corrected a number of splits and dividends that were not properly rendered. The list of those fixes is below:

Splits:
SID 34010 - COV - Should have been 1:1 (1:100, 100:1) on 3/21/11
SID 25805 - TZOO - Should have been 1:1 (1:25, 25:1) on 11/7/13
SID 6900 - SJI - Should have been 2:1 on 5/08/15
SID 32269 - DDM - Should have been 2:1 on 5/20/15
SID 32270 - SSO - Should have been 2:1 on 5/20/15
SID 32272 - QLD - Should have been 2:1 on 5/20/15
SID 33209 - SAA - Should have been 2:1 on 5/20/15
SID 33262 - ROM - Should have been 2:1 on 5/20/15
SID 33265 - UYG - Should have been 2:1 on 5/20/15
SID 33270 - RXL - Should have been 2:1 on 5/20/15
SID 38533 - UPRO - Should have been 2:1 on 5/20/15
SID 38583 - CSM - Should have been 2:1 on 5/20/15
SID 39215 - UDOW - Should have been 2:1 on 5/20/15
SID 39216 - UMDD - Should have been 2:1 on 5/20/15
SID 39479 - BIB - Should have been 2:1 on 5/20/15
SID 47404 - SYTL - Should have been 2:1 on 5/20/15
SID 39129 - IBME - Should have been 2:1 on 5/21/15
SID 39132 - IBMF - Should have been 2:1 on 5/21/15
SID 18417 - EXPO - Should have been 2:1 on 6/05/15
SID 40515 - TVIX - Should have been 1:10 on 6/23/15
SID 19894 - INFY - Should have been 2:1 on 6/25/15

Dividends:
SID 34977 - BCOM - Should have been $.97 on 12/03/13
SID 26578 - GOOG_L - Should have been ex_date of 4/03/14

Most of these were found because members noticed anomalous behavior in their backtests. If you notice any anomalous dividends, splits, or other behavior, please let us know!

-James

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

1 response

Thanks, I am very happy to see this fixed!