Back

Confusion about SecurityManager

According to the reference, Securities is a Dictionary<Symbol, Security> so you can access your Security objects with their ticker Securities["IBM"].Price

However, in the sample RiskManagementModels, this is used:

for kvp in algorithm.Securities:
    symbol = kvp.Key
    security = kvp.Value

How does the above construction work? I am a relative beginner, but from what I know about dictionaries, kvp would be the key and Securities[kvp] would be the individual security. 
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 Tamim,

The Securities object behaves like a Python dictionary in regards to how we access it with keys. But under the hood, it's a C# class. Thus, when we iterate over it with

for kvp in algorithm.Securities:

`kvp` is of type System.Collections.Generic.

That is why, in this case, we access the key and value with

kvp.Key
kvp.Value

If instead, we iterate over the object with

for kvp, val in self.Securities.items():

`kvp` will be of type Symbol and `val` will be of type Security.

See the attached backtest and logs for reference.

Best,
Derek Melchin

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.


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