From 69b658b775b0477d312cc7151cc8ea5f87c0d9f5 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Wed, 8 Nov 2023 10:53:37 -0500 Subject: [PATCH] doc fixes, more complete constructors --- quantlib/instruments/bond.pyx | 12 +++--- quantlib/instruments/bonds/_fixedratebond.pxd | 3 +- .../instruments/bonds/_floatingratebond.pxd | 26 +++---------- quantlib/instruments/bonds/fixedratebond.pyx | 6 ++- .../instruments/bonds/floatingratebond.pyx | 39 ++++++++++++------- 5 files changed, 44 insertions(+), 42 deletions(-) diff --git a/quantlib/instruments/bond.pyx b/quantlib/instruments/bond.pyx index 53209e02d..e885a31c2 100644 --- a/quantlib/instruments/bond.pyx +++ b/quantlib/instruments/bond.pyx @@ -46,18 +46,18 @@ cdef class Bond(Instrument): @property def start_date(self): - """ Bond start date. """ + """ Bond start date""" return date_from_qldate(self.as_ptr().startDate()) @property def maturity_date(self): - """ Bond maturity date. """ + """ Bond maturity date""" return date_from_qldate(self.as_ptr().maturityDate()) @property def issue_date(self): - """ Bond issue date. """ + """ Bond issue date""" return date_from_qldate(self.as_ptr().issueDate()) def settlement_date(self, Date from_date=Date()): @@ -71,14 +71,14 @@ cdef class Bond(Instrument): @property def dirty_price(self): - """ Bond dirty price. """ + """ Bond dirty price""" return self.as_ptr().dirtyPrice() def bond_yield(self, Real price, DayCounter dc not None, Compounding comp, Frequency freq, Date settlement_date=Date(), Real accuracy=1e-08, Size max_evaluations=100, Real guess=0.5, Type price_type = Price.Clean): - """ Return the yield given a (clean) price and settlement date + """ Return the yield given a price and settlement date The default bond settlement is used if no date is given. @@ -93,7 +93,7 @@ cdef class Bond(Instrument): ) def accrued_amount(self, Date date=Date()): - """ Returns the bond accrued amount at the given date. """ + """ Returns the bond accrued amount at the given date""" return self.as_ptr().accruedAmount(deref(date._thisptr)) @property diff --git a/quantlib/instruments/bonds/_fixedratebond.pxd b/quantlib/instruments/bonds/_fixedratebond.pxd index 53fd43178..8b33f1b3c 100644 --- a/quantlib/instruments/bonds/_fixedratebond.pxd +++ b/quantlib/instruments/bonds/_fixedratebond.pxd @@ -15,7 +15,7 @@ cdef extern from 'ql/instruments/bonds/fixedratebond.hpp' namespace 'QuantLib' n Real faceAmount, const Schedule& schedule, vector[Rate]& coupons, - DayCounter& accrualDayCounter, + const DayCounter& accrualDayCounter, BusinessDayConvention paymentConvention, Real redemption, # 100.0 const Date& issueDate, # Date() @@ -24,4 +24,5 @@ cdef extern from 'ql/instruments/bonds/fixedratebond.hpp' namespace 'QuantLib' n const Calendar& exCouponCalendar, # Calendar() const BusinessDayConvention exCouponConvention, # Unadjusted, bool exCouponEndOfMonth, # false + const DayCounter& firstPeriodDayCounter, # = DayCounter() ) except + diff --git a/quantlib/instruments/bonds/_floatingratebond.pxd b/quantlib/instruments/bonds/_floatingratebond.pxd index 20bd5d09d..6b57438f5 100644 --- a/quantlib/instruments/bonds/_floatingratebond.pxd +++ b/quantlib/instruments/bonds/_floatingratebond.pxd @@ -4,6 +4,7 @@ from quantlib.types cimport Natural, Rate, Real, Spread from quantlib.handle cimport shared_ptr from quantlib.time._calendar cimport Calendar from quantlib.time._date cimport Date +from quantlib.time._period cimport Period from quantlib.time.frequency cimport Frequency from quantlib.time.businessdayconvention cimport BusinessDayConvention from quantlib.time.dategeneration cimport DateGeneration @@ -27,24 +28,9 @@ cdef extern from 'ql/instruments/bonds/floatingratebond.hpp' namespace 'QuantLib vector[Rate]& floors, # std::vector() bool inArrears, # false Real redemption, # 100. - Date& issueDate # Date() + Date& issueDate, # Date() + const Period& exCouponPeriod, # = Period() + const Calendar& exCouponCalendar, # = Calendar() + BusinessDayConvention exCouponConvention, # = Unadjusted + bool exCouponEndOfMoanth # = false ) except + - FloatingRateBond(Natural settlementDays, - Real faceAmount, - Date& startDate, - Date& maturityDate, - Frequency couponFrequency, - Calendar& calendar, - shared_ptr[IborIndex]& iborIndex, - DayCounter& accrualDayCounter, - BusinessDayConvention accrualConvention, - BusinessDayConvention paymentConvention, - Natural fixingDays, - vector[Real]& gearings, - vector[Spread]& spreads, - vector[Rate]& caps, - vector[Rate]& floors, - Real redemption, - Date& issueDate, - Date& stubDate, - DateGeneration rule) except + diff --git a/quantlib/instruments/bonds/fixedratebond.pyx b/quantlib/instruments/bonds/fixedratebond.pyx index 0162b0223..a592a79c3 100644 --- a/quantlib/instruments/bonds/fixedratebond.pyx +++ b/quantlib/instruments/bonds/fixedratebond.pyx @@ -31,7 +31,8 @@ cdef class FixedRateBond(Bond): Period ex_coupon_period=Period(), Calendar ex_coupon_calendar=Calendar(), BusinessDayConvention ex_coupon_convention=Unadjusted, - bool ex_coupon_end_of_month=False): + bool ex_coupon_end_of_month=False, + DayCounter first_period_day_counter=DayCounter()): """ Fixed rate bond Parameters @@ -67,6 +68,7 @@ cdef class FixedRateBond(Bond): deref(ex_coupon_period._thisptr), ex_coupon_calendar._thisptr, ex_coupon_convention, - ex_coupon_end_of_month + ex_coupon_end_of_month, + deref(first_period_day_counter._thisptr) ) ) diff --git a/quantlib/instruments/bonds/floatingratebond.pyx b/quantlib/instruments/bonds/floatingratebond.pyx index 2e1d71ee4..73decc325 100644 --- a/quantlib/instruments/bonds/floatingratebond.pyx +++ b/quantlib/instruments/bonds/floatingratebond.pyx @@ -5,24 +5,29 @@ from libcpp cimport bool from quantlib.handle cimport static_pointer_cast from quantlib.indexes.ibor_index cimport IborIndex cimport quantlib.indexes._ibor_index as _ii -from quantlib.time.businessdayconvention cimport BusinessDayConvention, Following -from quantlib.time.date cimport Date +from quantlib.time.businessdayconvention cimport BusinessDayConvention, Following, Unadjusted +from quantlib.time.date cimport Date, Period +from quantlib.time.calendar cimport Calendar from quantlib.time.daycounter cimport DayCounter from quantlib.time.schedule cimport Schedule - +from quantlib.utilities.null cimport Null from . cimport _floatingratebond as _frb cdef class FloatingRateBond(Bond): """ Floating rate bond """ def __init__(self, Natural settlement_days, Real face_amount, - Schedule schedule, IborIndex ibor_index, - DayCounter accrual_day_counter, Natural fixing_days, - vector[Real] gearings=[1.], vector[Spread] spreads=[0.], - vector[Rate] caps=[], vector[Rate] floors=[], - BusinessDayConvention payment_convention=Following, - bool in_arrears=True, - Real redemption=100.0, Date issue_date=Date() + Schedule schedule, IborIndex ibor_index, + DayCounter accrual_day_counter, Natural fixing_days=Null[Natural](), + vector[Real] gearings=[1.], vector[Spread] spreads=[0.], + vector[Rate] caps=[], vector[Rate] floors=[], + BusinessDayConvention payment_convention=Following, + bool in_arrears=False, + Real redemption=100.0, Date issue_date=Date(), + Period ex_coupon_period=Period(), + Calendar ex_coupon_calendar=Calendar(), + BusinessDayConvention ex_coupon_convention=Unadjusted, + bool ex_coupon_end_of_month=False ): """ Floating rate bond @@ -55,6 +60,10 @@ cdef class FloatingRateBond(Bond): Amount at redemption issue_date : Date Date bond was issued + ex_coupon_period : Period + ex_coupon_calendar : Calendar + ex_coupon_convention: BusinessDayConvention + ex_coupon_end_of_month: bool """ self._thisptr.reset( @@ -64,8 +73,12 @@ cdef class FloatingRateBond(Bond): static_pointer_cast[_ii.IborIndex](ibor_index._thisptr), deref(accrual_day_counter._thisptr), payment_convention, - fixing_days, gearings, spreads, caps, floors, True, + fixing_days, gearings, spreads, caps, floors, in_arrears, redemption, - deref(issue_date._thisptr) - ) + deref(issue_date._thisptr), + deref(ex_coupon_period._thisptr), + ex_coupon_calendar._thisptr, + ex_coupon_convention, + ex_coupon_end_of_month ) + )