38 class OvernightIndexedCouponPricer :
public FloatingRateCouponPricer {
40 void initialize(
const FloatingRateCoupon& coupon)
override {
41 coupon_ =
dynamic_cast<const OvernightIndexedCoupon*
>(&coupon);
45 Rate averageRate(
const Date& date)
const {
49 const ext::shared_ptr<OvernightIndex> index =
50 ext::dynamic_pointer_cast<OvernightIndex>(
coupon_->index());
53 const vector<Date>& fixingDates =
coupon_->fixingDates();
54 const vector<Date>& valueDates =
coupon_->valueDates();
55 const vector<Time>& dt =
coupon_->dt();
58 const size_t n = std::lower_bound(valueDates.begin(), valueDates.end(), date) - valueDates.begin();
59 Real compoundFactor = 1.0;
62 while (i <
n && fixingDates[i] < today) {
64 const Rate fixing = pastFixings[fixingDates[i]];
66 "Missing " << index->name() <<
67 " fixing for " << fixingDates[i]);
68 Time span = (date >= valueDates[i+1] ?
70 index->dayCounter().yearFraction(valueDates[i], date));
71 compoundFactor *= (1.0 + fixing * span);
76 if (i <
n && fixingDates[i] == today) {
79 Rate fixing = pastFixings[fixingDates[i]];
80 if (fixing != Null<Real>()) {
81 Time span = (date >= valueDates[i+1] ?
83 index->dayCounter().yearFraction(valueDates[i], date));
84 compoundFactor *= (1.0 + fixing * span);
97 const Handle<YieldTermStructure> curve = index->forwardingTermStructure();
99 "null term structure set to this instance of " << index->name());
101 const DiscountFactor startDiscount = curve->discount(valueDates[i]);
102 if (valueDates[
n] == date) {
105 compoundFactor *= startDiscount / endDiscount;
111 compoundFactor *= startDiscount / endDiscount;
113 Rate fixing = index->fixing(fixingDates[
n-1]);
114 Time span = index->dayCounter().yearFraction(valueDates[
n-1], date);
115 compoundFactor *= (1.0 + fixing * span);
119 const Rate rate = (compoundFactor - 1.0) /
coupon_->accruedPeriod(date);
123 Rate swapletRate()
const override {
124 return averageRate(
coupon_->accrualEndDate());
127 Real swapletPrice()
const override {
QL_FAIL(
"swapletPrice not available"); }
128 Real capletPrice(
Rate)
const override {
QL_FAIL(
"capletPrice not available"); }
129 Rate capletRate(
Rate)
const override {
QL_FAIL(
"capletRate not available"); }
130 Real floorletPrice(
Rate)
const override {
QL_FAIL(
"floorletPrice not available"); }
131 Rate floorletRate(
Rate)
const override {
QL_FAIL(
"floorletRate not available"); }
139 const Date& paymentDate,
141 const Date& startDate,
143 const ext::shared_ptr<OvernightIndex>& overnightIndex,
146 const Date& refPeriodStart,
147 const Date& refPeriodEnd,
149 bool telescopicValueDates,
152 overnightIndex ? overnightIndex->fixingDays() : 0,
155 refPeriodStart, refPeriodEnd,
156 dayCounter, false), averagingMethod_(averagingMethod) {
159 Date tmpEndDate = endDate;
169 if (telescopicValueDates) {
173 tmpEndDate = overnightIndex->fixingCalendar().
advance(
175 tmpEndDate = std::min(tmpEndDate, endDate);
188 if (telescopicValueDates) {
191 Date tmp = overnightIndex->fixingCalendar().
advance(
195 tmp = overnightIndex->fixingCalendar().adjust(
196 endDate, overnightIndex->businessDayConvention());
205 if (overnightIndex->fixingDays()==0) {
216 const DayCounter& dc = overnightIndex->dayCounter();
222 setPricer(ext::shared_ptr<FloatingRateCouponPricer>(
227 ext::shared_ptr<FloatingRateCouponPricer>(
new OvernightIndexedCouponPricer));
249 const auto overnightIndexPricer = ext::dynamic_pointer_cast<OvernightIndexedCouponPricer>(
pricer_);
250 if (overnightIndexPricer)
251 return overnightIndexPricer->averageRate(
d);
273 : schedule_(
std::move(schedule)), overnightIndex_(
std::move(i)), paymentCalendar_(schedule_.calendar()) {
319 spreads_ = vector<Spread>(1,spread);
338 OvernightLeg::operator
Leg()
const {
340 QL_REQUIRE(!notionals_.empty(),
"no notional given");
345 Calendar calendar = schedule_.calendar();
347 Date refStart, start, refEnd, end;
350 Size n = schedule_.size()-1;
351 for (
Size i=0; i<
n; ++i) {
352 refStart = start = schedule_.date(i);
353 refEnd = end = schedule_.date(i+1);
354 paymentDate = paymentCalendar_.
advance(end, paymentLag_,
Days, paymentAdjustment_);
356 if (i == 0 && schedule_.hasIsRegular() && !schedule_.isRegular(i+1))
357 refStart = calendar.
adjust(end - schedule_.tenor(),
359 if (i ==
n-1 && schedule_.hasIsRegular() && !schedule_.isRegular(i+1))
360 refEnd = calendar.
adjust(start + schedule_.tenor(),
363 cashflows.push_back(ext::shared_ptr<CashFlow>(
new
373 telescopicValueDates_,
const AverageBMACoupon * coupon_
pricer for arithmetically-averaged overnight-indexed coupons
degenerate base class for the Acyclic Visitor pattern
Date adjust(const Date &, BusinessDayConvention convention=Following) 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
const TimeSeries< Real > & getHistory(const std::string &name) const
returns the (possibly empty) history of the index fixings
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 > fixingDates_
const RateAveraging::Type averagingMethod() const
averaging method
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)
const std::vector< Rate > & indexFixings() const
fixings to be compounded
void accept(AcyclicVisitor &) override
std::vector< Rate > fixings_
Real accruedAmount(const Date &) const override
accrued amount at the given date
std::vector< Date > valueDates_
Rate averageRate(const Date &date) const
helper class building a sequence of overnight coupons
ext::shared_ptr< OvernightIndex > overnightIndex_
BusinessDayConvention paymentAdjustment_
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_
OvernightLeg & withNotionals(Real notional)
RateAveraging::Type averagingMethod_
OvernightLeg & withAveragingMethod(RateAveraging::Type averagingMethod)
OvernightLeg & withPaymentDayCounter(const DayCounter &)
OvernightLeg & withSpreads(Spread spread)
OvernightLeg(Schedule schedule, ext::shared_ptr< OvernightIndex > overnightIndex)
OvernightLeg & withPaymentLag(Integer lag)
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
#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.
detail::percent_holder rate(Rate)
output rates and spreads as percentages
Real Time
continuous quantity with 1-year units
Real DiscountFactor
discount factor between dates
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
ext::shared_ptr< BlackVolTermStructure > v
Utilities for vector manipulation.
Interest-rate term structure.