I'm rebalancing my portfolio every week and I'm using the algorithm framework.
To send correct signals I send insights with duration of 5 days at time of the rebalance: basically with the following code (which works but I'm wondering if there is better / more correct way):
insights = []
for eq, weight in pos.items():
if weight != 0:
insight = Insight.Price(eq, timedelta(days=5), InsightDirection.Up, weight, weight)
insight.Weight = weight
insights.append(insight)
self.EmitInsights(Insight.Group(insights))
Is this correct way to do this? How I specify a signal that is active until next week start day so that the position is never liquidated (for example with InsightWeightingPortfolioConstructionModel and ImmediateExecutionModel)
Alexandre Catarino
Hi Mikko M
The Insinght.Price method also accepts a function that can set the expiry date based on the current date/time. There are helpers to set the end of the day/week/month, etc... For the end of the week case where all insights expiry on Monday morning, we can use:
insight = Insight.Price(symbol, Expiry.EndOfWeek, InsightDirection.Up)
Mikko M
That is almost exactly what I need, thanks for that!
The problem is that I rebalance approx 1-2 minutes after open to see the open prices and when I do this, the position is liquidated before the rebalancing - is there maybe some way to addt time delta to the expiration?
(to clarify things I'm using the following code for rebalancing the portfolio and I want the positio/signal to stay as I specified it until rebalancing/sending next signals)
self.Schedule.On(self.DateRules.MonthStart('SPY'), \
self.TimeRules.AfterMarketOpen('SPY', 2), \
self.tradingModel)
Alexandre Catarino
Hi Mikko M ,
The Insinght.Price method also accepts a date/time that sets the expiry date:
expiry = datetime(2019, 1, 3, 9, 32, 0) insight = Insight.Price(symbol, expiry, InsightDirection.Up)
so we can define expiry, based on QCAlgorithm.Time, to meet your algorithm's requirements.
Mikko M
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!