Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How to exclude leveraged ETFs from universe

Hi, I really like that Quantopian has this method to select symbols. However, I'm interested in participating in the Quantopian Open and that doesn't allow leveraged ETFs. However, I recognized my algorithm picking up Direxion 3x stuff. How could I exclude those?

32 responses

Yeah, compliance with this could be tricky:

The Participants' algorithm must not trade in leveraged ETFs, such as the Ultra S&P500 or Ultra Dow30.

And if you are talking about using set_universe, even if you manage to filter out any leveraged ETFs in backtesting, the universe gets updated periodically so leveraged ETFs could creep back in. It seems like Quantopian needs to supply an up-to-date list of the excluded sids (which they must be establishing if they are gonna enforce the rule):

import leveraged_ETF_list  

The list could be updated every night. Then, in the algo, the leveraged ETFs could be excluded from the list of securities to be traded.

Grant

I'm amused that I can't say "Grant. . . " or even "GrantK . . ."

Grant Kot! We've been kicking around this problem too. I'm curious - how did you algorithm start picking those up? Are you using fundamentals, or the DollarVolumeUniverse, or some other method?

Grand Kiehne: Yes, that is indeed a way to do it. It's pretty heavyweight and will take time to enter. I'm hoping to come up with something quick and dirty in the next day or two.

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.

I was using DollarVolumeUniverse, 98-100 percentile. I'm just trading technically.

Grant Kot,

I created what I believe to be a complete list of leveraged ETFs and attempted to trade them within a 95-100% dollar volume universe between 2011 and 2015. As you can see in my backtest, none of these securities were traded. Can you reproduce a case where you were able to pick up a leveraged ETF in your universe?

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.

Andrew, I changed line 8 to use stock.symbol instead of just stock.

I also humbly ask the Q team to make an explicit "banned list" for the Quantopian Open. Since you're talking about awarding what could be a decent chunk of change, you might want the disqualifying factors to be a lot more unambiguous.

TVIX is a leveraged ETN..... As of right now, I'm going to say that since it is not a "leveraged ETF", it is not banned. But that is only my interpretation....

Hi Andrew,

I searched through your list, and did not find SH, ProShares Short S&P500, which I had been considering a "leveraged ETF" even though it tracks SPY by -1X, and hence is a lowly inverse ETF. My thinking was that for SH, there is some behind-the-scenes effective debt, which presumably is the rationale of the rule prohibiting "leveraged ETFs."

So, rather than trying to refine the definition of "leveraged ETF" there just needs to be a definitive public list of excluded securities.

Regarding the mechanics of incorporating such a list, pasting a list, which can go out-of-date, into an algo is not the right solution. I guess I don't see what is so difficult about setting it up for import. Or are you thinking of putting it on a controlled site, and then perhaps fetcher could be used?

Grant

Also, it wasn't too clear on the documentation but what other methods/properties are available for the Security class? I'm also interested in testing out how my algorithms perform on a stock only universe, without ETFs. Maybe there could be a security_type and leverage property?

I assumed that -1x inverse ETPs were fine, and that the purpose of the rule was to preserve their own capital in the case that someone decided to take a flyer on thrice-leveraged investments in 3x "ultra" ETPs for an effective daily leverage of 9x, which might cause them to drop below their 90k stop before they can halt the algorithm.

@Grant Kot- Thank you for the bug fix. Glad you caught that!

@Grant Kiehne- We are not banning -1x ETFs and ETNs. While they do involve debt, these securities will not allow users to cheat the contest leverage limits.

We are working on an API change that will allow you to easily block leveraged securities from entering your algorithm's universe. Even as we periodically update our list of leveraged securities, all algorithms using this new exclusion functionality will be automatically compliant with future "do not trade" contest rules. There will be no need for you to provide and update a list of banned securities yourself.

Until this is done, we are providing you with a workaround using the list of securities we are currently using to screen contest entry trades for violations. This list will remain the same for the time being and any changes will be posted to this thread. See the algorithm below.

Thank you all for your feedback! Your comments help shape the future of the Quantopian platform.

Why not just count leveraged ETFs at using up 2x or 3x leverage respectively, just like real brokers do? Shouldn't be that hard to program and then users could just use the leverage function to make sure they're OK without worrying about a whole new function to check.
That aside, there is a rich set of opportunities in leveraged ETFs/ETNs, it seems rather shortsighted to arbitrarily exclude them since they can be legally traded just like any other stock and can make or lose money just like any other stock. The whole restriction makes even less sense when you consider the fact that it's OK to invest in FNMA, FMCC, GSAT, ODP ....all with betas greater than 3, but not a 2x or 3x S&P 500 fund which have betas of approximately 2 and 3 respectively (not exactly 2 and 3 because of the daily percentage change feature vs index tracking). If you were worried about drawdown risk and convinced that it is represented by leverage/beta, one would think you would restrict purchases based on beta, not some arbitrary measure of the internal leverage of an ETF? Just a reminder, beta is a measure of a security's volatility in relation to the market. A security with a beta of 2 would be expected to move 2% for every 1% move in the market. A security with a beta of 1 that used 2:1 leverage would also move 2% for every 1% move in the market. A security like FNMA with a beta of 3.5 will move 3.5% for every 1% move in the market, while a "competition restricted" 2X leveraged S&P 500 ETF like SSO will move only 2% for every 1% move in the market, which doesn't make much sense if you're trying to protect against drawdown. I'm not saying that its a bad idea to restrict high beta securities from the competition per se, it just seems you'd want to be consistent with it if you decided to go that route.

Kevin,
Thanks for your opinion.
Leverage and Beta are 2 separate things. Leverage, as in a 2x or 3x ETF is always present. It will be 2x or 3x today, and is 'guaranteed' to be as such at any point down the road per the mandate of the ETF provider (As well, in much of the fine print in the leveraged ETF prospectus, many only guarantee the 2x or 3x leverage over the course of a 1-day time horizon, anytime after that the leverage is a variant as close to the X they target in that single day. More details below.). A security like FNMA, FMCC, etc which has a beta of 3x, as you put it, is not always 3x, and in fact will oscillate between many values, from 1 to 3, to 4, back down to 2,etc.. Betas are very unstable for stocks -- as in they're ever changing and hugely dependent upon the lookback window you use to run the regression to compute the beta.

With regards to just allowing the leverage ETF's and providing a leverage factor attached to each security: It's actually a detriment to you as the investor to use a leverage ETF. There is lots of research that discusses how leveraged ETF's essentially decay away because of the mechanism used to implement the leverage (This is why they say they can only match the X leverage over a 1-day time horizon for many of these leveraged ETFs). Here are some of the google results regarding this: https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=leveraged%20etf%20decay

Given the consistent decay of these leveraged ETF's, if your trading system is telling you to enter them, you are always likely going to be better off to simply enter a position in the 1x underlying stock, index ETF, of which the leveraged ETF is based off. No need to suffer from the leverage decay if you can avoid it, is how I like to think about it.

So why are leveraged ETF's available? For the most part leveraged ETF's are likely best suited as hedging vehicles in non-margin, cash accounts where you can't go short, or you are working with a constrained amount of capital (ie: an IRA or something where you never deposit more money into it, or you can only deposit a maximum amount per year). In which case you could use a 3x short ETF to, for example, hedge your long stock exposure with one-third of the capital.

Hope that helps describe the thinking behind our restrictions.

-Justin

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.

Mr Campbell, was this list composed from perhaps these two lists?

http://etfdb.com/screener/#leveraged=3x
http://etfdb.com/screener/#leveraged=2x

I ask as then, knowing the source, we can build our own lists, and keep them up to date. If you have a different source perhaps you could share that.

I'm still perplexed about the rationale for excluding leveraged ETFs. As Andrew suggests above, the concern is over allowing "users to cheat the contest leverage limits." Justin comments "It's actually a detriment to you as the investor to use a leverage ETF." Or perhaps there is some underlying Quantopian angst, as Simon surmises, based on volatility, and the feasibility of applying the $90,000 limit on context.portfolio.portfolio_value.

Is it that the Quantopian backtester and simulated live trading are not yet sophisticated enough to handle leveraged ETFs? From Kevin's comment, it sounds like brokers have this figured out, and I see that Interactive Brokers (IB) has some special margin requirements for leveraged ETFs (http://ibkb.interactivebrokers.com/node/1124). If the backtester and simulated live trading matched IB's rules, wouldn't everything be copacetic? In other words, there would be no possibility of "cheating" if Quantopian simulations were more realistic, right?

Also, I'd be curious how Quantopian will implement the $90,000 limit. Will it be at IB, so that the instant the limit is reached, the positions would be liquidated (perhaps even looking at pre-/post-market and overnight portfolio values), or will it be on the Quantopian side, run as an algo, with minutely updates, orders cancelled at market close, and the first order delayed until 9:31 am? If the latter, there'd be some additional risk, I suppose.

I agree with you Grant. All my algorithms contains leveraged ETF as hedge or multiplier and as I really deploy them I make damn sure I protect them. These algo's need to contain risk just as much as other algo's that don't use leveraged ETFs. I would argue that one should exclude Netflix, Tesla as too volatile and a whole bunch of others like all the Gold Royalty firms as they are in fact a leverage stock on Gold...

I have decided not to compete and put my effort in profitable algo development... too bad as I would have liked to compete...

More info below regarding the ability to practically implement these arbitrage strategies because of them being consistently on the hard-to-borrow list, as well as the stock loan (interest rates) charged on the amount shorted (if in fact you do get the locate from a broker). An excellent write up on leveraged ETF strategies, as well as some of the many caveats to practically implementing them in real-live trading is presented here by the excellent research site CXO Advisory which has backtested and performed statistical significance testing on a multitude of strategies:

http://www.cxoadvisory.com/4246/short-selling/shorting-leveraged-etf-pairs/
http://www.cxoadvisory.com/20492/volatility-effects/returns-of-matched-long-and-short-leveraged-etfs/

Another point, I would like to state is that leverage, volatility, and beta are 3 entirely different beasts. Similar, but different. Leverage is stable (in a leveraged ETF, per the daily rebalancing defined by the ETF provider), beta and volatility are not and suffer from quite instability and regime shifts over time.

As well, here is some of my personal experiences research the ability to put these strategies on in previous work prior to joining Quantopian:

Yes, I totally hear you about these great stat arb opportunities available in these leverage ETFs in order to take advantage of the decay. In practice however I've found these strategies to be difficult to put on in a couple ways: 1) as a retail investor its virtually impossible to get a locate on any stock to short of an leveraged ETF, and very difficult to get a locate on the pair of them to put the arbitrage on for full effect. 2) as an institutional investor, if you are able to locate the leveraged ETF's to short, the prime broker will often charge fairly high interest rates on the stock they locate for you to short.

Have you had some good experience putting these trades on in real-time in a retail brokerage account, or in size perhaps at the institutional level? I know over the years prior to joining Quantopian, as a retail investor I have never had any luck getting locates on these leveraged ETF's in order to short them. Recently I've started looking at the short availability list that IB posts here, and I consulted it when thinking about rules for the contest: https://www.interactivebrokers.com/en/?f=%2Fen%2Ftrading%2FSearchShortableStocks.php%3Fcntry%3Dusa%26amp%3Btag%3DUnited%2520States%26amp%3Bib_entity%3Dllc%26amp%3Bln%3D

I can usually only find a handful of leveraged ETF's available to short, and many in very small size. As well, if you do get some stock to short, the broker can "buy you in" whenever they want, without warning in which case you can be short term exposed on the other leg of the arbitrage.

So since many of these strategies have some issues with scalability is 1 reason why we are disallowing them. However I will say, if brokers do start having greater supply available and making them easier to get short without paying exorbitant rates, it might become easier for us to start allowing them. From an operational perspective, currently we don't have a way to integrate stock loan availability in our backtester, or in the paper trading simulator. As well, we don't have a way integrate the stock loan interest rates that often vary wildly for hard-to-borrow securities -- they even vary wildly across different brokers, and even change intra-day at the same broker if the stock is really hard-to-borrow. If/when our papertrading platform can handle these details so as to mimick a more "real life" trading environment we will surely enable such additional aspects in future contests.

Would definitely like to hear more from you if you've had a strongly positive, consistent experience first-hand getting a locate on these ETFs to short, and if the borrow rates weren't prohibitive. It would definitely shed some light on it for me. As well would love to hear if anyone has put these trades on and did not experience the "buy-in" risk I describe above about the broker calling in your short in the middle of a trade.

I believe our best decisions can be guided by both data and experiences, so I'm always willing to revisit previous made decisions as either new data or new experiences come in to direct my views.

Really appreciate all this feedback -- keep it coming :)

Why all the angst? You don't walk into a Vegas casino and start trying to rework the rules of their games. "I don't like those single and double zero slots on the roulette wheel. If you won't remove them then at least add a double black and a double red."

Or imagine a fishing derby, "he who delivers back the most fish, at the end of the day, wins!" One guys uses a rod and reel, one guys uses dynamite. But what was the spirit of the competition? The test of fishing prowess, no? So such a contest needs strict rules to ensure that the skill of fishing is what is being judged here. The same could be said of this Q-Open.

In fact, if the judging of algorithmic merit were truly the goal here, and I think it is, then even more stricter rules should be in place.
• No use of leverage nor 2x and 3x ETFs.
• Set_universe use mandatory. [Or perhaps, a fixed list of securities -- all 2x EFTs...]
• A minimum number of traded securities per time frame.
• And all the other constraints already in place.

It's a pinewood derby: here's your block of wood, your wire axles and wheels.
!No grease. Final car must use all wheels, weigh at least 10oz. and be thicker than 1/2" in all areas. Let's see some great carving skills -- have at it!

(What's the limit to how many analogies can I have in one post?)

The difference from a casino is that the Quantopian folks are looking for our feedback on a Beta product and have so far been great about incorporating the good ideas and telling us why the bad ideas won't work. In addition, they're not the house, the market is. Their business model appears to be to find and back players that can beat the house. The game inside the game is just a clever way of doing this.
Just out of curiousity, if you're trying to maximize returns while minimizing volatility, as appears to be the goal here, why would you want to require a minimum number of trades per time frame? If strategy one with 5 trades can accomplish the same or better results as strategy two with 5000 trades, why would you throw strategy one out or think that it lacks algorithmic merit simply because it isn't engaged in frequent trading. In other words, I can duplicate the results of strategy two by doing strategy one plus a wash trade every day to meet a time frame trade minimum, but it doesn't have any more algorithmic merit than it had before.

The casino analogy was to point out that rules of the game are fixed. The next game might change, and sure, that's why I also have proposed alternate conditions.

Judging algorithmic merit, I'll admit, is a difficult task without the ability to peer into the code. If there really is no concept of divining out the best quantitative approach given consistent constraints, then there should be no constraints. Whatever a $100k account at IB can withstand -- let'er rip! "Show us the money!" The performance metrics will filter in/out those that, regardless of their market treatment, market selection or inherent (or hidden) risks, perform well. The Wild West of algo showdowns.

So maybe there should be two types of contest. A no hold's barred version and a conservative, narrowly defined version.

One of the concepts I think I was going for, with the restrictive, minimum number of securities idea, was that it's difficult to judge between luck and skill in such a competition. And, if you could, wouldn't you want to find a way to judge for skill and then pick the most skilled?

Hello Justin,

Thanks for the detailed feedback regarding the exclusion of leveraged ETFs in the Open. Some follow-on questions:

  1. Do you anticipate excluding leveraged ETFs from the Quantopian Fund?
  2. Under paper trading at Interactive Brokers (IB), are leveraged ETFs accurately simulated? In other words, are all of the unique pitfalls you highlight captured by IB with paper trading?

Grant

So my algo got cancelled supposedly because of using leveraged securities even though its not using any in the list above.

@Grant,
Response to your questions:

1) Yes, I do believe we would excluded them from the fund, unless the restrictions, or cost-prohibitive nature of them improve in the future. Leverage boundaries are something I intend to monitor very closely with the Q fund, and outside of the arbitrage opportunity aspects of leveraged ETF's I find no need for every using them to achieve desired exposure in an institutional portfolio. Again, I would only revisit the arbitrage opportunities, if the shares somehow became a) much easier to locate to short in size, b) less prohibitive short interest rates charged by the broker to clients when borrowing hard-to-borrow stocks. I don't see this aspect changing anytime soon, but I suppose it's possible.

2) I personally am not extremely familiar with IB's paper trading simulator, but my guess would be that they do not capture the unique aspects of shorting hard-to-borrow stocks either. But don't hold me to that :) I'll try to dig around IB's website this weekend to see if I can find if they describe the features of their live paper trading simulator. Otherwise, I'll see if someone else at Q knows the answer.

@Justin,

As I recall for the Fund, you'd require something like 6 months of a real money trading record, with the algo writer's own capital and trading in his own account. And then, if selected, the manager would have "skin in the game" for the Fund. So, if the leveraged ETFs really don't work, then it'll all come out in the wash. My thought would be to just let the managers manage and instead focus on ways to measure and monitor the risk. Otherwise, you'll be screening securities for risk until the cows come home, which should be the manager's job, right?

Grant

Reviewing IB's margin requirements I can see why leveraged ETFs are excluded from the competition (and also from the fund). One of the problems is the discrepancy between opening long, opening short, maintenance long, maintenance short and and end of day maintenance margin. They're all different. Add to this the additional margin, a multiplier for leveraged ETFs, and you end up with an ugly account management problem, closing of positions to meet margin, or the influx of cash from some other account.

Trying to piece these together, (maybe others can confirm or refute my findings):
Assuming a $100,000 account:

Non-leveraged security:
• Buy 1000 @ $100.00 -- initial margin: $25k, eod margin: $50k
• Buy 2000 @ $100.00 -- initial margin: $50k, eod margin: $100k
• Buy 3000 @ $100.00 -- initial margin: $75k, eod margin: $150k (Boink, problem. Margin Call!)

Leveraged 2x security:
• Buy 1000 @ $100.00 -- initial margin: $50k, eod margin: $100k
• Buy 2000 @ $100.00 -- initial margin: $100k, eod margin: $200k (Boink, problem. Margin Call!)

The 3x ETFs are even more problematic. Not to mention short positions and the strange margin calculations therein.

Why the Q-Open even allows leverage up to 3 times? I can only guess they've got such a large master account open at IB that IB will let them float a, per client account, extra EOD margin of $50k.

https://www.interactivebrokers.com/en/?f=margin&p=stk

I'm pretty sure pattern day traders can get 4x leverage with retail margin accounts?

If shorting leveraged etfs is the real problem why not preventing that. Since the interest is prohibitive anyway. So allow leveraged ETFs when Algos has long only on, else not. Very easy to check.

My intent was to try and illustrate the pitfalls with any side taken with 2x and 3x ETFs. If the initial and EOD margin were the same, so that positions held over night were the same as initial positions, then there would be no margin calls at the end of the day. (A PDT could never stipulate that all positions are closed at EOD.) If you could buy or sell it, then you should be good to go (barring obvious price moves against you of course). But they're not the same, and so it raises an account maintenance problem.

Hi,

I've been working on an implementation of this, and I have a github pull request open for zipline to add it. The change introduces a directory structure for storing point-in-time history for any list of securities, so that a list can be referenced by name in your algo, but behind the scenes is dynamically updated to reflect the knowledge of the list over time. The primary use cases are:

# add a trading guard that will raise an exception if a leveraged etf is ordered  
set_do_not_order_list(security_lists.leveraged_etf_list)

# code a check to avoid ordering a leveraged_etf  
if stock not in security_lists.leveraged_etf_list:  
    order(stock, 100)  

The leveraged_etf_list is the first list defined. The directory structure is list_name/knowledge_date/symbol_lookup_date/[add delete], where add and delete are data files with one symbol per line. Knowledge date reflects when the add/delete changes to the list will be applied in a backtest. Symbol lookup date is used to resolve the symbols in the files back to sids (that part is quntopian only, zipline just uses the symbols ). You can browse the leveraged_etf_list on github here: https://github.com/quantopian/zipline/tree/dnt_list/zipline/resources/security_lists/leveraged_etf_list/.

Maybe the community will contribute other useful PIT lists of stocks in the future.

thanks,
fawce

p.s.
If you're curious, here's the implementation of the list object: https://github.com/quantopian/zipline/blob/dnt_list/zipline/utils/security_list.py

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.

The very most useful would be point-in-time index constituents, but I wonder if that would violate some copyrights of index providers.

Hi guys, great posts.
Just a simple question: is there a way I can use leveraged ETFs in my backtesting/trading algos or NOT?
My system allows their usage (i.e TNA, TQQQ, ...) so would like to know before start writing my functions.
thanks in advance

You can use them, but any such algorithms will not be eligible for the Quantopian Open contest.

Simon, thanks