本文整理汇总了C++中Period类的典型用法代码示例。如果您正苦于以下问题:C++ Period类的具体用法?C++ Period怎么用?C++ Period使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Period类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getMillis
Period *Period::normalizedStandard(const PeriodType *type) {
type = DateTimeUtils::getPeriodType(type);
int64_t millis = getMillis(); // no overflow can happen, even with Integer.MAX_VALUEs
millis += (((int64_t) getSeconds()) * ((int64_t) DateTimeConstants::MILLIS_PER_SECOND));
millis += (((int64_t) getMinutes()) * ((int64_t) DateTimeConstants::MILLIS_PER_MINUTE));
millis += (((int64_t) getHours()) * ((int64_t) DateTimeConstants::MILLIS_PER_HOUR));
millis += (((int64_t) getDays()) * ((int64_t) DateTimeConstants::MILLIS_PER_DAY));
millis += (((int64_t) getWeeks()) * ((int64_t) DateTimeConstants::MILLIS_PER_WEEK));
Period *result = new Period(millis, type, ISOChronology::getInstanceUTC());
int years = getYears();
int months = getMonths();
if (years != 0 || months != 0) {
int64_t totalMonths = years * 12L + months;
if (type->isSupported(DurationFieldType::YEARS_TYPE)) {
int normalizedYears = FieldUtils::safeToInt(totalMonths / 12);
result = result->withYears(normalizedYears);
totalMonths = totalMonths - (normalizedYears * 12);
}
if (type->isSupported(DurationFieldType::MONTHS_TYPE)) {
int normalizedMonths = FieldUtils::safeToInt(totalMonths);
result = result->withMonths(normalizedMonths);
totalMonths = totalMonths - normalizedMonths;
}
if (totalMonths != 0) {
string err("Unable to normalize as PeriodType is missing either years or months but period has a month/year amount: ");
err.append(toString());
throw UnsupportedOperationException(err);
}
}
return result;
}
示例2: new
void IsoffMainParser::parsePeriods(Node *root)
{
std::vector<Node *> periods = DOMHelper::getElementByTagName(root, "Period", false);
std::vector<Node *>::const_iterator it;
for(it = periods.begin(); it != periods.end(); ++it)
{
Period *period = new (std::nothrow) Period(mpd);
if (!period)
continue;
parseSegmentInformation(*it, period);
if((*it)->hasAttribute("start"))
period->startTime.Set(IsoTime((*it)->getAttributeValue("start")));
if((*it)->hasAttribute("duration"))
period->duration.Set(IsoTime((*it)->getAttributeValue("duration")));
if((*it)->hasAttribute("id"))
period->setId((*it)->getAttributeValue("id"));
std::vector<Node *> baseUrls = DOMHelper::getChildElementByTagName(*it, "BaseURL");
if(!baseUrls.empty())
period->baseUrl.Set( new Url( baseUrls.front()->getText() ) );
setAdaptationSets(*it, period);
mpd->addPeriod(period);
}
}
示例3: 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");
}
}
示例4: 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();
}
示例5: 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()) << ")");
}
}
示例6: schedule
FixedRateBond::FixedRateBond(Natural settlementDays,
const Calendar& calendar,
Real faceAmount,
const Date& startDate,
const Date& maturityDate,
const Period& tenor,
const std::vector<Rate>& coupons,
const DayCounter& accrualDayCounter,
BusinessDayConvention accrualConvention,
BusinessDayConvention paymentConvention,
Real redemption,
const Date& issueDate,
const Date& stubDate,
DateGeneration::Rule rule,
bool endOfMonth,
const Calendar& paymentCalendar)
: Bond(settlementDays,
paymentCalendar==Calendar() ? calendar : paymentCalendar,
issueDate),
frequency_(tenor.frequency()), dayCounter_(accrualDayCounter) {
maturityDate_ = maturityDate;
Date firstDate, nextToLastDate;
switch (rule) {
case DateGeneration::Backward:
firstDate = Date();
nextToLastDate = stubDate;
break;
case DateGeneration::Forward:
firstDate = stubDate;
nextToLastDate = Date();
break;
case DateGeneration::Zero:
case DateGeneration::ThirdWednesday:
case DateGeneration::Twentieth:
case DateGeneration::TwentiethIMM:
QL_FAIL("stub date (" << stubDate << ") not allowed with " <<
rule << " DateGeneration::Rule");
default:
QL_FAIL("unknown DateGeneration::Rule (" << Integer(rule) << ")");
}
Schedule schedule(startDate, maturityDate_, tenor,
calendar, accrualConvention, accrualConvention,
rule, endOfMonth,
firstDate, nextToLastDate);
cashflows_ = FixedRateLeg(schedule)
.withNotionals(faceAmount)
.withCouponRates(coupons, accrualDayCounter)
.withPaymentCalendar(calendar_)
.withPaymentAdjustment(paymentConvention);
addRedemptionsToCashflows(std::vector<Real>(1, redemption));
QL_ENSURE(!cashflows().empty(), "bond with no cashflows!");
QL_ENSURE(redemptions_.size() == 1, "multiple redemptions created");
}
示例7: 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() << ")");
}
示例8: main
int main()
{
//creating object of period by calling default constructor
Period period;
//creating object of period by calling constructor w/ param
PeriodName name;
char ch = 'y';
int range1, range2;
//loop
while (ch == 'y' || ch == 'Y')
{
//user prompt to enter year ranges
cout << "Enter the range of the prehistoric dates"
<< endl << "(in Million years, seperated" << "by space):";
//read years
cin >> range1 >> range2;
//check validity of range then display error
if(range1 < 0||range2 < 0)
cout << "Invalid range. Please try again." << endl;
else
{
//loop to display peroid names within range
for(name = NEOGENE; name <= PRECAMBRIAN;
name = PeriodName(name + 1))
{
if(period.toInt(name) >= range1 &&
period.toInt(name)< range2)
cout << "Period Name: " << period.toString(name) << endl << "The Period Began At " << period.toInt(name) << " Million Years." << endl << endl;
}//end of for statement
cout << endl << endl;
//prompt user to continue
cout << "Do you want to continue?"
<< "(Press 'n' to Exit 'y' to continue):";
cin >> ch;
cout << endl;
}
}
system("Pause");
return 0;
}
示例9: msg_Dbg
void IsoffMainParser::print ()
{
if(this->mpd)
{
msg_Dbg(this->p_stream, "MPD profile=%d mediaPresentationDuration=%ld minBufferTime=%ld", this->mpd->getProfile(),
this->mpd->getDuration(),
this->mpd->getMinBufferTime());
const std::vector<BaseUrl *> baseurls = this->mpd->getBaseUrls();
for(size_t i = 0; i < baseurls.size(); i++)
msg_Dbg(this->p_stream, "BaseUrl=%s", baseurls.at(i)->getUrl().c_str());
const std::vector<Period *> periods = this->mpd->getPeriods();
for(size_t i = 0; i < periods.size(); i++)
{
Period *period = periods.at(i);
msg_Dbg(this->p_stream, " Period");
for(size_t j = 0; j < period->getAdaptationSets().size(); j++)
{
AdaptationSet *aset = period->getAdaptationSets().at(j);
msg_Dbg(this->p_stream, " AdaptationSet");
for(size_t k = 0; k < aset->getRepresentations().size(); k++)
{
Representation *rep = aset->getRepresentations().at(k);
msg_Dbg(this->p_stream, " Representation");
Segment *initSeg = rep->getSegmentBase()->getInitSegment();
msg_Dbg(this->p_stream, " InitSeg url=%s", initSeg->getSourceUrl().c_str());
for(size_t l = 0; l < rep->getSegmentList()->getSegments().size(); l++)
{
Segment *seg = rep->getSegmentList()->getSegments().at(l);
msg_Dbg(this->p_stream, " Segment url=%s", seg->getSourceUrl().c_str());
}
}
}
}
}
}
示例10: 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()<< "]");
}
示例11: advance
inline Date Date::operator-(const Period& p) const {
return advance(*this,-p.length(),p.units());
}
示例12: return
/*!
* @brief Add period to Date
*/
Date operator+(const Period& add) const
{ return (utc + add.get_nsecs()); }
示例13: load_courses_from_csv
void load_courses_from_csv(SchoolSchedule *sopti, string periods_file)
{
ifstream period_list;
string tmps;
char tmpa[500];
vector<string> fields;
// Open the file
period_list.open(periods_file.c_str());
if(period_list.fail()) {
error("error opening file %s", periods_file.c_str());
}
// Ignore header line
period_list.getline(tmpa, 500);
while(1) {
period_list.getline(tmpa, 500);
if(!period_list.good()) {
break;
}
tmps = tmpa;
if(tmps[tmps.size()-1] == '\r')
tmps.erase(tmps.size()-1, 1);
fields = split_string(tmps, ";");
if(fields.size() != 15) {
error("invalid course file format (field_num != 15)");
}
// prepare some variables in advance
bool islab;
int type;
SchoolCourse *current_course;
if(fields[COURSEFILE_FIELD_COURSELAB] == "L")
islab=true;
else if(fields[COURSEFILE_FIELD_COURSELAB] == "C")
islab=false;
else
error("unrecognized course type");
if(fields[COURSEFILE_FIELD_COURSETYPE] == "T")
type = COURSE_TYPE_THEORYONLY;
else if(fields[COURSEFILE_FIELD_COURSETYPE] == "L")
type = COURSE_TYPE_LABONLY;
else if(fields[COURSEFILE_FIELD_COURSETYPE] == "TL")
type = COURSE_TYPE_THEORYLABSAME;
else if(fields[COURSEFILE_FIELD_COURSETYPE] == "TLS")
type = COURSE_TYPE_THEORYLABIND;
// Add course if not exists
if(!sopti->course_exists(fields[COURSEFILE_FIELD_SYMBOL])) {
SchoolCourse newcourse(fields[COURSEFILE_FIELD_SYMBOL]);
newcourse.set_title(fields[COURSEFILE_FIELD_TITLE]);
newcourse.set_type(type);
sopti->course_add(newcourse);
}
current_course = sopti->course(fields[COURSEFILE_FIELD_SYMBOL]);
// Add group if not exists
if(!current_course->group_exists(fields[COURSEFILE_FIELD_GROUP], islab)) {
Group newgroup(fields[COURSEFILE_FIELD_GROUP]);
newgroup.set_lab(islab);
current_course->add_group(newgroup, islab);
}
// Add period. It should not exist.
int period_no = poly_make_period_no(fields[COURSEFILE_FIELD_DAY], fields[COURSEFILE_FIELD_TIME]);
if(current_course->group(fields[COURSEFILE_FIELD_GROUP], islab)->has_period(period_no)) {
error("two occurences of the same period in course file");
}
Period newperiod;
newperiod.set_room(fields[COURSEFILE_FIELD_ROOM]);
newperiod.set_period_no(period_no);
if(fields[COURSEFILE_FIELD_LABWEEK] == "I") {
newperiod.set_week(1);
}
else if(fields[COURSEFILE_FIELD_LABWEEK] == "P") {
newperiod.set_week(2);
}
else {
newperiod.set_week(0);
}
current_course->group(fields[COURSEFILE_FIELD_GROUP], islab)->add_period(newperiod);
}
period_list.close();
}
示例14: advance
Date Calendar::advance(const Date & d,
const Period & p,
BusinessDayConvention c,
bool endOfMonth) const {
return advance(d, p.length(), p.units(), c, endOfMonth);
}
示例15: performCalculations
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;
}
*/
}