31 Size determineNumberOfFixings(
const std::vector<Date>& interestDates,
33 bool applyObservationShift) {
34 Size n = std::lower_bound(interestDates.begin(), interestDates.end(), date) -
35 interestDates.begin();
41 return n == interestDates.size() && applyObservationShift ?
n - 1 :
n;
57 const ext::shared_ptr<OvernightIndex> index =
58 ext::dynamic_pointer_cast<OvernightIndex>(
coupon_->
index());
59 const auto& pastFixings = index->timeSeries();
68 const Size n = determineNumberOfFixings(interestDates, date, applyObservationShift);
70 Real compoundFactor = 1.0;
73 while (i <
n && fixingDates[i] < today) {
75 const Rate fixing = pastFixings[fixingDates[i]];
77 "Missing " << index->name() <<
" fixing for " << fixingDates[i]);
78 Time span = (date >= interestDates[i + 1] ?
80 index->dayCounter().yearFraction(interestDates[i], date));
81 compoundFactor *= (1.0 + fixing * span);
86 if (i <
n && fixingDates[i] == today) {
89 Rate fixing = pastFixings[fixingDates[i]];
91 Time span = (date >= interestDates[i + 1] ?
93 index->dayCounter().yearFraction(interestDates[i], date));
94 compoundFactor *= (1.0 + fixing * span);
110 "null term structure set to this instance of " << index->name());
112 const auto effectiveRate = [&index, &fixingDates, &date, &interestDates,
113 &dt](
Size position) {
114 Rate fixing = index->fixing(fixingDates[position]);
115 Time span = (date >= interestDates[position + 1] ?
117 index->dayCounter().yearFraction(interestDates[position], date));
118 return span * fixing;
133 compoundFactor *= (1.0 + effectiveRate(i));
145 curve->discount(valueDates[std::min<Size>(nLockout, i)]);
146 if (interestDates[
n] == date || isLockoutApplied) {
149 curve->discount(valueDates[std::min<Size>(nLockout,
n)]);
150 compoundFactor *= startDiscount / endDiscount;
156 i = std::max(nLockout, i);
160 compoundFactor *= (1.0 + effectiveRate(i));
169 compoundFactor *= startDiscount / endDiscount;
170 compoundFactor *= (1.0 + effectiveRate(
n - 1));
187 ext::shared_ptr<OvernightIndex> index =
188 ext::dynamic_pointer_cast<OvernightIndex>(
coupon_->
index());
193 Size n = dt.size(), i = 0;
195 Real accumulatedRate = 0.0;
197 const auto& pastFixings = index->timeSeries();
201 while (i <
n && fixingDates[i] < today) {
203 Rate pastFixing = pastFixings[fixingDates[i]];
205 "Missing " << index->name() <<
" fixing for " << fixingDates[i]);
206 accumulatedRate += pastFixing * dt[i];
211 if (i <
n && fixingDates[i] == today) {
214 Rate pastFixing = pastFixings[fixingDates[i]];
216 accumulatedRate += pastFixing * dt[i];
232 "null term structure set to this instance of " << index->name());
239 log(startDiscount / endDiscount) -
240 convAdj1(curve->timeFromReference(dates[i]), curve->timeFromReference(dates[
n])) -
241 convAdj2(curve->timeFromReference(dates[i]), curve->timeFromReference(dates[
n]));
247 "null term structure set to this instance of " << index->name());
250 Time te = curve->timeFromReference(dates[
n]);
253 Rate forecastFixing = index->fixing(fixingDates[i]);
254 Time ti1 = curve->timeFromReference(dates[i]);
255 Time ti2 = curve->timeFromReference(dates[i + 1]);
259 0.5 * pow(
vol_, 2.0) / pow(
mrs_, 3.0) * (exp(2 *
mrs_ * ti1) - 1) *
260 (exp(-
mrs_ * ti2) - exp(-
mrs_ * te)) * (exp(-
mrs_ * ti2) - exp(-
mrs_ * ti1)));
261 accumulatedRate += convAdj * (1 + forecastFixing * dt[i]) - 1;
271 return vol_ *
vol_ / (4.0 * pow(
mrs_, 3.0)) * (1.0 - exp(-2.0 *
mrs_ * ts)) *
272 pow((1.0 - exp(-
mrs_ * (te - ts))), 2.0);
277 ((te - ts) - pow(1.0 - exp(-
mrs_ * (te - ts)), 2.0) /
mrs_ -
278 (1.0 - exp(-2.0 *
mrs_ * (te - ts))) / (2.0 *
mrs_));
void initialize(const FloatingRateCoupon &coupon) override
Real convAdj2(Time ts, Time te) const
const OvernightIndexedCoupon * coupon_
Rate swapletRate() const override
Real convAdj1(Time ts, Time te) const
void initialize(const FloatingRateCoupon &coupon) override
const OvernightIndexedCoupon * coupon_
Rate swapletRate() const override
Rate averageRate(const Date &date) const
const Date & accrualEndDate() const
end of the accrual period
Time accruedPeriod(const Date &) const
accrued period as fraction of year at the given date
Time accrualPeriod() const
accrual period as fraction of year
base floating-rate coupon class
Real gearing() const
index gearing, i.e. multiplicative coefficient for the index
const ext::shared_ptr< InterestRateIndex > & index() const
floating index
Spread spread() const
spread paid over the fixing of the underlying index
Shared handle to an observable.
bool empty() const
checks if the contained shared pointer points to anything
template class providing a null value for a given type.
const std::vector< Date > & valueDates() const
value dates for the rates to be compounded
const std::vector< Date > & interestDates() const
interest dates for the rates to be compounded
Natural lockoutDays() const
lockout days
bool applyObservationShift() const
apply observation shift
bool canApplyTelescopicFormula() const
const std::vector< Time > & dt() const
accrual (compounding) periods
const std::vector< Date > & fixingDates() const
fixing dates for the rates to be compounded
DateProxy & evaluationDate()
the date at which pricing is to be performed.
static Settings & instance()
access to the unique instance
#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
Real Time
continuous quantity with 1-year units
Real DiscountFactor
discount factor between dates
std::size_t Size
size of a container
contains the pricer for an OvernightIndexedCoupon