Back

How to access History?

I get the following error:

Runtime Error: AttributeError : 'SelectionModel' object has no attribute 'History'

The class I am using however inherits from (FundamentalUniverseSelectionModel).

The reason for this is that I am using the Course and Fine Filters. And I am also trying to implement Momentum in the Fine Filter Function along the lines shown here:

Lean/Algorithm.Python/EmaCrossUniverseSelectionAlgorithm.py

However I note that the EmaCrossUniverseSelectionAlgorithm inherits from (QCAlgorithm) and adds the Course Filter using:

self.AddUniverse(self.CoarseSelectionFunction)

Is this my mistake? Trying to access History in a class which inherits from FundamentalUniverseSelectionModel?

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.


Without seeing the code I am guessing you're calling self.History(), you need to access the algorithm parameter which is passed into the selection model. i.e. algorithm.History. The self refers to the current class; if you're in the history API is accessible on the algorithm object.

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 Anthony FJ Garner ,

On the 'AttributeError' issue, we can see that it was fixed after you changed self.History for algorithm.History (line 30).

fine is a list of FineFundamental objects where each item has the AdjustedPrice attribute. If you loop through fine or sortedByDEratio, you should be able to access it:

for f in sortedByDEratio:
self.averages[f.Symbol].update(f.EndTime, f.AdjustedPrice)

 

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 Anthony FJ Garner ,

Sorry about the misinformation.

Please find in the attached backtest a working version of what you are trying to accomplish.

If you have further questions, do not hesitate to ask. :-)

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.


Thanks for the exampleAlexandre Catarino - this is helpful for me as well.

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