Here is my implementation of Garry Antonacci's Dual Momentum GEM strategy, with an emphasis on simplicity. Comment, discuss, improve...
QUANTCONNECT COMMUNITY
Here is my implementation of Garry Antonacci's Dual Momentum GEM strategy, with an emphasis on simplicity. Comment, discuss, improve...
Hi Juhwan,
Implementing this re-entry logic in the alpha model violates the separation of concerns design principle. Instead, we can accomplish the same thing by utilizing a custom risk management model. The risk management model below liquidates securities that experience a drawdown >=5%. When a security is liquidated, the risk management model keeps the PortfolioTarget value at 0 until 5 days have passed.
class MaximumDrawdownPercentPerSecurityCustom(RiskManagementModel):
def __init__(self, maximumDrawdownPercent = 0.05, reenter_after_days = 5):
self.maximumDrawdownPercent = -abs(maximumDrawdownPercent)
self.liquidated_dates_by_symbol = {}
self.reenter_after_days = timedelta(reenter_after_days)
def ManageRisk(self, algorithm, targets):
symbols_to_pop = []
for symbol, liquidation_date in self.liquidated_dates_by_symbol.items():
if algorithm.Time - liquidation_date >= self.reenter_after_days:
symbols_to_pop.append(symbol)
for symbol in symbols_to_pop:
self.liquidated_dates_by_symbol.pop(symbol, None)
targets = []
for kvp in algorithm.Securities:
security = kvp.Value
pnl = security.Holdings.UnrealizedProfitPercent
if pnl < self.maximumDrawdownPercent or security.Symbol in self.liquidated_dates_by_symbol:
# liquidate
targets.append(PortfolioTarget(security.Symbol, 0))
if algorithm.Securities[security.Symbol].Invested:
self.liquidated_dates_by_symbol[security.Symbol] = algorithm.Time
return targets
See the attached backtest for a full example algorithm. Also, consider reviewing our documentation on risk management models.
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.
Filib Uster
Here is an updated version of the code, without all the obsolete lines:
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.
Michael Manus
nicely done.
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.
Filib Uster
Here is a an updated version, using OnData to collect the data in real time instead of obtaining it through History each month. The algorithm curve has the same characteristics as in the previous version. The net profit, however, is significantly lower. Can anyone see why?
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.
Filib Uster
The only obvious difference to the previous version I can see, is the start-of-the month instead of the end-of-the-month rebalancing. How can that have such a huge impact on the overall performance?
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.
Hao Bin Zhang
Try testing it with each day. I'm assuming you will find the best performance around the middle of the month. I haven't tested it but I remember it from blogs.
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.
Filib Uster
There doesn't seem to be an easy way to schedule rebalancing for the middle of the month. Any idea, besides the obvious do-it-yourself-approach?
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.
Walter
The day on which the algo is rebalanced can have a big impact on returns. Look at this article:
Quantifying Timing Luck
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.
Tony Walker
There is quite a variation depending on the rebalance day. I tested every day of the month and day-2 shows the largest historical premium, day-17 is the worst performer.
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.
Walter
Any reason why those patterns should hold up going forward? If not, best best is to diverisfy across rebalance dates like in the article mentioned above.
Also take a look at this recent paper:
Global Equity Momentum: A Craftman's Perspective
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.
Stanley Yang
When I cloned the algo and downloaded the trades, it shows theWarning: fill at stale price in tag.
Does anyone know why this happened?
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.
Brian Christopher
Stanley Yang I had the same issue with one of my algorithms. If I remember correctly there's a mismatch between the time the rebalance component is firing and the resolution of the data updates. I'd have to check to see what I had to do to fix it but it might have been to change the symbol resolution for AddEquity.
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!