Introduction
In this research post, we examine a popular momentum strategy for intraday traders, the opening range breakout. To diversify our portfolio and reduce risk, we apply the strategy to a universe of liquid US Equities that are experiencing abnormally large trading volumes. The results show that the strategy outperforms buy and hold, achieving a 2.4 Sharpe ratio and a beta close to zero. The algorithm we implement in this post is a recreation of the research done by Zarattini, Barbon, & Aziz (2024).
Background
The opening range breakout strategy is a momentum strategy where we examine the asset's price action during the first n minutes of the day. If the price increases at the start of the day, we enter a long position when the price breaks above the highest price of the opening range. Conversely, if the price decreases during the start of the day, we enter a short position when the price breaks below the lowest price of the opening range. In this strategy, we use an opening range duration of 5 minutes.
Stocks in Play
We apply this strategy to a universe of assets to increase diversification and reduce risk. The universe consists of the 1,000 most liquid US Equities that are trading above $5/share and have an Average True Range (ATR) > $0.50. We then trade the 20 stocks that are most “in play,” meaning they have abnormally high trading volume, probably from some positive or negative catalyst. To quantify the stocks that are the most “in play,” we divide the asset’s volume during the first 5 minutes of trading activity in the current day by the average trading volume during the first 5 minutes of trading activity in the previous 14 days.
Risk Management
After one of the stocks in play breaks out of its opening range and we enter a position, there are two cases for exiting the position. In the first case, the momentum continues throughout the rest of the day, and we exit the position at close with a profit. In the second case, the stock reverts, hits our stop loss, and we exit the position before the market closes with a loss.
Stop Loss Placement
There are many techniques for placing a stop loss. In this strategy, we place the stop loss as a function of the entry price and the 14-day ATR. This technique means we apply wider stop losses to assets with greater volatility.
Position Sizing
The trade quantity is set so that if the stop loss is hit, we lose 1% of the portfolio value allocated to the asset. To reduce concentration risk, we limit the position size of each trade so that the weight of each asset doesn’t exceed the weight we would give the asset in an equal-weighted portfolio.
Implementation
To implement this strategy, we start by adding the universe of US Equities in the Initialize method.
_universe = AddUniverse(fundamentals => fundamentals
.Where(f => f.Price > 5 && f.Symbol != spy)
.OrderByDescending(f => f.DollarVolume)
.Take(_universeSize)
.Select(f => f.Symbol)
.ToList()
);
For each asset that enters the universe, we create a SymbolData object. At 9:35 AM, in the OnData method, we select the stocks in play and look for entries.
var filtered = ActiveSecurities.Values
.Where(s => s.Price != 0 && _universe.Selected.Contains(s.Symbol)).Select(s => _symbolDataBySymbol[s.Symbol]).Where(s => s.RelativeVolume > 1 && s.ATR > _atrThreshold)
.OrderByDescending(s => s.RelativeVolume).Take(MaxPositions);
foreach (var symbolData in filtered)
{
symbolData.Scan();
}
The Scan method uses the opening range bar to determine the stop price for the entry and exit orders.
if (OpeningBar.Close > OpeningBar.Open)
{
PlaceTrade(OpeningBar.High, OpeningBar.High - _stopLossAtrDistance * ATR);
}
else if (OpeningBar.Close < OpeningBar.Open)
{
PlaceTrade(OpeningBar.Low, OpeningBar.Low + _stopLossAtrDistance * ATR);
}
The PlaceTrade method determines the trade size, places the entry order, and records the stop loss price.
var quantity = (int)((_stopLossRiskSize * _algorithm.Portfolio.TotalPortfolioValue / _algorithm.MaxPositions) / (entryPrice - stopPrice));
var quantityLimit = _algorithm.CalculateOrderQuantity(_security.Symbol, 1m/_algorithm.MaxPositions);
quantity = (int)(Math.Min(Math.Abs(quantity), quantityLimit) * Math.Sign(quantity));
if (quantity != 0)
{
StopLossPrice = stopPrice;
EntryTicket = _algorithm.StopMarketOrder(_security.Symbol, quantity, entryPrice, $"Entry");
}
Results
We backtested the algorithm during 2016, the first year of the paper's backtest period. The benchmark is buy-and-hold with the SPY, which produced a 0.836 Sharpe ratio. In contrast, the opening range breakout strategy generated a 2.396 Sharpe ratio and a -0.042 beta. Therefore, the strategy outperformed buy-and-hold.
To test the sensitivity of the parameters chosen, we ran a parameter optimization job. We tested opening range durations of 5 to 25 minutes in steps of 5 minutes, and we tested universe sizes of 500 to 1500 US Equities in steps of 250. Of the 25 parameter combinations, 17 (68%) produced a greater Sharpe ratio than the benchmark. The following image shows the heatmap of Sharpe ratios for the parameter combinations:
The red circle in the preceding image identifies the parameters we chose as the default parameter for the strategy. We chose an opening range duration of 5 minutes because it was the best-performing duration of all the intervals tested by Zarattini et al. (2024). We chose a universe size of 1,000 because it was a round number that was large enough to diversify the strategy across many assets yet small enough that the backtest could run in under 10 minutes.
All of the parameters in this implementation match the parameters selected by the original authors. The only exception is the size of the universe. Zarattini et al. (2024) use a universe of 7,000 US Equities. However, the preceding optimization result shows that any universe size we selected produces a Sharpe ratio above 2, outperforming the benchmark.
It seemed odd to filter the ATR according to an arbitrary absolute value when the price of the stocks in the portfolio can be at greatly different scales. To ensure this parameter ($0.50) was not a cherry-picked value, we ran an optimization to test the sensitivity of the strategy to the ATR value. We tested $0 ATR to $2 ATR in steps of $0.25. We discovered all of these ATR values outperformed buy-and-hold, with Sharpe ratios ranging from 1.5 to 2.7.

In addition to testing the sensitivity of ATR dollar values, we adjusted the filter to select stocks that had an ATR above 1% of the asset's price, effectively making the filter unit-less. With this adjustment, the algorithm still produced a 2.237 Sharpe ratio and a 97% Probabilistic Sharpe Ratio.
References
- Zarattini, Carlo and Barbon, Andrea and Aziz, Andrew, A Profitable Day Trading Strategy For The U.S. Equity Market (February 16, 2024). Swiss Finance Institute Research Paper No. 24-98, Available at SSRN: https://ssrn.com/abstract=4729284 or http://dx.doi.org/10.2139/ssrn.4729284
Sylvain Thibault
Great post, would be great to have the equivalent Python code.
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Petr Zurek
How does it perform from 2016 - 2024. Oh wait, I can test it myself ;-)
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Derek Melchin
Here is a Python implementation of the strategy. It's not exactly the same as the C# version above, so expect slightly different results. For instance, this version doesn't have the ATR filter and it relies on both daily and minute resolution data subscriptions, so indicators may not be accurate. For the most accurate results and execution speed, use the C# version above.
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Enjolras Leigh
The backtest doesn't look good for other years. Does it overfit?
Why so many KOL are teaching this pattern? did they do the backtest?
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
AleNoc
Thank's for the post, I was just trying to implement this strategy it in these weeks :) ; any further suggestions regarding order execution with possible slippage in real trading?
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Jack Pizza
thing is how to get these trading costs under control…. 25% that's only trading 6 symbols….
You can argue the fees are covered if IBKR gives you price improvements, or can use a free broker that will probably get you worst fills… so you end up in the same boat.
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Yuri Lopukhov
This is my attempt at replicating it in Python, it is close, but not as good. Upon closer look, ATR in Python are 3x lower or so, also, on first entry ATR has ~7k samples, this looks insane for daily indicator. In C# code it has only 33 samples, which looks correct to me. It looks like for some reason it is being warmed up with minute resolution bars instead of daily. This looks similar to this bug I necountered before: IdentityDataConsolidator Does Not Handle Fill Forward Correctly · Issue #8392 · QuantConnect/Lean Or maybe I did something wrong…
Because of this, stop loss is too close and triggers far too often. Workaround shouldn't be too difficult, I just won't work on it today…
Backtesting time of Python version is 1588.03 seconds vs 730.75 seconds of C# version on B2-8 node. Definitely use C# for optimization or backtesting on larger date spans.
Overall, strategy looks good to me as long as the market is not crashing. Maybe add some filters to detect that. It has low win rate, but high profit ratio to accomodate for that. Stop loss triggers for most of the trades. Perhaps there is room to improvement in symbols selection, entry orders or risk management…
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Yuri Lopukhov
I actually found a mistake in my code, here is a fixed version. It's almost a match with C# version, except its a little bit better )))
It also took 1171.79 seconds vs 1588.03 from the previous Python version…
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
.ekz. INVESTOR
Great to see this! i actually worked on this for python some months ago but it didnt seem to work too well on a single symbol so I doubted their reserarch was credible. Now i see i was wrong and i should i have tried harder :)
My goal was to create a system that uses the proven ORB entry, but trades options instead, based on IV Rank and Gamma exposure. I believe there is some alpha there.
Now i can do actually give my goal another shot. Thank you Derek Melchin and Yuri Lopukhov .
Including a link to my technical spec if anyone wants to give feedback or try building it as well!
The GEX-Enhanced Opening Range Options Breakout Strategy
( Sorry I tried to delete previous post where i pasted the whole thing, but I was too late. someone from QC team please help cc: Derek Melchin )
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Jack Pizza
@yuri_lopukhov
I already tried with momentum filters, problem is the returns are just too painfully low already... adding that filter made them go down even more... as it would sit out of market. Also tried adding them individually to only trade long with positive momentum and only trade short with negative momentum same thing.
next step is maybe trying an MA filter... but suspect same results...
I tried hard coding MEGA stocks META, NVDA Ect. completely crashes in 08'
Also noticed if you raise the filter to stocks > $50 performance goes down the can too, so it seems like there might be some sort of bias because out of a universe of 1000 stocks there is plenty to choose from, so starting to think performance has more to do with the actual selected stock vs all the ATR selection process.
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Jack Pizza
or i guess ATR makes sense with smaller stocks, as if it increases that much, it means some major news has happened and it will effect it more profoundly than say a mega cap… not sure.
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Jack Pizza
Also completely collapses during dot com, for some reason it does decent in 07-08, and only around a 10% DD during covid…
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Mark Kust
Has anyone tried the contrarian trade? For example, when a stock is identified as having a long opening range breakout, flag it for shorting once it reverses below that same level. Vice versa for short opening range breakouts. The fact that the algorithm as written has a 17% win rate (83% loss rate), kind of makes this the obvious follow-up. Would then set the stop-out level to 1 ATR above the entry (and vice-versa for shorts). If no one has tried this yet, I may go ahead and implement it. Obviously, I don't know that this will work, but can't help thinking that I'd like to see it.
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
AleNoc
Which is the minimum RAM needed to deploy live this code? It could be nice to implement some control also to check if orders became invalid and not accepted by the broker, for example Alpaca in paper trading rejected me some stop orders as “Wash trade” invalidating the strategy
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Yuri Lopukhov
Just a heads up: this condition is really not working well on resolution lower than minute and most likely in live deployments:
Basically, on every new piece of data in this minute it will place entry orders. On live instance I believe it will run for every new group of ticks…
Easiest fix would be to add a variable to check if entries were already placed today and reset it at the end of the day or on the beginning. I might share updated C# code a bit later (not really working with Python version since C# is faster and most likely requires less RAM, which is important for live instance…)
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Yuri Lopukhov
Here is an updated C# version, also added some extra features and plots
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Projectedxyz
Given the fees, this strategy seems tailor made for TradeStation $0 commissions for equities, no?
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Yuri Lopukhov
Ok, so I've identified an issue with transferring backtesting results to live trading:
We place stop loss order after entry stop order is filled. In backtesting (or live trading with QC paper account) with minute resolution this means that stop order will be placed on the next minute after entry order is filled. In real-time or on lower resolution, e.g. second/tick, stop order will be placed as soon as entry was filled, so it can be on the next tick or second.
So for example, entry order may be filled at 9:35:01, and in real-time stop order will be placed at that time, while in backtesting it will be placed at 9:36:00. This creates quite a difference between backtesting and live trading.
There are two solution I can see here:
Any other thoughts?
P.S. I was able to run C# version on lowest tier node with 500 securities in universe with minute resolution and with 250 securities on second resolution. It may run out of RAM during warm up, but on the next attempt it usually succeeds.
P.P.S. if anyone feels risky, they can unleash full leverage by changing 1m to something up to 4m in this line:
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
AleNoc
In the backtest we could use something like this in public override void Initialize() to boost performance with seconds resolution:
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Lars Klawitter
Hi all,
Happy new year and many thanks to Derek and Yuri for the great work!
Having played with Yuri's implementation (both the python version and also the most recent C# version for performance reasons), I noticed that the risk adjusted returns increase significantly with larger universe sizes and with shorter opening ranges.
A universe of 2000 and openingRangeMinutes as short as 1 minute does really well:
This was based on a 2020-2022 three year backtest, but the above pattern (larger universeSizes and openingRangeMinutes of 1 or 2 minute doing significantly better than longer ranges and smaller universes) is consistent over all backtest periods between 2010 and today that I tried.
An L2-4 node will happily run a 2000 Universe.
The most significant improvement though, comes from the shortening of the openingRange to just one minute, which would make sense considering that both algorithmic trading and MOO orders would cause a lot of the breakout momentum described in the paper within the first minute after market open.
I'm paper trading with this set of parameters right now, as I'm not sure if this assumption holds up in reality…
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Nathan Swenson
Getting out of the Market early is more of a conservative move rather than aggressive such as going to war. I think the point of it is to take the least risk possible. The outer 1% of std deviation if a very high standard to meet, so I can understand why Peter made it that way. If you want multiple confirming signals, then you likely can't use 1% outliers.
The In and Out does very well with 3x leveraged funds because it is overly cautious, generally exiting the market too early, but safetly for the most part. So while you don't get all of the move, you could perhaps take greater risk for the shorter period you are in. The "jitter" from only 1 signal appears valid as the Out holding have done well, at least in the In sample data we've tested. That being said, it's difficult to watch this market zoom higher while sitting in Out holding since 10/6. In reality this is our first real "Out of Sample" data and it's not looking good so far but who knows what happens in the coming weeks. Everyone is predicting all time highs. We shall see.
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Goldie Yalamanchi
Removing SHY from 2020 makes 2020 and possibly 2020+ trade normally and perform normally -- until such time as we can comment back in the SHY indicator.
If we are trying to "ace" the backtest then keeping SHY in always looks good until of course late 2020 when the algo stops trading in October.
But credit where credit is due... T Smith multiple signals (5 of 8) approach still did well with the Qual-Up universe approach from 2014-2018 as well. During those years by commenting out SHY in the original IN/OUT algo, the Qual-Up stocks didn't do well i.e. QQQ would have done well regardless during 2013-2018 because tech has been on a tear the whole past decard.
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Vladimir
Here is updated DUAL MOMENTUM IN OUT v2.1
I have changed line 97 to:
prices = self.History(symbol, period + excl, Resolution.Daily).close
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
EllaHamilton
Thx, nice one.
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Guy Fleury
@Vladimir, I go with Nathan's explanation. The strategy goes to the sideline at the first sign of trouble. You do not want to wait for a consensus since you are already dealing with ETFs.
Trading QQQ is like trading a market average surrogate. It holds the same shares as the NASDAQ 100 index as everyone knows. The top ten holdings (AAPL, MSFT, AMZN, TSLA, FB, GOOGL, GOOG, NVDA, PYPL, ADBE) account for 55% of QQQ. It should be view as one of the easiest stock selection you can make. Playing QQQ tends to dampen overall volatility. While using TQQQ puts volatility back into play and at a higher level with an expected beta of 3.0x. Therefore, you are playing QQQ on steroids which evidently brings in higher risk. The reason for “extreme” caution even if there is a cost to it.
This is not a game where we will fix things after we lose. So, we should first play safe whatever the performance level we are at. We might need to compromise like playing this strategy at a higher level but with other strategies in order to reduce overall volatility and drawdowns, or only use part of the available capital (say 10 to 20% as if on riskier assets).
In my previous post, the point was made that you could drop some of the signal components (3 out of 4) and it would increase overall performance. Well, here is another point of interest: self.INI_WAIT_DAYS. I see its use as a way to reduce whipsaws around the moving average crossovers. The original code has it at 15 trading days. No one questioned this as it was a reasonable assumption since there are indeed a lot of whipsaws near those crossovers. Removing it, for instance, making self.INI_WAIT_DAYS = 0, dropped performance considerably and thereby justified its use.
In my version of the program, if you set it to zero, you get a 62.68% CAGR. If you keep it at 15, you have a 97.84% CAGR. If you set it to 10, you get about the same result (97.82%). However, if you set it below 5, something like 2 or 1, you improve the picture considerably. The economic reasoning is simple. The wait days operate on a high decay function: e^(-0,5t). It might also suggest that whipsaws fade away rather fast near the crossovers. Also, by reducing the wait days, you are increasing the number of days the strategy is fully invested.
The table below shows the evolution of the strategy where only the wait days are changed from 15 to 0. I think that the chart speaks for itself. Changing a single number in the program can have a tremendous long-term impact. Note that this is close to a 6000% improvement going from zero wait days to one. Nothing else in the program was changed for these tests.
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Vladimir
Guy Fleury,
Looks like I saw a spreadsheet like above two months ago.
The only difference was Quantopian instead of Quantconnect.
But that not optimized strategy had a completely different decision-making structure:
-Consensus of individual signals.
-Far less degree of freedom.
-Three times fewer sources of information.
-Three times fewer variables.
-Static parameters.
Something like the one below.
In terms of total return, it exceeds the latest In_out_flex_v5 2020-12-16
BTW: What will be your decisions?
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Frank Schikarski
Hi there,
some comments regarding the trigger for in or out:
if (extreme[self.SIGNALS + self.PAIR_LIST]).any():
What if we would (a) keep calculating daily returns for our signals, but (b) do this for every hour with a rolling 24-hours window? This should result in 24 times more observations = increase our resolution, allowing to optimize the 1%, the lookback period and increase the "any" until we get some redundancy from our scouts. Keep exploring ;)...
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Vladimir
Here is the updated DUAL MOMENTUM IN OUT v2.2
-Based on In_out_flex_v5_try.
-Used exponential like smoothing on line 116-121
-Line 120 is commented out.
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Guy Fleury
@Vladimir, yes, as you say: "...the strategy had a completely different decision-making structure". You improved on that strategy design since... thanks.
Changing the number of wait days (self.INI_WAIT_DAYS) in the program is more like an administrative decision. The idea is not bad since we know there will be some whipsaws at crossover times. However, there was no need to wait more than one day or maybe two at the most.
It is not that surprising an observation. We want security, be decisive, and not be clobbered by added trading costs due to whipsaw after whipsaw for days after an exit, and yet, this says do wait but at most one day and probably no more.
Such a small decision with such an impact. You change a single number in the program from 0 to 1 and it increases performance by 5910%!
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
BukavuTrader
@Vladimir, Do you have one like that for FOREX?
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Vladimir
BukavuTrader,
Do you have one like that for FOREX?
Not yet, but you can try yourself.
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Guy Fleury
Some added notes. This trading strategy has shown that it could go quite far depending on some of its parameter settings, ETF selection, trading logic, and initial capital. Using 10k, 100k or 1 million is an administrative decision. The program will do its job either way since it is scalable (but up to a limit). It is a simple bond switcher based on QQQ, but it has interesting properties.
The max drawdown and overall volatility will be the same with either capital options. All you will be changing is the ongoing bet size. This will barely change the price at which a trade is executed. But will change the traded quantity. Increasing the capital ten-fold will increase the bet size 10-fold, and in turn, increase profits (losses) 10-fold. However, going for 10 million as initial capital will tend to make the strategy unfeasible since you might end up trading 175,000,000 shares of TQQQ on practically a weekly basis which is more than the average daily volume. So, there are practical limits to the strategy which will need to be addressed.
With 100k you can push the strategy beyond 1 B and with 1 M you can pass the 10 B mark. Almost incredible. However, this is achieved by taking on more risk, using 3x-leveraged ETFs which are also leveraged at 1.4x. Thereby pushing on the machine way beyond what the original design was. Of note, changing the wait days (self.INI_WAIT_DAYS) to 1 had a tremendous impact on overall performance, a real game-changer, and yet, just another administrative decision.
I have not touched risk reduction procedures yet. This comes at a later stage in my testing process. It is expected that by installing protective measures the overall performance will be reduced to some extent. But, I will know that after those measures are added. Meanwhile, I have other tests to make.
My version of this program is dealing with a 3.x leveraged QQQ surrogate (TQQQ). It is playing an index tracker but with 3.x the average market beta saying it swings more than QQQ which is itself an average market consensus equivalent.
In pushing further, the strategy reaches a performance plateau from which it starts breaking down. It does not blow up mind you. It simply trades less and less and thereby generates less and less suggesting not to go that far. But that should be expected. Knowing that the strategy has seen its own built-in structural limits, it is almost time to apply protective measures and scale it down to a more acceptable risk/reward level.
Here is my take. You PLAY the game for its long-term CAGR potential. Which trading methods will give you the highest return within your own trading constraints? Not somebody else's, but your own. We need to answer the question: will we accept 5% more on a temporary max drawdown for 5% more in CAGR? The decision has value and is based on the initial stake:
10k ∙ (1+0.30)^20 - 10k ∙ (1+0.25)^20 = 1,033,135
100k ∙ (1+0.30)^20 - 100k ∙ (1+0.25)^20 = 10,331,346
1M ∙ (1+0.30)^20 - 1M ∙ (1+0.25)^20 = 103,313,464
This should weigh in the evaluation of your acceptable risk/reward scenario. It can be a costly decision.
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Vladimir
Here is the updated DUAL MOMENTUM IN OUT v2.3
Based on In_out_flex_v5_disambiguate_v2.
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Simone Pantaleoni
Great idea Vladimir! I was working on a similar update on the INOUT algo, but you anticipated me! :P
Have you also tried to decrease further the "decay" value for the SELF.WAIT_DAYS variable, reducing the waiting to increase sharpe and return? (guess probably yes, isn't it?)
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Carsten
Vladimir as you requested.. :) was a bit trick, just happy to get it as a multi AlphaModel running. Its a super simplified version, but you can easily upgrade it. At the end it has much more lines than the normal version. It was quite trick to get the signal into the two AlphaModels. At the end I used ObjectStore. If someone has a simpler solution, with a global variable? please comment.
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Guy Fleury
@Vladimir, I like the behavior and equity line of version 2.3. Remarkable, and great numbers. I will try to find some time to look at it since I think there are things I will learn in the process. Thanks for sharing.
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Damiano Bolzoni
Guys, I really fell in love with this strategy (I actually started following the thread on Quantopian) and so ran some additional backtests taking into consideration several 5-year periods.
The strategy really shines during the 2008-2012 timeframe and then again in 2020. That's how it delivers 30% annual return. Take any other period of time and it will barely matches the returns of holding QQQ: I literally just finished a backtest between 1-1-2013 and 12-31-2019 and it's underperforming by nearly 10% overall.
If one substites QQQ and FDN with SP500 equivalents the same behavior can be observed, actually returns are even worse.
Am I the only one experiecing this?
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Simone Pantaleoni
Just tweeking the Waiting variable using a bigger decay, as suggested above to get slightly better returns and sharpe :)
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Carsten
Vladimir could you plese check again, should work now, the objektstore object was not created in the initialize, but it was yesterday on my disk as i was finding out how to impement it....
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Jack Pizza
FYI to make this more robust these same arguments were brought up in the old QT thread.
Not sure if this is implemented in this or not.
There should be a 3rd option or ultimate out where it just goes into cash or adding gold as a 3rd / 4th asset to rotate into.
Given at some point in time stocks and bonds might breakdown together.
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!