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!