|
From: Matthias S. <mat...@gm...> - 2021-02-12 09:33:56
|
Personally, I would consider QuantLib as a low-level layer in whatever
financial application you want to create - unless you want to use it for
some quick analysis in which case the Python (or R) bindings present a nice
alternative, albeit not as feature-complete as the underlying C++ library.
So, I would create a composite with a [FixedRate|FloatingRate]Bond instance
for the pricing related functions and such attributes you would like to
access on a frequent basis, e.g. DCM or frequency. Some FOSS actually
follows this approach - I think, for instance ORE does something similar
(maybe exposing properties as string rather than "strongly typed", but my
memory about the OREData structures is a bit rusty).
Otherwise, obviously Luigi's suggestion to parse the leg(s) and their
flowlets is a good way to retrieve details you would like to see on a
cashflow table of some kind. I was going to say that this works for
FixedRateBond and FloatingRateBond, because those wrappers should leave you
with only one leg. But other bond packages do allow you to specifiy more
than one leg. The fixed-to-float example is an obvious one. Maybe also
bonds with a fixed coupon as teaser and structured coupon period thereafter.
By the way: Downcast, but no love for the visitor? Have been in the one or
other battle about "Visitor pattern considered harmful", but maybe that is
beyond the scope of the original question...
struct CashflowVisitor : public Visitor<QuantLib::Coupon>
{
// some members
void visit(QuantLib::Coupon &coupon) override
{
someConsumer.consume(coupon.dayCounter());
}
};
Frequency needs to be implied from the start and end dates, so using the
leg info may not be desirable after all.
On Fri, Feb 12, 2021 at 9:19 AM Luigi Ballabio <lui...@gm...>
wrote:
> Given a bond in general, you can't. For instance, you might have a
> convertible fixed-to-floater where the first part of the bond pays annual
> fixed coupons and the second part pays semiannual floating-rate coupons,
> possibly with a different day count. What you might do is examine the
> coupons themselves: call bond.cashflows(), iterate over it, and for each of
> the cash flows try to downcast it to a coupon (using
> ext::dynamic_pointer_cast<Coupon>) and call its methods.
>
> Luigi
>
>
> On Fri, Feb 12, 2021 at 6:29 AM jian Xu <jia...@gm...> wrote:
>
>> So given a bond in general, how to find out its accrual day count and
>> the payment frequency?
>>
>> On Thu, Feb 11, 2021 at 3:33 PM Luigi Ballabio <lui...@gm...>
>> wrote:
>> >
>> > Hello,
>> > as Matthias says, FixedRateCoupon and FloatingRateCoupon are
>> convenience classes used to build a bond, but don't have specific
>> behavior. I'm not opposed to having them return some info, but I'd try to
>> avoid storing too much extra data in them just for that purpose...
>> >
>> > Luigi
>> >
>> >
>> > On Thu, Feb 11, 2021 at 9:44 PM <mat...@gm...> wrote:
>> >>
>> >> Hello Jian,
>> >>
>> >> I can only guess, but maybe the classes FixedRateBond and
>> FloatingRateBond were thought of as "easy wrappers" around the main Bond
>> class - making it more convenient for users to create a Bond instance with
>> floating or fixed coupon legs (or none, in case of ZeroCouponBond).
>> >>
>> >> Actually I can only find one reference for the "frequency" accessor -
>> and that one is in a unit test to ensure that frequency setting is sort of
>> ignored for a custom schedule.
>> >>
>> >> Curious to hear other opinions.
>> >>
>> >> Thanks,
>> >>
>> >> Matthias
>> >>
>> >>
>> >> -----Original Message-----
>> >> From: jian Xu <jia...@gm...>
>> >> Sent: Thursday, 11 February 2021 21:13
>> >> To: QuantLib users <qua...@li...>
>> >> Subject: [Quantlib-users] Why doesn't FloatingRateBond has
>> dayCounter() and frequency()?
>> >>
>> >> Hi,
>> >>
>> >> I noticed that FixedRateBond has dayCounter() and frequency() methods,
>> but the FloatingRateBond does not. What's the reason for that? It seems
>> to me that dayCounter and frequency are equally valid concepts for floating
>> and fixed rate bonds. Or am I missing something?
>> >> Thanks.
>> >>
>> >> Jian
>> >>
>> >>
>> >> _______________________________________________
>> >> QuantLib-users mailing list
>> >> Qua...@li...
>> >> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>> >>
>> >>
>> >>
>> >> _______________________________________________
>> >> QuantLib-users mailing list
>> >> Qua...@li...
>> >> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>>
>
|