Back to Community
New Trading Guard to Exclude Leveraged ETFs from Algo Universe

In the Quantopian Open, leveraged ETFs are not allowed in the algorithm's universe. To help you avoid them, we created a trading guard that will prevent your algorithm from ordering these securities.

In the initialize() function, you can add in the new trading guard: set_do_not_order_list(security_lists.leveraged_etf_list). The list is maintained by Quantopian, and will be modified as securities come and go on the exchanges. It's point-in-time and becomes active in the backtester on January 23, 2015. You can read more in the documentation.

You can also pass a custom list as a parameter to set_do_not_order_list. This will prevent your algorithm from ordering any security in the tailored list.

Below is an example of an algo that checks if the trading guard is violated before placing orders.

Clone Algorithm
95
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: 54eb808aa638a10f0717f1f3
There was a runtime error.
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.

8 responses

Hi - is there anyway to expand the security_lists? Currently only seems to leveraged etf's only. Can it be expanded to include volatility etfs and other various etfs based on investment strategy/geography etc. Currently I manually omit them from my universe but was wondering if there is a more effective method.

http://etf.stock-encyclopedia.com/category/volatility-index-(vix)-etfs.html

Is there a way to drop security_lists.leveraged_etf_list from the universe itself.

This will also exclude them from the algo crunching their numbers before coming to
ordering stage.

I posted this request earlier

If we have an algo running in the contest, should we stop the algo (after hours) to add this line?

It seems that adding set_do_not_order_list(security_lists.leveraged_etf_list) in initialize() does not protect the algo from trading leveraged ETFs. I added it as the 1st line of initialize() and my algo is still DQ'd from contest. While fetcher-based algos are no longer accepted after this month, my submission uses fetcher and sets the universe with that data - perhaps something like Yagnesh's idea needs to be implemented to keep such algos from being DQd?

You would need 2 parts in your code to protect against trading leveraged ETFs:

  1. Set the trading guard (line 7 in the example above)
  2. Check if the security is a leveraged ETF before trading (line 14 in the example above)

Yagnesh, I had missed your suggestion earlier! I like that idea and we'll see how to add it in the API.

@Alisa,

This solution does not seem to be working well. It just throws an exception and does not let the backtest complete. It would be better if the rule actually just skipped over the security and allowed the backtest to complete. Can you confirm this is how it is currently set up to work?

Here is the exception:
TradingControlViolation

There was a runtime error on line 136.
Order for -2532 shares of Equity(39898 [GASL]) at 2016-01-04 14:31:00+00:00 violates trading constraint set_do_not_order_list.

John, if i'm reading this correctly, you can replace "log.info("%s is an over-leveraged ETF, not purchasing" % (sec.symbol)))" with "pass" and that should just quietly ignore the problem.

I wrote a CustomFactor to exclude leveraged ETFs from pipeline results. Now when we are in Q2 and there no longer is universe this (or similar solution) is probably optimal;

https://www.quantopian.com/posts/how-to-exclude-leveraged-etfs-from-pipeline-results