Hi,
I've been trying to register an Observable of (in my case it is an ImpliedTermStructure object, let's say ts=ImpliedTermStructure(...) ) with an observer which I created as follows: class MyObserver(Observable): ... (nothing special is going on there - just some attributes are being initialized and an update(self) method is being implemented. When trying to do MyObserver.registerWith(ts) I'm getting an error: TypeError: in method 'Observer__registerWith', argument 1 of type 'PyObserver *' What am I missing here? Thanks! |
Do you have some code that reproduces the problem?
Luigi On Thu, Jul 24, 2014 at 12:46 PM, aborodya <[hidden email]> wrote: > Hi, > I've been trying to register an Observable of (in my case it is an > ImpliedTermStructure object, let's say ts=ImpliedTermStructure(...) ) with > an observer which I created as follows: > class MyObserver(Observable): ... (nothing special is going on there - just > some attributes are being initialized and an update(self) method is being > implemented. > > When trying to do MyObserver.registerWith(ts) I'm getting an error: > > TypeError: in method 'Observer__registerWith', argument 1 of type > 'PyObserver *' > > > What am I missing here? > > Thanks! > > > > -- > View this message in context: http://quantlib.10058.n7.nabble.com/SWIG-Python-failure-to-register-observer-with-observable-tp15650.html > Sent from the quantlib-users mailing list archive at Nabble.com. > > ------------------------------------------------------------------------------ > Want fast and easy access to all the code in your enterprise? Index and > search up to 200,000 lines of code with a free copy of Black Duck > Code Sight - the same software that powers the world's largest code > search on Ohloh, the Black Duck Open Hub! Try it now. > http://p.sf.net/sfu/bds > _______________________________________________ > QuantLib-users mailing list > [hidden email] > https://lists.sourceforge.net/lists/listinfo/quantlib-users -- <https://implementingquantlib.blogspot.com> <https://twitter.com/lballabio> ------------------------------------------------------------------------------ Infragistics Professional Build stunning WinForms apps today! Reboot your WinForms applications with our WinForms controls. Build a bridge from your legacy apps to the future. http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Sorry, Luigi, didn't see you reply -
I was to reproduce the functionality of TermStructureTest::testImpliedObs() from the test suite. So I defined a Flag class in Python class Flag(Observer): def __init__(self): self.up_ = False def raiseFlag(self): self.up_ = True def lowerFlag(self): self.up_ = False def isUp(self): return self.up_ def update(self): self.raiseFlag() and created a function def testImpliedObs(logger): vars = CommonVars() today = Settings.instance().evaluationDate newToday = today + Period(3,Years) newSettlement = vars.calendar.advance(newToday, vars.settlementDays, Days) h = RelinkableYieldTermStructureHandle() implied = ImpliedTermStructure(h, newSettlement) flag = Flag() flag.registerWith(implied) h.linkTo(vars.termStructure) This gives me the error I mentioned earlier Thanks, Anatoly |
Need to init the Observer
class Flag(Observer): def __init__(self): self.up_ = False Observer.__init__(self, self.update) >>> flag = Flag() >>> flag <__main__.Flag; proxy of <Swig Object of type 'PyObserver *' at 0x02B44FB0> > Now flag is of type PyObserver. Hope this helps |
Free forum by Nabble | Edit this page |