Hey!
I recently coded up a algorithm in the QC framework. It works alright, but i seem to have some problems, when it comes to removing securities from my universe, in my alpha model. I cant really spot my mistake, and have been trying to debug and work around the problem for some time now. The backtest i linked, you can see under “Symboler”, that the further the algoritm runs, more symbols is accumilated. From 10 in the start to 22. Any advice or fix will be greatly appriciated :)
Thank you in advance
Lucas
Varad Kabade
Hi Lucas,
Would you mind elaborating more on the following:
i seem to have some problems, when it comes to removing securities from my universe, in my alpha model
As the above algorithm is removing the SymbolData object from self.symbolDataBySymbol when the security is removed. We think that the algorithm should work as expected.
Best,
Varad Kabade
Lucas
Hi Varad
I am sorry for the bad explanation. I will elaborate.
The symbol seems to not remove be remove from the universe. I have created a global variable named “symbols_in_universe” which is just a new variable that contains the elements of “self.symbolDataBySymbol”. I have plotted the amount of symbols in the method “OnEndOfDay(self)”. The futher the algorithm has run, the more symbols is in this variable. Futhermore, the insights created seems to be highter, the futher the algorithm runs. Also, there is a lot of cash left sitting, and not being used. This is reflected in the “cash” plot. The algortihm should only keep 10 stocks in the “self.symbolDataBySymbol", and trade if the stocks move more than 2 standard deviations in either direction.
I am missing something, and i really don't know what.
Thank you
Lucas
Louis Szeto
Hi Lucas
The keys of self.symbolDataBySymbol were security objects, while the .pop function passed a Symbol object. Therefore, the key-value pair was never removed from the dictionary, so the increasing number of consolidators eventually dragged your backtest down.
Also, please note that the RemoveConsolidator method receives (Symbol, Consolidator) arguments, but not (Security, Consolidator). Please find the attached backtest for your reference.
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.
Lucas
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!