I'm having trouble transitioning a successful project into an Alpha because I cannot get it to give out any Insights during backtesting.
I just want the Alpha to emit insights exactly when the algorithm places trades, but I can't get that to work because Insights need to come from Update method, and my algorithm places trades in the OnSecuritiesChanged method. I've tried copy and pasting the trade process into the Update method, but it doesn't work because I then can't use the loop "for security in changes.AddedSecurities:" because "changes" does not work in the Update method.
Can someone help me out with this? How exactly can I get Insights to copy the algorithm when the algorithm is in "OnSecuritiesChanged" but the Insights have to come from "Update"?
And as for the feature request tag, shouldn't there be a way to have the algorithm emit insights whenever it is programmed to placed a trade with just a simple command?
Vladimir
Ethan Wertlieb
The best way to get help fast --> post the algorithm you're having trouble with.
Ethan Wertlieb
class MyAlphaModel: def OnSecuritiesChanged(self, changes, algorithm): for security in changes.RemovedSecurities: algorithm.Liquidate(security.Symbol) for security in changes.AddedSecurities: if security is not algorithm.IsWarmingUp: FsymbolP = security.Price if FsymbolP > self.Fsmol.Current.Value: algorithm.SetHoldings(security.Symbol, .3) if FsymbolP > self.Fsmol.Current.Value and self.Fmedium.Current.Value: algorithm.SetHoldings(security.Symbol, .35) if FsymbolP > self.Fsmol.Current.Value and self.Fmedium.Current.Value and self.Flawge.Current.Value: algorithm.SetHoldings(security.Symbol, .4) if FsymbolP < self.Fsmol.Current.Value and self.Fmedium.Current.Value and self.Flawge.Current.Value: algorithm.Liquidate(security.Symbol)
Thank you for the quick response.
How do I get each of these trade signals to emit an Insight the same way they SetHoldings?
Ethan Wertlieb
I solved the problem. In Documentation there was a "self.EmitInsights" value, and I used this along with deleting the "MyAlphaModel" set up in Initialize, because this way It doesnt require an Update method. Now I just have to figure out why my regular algorithm with the exact same code is returning a better value than the alpha is...
Shile Wen
Hi Ethan,
To make trades from Insights Generated from our Alpha Model, we need to have a Portfolio Construction model. To specify allocations, I suggest using the InsightWeightingPortfolioConstructionModel and specify the Insight weight when creating Insights, and if we use this model, we no longer need to use SetHoldings.
Best,
Shile Wen
Ethan Wertlieb
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!