📄 ratehelpers.cpp
字号:
void DepositRateHelper::initializeDates() {
earliestDate_ =
index_->fixingCalendar().advance(evaluationDate_,
settlementDays_,
Days);
latestDate_ = index_->maturityDate(earliestDate_);
fixingDate_ = index_->fixingCalendar().advance(earliestDate_,
-static_cast<Integer>(index_->fixingDays()), Days);
}
FraRateHelper::FraRateHelper(const Handle<Quote>& rate,
Natural monthsToStart,
Natural monthsToEnd,
Natural settlementDays,
const Calendar& calendar,
BusinessDayConvention convention,
bool endOfMonth,
Natural fixingDays,
const DayCounter& dayCounter)
: RelativeDateRateHelper(rate), monthsToStart_(monthsToStart),
settlementDays_(settlementDays) {
QL_REQUIRE(monthsToEnd>monthsToStart,
"monthsToEnd must be grater than monthsToStart");
index_ = boost::shared_ptr<IborIndex>(new
IborIndex("dummy",
(monthsToEnd-monthsToStart)*Months,
fixingDays,
Currency(), calendar, convention,
endOfMonth, dayCounter, termStructureHandle_));
initializeDates();
}
FraRateHelper::FraRateHelper(Rate rate,
Natural monthsToStart,
Natural monthsToEnd,
Natural settlementDays,
const Calendar& calendar,
BusinessDayConvention convention,
bool endOfMonth,
Natural fixingDays,
const DayCounter& dayCounter)
: RelativeDateRateHelper(rate), monthsToStart_(monthsToStart),
settlementDays_(settlementDays) {
QL_REQUIRE(monthsToEnd>monthsToStart,
"monthsToEnd must be grater than monthsToStart");
index_ = boost::shared_ptr<IborIndex>(new
IborIndex("dummy",
(monthsToEnd-monthsToStart)*Months,
fixingDays,
Currency(), calendar, convention,
endOfMonth, dayCounter, termStructureHandle_));
initializeDates();
}
Real FraRateHelper::impliedQuote() const {
QL_REQUIRE(termStructure_ != 0, "term structure not set");
return index_->fixing(fixingDate_,true);
}
DiscountFactor FraRateHelper::discountGuess() const {
QL_REQUIRE(termStructure_ != 0, "term structure not set");
Time T = index_->dayCounter().yearFraction(earliestDate_,
latestDate_);
return termStructure_->discount(earliestDate_,true) /
(1.0+quote_->value()*T);
}
void FraRateHelper::setTermStructure(YieldTermStructure* t) {
// no need to register---the index is not lazy
termStructureHandle_.linkTo(
boost::shared_ptr<YieldTermStructure>(t,no_deletion),
false);
RelativeDateRateHelper::setTermStructure(t);
}
void FraRateHelper::initializeDates() {
Date settlement = index_->fixingCalendar().advance(evaluationDate_,
settlementDays_,
Days);
earliestDate_ = index_->fixingCalendar().advance(
settlement,monthsToStart_,Months,
index_->businessDayConvention(),
index_->endOfMonth());
latestDate_ = index_->maturityDate(earliestDate_);
fixingDate_ = index_->fixingCalendar().advance(earliestDate_,
-static_cast<Integer>(index_->fixingDays()), Days);
}
SwapRateHelper::SwapRateHelper(const Handle<Quote>& rate,
const Period& tenor,
Natural settlementDays,
const Calendar& calendar,
Frequency fixedFrequency,
BusinessDayConvention fixedConvention,
const DayCounter& fixedDayCount,
const boost::shared_ptr<IborIndex>& index)
: RelativeDateRateHelper(rate),
tenor_(tenor), settlementDays_(settlementDays),
calendar_(calendar), fixedConvention_(fixedConvention),
fixedFrequency_(fixedFrequency),
fixedDayCount_(fixedDayCount),
index_(index) {
registerWith(index_);
initializeDates();
}
SwapRateHelper::SwapRateHelper(Rate rate,
const Period& tenor,
Natural settlementDays,
const Calendar& calendar,
Frequency fixedFrequency,
BusinessDayConvention fixedConvention,
const DayCounter& fixedDayCount,
const boost::shared_ptr<IborIndex>& index)
: RelativeDateRateHelper(rate),
tenor_(tenor), settlementDays_(settlementDays),
calendar_(calendar), fixedConvention_(fixedConvention),
fixedFrequency_(fixedFrequency),
fixedDayCount_(fixedDayCount),
index_(index) {
registerWith(index_);
initializeDates();
}
void SwapRateHelper::initializeDates() {
earliestDate_ = calendar_.advance(evaluationDate_,
settlementDays_, Days);
// dummy Libor index with curve/swap arguments
boost::shared_ptr<IborIndex> clonedIndex(new
IborIndex(index_->familyName(),
index_->tenor(),
index_->fixingDays(),
index_->currency(),
index_->fixingCalendar(),
index_->businessDayConvention(),
index_->endOfMonth(),
index_->dayCounter(),
termStructureHandle_));
swap_ = MakeVanillaSwap(tenor_, clonedIndex, 0.0)
.withEffectiveDate(earliestDate_)
.withFixedLegDayCount(fixedDayCount_)
.withFixedLegTenor(Period(fixedFrequency_))
.withFixedLegConvention(fixedConvention_)
.withFixedLegTerminationDateConvention(fixedConvention_);
// Usually...
latestDate_ = swap_->maturityDate();
// ...but due to adjustments, the last floating coupon might
// need a later date for fixing
#ifdef QL_USE_INDEXED_COUPON
boost::shared_ptr<FloatingRateCoupon> lastFloating =
boost::dynamic_pointer_cast<FloatingRateCoupon>(
swap_->floatingLeg().back());
Date fixingValueDate = calendar_.advance(lastFloating->fixingDate(),
settlementDays_,Days);
Date endValueDate = calendar_.advance(fixingValueDate,
index_->tenor(),
index_->businessDayConvention(),
index_->endOfMonth());
latestDate_ = std::max(latestDate_,endValueDate);
#endif
}
void SwapRateHelper::setTermStructure(YieldTermStructure* t) {
// do not set the relinkable handle as an observer -
// force recalculation when needed
termStructureHandle_.linkTo(
boost::shared_ptr<YieldTermStructure>(t,no_deletion),
false);
RelativeDateRateHelper::setTermStructure(t);
}
Real SwapRateHelper::impliedQuote() const {
QL_REQUIRE(termStructure_ != 0, "term structure not set");
// we didn't register as observers - force calculation
swap_->recalculate();
return swap_->fairRate();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -