Skip to content
63 changes: 32 additions & 31 deletions quantlib/cashflows/_cashflows.pxd
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from libcpp cimport bool
from libcpp.pair cimport pair
from quantlib.ext cimport optional
from quantlib.time._date cimport Date
from quantlib.types cimport Rate, Real
from quantlib.termstructures._yield_term_structure cimport YieldTermStructure
from .._cashflow cimport Leg

cdef extern from 'ql/cashflows/cashflows.hpp' namespace 'QuantLib':
cdef extern from 'ql/cashflows/cashflows.hpp' namespace 'QuantLib' nogil:
cdef cppclass CashFlows:
@staticmethod
Date startDate(const Leg& leg)
Expand All @@ -15,26 +16,26 @@ cdef extern from 'ql/cashflows/cashflows.hpp' namespace 'QuantLib':

@staticmethod
bool isExpired(const Leg& leg,
bool includeSettlementDateFlows,
Date settlementDate = Date())
optional[bool] includeSettlementDateFlows, # = nullopt
Date settlementDate) # = Date()

@staticmethod
Date previousCashFlowDate(const Leg& leg,
bool includeSettlementDateFlows,
optional[bool] includeSettlementDateFlows, # = nullopt
Date settlementDate)# = Date())

@staticmethod
Date nextCashFlowDate(const Leg& leg,
bool includeSettlementDateFlows,
optional[bool] includeSettlementDateFlows, # = nullopt
Date settlementDate)# = Date())

@staticmethod
Real previousCashFlowAmount(const Leg& leg,
bool includeSettlementDateFlows,
Date settlementDate)# = Date())
optional[bool] includeSettlementDateFlows, # = nullopt
Date settlementDate)# = Date())
@staticmethod
Real nextCashFlowAmount(const Leg& leg,
bool includeSettlementDateFlows,
optional[bool] includeSettlementDateFlows, # = nullopt
Date settlementDate)# = Date())
# static Rate
# previousCouponRate(const Leg& leg,
Expand All @@ -49,14 +50,14 @@ cdef extern from 'ql/cashflows/cashflows.hpp' namespace 'QuantLib':
# nominal(const Leg& leg,
# bool includeSettlementDateFlows,
# Date settlDate = Date());
# static Date
# accrualStartDate(const Leg& leg,
# bool includeSettlementDateFlows,
# Date settlDate = Date());
# static Date
# accrualEndDate(const Leg& leg,
# bool includeSettlementDateFlows,
# Date settlementDate = Date());
@staticmethod
Date accrualStartDate(const Leg& leg,
optional[bool] includeSettlementDateFlows, # = nullopt
Date settlDate) # = Date()
@staticmethod
Date accrualEndDate(const Leg& leg,
optional[bool] includeSettlementDateFlows, # = nullopt
Date settlementDate) # = Date()
# static Date
# referencePeriodStart(const Leg& leg,
# bool includeSettlementDateFlows,
Expand All @@ -69,39 +70,39 @@ cdef extern from 'ql/cashflows/cashflows.hpp' namespace 'QuantLib':
# accrualPeriod(const Leg& leg,
# bool includeSettlementDateFlows,
# Date settlementDate = Date());
# static Date::serial_type
# accrualDays(const Leg& leg,
# bool includeSettlementDateFlows,
# Date settlementDate = Date());
@staticmethod
Date.serial_type accrualDays(const Leg& leg,
optional[bool] includeSettlementDateFlows, # = nullopt
Date settlementDate) # = Date()
# static Time
# accruedPeriod(const Leg& leg,
# bool includeSettlementDateFlows,
# Date settlementDate = Date());
# static Date::serial_type
# accruedDays(const Leg& leg,
# bool includeSettlementDateFlows,
# Date settlementDate = Date());
# static Real
# accruedAmount(const Leg& leg,
# bool includeSettlementDateFlows,
# Date settlementDate = Date());
@staticmethod
Date.serial_type accruedDays(const Leg& leg,
optional[bool] includeSettlementDateFlows, # = nullopt
Date settlementDate) # = Date()
@staticmethod
Real accruedAmount(const Leg& leg,
optional[bool] includeSettlementDateFlows, # =nullopt
Date settlementDate) # = Date()
@staticmethod
Real npv(const Leg& leg,
const YieldTermStructure& discountCurve,
bool includeSettlementDateFlows,
optional[bool] includeSettlementDateFlows, # = nullopt
Date settlementDate, # = Date(),
Date npvDate) # = Date())

@staticmethod
Real bps(const Leg& leg,
const YieldTermStructure& discountCurve,
bool includeSettlementDateFlows,
optional[bool] includeSettlementDateFlows, # = nullopt
Date settlementDate, # = Date(),
Date npvDate) # = Date())

@staticmethod
pair[Real, Real] npvbps(const Leg& leg,
const YieldTermStructure& discountCurve,
bool includeSettlementDateFlows,
optional[bool] includeSettlementDateFlows, # = nullopt
Date settlementDate, # = Date(),
Date npvDate) #= Date())
3 changes: 3 additions & 0 deletions quantlib/cashflows/_floating_rate_coupon.pxd
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from quantlib.types cimport Natural, Rate, Real, Spread
from libcpp cimport bool
from quantlib.ext cimport shared_ptr
from quantlib.handle cimport Handle
from quantlib.time._date cimport Date
from quantlib.time._daycounter cimport DayCounter
from quantlib._cashflow cimport CashFlow
from quantlib._interest_rate cimport InterestRate
from quantlib.cashflows._coupon cimport Coupon
from quantlib.termstructures._yield_term_structure cimport YieldTermStructure
from ._coupon_pricer cimport FloatingRateCouponPricer
from quantlib.indexes._interest_rate_index cimport InterestRateIndex

Expand All @@ -29,6 +31,7 @@ cdef extern from 'ql/cashflows/floatingratecoupon.hpp' namespace 'QuantLib' nogi
Date fixingDate()
Real gearing()
Spread spread()
Real price(Handle[YieldTermStructure])
Rate indexFixing()
Rate convexityAdjustment() except +
Rate adjustedFixing() except +
Expand Down
34 changes: 29 additions & 5 deletions quantlib/cashflows/_overnight_indexed_coupon.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ from quantlib.types cimport Integer, Natural, Rate, Real, Spread, Time

from libcpp cimport bool
from libcpp.vector cimport vector
from quantlib.ext cimport shared_ptr
from quantlib.ext cimport shared_ptr, optional
from quantlib.time._date cimport Date
from quantlib.time._period cimport Period
from quantlib.time._daycounter cimport DayCounter
from quantlib.time._schedule cimport Schedule
from quantlib.time._calendar cimport Calendar
from quantlib.time.businessdayconvention cimport BusinessDayConvention

from quantlib.indexes._ibor_index cimport OvernightIndex
from ._floating_rate_coupon cimport FloatingRateCoupon
from ._overnight_indexed_coupon_pricer cimport OvernightIndexedCouponPricer
from .rateaveraging cimport RateAveraging
from .._cashflow cimport Leg

Expand All @@ -28,9 +30,11 @@ cdef extern from 'ql/cashflows/overnightindexedcoupon.hpp' namespace 'QuantLib'
const DayCounter& dayCounter, #= DayCounter(),
bool telescopicValueDates, #=False,
RateAveraging averagingMethod, # = RateAveraging::Compound
Natural lookback_days,
Natural lockout_days,
bool apply_observation_shift)
Natural lookback_days, # = Null<Natural>
Natural lockout_days, # = 0
bool apply_observation_shift, #+ False
bool compound_spread, # = False
)

vector[Date]& fixingDates()
vector[Time]& dt()
Expand All @@ -39,6 +43,10 @@ cdef extern from 'ql/cashflows/overnightindexedcoupon.hpp' namespace 'QuantLib'
RateAveraging averagingMethod()
Natural lockoutDays()
bool applyObservationShift()
bool compoundSpreadDaily()
Real effectiveSpread()
Real effectiveIndexFixing()


cdef cppclass OvernightLeg:
OvernightLeg(Schedule schedule, shared_ptr[OvernightIndex] overnightIndex)
Expand All @@ -48,9 +56,25 @@ cdef extern from 'ql/cashflows/overnightindexedcoupon.hpp' namespace 'QuantLib'
OvernightLeg& withPaymentCalendar(Calendar)
OvernightLeg& withPaymentLag(Integer Lag)
OvernightLeg& withSpreads(Real spread)
OvernightLeg& withObservationShift(bool)
OvernightLeg& withSpreads(const vector[Spread]& spreads)
OvernightLeg& withTelescopicValueDates(bool telescopicValueDates)
OvernightLeg& withAveragingMethod(RateAveraging averagingMethod)
OvernightLeg& withLookbackDays(Natural)
OvernightLeg& withLockoutDays(Natural)
OvernightLeg& withObservationShift(bool applyObservationShift) # = true);
OvernightLeg& compoundingSpreadDaily(bool compoundSpreadDaily) # = true);
OvernightLeg& withLookback(const Period& lookback)
OvernightLeg& withCaps(Rate cap)
OvernightLeg& withCaps(const vector[Rate]& caps)
OvernightLeg& withFloors(Rate floor)
OvernightLeg& withFloors(const vector[Rate]& floors);
OvernightLeg& withNakedOption(bool nakedOption)
OvernightLeg& withDailyCapFloor(bool dailyCapFloor) # = true);
OvernightLeg& inArrears(bool inArrears)
OvernightLeg& withLastRecentPeriod(const optional[Period]& lastRecentPeriod)
OvernightLeg& withLastRecentPeriodCalendar(const Calendar& lastRecentPeriodCalendar)
OvernightLeg& withPaymentDates(const vector[Date]& paymentDates)
OvernightLeg& withCouponPricer(const shared_ptr[OvernightIndexedCouponPricer]& couponPricer)
Leg operator() const

cdef extern from 'ql/cashflows/overnightindexedcoupon.hpp':
Expand Down
14 changes: 11 additions & 3 deletions quantlib/cashflows/_overnight_indexed_coupon_pricer.pxd
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
from quantlib.types cimport Rate, Real
from libcpp cimport bool
from quantlib.handle cimport Handle
from ._coupon_pricer cimport FloatingRateCouponPricer
from quantlib.termstructures.volatility.optionlet._optionlet_volatility_structure cimport OptionletVolatilityStructure

cdef extern from 'ql/cashflows/overnightindexedcouponpricer.hpp' namespace 'QuantLib' nogil:
cdef cppclass CompoundingOvernightIndexedCouponPricer(FloatingRateCouponPricer):

cdef cppclass OvernightIndexedCouponPricer(FloatingRateCouponPricer):
pass

cdef cppclass CompoundingOvernightIndexedCouponPricer(OvernightIndexedCouponPricer):
pass
cdef cppclass ArithmeticAveragedOvernightIndexedCouponPricer(FloatingRateCouponPricer):
cdef cppclass ArithmeticAveragedOvernightIndexedCouponPricer(OvernightIndexedCouponPricer):
ArithmeticAveragedOvernightIndexedCouponPricer(
Real meanReversion, # = 0.03
Real volatility, # = 0.00 No convexity adjustment by default
bool byApprox # = false, True to use Katsumi Takada approximation
bool byApprox, # = false, True to use Katsumi Takada approximation
Handle[OptionletVolatilityStructure] v, # = Handle[OptionletVolatilityStructure]()
const bool effective_volatility_input, # = False
)
8 changes: 5 additions & 3 deletions quantlib/cashflows/api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from .overnight_indexed_coupon import OvernightIndexedCoupon, OvernightLeg
from .overnight_indexed_coupon import OvernightIndexedCoupon, OvernightLeg, as_overnight_indexed_coupon
from .cms_coupon import CmsCoupon
from .ibor_coupon import IborCoupon
from .fixed_rate_coupon import FixedRateCoupon, FixedRateLeg
from .ibor_coupon import IborCoupon, as_ibor_coupon
from .floating_rate_coupon import FloatingRateCoupon, as_floating_rate_coupon
from .fixed_rate_coupon import FixedRateCoupon, FixedRateLeg, as_fixed_rate_coupon
from ..cashflow import SimpleCashFlow, Leg
from .cap_floored_coupon import CappedFlooredCoupon, as_capped_floored_coupon
2 changes: 1 addition & 1 deletion quantlib/cashflows/cap_floored_coupon.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from .floating_rate_coupon cimport FloatingRateCoupon
from . cimport _cap_floored_coupon as _cfc

cdef class CappedFlooredCoupon(FloatingRateCoupon):
cdef inline _cfc.CappedFlooredCoupon* as_ptr(self)
cdef inline _cfc.CappedFlooredCoupon* as_ptr(self) noexcept

cdef class CappedFlooredIborCoupon(CappedFlooredCoupon):
pass
Expand Down
45 changes: 30 additions & 15 deletions quantlib/cashflows/cap_floored_coupon.pyx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
include '../types.pxi'
from quantlib.types cimport Natural, Rate, Real, Spread
from libcpp cimport bool
from cython.operator cimport dereference as deref
from quantlib.utilities.null cimport Null
from quantlib.ext cimport shared_ptr, static_pointer_cast
from quantlib.ext cimport static_pointer_cast, dynamic_pointer_cast
from quantlib.cashflows.coupon_pricer cimport FloatingRateCouponPricer
from quantlib.indexes.ibor_index cimport IborIndex
from quantlib.indexes.swap_index cimport SwapIndex
from quantlib.time.date cimport Date, Period
from quantlib.time.daycounter cimport DayCounter

from .._cashflow cimport CashFlow
from ..cashflow cimport CashFlow
from . cimport _floating_rate_coupon as _frc
cimport quantlib.indexes._ibor_index as _ii
cimport quantlib.indexes._swap_index as _si
Expand All @@ -18,12 +18,15 @@ cdef class CappedFlooredCoupon(FloatingRateCoupon):
def __init__(self, FloatingRateCoupon underlying not None,
Rate cap=Null[Real](),
Rate floor=Null[Real]()):
self._thisptr = shared_ptr[CashFlow](new _cfc.CappedFlooredCoupon(
static_pointer_cast[_frc.FloatingRateCoupon](underlying._thisptr),
cap,
floor))
self._thisptr.reset(
new _cfc.CappedFlooredCoupon(
static_pointer_cast[_frc.FloatingRateCoupon](underlying._thisptr),
cap,
floor
)
)

cdef inline _cfc.CappedFlooredCoupon* as_ptr(self):
cdef inline _cfc.CappedFlooredCoupon* as_ptr(self) noexcept:
return <_cfc.CappedFlooredCoupon*>self._thisptr.get()

@property
Expand Down Expand Up @@ -56,15 +59,22 @@ cdef class CappedFlooredCoupon(FloatingRateCoupon):

@property
def is_floored(self):
return (<_cfc.CappedFlooredCoupon*>self._thisptr.get()).isFloored()
return self.as_ptr().isFloored()

@property
def underlying(self):
cdef FloatingRateCoupon instance = FloatingRateCoupon.__new__(FloatingRateCoupon)
instance._thisptr = static_pointer_cast[CashFlow](
(<_cfc.CappedFlooredCoupon*>self._thisptr.get()).underlying())
instance._thisptr = self.as_ptr().underlying()
return instance

def as_capped_floored_coupon(CashFlow cf):
cdef CappedFlooredCoupon coupon = CappedFlooredCoupon.__new__(CappedFlooredCoupon)
coupon._thisptr = dynamic_pointer_cast[_cfc.CappedFlooredCoupon](cf._thisptr)
if not coupon._thisptr:
return None
else:
return coupon

cdef class CappedFlooredIborCoupon(CappedFlooredCoupon):
def __init__(self, Date payment_date not None,
Real nominal,
Expand All @@ -80,7 +90,8 @@ cdef class CappedFlooredIborCoupon(CappedFlooredCoupon):
Date ref_period_end=Date(),
DayCounter day_counter=DayCounter(),
bool is_in_arrears=False):
self._thisptr = shared_ptr[CashFlow](new _cfc.CappedFlooredIborCoupon(
self._thisptr.reset(
new _cfc.CappedFlooredIborCoupon(
payment_date._thisptr,
nominal,
start_date._thisptr,
Expand All @@ -94,7 +105,8 @@ cdef class CappedFlooredIborCoupon(CappedFlooredCoupon):
ref_period_start._thisptr,
ref_period_end._thisptr,
deref(day_counter._thisptr),
is_in_arrears))
is_in_arrears)
)

cdef class CappedFlooredCmsCoupon(CappedFlooredCoupon):
def __init__(self, Date payment_date not None,
Expand All @@ -111,7 +123,8 @@ cdef class CappedFlooredCmsCoupon(CappedFlooredCoupon):
Date ref_period_end=Date(),
DayCounter day_counter=DayCounter(),
bool is_in_arrears=False):
self._thisptr = shared_ptr[CashFlow](new _cfc.CappedFlooredCmsCoupon(
self._thisptr.reset(
new _cfc.CappedFlooredCmsCoupon(
payment_date._thisptr,
nominal,
start_date._thisptr,
Expand All @@ -125,4 +138,6 @@ cdef class CappedFlooredCmsCoupon(CappedFlooredCoupon):
ref_period_start._thisptr,
ref_period_end._thisptr,
deref(day_counter._thisptr),
is_in_arrears))
is_in_arrears
)
)
Loading
Loading