Back

Update fundamentals in universe monthly & chart

Hi, trying out a couple of things but not successful this far:

a.) Update Fundamentals

I filter my fine universe monthly & want to update the P/B ratio of one ticker in the same method as well (due to access to fundamental data). Doing this as follows:

self.test_asset_pb = self.test_asset_object.ValuationRatios.PBRatio

where test_asset_object is a security object originating from the very first iteration of FineSelectionFunction(self, fine), think of it as being picked out from fine = [x for x in fine if (x.ValuationRatios.PBRatio > 0)].

Then once I updated the variable I wish to reference it & plot the current P/B ratio alongside two boundaries like so:

self.Plot('Fundamentals', 'Test-Asset P/B Ratio', self.test_asset_pb)
self.Plot('Fundamentals', 'Breakpoint Min', self.breakpoint_min)
self.Plot('Fundamentals', 'Breakpoint Max', self.breakpoint_max)

 I´m doing that in OnData currently at the very end. The problem is that while the boundaries seem to work properly the "Test-Asset P/B Ratio" remains constant, i.e. seems to not get updated & I don´t understand why. Also, should I rather plot it inside FineSelectionFunction(self, fine) right away?

b.) Fetch last price

My second problem should be an easy one but I haven´t manage to solve it. For the same object as above, which is instantiated in the first iteration of FineSelectionFunction(self, fine) I want to fetch the last price at each rebalancing date within OnData (OnData only runs monthly at rebalancing). Inside (the first iteration of) FineSelectionFunction(self, fine) I´m also adding the security with:

self.test_asset_ticker = self.test_asset_object.SecurityReference.SecuritySymbol
self.AddEquity(str(self.test_asset_ticker), Resolution.Daily)

Then fetching the price in OnData as follows without success:

if self.flag0 == 0:
self.test_lastPrice = self.ActiveSecurities[str(self.test_asset_ticker)].Price

I keep getting the error:


Runtime Error: KeyNotFoundException : The given key ' ' was not present in the dictionary.

Which I really do not understand, because I have 3 flags in place that should prevent the algo from going into the last if-statement while the test_asset is not instantiated yet.

 

Thank you!

 

 

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

I've responded to another post you made regarding some of the functioning of this algorithm, and it should address your concerns here. You can view it and the accompanying backtest here.

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