Quantconnect's Idea Stream posted an interesting video on YouTube about Traunch Rebalancing Risk Parity a few months ago.
https://www.youtube.com/watch?v=q1VjM1nHPfE&list=PLD7-B3LE6mz7_H1xzHiy1J8whTgnQK7nJ&index=7
The Traunch Rebalancing Risk Parity strategy rebalances a 1/12 of the portfolio monthly to maintain a 60/40 between stocks and bonds regardless of how the market is moving.
This algorithm uses Parabolic Stop And Reverse to adjust the ratio of stock and bonds depending on how the market is moving on a month by month basis. The alpha model uses the Parabolic SAR to either emmit bull or bear insights:
if self.algorithm.Securities[str(self.risk)].Price > self.psars[str(self.risk)].Current.Value:
return self.bull_insights
elif self.algorithm.Securities[str(self.risk)].Price < self.psars[str(self.risk)].Current.Value:
return self.bear_insights
I would appreciate any ideas or thoughts on this algorithm.
Derek Melchin
Hi Nibraas,
Great work on this strategy!
There are a few changes we could make though.(1) When setting a custom fee model for securities in a universe, we can use
class MyAlgo(QCAlgorithm): def Initialize(self): ... self.SetSecurityInitializer(self.CustomSecurityInitializer) def CustomSecurityInitializer(self, security): security.SetFeeModel(ConstantFeeModel(0))
(2) In the alpha model's Update method, we can access the current price of a security with
slice[self.risk].Close
instead of
self.algorithm.Securities[str(self.risk)].Price
With this change, we no longer need to save a reference to algorithm and follow the separation of concerns design principle.
(3) Instead of creating a dictionary of PSAR indicators, we only need to setup a PSAR indicator for QQQ.
See the attached backtest which implements the fixes above. Going forward with development, the PSAR indicator needs to be manually warmed up. During the first rebalance, the indicator is not ready. Refer to our documentation for assistance.
Best,
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.
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.
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!