37 Date applyLookbackPeriod(
const ext::shared_ptr<InterestRateIndex>& index,
38 const Date& valueDate,
40 return index->fixingCalendar().advance(valueDate, -
static_cast<Integer>(lookbackDays),
46 const Date& paymentDate,
48 const Date& startDate,
50 const ext::shared_ptr<OvernightIndex>& overnightIndex,
53 const Date& refPeriodStart,
54 const Date& refPeriodEnd,
56 bool telescopicValueDates,
60 bool applyObservationShift)
65 refPeriodStart, refPeriodEnd,
67 averagingMethod_(averagingMethod), lockoutDays_(lockoutDays),
68 applyObservationShift_(applyObservationShift) {
71 Date tmpEndDate = endDate;
82 "Telescopic formula cannot be applied for a coupon with lookback.");
84 if (telescopicValueDates) {
88 tmpEndDate = overnightIndex->fixingCalendar().
advance(
90 tmpEndDate = std::min(tmpEndDate, endDate);
103 if (telescopicValueDates) {
106 tmpEndDate = overnightIndex->fixingCalendar().adjust(
107 endDate, overnightIndex->businessDayConvention());
108 Date tmpLockoutDate = overnightIndex->fixingCalendar().
advance(
110 while (tmpLockoutDate <= tmpEndDate)
134 for (
Size i = 0; i <=
n_; ++i) {
160 "Lockout period cannot be negative or exceed the number of fixing days.");
168 const DayCounter& dc = overnightIndex->dayCounter();
176 "Cannot price an overnight coupon with simple averaging with lookback or lockout.");
177 setPricer(ext::make_shared<ArithmeticAveragedOvernightIndexedCouponPricer>(telescopicValueDates));
180 setPricer(ext::make_shared<CompoundingOvernightIndexedCouponPricer>());
202 if (
const auto compoundingPricer =
203 ext::dynamic_pointer_cast<CompoundingOvernightIndexedCouponPricer>(
pricer_)) {
204 return compoundingPricer->averageRate(
d);
272 spreads_ = vector<Spread>(1,spread);
304 OvernightLeg::operator
Leg()
const {
306 QL_REQUIRE(!notionals_.empty(),
"no notional given");
311 Calendar calendar = schedule_.calendar();
313 Date refStart, start, refEnd, end;
316 Size n = schedule_.size()-1;
317 for (
Size i=0; i<
n; ++i) {
318 refStart = start = schedule_.date(i);
319 refEnd = end = schedule_.date(i+1);
322 if (i == 0 && schedule_.hasIsRegular() && !schedule_.isRegular(i+1))
323 refStart = calendar.
adjust(end - schedule_.tenor(),
325 if (i ==
n-1 && schedule_.hasIsRegular() && !schedule_.isRegular(i+1))
326 refEnd = calendar.
adjust(start + schedule_.tenor(),
329 const auto overnightIndexedCoupon = ext::make_shared<OvernightIndexedCoupon>(
330 paymentDate,
detail::get(notionals_, i, notionals_.back()), start, end,
332 refStart, refEnd, paymentDayCounter_, telescopicValueDates_, averagingMethod_,
333 lookbackDays_, lockoutDays_, applyObservationShift_);
335 cashflows.push_back(overnightIndexedCoupon);
degenerate base class for the Acyclic Visitor pattern
Date adjust(const Date &, BusinessDayConvention convention=Following) const
Date advance(const Date &, Integer n, TimeUnit unit, BusinessDayConvention convention=Following, bool endOfMonth=false) const
bool tradingExCoupon(const Date &refDate=Date()) const
returns true if the cashflow is trading ex-coupon on the refDate
virtual Real nominal() const
Time accruedPeriod(const Date &) const
accrued period as fraction of year at the given date
static Date advance(const Date &d, Integer units, TimeUnit)
Time yearFraction(const Date &, const Date &, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date()) const
Returns the period between two dates as a fraction of year.
base floating-rate coupon class
ext::shared_ptr< InterestRateIndex > index_
virtual void setPricer(const ext::shared_ptr< FloatingRateCouponPricer > &)
ext::shared_ptr< FloatingRateCouponPricer > pricer_
void accept(AcyclicVisitor &) override
MakeSchedule & withConvention(BusinessDayConvention)
MakeSchedule & backwards()
MakeSchedule & to(const Date &terminationDate)
MakeSchedule & withTenor(const Period &)
MakeSchedule & from(const Date &effectiveDate)
MakeSchedule & withCalendar(const Calendar &)
std::vector< Date > interestDates_
std::vector< Date > fixingDates_
OvernightIndexedCoupon(const Date &paymentDate, Real nominal, const Date &startDate, const Date &endDate, const ext::shared_ptr< OvernightIndex > &overnightIndex, Real gearing=1.0, Spread spread=0.0, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date(), const DayCounter &dayCounter=DayCounter(), bool telescopicValueDates=false, RateAveraging::Type averagingMethod=RateAveraging::Compound, Natural lookbackDays=Null< Natural >(), Natural lockoutDays=0, bool applyObservationShift=false)
const std::vector< Rate > & indexFixings() const
fixings to be compounded
void accept(AcyclicVisitor &) override
std::vector< Rate > fixings_
bool applyObservationShift_
bool canApplyTelescopicFormula() const
Real accruedAmount(const Date &) const override
accrued amount at the given date
std::vector< Date > valueDates_
RateAveraging::Type averagingMethod() const
averaging method
Rate averageRate(const Date &date) const
helper class building a sequence of overnight coupons
ext::shared_ptr< OvernightIndex > overnightIndex_
BusinessDayConvention paymentAdjustment_
OvernightLeg & withObservationShift(bool applyObservationShift=true)
bool telescopicValueDates_
OvernightLeg & withGearings(Real gearing)
OvernightLeg & withPaymentCalendar(const Calendar &)
Calendar paymentCalendar_
OvernightLeg & withTelescopicValueDates(bool telescopicValueDates)
OvernightLeg & withPaymentAdjustment(BusinessDayConvention)
std::vector< Real > notionals_
std::vector< Spread > spreads_
bool applyObservationShift_
OvernightLeg & withNotionals(Real notional)
RateAveraging::Type averagingMethod_
OvernightLeg & withAveragingMethod(RateAveraging::Type averagingMethod)
OvernightLeg & withPaymentDayCounter(const DayCounter &)
OvernightLeg & withLockoutDays(Natural lockoutDays)
OvernightLeg & withSpreads(Spread spread)
OvernightLeg(Schedule schedule, ext::shared_ptr< OvernightIndex > overnightIndex)
OvernightLeg & withPaymentLag(Integer lag)
OvernightLeg & withLookbackDays(Natural lookbackDays)
std::vector< Real > gearings_
DayCounter paymentDayCounter_
const std::vector< Date > & dates() const
DateProxy & evaluationDate()
the date at which pricing is to be performed.
static Settings & instance()
access to the unique instance
Visitor for a specific class
virtual void visit(T &)=0
Calendar paymentCalendar_
#define QL_ENSURE(condition, message)
throw an error if the given post-condition is not verified
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_FAIL(message)
throw an error (possibly with file and line information)
BusinessDayConvention
Business Day conventions.
unsigned QL_INTEGER Natural
positive integer
QL_INTEGER Integer
integer number
Real Spread
spreads on interest rates
std::size_t Size
size of a container
T get(const std::vector< T > &v, Size i, U defaultValue)
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
coupon paying the compounded daily overnight rate
contains the pricer for an OvernightIndexedCoupon
ext::shared_ptr< BlackVolTermStructure > v
Utilities for vector manipulation.
Interest-rate term structure.