本文整理汇总了C++中Period::length方法的典型用法代码示例。如果您正苦于以下问题:C++ Period::length方法的具体用法?C++ Period::length怎么用?C++ Period::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Period
的用法示例。
在下文中一共展示了Period::length方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: swapLength
Time SwaptionVolatilityStructure::swapLength(const Period& p) const {
QL_REQUIRE(p.length()>0,
"non-positive swap tenor (" << p << ") given");
switch (p.units()) {
case Months:
return p.length()/12.0;
case Years:
return static_cast<Time>(p.length());
default:
QL_FAIL("invalid Time Unit (" << p.units() << ") for swap length");
}
}
示例2: Bond
AmortizingFixedRateBond::AmortizingFixedRateBond(
Natural settlementDays,
const Calendar& calendar,
Real initialFaceAmount,
const Date& startDate,
const Period& bondTenor,
const Frequency& sinkingFrequency,
const Rate coupon,
const DayCounter& accrualDayCounter,
BusinessDayConvention paymentConvention,
const Date& issueDate)
: Bond(settlementDays, calendar, issueDate),
frequency_(sinkingFrequency),
dayCounter_(accrualDayCounter) {
QL_REQUIRE(bondTenor.length() > 0,
"bond tenor must be positive. "
<< bondTenor << " is not allowed.");
maturityDate_ = startDate + bondTenor;
cashflows_ =
FixedRateLeg(sinkingSchedule(startDate, bondTenor,
sinkingFrequency, calendar))
.withNotionals(sinkingNotionals(bondTenor,
sinkingFrequency, coupon,
initialFaceAmount))
.withCouponRates(coupon, accrualDayCounter)
.withPaymentAdjustment(paymentConvention);
addRedemptionsToCashflows();
}
示例3: days
Real days(const Period& p) {
if (p.length()==0) return 0.0;
switch (p.units()) {
case Days:
return p.length();
case Weeks:
return p.length()*7.0;
case Months:
QL_FAIL("cannot convert Months into Days");
case Years:
QL_FAIL("cannot convert Years into Days");
default:
QL_FAIL("unknown time unit (" << Integer(p.units()) << ")");
}
}
示例4: checkSwapTenor
void SwaptionVolatilityStructure::checkSwapTenor(const Period& swapTenor,
bool extrapolate) const {
QL_REQUIRE(swapTenor.length() > 0,
"non-positive swap tenor (" << swapTenor << ") given");
QL_REQUIRE(extrapolate || allowsExtrapolation() ||
swapTenor <= maxSwapTenor(),
"swap tenor (" << swapTenor << ") is past max tenor ("
<< maxSwapTenor() << ")");
}
示例5: checkRange
void CallableBondVolatilityStructure::checkRange(const Date& optionDate,
const Period& bondTenor,
Rate k,
bool extrapolate) const {
TermStructure::checkRange(timeFromReference(optionDate),
extrapolate);
QL_REQUIRE(bondTenor.length() > 0,
"negative bond tenor (" << bondTenor << ") given");
QL_REQUIRE(extrapolate || allowsExtrapolation() ||
bondTenor <= maxBondTenor(),
"bond tenor (" << bondTenor << ") is past max tenor ("
<< maxBondTenor() << ")");
QL_REQUIRE(extrapolate || allowsExtrapolation() ||
(k >= minStrike() && k <= maxStrike()),
"strike (" << k << ") is outside the curve domain ["
<< minStrike() << "," << maxStrike()<< "]");
}
示例6: advance
Date Calendar::advance(const Date & d,
const Period & p,
BusinessDayConvention c,
bool endOfMonth) const {
return advance(d, p.length(), p.units(), c, endOfMonth);
}
示例7: cP
void InterpolatedCPICapFloorTermPriceSurface<I2D>::
performCalculations() const {
Size nMat = cfMaturities_.size(), ncK = cStrikes_.size(), nfK = fStrikes_.size(),
nK = ncK + nfK;
Matrix cP(nK, nMat), fP(nK, nMat);
Handle<ZeroInflationTermStructure> zts = zii_->zeroInflationTermStructure();
Handle<YieldTermStructure> yts = this->nominalTermStructure();
QL_REQUIRE(!zts.empty(),"Zts is empty!!!");
QL_REQUIRE(!yts.empty(),"Yts is empty!!!");
for (Size i =0; i<nfK; i++){
allStrikes_.push_back(fStrikes_[i]);
for (Size j=0; j<nMat; j++) {
Period mat = cfMaturities_[j];
Real df = yts->discount(cpiOptionDateFromTenor(mat));
Real atm_quote = zts->zeroRate(cpiOptionDateFromTenor(mat));
Real atm = pow(1.0+atm_quote, mat.length());
Real S = atm * df;
Real K_quote = fStrikes_[i]/100.0;
Real K = pow(1.0+K_quote, mat.length());
cP[i][j] = fPrice_[i][j] + S - K * df;
fP[i][j] = fPrice_[i][j];
}
}
for (Size i =0; i<ncK; i++){
allStrikes_.push_back(cStrikes_[i]);
for (Size j=0; j<nMat; j++) {
Period mat = cfMaturities_[j];
Real df = yts->discount(cpiOptionDateFromTenor(mat));
Real atm_quote = zts->zeroRate(cpiOptionDateFromTenor(mat));
Real atm = pow(1.0+atm_quote, mat.length());
Real S = atm * df;
Real K_quote = cStrikes_[i]/100.0;
Real K = pow(1.0+K_quote, mat.length());
cP[i+nfK][j] = cPrice_[i][j];
fP[i+nfK][j] = cPrice_[i][j] + K * df - S;
}
}
// copy to store
cPriceB_ = cP;
fPriceB_ = fP;
cfMaturityTimes_.clear();
for (Size i=0; i<cfMaturities_.size();i++) {
cfMaturityTimes_.push_back(timeFromReference(cpiOptionDateFromTenor(cfMaturities_[i])));
}
capPrice_ = interpolator2d_.interpolate(cfMaturityTimes_.begin(),cfMaturityTimes_.end(),
allStrikes_.begin(), allStrikes_.end(),
cPriceB_
);
capPrice_.enableExtrapolation();
floorPrice_ = interpolator2d_.interpolate(cfMaturityTimes_.begin(),cfMaturityTimes_.end(),
allStrikes_.begin(), allStrikes_.end(),
fPriceB_
);
floorPrice_.enableExtrapolation();
/* test code - note order of indices
for (Size i =0; i<nK; i++){
std::cout << allStrikes_[i] << ": ";
Real qK = allStrikes_[i];
for (Size j=0; j<nMat; j++) {
Real t = cfMaturityTimes_[j];
std::cout << fP[i][j] << "," << floorPrice_(t,qK) << " | " ;
}
std::cout << std::endl;
}
for (Size i =0; i<nK; i++){
std::cout << allStrikes_[i] << ": ";
Real qK = allStrikes_[i];
for (Size j=0; j<nMat; j++) {
Real t = cfMaturityTimes_[j];
std::cout << cP[i][j] << "," << capPrice_(t,qK) << " | " ;
}
std::cout << std::endl;
}
*/
}
示例8: advance
inline Date Date::operator-(const Period& p) const {
return advance(*this,-p.length(),p.units());
}
示例9: Date
Schedule::Schedule(Date effectiveDate,
const Date& terminationDate,
const Period& tenor,
const Calendar& cal,
BusinessDayConvention convention,
BusinessDayConvention terminationDateConvention,
DateGeneration::Rule rule,
bool endOfMonth,
const Date& first,
const Date& nextToLast)
: tenor_(tenor), calendar_(cal), convention_(convention),
terminationDateConvention_(terminationDateConvention), rule_(rule),
endOfMonth_(allowsEndOfMonth(tenor) ? endOfMonth : false),
firstDate_(first==effectiveDate ? Date() : first),
nextToLastDate_(nextToLast==terminationDate ? Date() : nextToLast)
{
// sanity checks
QL_REQUIRE(terminationDate != Date(), "null termination date");
// in many cases (e.g. non-expired bonds) the effective date is not
// really necessary. In these cases a decent placeholder is enough
if (effectiveDate==Date() && first==Date()
&& rule==DateGeneration::Backward) {
Date evalDate = Settings::instance().evaluationDate();
QL_REQUIRE(evalDate < terminationDate, "null effective date");
Natural y;
if (nextToLast != Date()) {
y = (nextToLast - evalDate)/366 + 1;
effectiveDate = nextToLast - y*Years;
} else {
y = (terminationDate - evalDate)/366 + 1;
effectiveDate = terminationDate - y*Years;
}
} else
QL_REQUIRE(effectiveDate != Date(), "null effective date");
QL_REQUIRE(effectiveDate < terminationDate,
"effective date (" << effectiveDate
<< ") later than or equal to termination date ("
<< terminationDate << ")");
if (tenor.length()==0)
rule_ = DateGeneration::Zero;
else
QL_REQUIRE(tenor.length()>0,
"non positive tenor (" << tenor << ") not allowed");
if (firstDate_ != Date()) {
switch (*rule_) {
case DateGeneration::Backward:
case DateGeneration::Forward:
QL_REQUIRE(firstDate_ > effectiveDate &&
firstDate_ < terminationDate,
"first date (" << firstDate_ <<
") out of effective-termination date range [" <<
effectiveDate << ", " << terminationDate << ")");
// we should ensure that the above condition is still
// verified after adjustment
break;
case DateGeneration::ThirdWednesday:
QL_REQUIRE(IMM::isIMMdate(firstDate_, false),
"first date (" << firstDate_ <<
") is not an IMM date");
break;
case DateGeneration::Zero:
case DateGeneration::Twentieth:
case DateGeneration::TwentiethIMM:
case DateGeneration::OldCDS:
case DateGeneration::CDS:
QL_FAIL("first date incompatible with " << *rule_ <<
" date generation rule");
default:
QL_FAIL("unknown rule (" << Integer(*rule_) << ")");
}
}
if (nextToLastDate_ != Date()) {
switch (*rule_) {
case DateGeneration::Backward:
case DateGeneration::Forward:
QL_REQUIRE(nextToLastDate_ > effectiveDate &&
nextToLastDate_ < terminationDate,
"next to last date (" << nextToLastDate_ <<
") out of effective-termination date range (" <<
effectiveDate << ", " << terminationDate << "]");
// we should ensure that the above condition is still
// verified after adjustment
break;
case DateGeneration::ThirdWednesday:
QL_REQUIRE(IMM::isIMMdate(nextToLastDate_, false),
"next-to-last date (" << nextToLastDate_ <<
") is not an IMM date");
break;
case DateGeneration::Zero:
case DateGeneration::Twentieth:
case DateGeneration::TwentiethIMM:
case DateGeneration::OldCDS:
case DateGeneration::CDS:
QL_FAIL("next to last date incompatible with " << *rule_ <<
" date generation rule");
default:
//.........这里部分代码省略.........
示例10: if
bool operator<(const Period& p1, const Period& p2) {
// special cases
if (p1.length() == 0)
return p2.length() > 0;
if (p2.length() == 0)
return p1.length() < 0;
// exact comparisons
if (p1.units() == p2.units())
return p1.length() < p2.length();
if (p1.units() == Months && p2.units() == Years)
return p1.length() < 12*p2.length();
if (p1.units() == Years && p2.units() == Months)
return 12*p1.length() < p2.length();
if (p1.units() == Days && p2.units() == Weeks)
return p1.length() < 7*p2.length();
if (p1.units() == Weeks && p2.units() == Days)
return 7*p1.length() < p2.length();
// inexact comparisons (handled by converting to days and using limits)
std::pair<Integer, Integer> p1lim = daysMinMax(p1);
std::pair<Integer, Integer> p2lim = daysMinMax(p2);
if (p1lim.second < p2lim.first)
return true;
else if (p1lim.first > p2lim.second)
return false;
else
QL_FAIL("undecidable comparison between " << p1 << " and " << p2);
}