|
From: Luigi B. <lui...@gm...> - 2010-02-17 09:21:26
|
On Tue, 2010-02-16 at 19:20 +0000, na...@us... wrote: > Revision: 17107 > http://quantlib.svn.sourceforge.net/quantlib/?rev=17107&view=rev > Author: nando > Date: 2010-02-16 19:20:57 +0000 (Tue, 16 Feb 2010) > > Log Message: > ----------- > added XXX::operator boost::shared_ptr<Leg>() const Why? Leg is not polymorphic (it's a std::vector), and shared_ptr<Leg> is not used anywhere in the library (I'd probably remove it if it was :) Luigi -- I am extraordinarily patient, provided I get my own way in the end. -- Margaret Thatcher |
|
From: Luigi B. <lui...@gm...> - 2010-02-17 09:21:33
|
On Tue, 2010-02-16 at 19:09 +0000, na...@us... wrote: > Revision: 17105 > http://quantlib.svn.sourceforge.net/quantlib/?rev=17105&view=rev > Author: nando > Date: 2010-02-16 19:09:58 +0000 (Tue, 16 Feb 2010) > > Log Message: > ----------- > added more Coupon inspectors We're duplicating code all over the place---they're all basically the same loop. Why don't you write a nextCoupon() method instead and call whatever method you want on the result? Luigi -- These are my principles, and if you don't like them... Well, I have others. -- Groucho Marx |
|
From: Ferdinando A. <na...@am...> - 2010-02-17 15:12:09
|
On Wed, Feb 17, 2010 at 10:21 AM, Luigi Ballabio <lui...@gm...> wrote: > On Tue, 2010-02-16 at 19:09 +0000, na...@us... wrote: >> added more Coupon inspectors > > We're duplicating code all over the place---they're all basically the > same loop. Why don't you write a nextCoupon() method instead and call > whatever method you want on the result? you're right and this is true for both nextCashFlow and nextCoupon, their "previous" variants, and their CashFlows and Bond flavors Anyway if bond_ is a shared_ptr<Bond> you would then have to write (*BondFunctions::nextCashFlow(*bond_))->date(); instead of bond_->nextCashFlowDate(); You might have multiple CashFlow on the same date, so nextCashFlow might actually aggregate flows and create a new AggregateCashFlow instance, then returning a shared_ptr instead of an iterator. In this case one would have to write: BondFunctions::nextCashFlow(*bond_)->date(); As for nextCoupon it should return an instance of some AggregateCoupon class. This class would have pointers to the Coupons to be aggregated for its own nominal() and rate() method implementations. What do you think about it ? ciao -- Nando |
|
From: Luigi B. <lui...@gm...> - 2010-02-17 15:27:22
|
On Wed, 2010-02-17 at 16:11 +0100, Ferdinando Ametrano wrote: > On Wed, Feb 17, 2010 at 10:21 AM, Luigi Ballabio > <lui...@gm...> wrote: > > On Tue, 2010-02-16 at 19:09 +0000, na...@us... wrote: > >> added more Coupon inspectors > > > > We're duplicating code all over the place---they're all basically the > > same loop. Why don't you write a nextCoupon() method instead and call > > whatever method you want on the result? > > you're right and this is true for both nextCashFlow and nextCoupon, > their "previous" variants, and their CashFlows and Bond flavors > > Anyway if bond_ is a shared_ptr<Bond> you would then have to write > > (*BondFunctions::nextCashFlow(*bond_))->date(); > > instead of > > bond_->nextCashFlowDate(); Worse---You'd have to check for a null iterator first. Ok, I can see it's good to have the whole bunch of functions for convenience. Plus there's the aggregation thing. It might still be worth to write the common loop in a nextCoupon() method (private, if need be) so that at least the functions returning a date can call it and remove a good part of the duplication. For the aggregation, I don't know. I had though of returning a range (begin,end) of the cashflows on the same date, but it wouldn't work if there was a non-coupon cashflow between two coupons. Maybe a composite, as you say. Well, I'll let you know if I get any ideas... Luigi -- A programming language is low-level when its programs require attention to the irrelevant. -- Alan Perlis |
|
From: Ferdinando A. <na...@am...> - 2010-02-17 14:26:00
|
On Wed, Feb 17, 2010 at 10:21 AM, Luigi Ballabio <lui...@gm...> wrote: > On Tue, 2010-02-16 at 19:20 +0000, na...@us... wrote: >> added XXX::operator boost::shared_ptr<Leg>() const > > Why? Leg is not polymorphic (it's a std::vector), and shared_ptr<Leg> is > not used anywhere in the library (I'd probably remove it if it was :) you're right, my fault: reverted. thank you ciao -- Nando |