Understanding insight periods

Back

I'm trying to figure out how exactly the insights returned from my alpha model works. I'm particularly confused about the insight period. As far as I understand, it's a timedelta that shows how long your insight is valid for, and after that period, the position should be automatically closed. 

However, that is not really the behavior I'm getting when trying to test it out. 

For example, in the attached code, the backtest sells my position the following day after 2 hours (so 26 hours) instead of the original 2 hours added as a timedelta period. 

Also, would there be a way to set the insight period to None so that the position wouldn't liquidate unless it was told? 

def Initialize(self):

self.SetStartDate(2020, 9, 9)
self.SetEndDate(2020, 9, 10)

self.UniverseSettings.Resolution = Resolution.Hour
self.SetUniverseSelection( ManualUniverseSelectionModel(Symbol.Create("SPY", SecurityType.Equity, Market.USA) )

self.AddAlpha(MyAlphaModel())
self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())
self.SetRiskManagement(NullRiskManagementModel())
self.SetExecution(ImmediateExecutionModel())


class MyAlphaModel:

def Update(self, algorithm, data):
if data["SPY"] is None: return
insights = []
if algorithm.Time.date() == date(2020, 9, 9):
insights.append(Insight.Price("SPY", timedelta(hours = 2), InsightDirection.Up))
return insights

def OnSecuritiesChanged(self, algorithm, changes):
# Handle security changes in from your universe model.
pass

 

Update Backtest







 
0

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.


Hi Stinus,

This is because multiple insights are continually emitted on that date. When an Insight is following by another Insight of the same direction, the position held in the previous Insight is extended (see this thread). Furthermore, buy and hold using Insights is explained in the same thread linked.

Best,
Shile Wen

1

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.


Hi Shile, 

That makes a lot of sense. Thanks for clearing that up for me. Here is another small issue that you might also be able to explain. If I change the resolution to be daily and the inisight periode to be a timedelta(days = 1) my holdings are liqudated over 2 days instead of the next day? screenshot: 

https://share.getcloudapp.com/P8ubL42o

 

0

ps. if I set the timedelta to 2 days it still liquidates a bit of shares the following day? 

https://share.getcloudapp.com/5zuGQzpB

 

0

Hi Stinus,

The early partial selling is due to rebalancing, and to stop the rebalancing, please pass lambda time: None to the Portfolio Construction Model constructor. Furthermore, extending the duration of the backtest, we can see the 2 day insight holds for three days. The Insights hold the securities for one extra day beyond the Insight Period because the Insights haven't expired yet.

Best,
Shile Wen 

1

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.


Update Backtest





0

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.


Loading...

This discussion is closed