Hi All,
I am currently trying to testing the Alpha model with insight. The testing is simple, i get 3 stocks from coarse universe every backtest days. All stocks for a given days will trigger a insight up.
Below is how i pick the stock from coarse universe
def TestFilter(self, universe):
selected = []
universe = [c for c in universe if c.HasFundamentalData]
universe = sorted(universe, key=lambda c: c.DollarVolume, reverse=True)[100:103]
for coarse in universe:
selected.append(coarse.Symbol)
self.Log(f"[LOG->ADDED] {self.Time}: {coarse.Symbol}")
return selected
I fire the insight in my alpha model
def Update(self, algo, slice):
insights = []
for symbol in slice.Keys:
if slice.ContainsKey(symbol) and slice[symbol] is not None:
insights.append(Insight.Price(symbol, timedelta(minutes=30), InsightDirection.Up, None, None, None, 0.05))
algo.Log(f"[LOG->INSIGHT] -> {algo.Time} {symbol} Up")
return insights
3 stocks are added and 3 insights are fired => As expected
2014-03-25 00:00:00 [LOG->ADDED] 2014-03-25 00:00:00: LYB UQRGJ93635GL
2014-03-25 00:00:00 [LOG->ADDED] 2014-03-25 00:00:00: JAZZ TT3D85SDWEW5
2014-03-25 00:00:00 [LOG->ADDED] 2014-03-25 00:00:00: AIG R735QTJ8XC9X
2014-03-25 00:00:00 [LOG->INSIGHT] -> 2014-03-25 00:00:00 AIG R735QTJ8XC9X Up
2014-03-25 00:00:00 [LOG->INSIGHT] -> 2014-03-25 00:00:00 JAZZ TT3D85SDWEW5 Up
2014-03-25 00:00:00 [LOG->INSIGHT] -> 2014-03-25 00:00:00 LYB UQRGJ93635GL Up
However, in the next day, interesting things happens. I added 3 stocks again but it fired 6 insights, together with those yesterday (but my insight period was 30mins, i don't expect i see them again in the next day.
2014-03-26 00:00:00 [LOG->ADDED] 2014-03-26 00:00:00: ICPT VAO9ZBE1SEAT
2014-03-26 00:00:00 [LOG->ADDED] 2014-03-26 00:00:00: ILMN RWQR2INKP0TH
2014-03-26 00:00:00 [LOG->ADDED] 2014-03-26 00:00:00: MCK R735QTJ8XC9X
2014-03-26 00:00:00 [LOG->INSIGHT] -> 2014-03-26 00:00:00 AIG R735QTJ8XC9X Up ← not expected as i didn't get this stock from coarse universe
2014-03-26 00:00:00 [LOG->INSIGHT] -> 2014-03-26 00:00:00 JAZZ TT3D85SDWEW5 Up ← not expected as i didn't get this stock from coarse universe
2014-03-26 00:00:00 [LOG->INSIGHT] -> 2014-03-26 00:00:00 LYB UQRGJ93635GL Up ← not expected as i didn't get this stock from coarse universe
2014-03-26 00:00:00 [LOG->INSIGHT] -> 2014-03-26 00:00:00 ICPT VAO9ZBE1SEAT Up
2014-03-26 00:00:00 [LOG->INSIGHT] -> 2014-03-26 00:00:00 ILMN RWQR2INKP0TH Up
2014-03-26 00:00:00 [LOG->INSIGHT] -> 2014-03-26 00:00:00 MCK R735QTJ8XC9X Up
Can anyone help to explain how does it happen and how to resolve the issue? I would like to fired the insight if and only if it is returned from my coarse universe for a given day
Enjolras Leigh
According to the class spec, Update function should be with the latest data. In my example, the latest data should be those stocks newly added from coarse universe for a given date, instead of aggregated stocks since the first day of backtesting. Did i miss anything here? Is it a bug?
Alexandre Catarino
Hi Enjolras Leigh ,
Your algorithm is setting the following Portfolio Construction model (PCM) rule:
When a security is removed from the universe, the PCM will not create zero-quantity portfolio targets (liquidation). In this case, securities can only be removed by Insight expiration which should have happened since the Insights expire in 30 minutes:
However, the algorithm is subscribing to daily data, so there is no granularity to liquidate the securities after 30 minutes.
Putting all of this together, the universe selection removes the securities, but the algorithm keeps them because they have an open position. The algorithm doesn't remove securities with open positions because it needs its data to calculate their impact on the portfolio.
Best regards,
Alex
Enjolras Leigh
Hi Alex,
Thanks for the reply. I am not sure if i following you. i tried to change the period to 2 days.
I am expecting AIG will hold for 2 days. However, it sold at the 2nd days i.e. the same as my initial result.
Enjolras Leigh
At last, i created my own PortfolioConstructionModel to get it done.
Louis Szeto
Hi Enjolras
That was because AIG was removed from your universe at 2014/3/26 00:00, so its position and insight were removed.
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.
Enjolras Leigh
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!