shared_ptr<SwapIndex> SwapIndex::clone(const Handle<YieldTermStructure>& forwarding) const { if (exogenousDiscount_) return shared_ptr<SwapIndex>(new SwapIndex(familyName(), tenor(), fixingDays(), currency(), fixingCalendar(), fixedLegTenor(), fixedLegConvention(), dayCounter(), iborIndex_->clone(forwarding), discount_)); else return shared_ptr<SwapIndex>(new SwapIndex(familyName(), tenor(), fixingDays(), currency(), fixingCalendar(), fixedLegTenor(), fixedLegConvention(), dayCounter(), iborIndex_->clone(forwarding))); }
void InterpolatedZeroCurve<T>::initialize(const Compounding& compounding, const Frequency& frequency) { QL_REQUIRE(dates_.size() >= T::requiredPoints, "not enough input dates given"); QL_REQUIRE(this->data_.size() == dates_.size(), "dates/data count mismatch"); this->times_.resize(dates_.size()); this->times_[0] = 0.0; if (compounding != Continuous) { // We also have to convert the first rate. // The first time is 0.0, so we can't use it. // We fall back to about one day. Time dt = 1.0/365; InterestRate r(this->data_[0], dayCounter(), compounding, frequency); this->data_[0] = r.equivalentRate(Continuous, NoFrequency, dt); #if !defined(QL_NEGATIVE_RATES) QL_REQUIRE(this->data_[0] > 0.0, "non-positive yield"); #endif } for (Size i=1; i<dates_.size(); ++i) { QL_REQUIRE(dates_[i] > dates_[i-1], "invalid date (" << dates_[i] << ", vs " << dates_[i-1] << ")"); this->times_[i] = dayCounter().yearFraction(dates_[0], dates_[i]); QL_REQUIRE(!close(this->times_[i],this->times_[i-1]), "two dates correspond to the same time " "under this curve's day count convention"); // adjusting zero rates to match continuous compounding if (compounding != Continuous) { InterestRate r(this->data_[i], dayCounter(), compounding, frequency); this->data_[i] = r.equivalentRate(Continuous, NoFrequency, this->times_[i]); } #if !defined(QL_NEGATIVE_RATES) QL_REQUIRE(this->data_[i] > 0.0, "non-positive yield"); // positive yields are not enough to ensure non-negative fwd rates // so here's a stronger requirement QL_REQUIRE(this->data_[i] * this->times_[i] - this->data_[i - 1] * this->times_[i - 1] >= 0.0, "negative forward rate implied by the zero yield " << io::rate(this->data_[i]) << " at " << dates_[i] << " (t=" << this->times_[i] << ") after the zero yield " << io::rate(this->data_[i - 1]) << " at " << dates_[i - 1] << " (t=" << this->times_[i - 1] << ")"); #endif } this->interpolation_ = this->interpolator_.interpolate(this->times_.begin(), this->times_.end(), this->data_.begin()); this->interpolation_.update(); }
void InterpolatedForwardCurve<T>::initialize() { QL_REQUIRE(dates_.size() >= T::requiredPoints, "not enough input dates given"); QL_REQUIRE(this->data_.size() == dates_.size(), "dates/data count mismatch"); this->times_.resize(dates_.size()); this->times_[0]=0.0; for (Size i=1; i<dates_.size(); ++i) { QL_REQUIRE(dates_[i] > dates_[i-1], "invalid date (" << dates_[i] << ", vs " << dates_[i-1] << ")"); this->times_[i] = dayCounter().yearFraction(dates_[0], dates_[i]); QL_REQUIRE(!close(this->times_[i], this->times_[i-1]), "two dates correspond to the same time " "under this curve's day count convention"); #if !defined(QL_NEGATIVE_RATES) QL_REQUIRE(this->data_[i] >= 0.0, "negative forward"); #endif } this->interpolation_ = this->interpolator_.interpolate(this->times_.begin(), this->times_.end(), this->data_.begin()); this->interpolation_.update(); }
Time Coupon::accrualPeriod() const { if (accrualPeriod_ == Null<Real>()) accrualPeriod_ = dayCounter().yearFraction(accrualStartDate_, accrualEndDate_, refPeriodStart_, refPeriodEnd_); return accrualPeriod_; }
BigInteger Coupon::accruedDays(const Date& d) const { if (d <= accrualStartDate_ || d > paymentDate_) { return 0; } else { return dayCounter().dayCount(accrualStartDate_, std::min(d, accrualEndDate_)); } }
boost::shared_ptr<SmileSection> SwaptionVolatilityMatrix::smileSectionImpl(Time optionTime, Time swapLength) const { // dummy strike Volatility atmVol = volatilityImpl(optionTime, swapLength, 0.05); return boost::shared_ptr<SmileSection>(new FlatSmileSection(optionTime, atmVol, dayCounter())); }
boost::shared_ptr<SmileSection> ConstantSwaptionVolatility::smileSectionImpl(const Date& d, const Period&) const { Volatility atmVol = volatility_->value(); return boost::shared_ptr<SmileSection>( new FlatSmileSection(d, atmVol, dayCounter(), referenceDate(), Null<Rate>(), volatilityType_, shift_)); }
boost::shared_ptr<SmileSection> ConstantSwaptionVolatility::smileSectionImpl(Time optionTime, Time) const { Volatility atmVol = volatility_->value(); return boost::shared_ptr<SmileSection>( new FlatSmileSection(optionTime, atmVol, dayCounter(), Null<Rate>(), volatilityType_, shift_)); }
boost::shared_ptr<SmileSection> SwaptionVolatilityMatrix::smileSectionImpl(Time optionTime, Time swapLength) const { // dummy strike Volatility atmVol = volatilityImpl(optionTime, swapLength, 0.05); Real shift = interpolationShifts_(optionTime, swapLength,true); return boost::shared_ptr<SmileSection>(new FlatSmileSection( optionTime, atmVol, dayCounter(), Null<Real>(), shift)); }
inline boost::shared_ptr<SmileSection> CapletVarianceCurve::smileSectionImpl(Time t) const { // dummy strike Volatility atmVol = blackCurve_.blackVol(t, 0.05, true); return boost::shared_ptr<SmileSection>(new FlatSmileSection(t, atmVol, dayCounter())); }
inline Rate CompositeZeroYieldStructure<BinaryFunction>::zeroYieldImpl(Time t) const { Rate zeroRate1 = curve1_->zeroRate(t, comp_, freq_, true); InterestRate zeroRate2 = curve2_->zeroRate(t, comp_, freq_, true); InterestRate compositeRate(f_(zeroRate1, zeroRate2), dayCounter(), comp_, freq_); return compositeRate.equivalentRate(Continuous, NoFrequency, t); }
boost::shared_ptr<IborIndex> OvernightIndex::clone( const Handle<YieldTermStructure>& h) const { return boost::shared_ptr<IborIndex>( new OvernightIndex(familyName(), fixingDays(), currency(), fixingCalendar(), dayCounter(), h)); }
InterestRate YieldTermStructure::zeroRate(Time t, Compounding comp, Frequency freq, bool extrapolate) const { if (t==0.0) t = dt; Real compound = 1.0/discount(t, extrapolate); return InterestRate::impliedRate(compound, dayCounter(), comp, freq, t); }
Time Coupon::accruedPeriod(const Date& d) const { if (d <= accrualStartDate_ || d > paymentDate_) { return 0.0; } else { return dayCounter().yearFraction(accrualStartDate_, std::min(d, accrualEndDate_), refPeriodStart_, refPeriodEnd_); } }
ext::shared_ptr<IborIndex> Libor::clone( const Handle<YieldTermStructure>& h) const { return ext::shared_ptr<IborIndex>(new Libor(familyName(), tenor(), fixingDays(), currency(), financialCenterCalendar_, dayCounter(), h)); }
std::pair<Time,Time> CallableBondVolatilityStructure::convertDates( const Date& optionDate, const Period& bondTenor) const { Date end = optionDate + bondTenor; QL_REQUIRE(end>optionDate, "negative bond tenor (" << bondTenor << ") given"); Time optionTime = timeFromReference(optionDate); Time timeLength = dayCounter().yearFraction(optionDate, end); return std::make_pair(optionTime, timeLength); }
Real InflationCoupon::accruedAmount(const Date& d) const { if (d <= accrualStartDate_ || d > paymentDate_) { return 0.0; } else { return nominal() * rate() * dayCounter().yearFraction(accrualStartDate_, std::min(d, accrualEndDate_), refPeriodStart_, refPeriodEnd_); } }
boost::shared_ptr<IborIndex> IborIndex::clone( const Handle<YieldTermStructure>& h) const { return boost::shared_ptr<IborIndex>( new IborIndex(familyName(), tenor(), fixingDays(), currency(), fixingCalendar(), businessDayConvention(), endOfMonth(), dayCounter(), h)); }
inline DiscountFactor ImpliedTermStructure::discountImpl(Time t) const { /* t is relative to the current reference date and needs to be converted to the time relative to the reference date of the original curve */ Date ref = referenceDate(); Time originalTime = t + dayCounter().yearFraction( originalCurve_->referenceDate(), ref); /* discount at evaluation date cannot be cached since the original curve could change between invocations of this method */ return originalCurve_->discount(originalTime, true) / originalCurve_->discount(ref, true); }
boost::shared_ptr<SmileSection> SingleSabrSwaptionVolatility::smileSectionImpl(const Date& d, const Period& tenor) const { std::vector<Real> params(4); params[0] = alpha_; params[1] = beta_; params[2] = nu_; params[3] = rho_; Real forward = indexBase_->clone(tenor)->fixing(d); boost::shared_ptr<SmileSection> raw(new SabrSmileSection(d,forward,params,dayCounter(),shift_)); // make it arbitrage free //boost::shared_ptr<SmileSection> af(new KahaleSmileSection(raw)); //return af; return raw; }
inline Real ImpliedVolTermStructure::blackVarianceImpl(Time t, Real strike) const { /* timeShift (and/or variance) variance at evaluation date cannot be cached since the original curve could change between invocations of this method */ Time timeShift = dayCounter().yearFraction(originalTS_->referenceDate(), referenceDate()); /* t is relative to the current reference date and needs to be converted to the time relative to the reference date of the original curve */ return originalTS_->blackForwardVariance(timeShift, timeShift+t, strike, true); }
InterestRate YieldTermStructure::forwardRate(Time t1, Time t2, Compounding comp, Frequency freq, bool extrapolate) const { Real compound; if (t2==t1) { checkRange(t1, extrapolate); t1 = std::max(t1 - dt/2.0, 0.0); t2 = t1 + dt; compound = discount(t1, true)/discount(t2, true); } else { QL_REQUIRE(t2>t1, "t2 (" << t2 << ") < t1 (" << t2 << ")"); compound = discount(t1, extrapolate)/discount(t2, extrapolate); } return InterestRate::impliedRate(compound, dayCounter(), comp, freq, t2-t1); }
//! needed for total variance calculations Time YoYOptionletVolatilitySurface::timeFromBase(const Date &maturityDate, const Period& obsLag) const { Period useLag = obsLag; if (obsLag==Period(-1,Days)) { useLag = observationLag(); } Date useDate; if (indexIsInterpolated()) { useDate = maturityDate - useLag; } else { useDate = inflationPeriod(maturityDate - useLag, frequency()).first; } // This assumes that the inflation term structure starts // as late as possible given the inflation index definition, // which is the usual case. return dayCounter().yearFraction(baseDate(), useDate); }
void ClonedYieldTermStructure::update() { YieldTermStructure::update(); if (reactionToTimeDecay_ != FixedReferenceDate) { Date today = Settings::instance().evaluationDate(); if (today < originalEvalDate_) { valid_ = false; } else { valid_ = true; referenceDate_ = calendar().advance(today, impliedSettlementDays_ * Days); if (reactionToTimeDecay_ == ForwardForward) { offset_ = dayCounter().yearFraction(originalReferenceDate_, referenceDate_); } if (reactionToTimeDecay_ == ConstantZeroYields) { BigNatural dayOffset = referenceDate_ - originalReferenceDate_; maxDate_ = Date(std::min<BigNatural>( originalMaxDate_.serialNumber() + dayOffset, Date::maxDate().serialNumber())); } } } }
void InterpolatedDiscountCurve<T>::initialize() { QL_REQUIRE(dates_.size() >= T::requiredPoints, "not enough input dates given"); QL_REQUIRE(this->data_.size() == dates_.size(), "dates/data count mismatch"); QL_REQUIRE(this->data_[0] == 1.0, "the first discount must be == 1.0 " "to flag the corresponding date as reference date"); this->times_.resize(dates_.size()); this->times_[0] = 0.0; for (Size i=1; i<dates_.size(); ++i) { QL_REQUIRE(dates_[i] > dates_[i-1], "invalid date (" << dates_[i] << ", vs " << dates_[i-1] << ")"); this->times_[i] = dayCounter().yearFraction(dates_[0], dates_[i]); QL_REQUIRE(!close(this->times_[i],this->times_[i-1]), "two dates correspond to the same time " "under this curve's day count convention"); QL_REQUIRE(this->data_[i] > 0.0, "negative discount"); #if !defined(QL_NEGATIVE_RATES) QL_REQUIRE(this->data_[i] <= this->data_[i-1], "negative forward rate implied by the discount " << this->data_[i] << " at " << dates_[i] << " (t=" << this->times_[i] << ") after the discount " << this->data_[i-1] << " at " << dates_[i-1] << " (t=" << this->times_[i-1] << ")"); #endif } this->interpolation_ = this->interpolator_.interpolate(this->times_.begin(), this->times_.end(), this->data_.begin()); this->interpolation_.update(); }
Time Coupon::accrualPeriod() const { return dayCounter().yearFraction(accrualStartDate_, accrualEndDate_, refPeriodStart_, refPeriodEnd_); }
inline Time TermStructure::timeFromReference(const Date& d) const { return dayCounter().yearFraction(referenceDate(), d); }
BigInteger Coupon::accrualDays() const { return dayCounter().dayCount(accrualStartDate_, accrualEndDate_); }
ext::shared_ptr<SmileSection> ConstantOptionletVolatility::smileSectionImpl(Time optionTime) const { Volatility atmVol = volatility_->value(); return ext::shared_ptr<SmileSection>(new FlatSmileSection(optionTime, atmVol, dayCounter())); }
ext::shared_ptr<SmileSection> ConstantOptionletVolatility::smileSectionImpl(const Date& d) const { Volatility atmVol = volatility_->value(); return ext::shared_ptr<SmileSection>(new FlatSmileSection(d, atmVol, dayCounter(), referenceDate())); }