Skip to content

Commit

Permalink
doc fixes, more complete constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
thrasibule committed Nov 22, 2023
1 parent 8851c01 commit b729e20
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 42 deletions.
12 changes: 6 additions & 6 deletions quantlib/instruments/bond.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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()):
Expand All @@ -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.
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion quantlib/instruments/bonds/_fixedratebond.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 +
26 changes: 6 additions & 20 deletions quantlib/instruments/bonds/_floatingratebond.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,24 +28,9 @@ cdef extern from 'ql/instruments/bonds/floatingratebond.hpp' namespace 'QuantLib
vector[Rate]& floors, # std::vector<Rate>()
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 +
6 changes: 4 additions & 2 deletions quantlib/instruments/bonds/fixedratebond.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
)
)
39 changes: 26 additions & 13 deletions quantlib/instruments/bonds/floatingratebond.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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
)
)

0 comments on commit b729e20

Please sign in to comment.