Back

Pull Securities From SecuritiesChanged Collection

Having some trouble accessing the securities that are added to my universe. I want to pull them out of the securities changed collection and put them into an array or a string to be used in other parts of my script. The following code is my filter.

https://kobra.io/#/e/-KB0go5JtfYWyUp2Kvmn
https://kobra.io/#/e/-KB0iuMmBwWhUQEc78HI

As you can see it returns 3 securities with the Take method. I've tried using AddedSecurities, ToString(), and ToArray() on the SecuritiesChanged collection.
The second script is the one I want to merge with the first one and use the coarse universe selection instead of the line that delegates symbols to a string.

Please help!

PS. Code snippets don't work.

Update Backtest








In the future please post an algorithm/backtest as this will make it easier to identify the exact issue you're having. The SecuritiesChanged object can be saved off directly for use in other parts of your algorithm. The first code snippet you link to already does this. In the OnSecuritiesChanged event it saves off the SecuritiesChanged object and then reuses it in the OnData method. If you just wanted to save the AddedSecurities you could do something like this:var addedSecurities = securityChanges.AddedSecurities.ToList();
Then you could reuse that list elsewhere in your algorithm.

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.


Michael - Thank you for your answer. I couldn't get the backtest to run so I couldn't link it. There is still some problem with code snippets since they usually return PHP errors like this one "DOMDocument::loadHTML(): Tag symbol invalid in Entity, line: 1". What am I doing wrong?

I didnt know about the ToList() method but that would work perfectly for another strategy I have in mind.
After some frustration I finally figured it out and didnt need to make list of symbols I only needed to pick one.

0


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