Back

Error but documentation says otherwise 'EquityHolding' object has no attribute 'Holdings'

Hi all,

 

this is the Equity Holdings class documentation

https://www.quantconnect.com/lean/documentation/topic27391.html

But when I use it in code to find open price of an investment it gives error.

Code that uses it, this used in onData method -

self.Portfolio[symbol].Price > self.Portfolio[symbol].Holdings.AveragePrice:

I already have a check before this line to make sure there is an investment - 

if self.Portfolio[symbol].Invested:

Any help would be really appreciated.

 

Thanks,

Ray

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 Ray,

The Portfolio class is a `Dictionary<Symbol, SecurityHolding>`, so we should be referencing the SecurityHoldings documentation instead. To avoid the error, we just need to remove `.Holdings` from the line above.

self.Portfolio[symbol].Price > self.Portfolio[symbol].AveragePrice

See the attached files for a working solution.

Best,
Derek Melchin

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.


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