Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How to make sure your contest algo is hedged

In the July contest, we introduced a hedged requirement. To make the top of the leaderboard, you need to be hedged with longs and shorts (or entirely in cash) for every day of your contest backtest.

It is worth double checking your backtest to ensure you are hedged at the end of every day. Sometimes, an open order can leave your portfolio long or short only at the end of a day. These gaps in your algo's hedging can be hard to spot. I thought this code snippet might be useful to anyone trying to make sure they earn the hedging badge. Check out the attached backtest!

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.

10 responses

I noticed in the leaderboards for August that my hedged algorithm is not appearing with the "HEDGED" icon beside it.
The algo itself has not entered into any short positions yet, but it is designed to do so.

Apparently the system determines the type of algo by checking long/short positions?

What about our submissions? How was the hedged requirement checked? Obviously it must have been checked
during the contest submission?

My concern is, what if my algo runs to the end of the contest and chooses not to enter a short position?

Also, that same algorithm is showing 2 short positions entered today 7/8. I will check back to see if it updates to show a "HEDGED" icon. :)

@Andrew
Hi! Maybe having long and short positions means the algo is hedged, but I think that does not mean that it is close to being perfectly hedged. The long positions versus short positions ratio must be as close to 1 as possible. For that we need to set up some limits.
So, I think we need to use a condition like:

if Short_Exposure * 1.03 > Long_Exposure > Short_Exposure * 0.97:  
    print ('Your long vs short exposure is now hedged')  

I've developed my algos to have an exposure as close to 1 as possible, but now I have a question regarding the hedge "ratio" in the Q contest. How close to 1 does an algo need to be in the long/short exposure ratio in order to get a "hedge" badge? I may get the badge with only a 0.5 ratio?

Also, it would be great if we had something like:

context.account.long_positions_value  
context.account.short_positions_value  
context.portfolio.long_exposure  
context.portfolio.short_exposure  
context.portfolio.positions._long  
context.portfolio.positions._short  

Adrian Boca,
Ideally hedged portfolio should have zero return and zero volatility.
Is that you are proposing?
We are here to create algos which can make more money than CD's.
A lot of people on this site already forgot this and introducing new metrics like green and blue belts and now "hedge" badge.
You can make more money than CD's only when yours portfolio is imperfectly hedged has as high beta as volatility allows in bull market and as low beta as volatility allows in bear market.
Beta is not only the measure of risk it is the measure of opportunity to make money.

@Christian, we are only checking to see if your algorithm is hedged in its backtest. While we don't check your paper trading for hedging every day, it is a good idea to make sure your algo continues hedging as it live trades. For our fund, we are looking for algorithms that show consistent behavior between their backtest and paper trading.

@Adrian The current implementation of the contest's hedging requirement does not require perfect hedging. You only need one share of long exposure and one share of short exposure (or all cash) to be considered "hedged." We aren't calculating a hedge ratio. That being said, for our fund, we are looking for algorithms that are genuinely hedging. I'd encourage you to continue thinking about hedging as a way to lower your beta and volatility!

Could you explain what you mean by one share of long exposure, and one share of short exposure. what is one share?
You neglect to consider that an algorithm could short during the day, but cover the position before daily close. just checking the short/long ratio at close really says very little about hedging while the market is open.
I understand your point, but you would be best trusting beta, volatility and max drawdown instead of things like this.

But I do need to know the answer to the question so I can change my algorithm

Hi David,

So long as you hold a single long position and a single short position at every market close in your backtest, you will get the hedging badge. You are correct in suggesting that this is an imperfect way to check for hedging. It's possible that future iterations of the contest will include more stringent hedging requirements. But for this first pass, we chose to favor simplicity.

While going long-only or short-only during the day and then covering your position for just the last bar will allow your entry to pass the hedging the filter, such a strategy could be considered "gaming" and won't qualify your algorithm for consideration in Quantopian's hedge fund.

Hope that helps!

What about strategies that require some warm up due to model training or timing an entry into the market?