void CalendarTemplateElement::apply( Calendar& result, const Calendar& mask ) const { // Empty mask : exit if(mask.empty()) { return; } // Min and max dates of the update date minDate(_minDate); if( minDate.is_neg_infinity() || (minDate < mask.getFirstActiveDate() && _step.days() == 1) ){ minDate = mask.getFirstActiveDate(); } date maxDate(_maxDate); if (maxDate > mask.getLastActiveDate()) { maxDate = mask.getLastActiveDate(); } // Abort if no date if(minDate > maxDate) { return; } // Base mask Calendar elementMask(minDate, maxDate, _step); elementMask &= mask; if(_include) { elementMask = _include->getResult(elementMask); } // Applying the element on the result switch(_operation) { case ADD: result |= elementMask; break; case SUB: result -= elementMask; break; case AND: result &= elementMask; break; } }
MakeSchedule::operator Schedule() const { // check for mandatory arguments QL_REQUIRE(effectiveDate_ != Date(), "effective date not provided"); QL_REQUIRE(terminationDate_ != Date(), "termination date not provided"); QL_REQUIRE(tenor_, "tenor/frequency not provided"); // set dynamic defaults: BusinessDayConvention convention; // if a convention was set, we use it. if (convention_) { convention = *convention_; } else { if (!calendar_.empty()) { // ...if we set a calendar, we probably want it to be used; convention = Following; } else { // if not, we don't care. convention = Unadjusted; } } BusinessDayConvention terminationDateConvention; // if set explicitly, we use it; if (terminationDateConvention_) { terminationDateConvention = *terminationDateConvention_; } else { // Unadjusted as per ISDA specification terminationDateConvention = convention; } Calendar calendar = calendar_; // if no calendar was set... if (calendar.empty()) { // ...we use a null one. calendar = NullCalendar(); } return Schedule(effectiveDate_, terminationDate_, *tenor_, calendar, convention, terminationDateConvention, rule_, endOfMonth_, firstDate_, nextToLastDate_); }
ClonedYieldTermStructure::ClonedYieldTermStructure( const boost::shared_ptr<YieldTermStructure> &source, const ReactionToTimeDecay reactionToTimeDecay, const Processing processing, const Calendar calendar) : YieldTermStructure(source->dayCounter()), reactionToTimeDecay_(reactionToTimeDecay), processing_(processing), originalEvalDate_(Settings::instance().evaluationDate()), originalReferenceDate_(Date(source->referenceDate())), originalMaxDate_(source->maxDate()) { calendar_ = calendar.empty() ? source->calendar() : calendar; QL_REQUIRE(!calendar_.empty() || reactionToTimeDecay_ == FixedReferenceDate, "a floating termstructure needs a calendar, none given and " "source termstructures' calendar is empty, too"); referenceDate_ = originalReferenceDate_; maxDate_ = originalMaxDate_; offset_ = 0.0; valid_ = true; instFwdMax_ = source->forwardRate(maxDate_, maxDate_, Actual365Fixed(), Continuous) .rate(); if (reactionToTimeDecay != FixedReferenceDate) { QL_REQUIRE(originalReferenceDate_ >= originalEvalDate_, "to construct a moving term structure the source term " "structure must have a reference date (" << originalReferenceDate_ << ") after the evaluation date (" << originalEvalDate_ << ")"); try { impliedSettlementDays_ = source->settlementDays(); } catch (...) { // if the source ts has no settlement days we imply // them from the difference of the original reference // date and the original evaluation date impliedSettlementDays_ = this->calendar().businessDaysBetween( originalEvalDate_, originalReferenceDate_); } } logDiscounts_.resize(originalMaxDate_.serialNumber() - originalReferenceDate_.serialNumber() + 1); times_.resize(logDiscounts_.size()); for (BigInteger i = 0; i <= originalMaxDate_.serialNumber() - originalReferenceDate_.serialNumber(); ++i) { Date d = Date(originalReferenceDate_.serialNumber() + i); logDiscounts_[i] = std::log(source->discount(d)); times_[i] = timeFromReference(d); if (processing == PositiveYieldsAndForwards) { logDiscounts_[i] = std::min(0.0, logDiscounts_[i]); } if (processing == PositiveForwards || processing == PositiveYieldsAndForwards) { if (i > 0) logDiscounts_[i] = std::min(logDiscounts_[i - 1], logDiscounts_[i]); } } if (reactionToTimeDecay_ != FixedReferenceDate) { registerWith(Settings::instance().evaluationDate()); } }
void BaseCalendarUpdateAction::_doCalendarUpdate( Calendar& object, server::Request& request ) const { // Link to remove if(_linkToRemove) { DeleteQuery<CalendarLinkTableSync> deleteQuery; deleteQuery.addWhereField(TABLE_COL_ID, *_linkToRemove); deleteQuery.execute(); } // Add date if(!object.isLinked() && !_addLink) { // Preparation of the mask Calendar mask; if( !_startDate.is_not_a_date() && !_endDate.is_not_a_date()) { for (date d = _startDate; d <= _endDate; d += _period) { mask.setActive(d); } } if(_calendarTemplate.get()) { if(!mask.empty()) { mask = _calendarTemplate->getResult(mask); } else if(_calendarTemplate->isLimited()) { mask = _calendarTemplate->getResult(); } else if(_calendarTemplate2.get() && _calendarTemplate2->isLimited()) { mask = _calendarTemplate->getResult(_calendarTemplate2->getResult()); } } if(_calendarTemplate2.get()) { if(!mask.empty()) { mask = _calendarTemplate2->getResult(mask); } else if(_calendarTemplate2->isLimited()) { mask = _calendarTemplate2->getResult(); } } // Applying the mask if( !mask.empty()) { if(_add) { object |= mask; } else { object -= mask; } } } else if(_calendarUpdateToDo()) // Add link { CalendarLink link; link.setCalendar(&object); link.setStartDate(_startDate); link.setEndDate(_endDate); link.setCalendarTemplate(_calendarTemplate.get()); link.setCalendarTemplate2(_calendarTemplate2.get()); CalendarLinkTableSync::Save(&link); } // Storage of parameters in session variable if( !_startDate.is_not_a_date() && !_endDate.is_not_a_date() && _startDate != _endDate ){ if(!_startDate.is_not_a_date() && !_startDate.is_special()) { request.getSession()->setSessionVariable( SESSION_VARIABLE_SERVICE_ADMIN_START_DATE, to_iso_extended_string(_startDate) ); } if(!_endDate.is_not_a_date() && !_endDate.is_special()) { request.getSession()->setSessionVariable( SESSION_VARIABLE_SERVICE_ADMIN_END_DATE, to_iso_extended_string(_endDate) ); } } if(_calendarTemplate.get()) { request.getSession()->setSessionVariable( SESSION_VARIABLE_SERVICE_ADMIN_CALENDAR_TEMPLATE_ID, lexical_cast<string>(_calendarTemplate->getKey()) ); } if(_calendarTemplate2.get()) { request.getSession()->setSessionVariable( SESSION_VARIABLE_SERVICE_ADMIN_CALENDAR_TEMPLATE_ID2, lexical_cast<string>(_calendarTemplate2->getKey()) ); } // Dates to force to add if(!_dateToForceToAdd.is_not_a_date()) { Calendar::DatesSet dates(object.getDatesToForce()); dates.insert(_dateToForceToAdd); object.setDatesToForce(dates); object.setActive(_dateToForceToAdd); // Add date if non linked calendar (linked calendar behavior emulation) object.setActive(_dateToForceToAdd); } // Dates to force to remove if(!_dateToForceToRemove.is_not_a_date()) { Calendar::DatesSet dates(object.getDatesToForce()); dates.erase(_dateToForceToRemove); object.setDatesToForce(dates); object.setInactive(_dateToForceToRemove); } // Dates to bypass to add if(!_dateToBypassToAdd.is_not_a_date()) { // Add date to bypass Calendar::DatesSet dates(object.getDatesToBypass()); dates.insert(_dateToBypassToAdd); object.setDatesToBypass(dates); // Remove date if non linked calendar (linked calendar behavior emulation) object.setInactive(_dateToBypassToAdd); } // Dates to bypass to remove if(!_dateToBypassToRemove.is_not_a_date()) { Calendar::DatesSet dates(object.getDatesToBypass()); dates.erase(_dateToBypassToRemove); object.setDatesToBypass(dates); object.setActive(_dateToBypassToRemove); } }
inline bool operator==(const Calendar& c1, const Calendar& c2) { return (c1.empty() && c2.empty()) || (!c1.empty() && !c2.empty() && c1.name() == c2.name()); }