Hi Members, I am new to Quantconnect and trying my best to convert ideas into Algorithm Framework. As a learning experience, Below is my basic idea:
- Filter out mid cap stocks with universe selection
- Alpha generation based on fast/slow Moving Average Momentum + Volume + Price action. I Liquidate and re-balance my portfolio quarterly
- Portfolio construction takes the inputs from Alpha Model and converts into Targets. Here I have gone with custom Portfolio construction because:
- I want to have only 10 Stocks at max in my portfolio in a quarter.
- I wish to liquidate my entire portfolio quarterly
I am facing below issues regarding above approach, request members to suggest better implementation than what I have opted for to solve these:
- Question 1: Could not use Equal Weighted Portfolio Construction Model(with 0.1 weight) as all 10 of my Insights are NOT generated at the same time/day, I am waiting for right price action of my candidate before deciding to add it as part of portfolio, so Insights are generated based on it. For example, among filtered candidate in the universe/criteria, I may enter 2 on 2nd Jan, while 3rd and 4th candidate I will buy on 10th Jan.
Solution I did: Created custom portfolio construction model and returned targets from CreateTargets function whenever I receive them, kept one variable to track how many stocks I hold in my portfolio to have max count as 10. - Question 2: Could not re balance/liquidate all my portfolio quarterly in my custom portfolio construction model. I tried many ways to achieve it :
i.passed re-balance function while creating instance of my custom portfolio construction:
self.SetPortfolioConstruction(MyCustomWeightingPortfolioConstructionModel(self.shallRebalance))
and called it like below:
def __init__(self,rebalance=None):
super().__init__(rebalance) # not working
if rebalance is not None: # not working either
self.SetRebalancingFunc(rebalance)
ii.I tried to define IsRebalanceDue manually, but seems it's not being called at all:
def IsRebalanceDue(self, insights, algorithmUtc):
if self.rebalance is not None:
return self.rebalance(algorithmUtc)
return True
Solution I did: After many attempts, I am doing it now inside OnData:
def OnData(self,slice):
if self.Time < self.rebalanceTime:
return
else:
#till found better place, liquidated from here
self.Liquidate()
self.rebalanceTime = Expiry.EndOfQuarter(self.Time)
- Question 3: Where shall I keep the track of re-balancing logic to achieve both: avoid code repetition and adhere to separation of concerns methodology? Currently I need to keep it at multiple places :
i.While universe selection to return Unchanged universe if same quarter
ii.in OnData function to check if to Liquidate portfolio on quarter end
iii.I need it in Alpha creation to modify weights if we are close to quarter end
Louis Szeto
Hi Log Up
Best
Louis
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.
Log Up
HI Louis Szeto thanks for the reply.
Louis Szeto
Hi Log Up
Sometimes, the same security could stay in the universe and emit a new insight for another quarter. If you liquidate everything and re-order them back right away, you would risk slippage and pay additional trading fees.
Best
Louis
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.
Log Up
Hi Louis Szeto completely agree with you, I have worked upon it and updated the algo such that now it only rebalances lagging securities in my portfolio(I compare quarterly change of benchmark with minimum one month to max quarterly change in my holdings and liquidate the ones which are lagging)
Log Up
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!