Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass Schedule by value and move #1942

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions ql/cashflows/cpicoupon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,13 @@ namespace QuantLib {
return notional() * (I1 / I0);
}

CPILeg::CPILeg(const Schedule& schedule,
CPILeg::CPILeg(Schedule schedule,
ext::shared_ptr<ZeroInflationIndex> index,
const Real baseCPI,
const Period& observationLag)
: schedule_(schedule), index_(std::move(index)), baseCPI_(baseCPI),
: schedule_(std::move(schedule)), index_(std::move(index)), baseCPI_(baseCPI),
observationLag_(observationLag), paymentDayCounter_(Thirty360(Thirty360::BondBasis)),
paymentCalendar_(schedule.calendar()),

paymentCalendar_(schedule_.calendar()),
spreads_(std::vector<Real>(1, 0)), baseDate_(Null<Date>()) {}


Expand Down Expand Up @@ -366,15 +365,15 @@ namespace QuantLib {
Size n = schedule_.size()-1;
Leg leg;
leg.reserve(n+1); // +1 for notional, we always have some sort ...

Date baseDate = baseDate_;
// BaseDate and baseCPI are not given, use the first date as startDate and the baseFixingg
// should be at startDate - observationLag

if (n>0) {
QL_REQUIRE(!fixedRates_.empty() || !spreads_.empty(),
"no fixedRates or spreads given");

if (baseDate_ == Null<Date>() && baseCPI_ == Null<Real>()) {
baseDate = schedule_.date(0) - observationLag_;
}
Expand Down Expand Up @@ -435,7 +434,7 @@ namespace QuantLib {
Date paymentDate = paymentCalendar_.adjust(schedule_.date(n), paymentAdjustment_);
leg.push_back(ext::make_shared<CPICashFlow>
(detail::get(notionals_, n, 0.0), index_,
baseDate, baseCPI_,
baseDate, baseCPI_,
schedule_.date(n), observationLag_, observationInterpolation_,
paymentDate, subtractInflationNominal_));

Expand All @@ -446,4 +445,3 @@ namespace QuantLib {
}

}

2 changes: 1 addition & 1 deletion ql/cashflows/cpicoupon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ namespace QuantLib {
*/
class CPILeg {
public:
CPILeg(const Schedule& schedule,
CPILeg(Schedule schedule,
ext::shared_ptr<ZeroInflationIndex> index,
Real baseCPI,
const Period& observationLag);
Expand Down
4 changes: 2 additions & 2 deletions ql/cashflows/fixedratecoupon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ namespace QuantLib {
}


FixedRateLeg::FixedRateLeg(const Schedule& schedule)
: schedule_(schedule), paymentCalendar_(schedule.calendar()) {}
FixedRateLeg::FixedRateLeg(Schedule schedule)
: schedule_(std::move(schedule)), paymentCalendar_(schedule_.calendar()) {}

FixedRateLeg& FixedRateLeg::withNotionals(Real notional) {
notionals_ = vector<Real>(1,notional);
Expand Down
2 changes: 1 addition & 1 deletion ql/cashflows/fixedratecoupon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace QuantLib {
//! helper class building a sequence of fixed rate coupons
class FixedRateLeg {
public:
FixedRateLeg(const Schedule& schedule);
FixedRateLeg(Schedule schedule);
FixedRateLeg& withNotionals(Real);
FixedRateLeg& withNotionals(const std::vector<Real>&);
FixedRateLeg& withCouponRates(Rate,
Expand Down
8 changes: 4 additions & 4 deletions ql/cashflows/overnightindexedcoupon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ namespace QuantLib {
const Date& refPeriodStart,
const Date& refPeriodEnd,
const DayCounter& dayCounter,
bool telescopicValueDates,
bool telescopicValueDates,
RateAveraging::Type averagingMethod)
: FloatingRateCoupon(paymentDate, nominal, startDate, endDate,
overnightIndex ? overnightIndex->fixingDays() : 0,
Expand Down Expand Up @@ -269,8 +269,8 @@ namespace QuantLib {
}
}

OvernightLeg::OvernightLeg(const Schedule& schedule, ext::shared_ptr<OvernightIndex> i)
: schedule_(schedule), overnightIndex_(std::move(i)), paymentCalendar_(schedule.calendar()) {
OvernightLeg::OvernightLeg(Schedule schedule, ext::shared_ptr<OvernightIndex> i)
: schedule_(std::move(schedule)), overnightIndex_(std::move(i)), paymentCalendar_(schedule_.calendar()) {
QL_REQUIRE(overnightIndex_, "no index provided");
}

Expand Down Expand Up @@ -370,7 +370,7 @@ namespace QuantLib {
detail::get(spreads_, i, 0.0),
refStart, refEnd,
paymentDayCounter_,
telescopicValueDates_,
telescopicValueDates_,
averagingMethod_)));
}
return cashflows;
Expand Down
2 changes: 1 addition & 1 deletion ql/cashflows/overnightindexedcoupon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ namespace QuantLib {
//! helper class building a sequence of overnight coupons
class OvernightLeg {
public:
OvernightLeg(const Schedule& schedule, ext::shared_ptr<OvernightIndex> overnightIndex);
OvernightLeg(Schedule schedule, ext::shared_ptr<OvernightIndex> overnightIndex);
OvernightLeg& withNotionals(Real notional);
OvernightLeg& withNotionals(const std::vector<Real>& notionals);
OvernightLeg& withPaymentDayCounter(const DayCounter&);
Expand Down
9 changes: 4 additions & 5 deletions ql/cashflows/subperiodcoupon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace QuantLib {
const Date& exCouponDate)
: FloatingRateCoupon(paymentDate, nominal, startDate, endDate,
fixingDays, index, gearing, couponSpread,
refPeriodStart, refPeriodEnd, dayCounter,
refPeriodStart, refPeriodEnd, dayCounter,
false, exCouponDate),
rateSpread_(rateSpread) {
Schedule sch = MakeSchedule()
Expand Down Expand Up @@ -107,7 +107,7 @@ namespace QuantLib {
}
}

Real SubPeriodsPricer::swapletPrice() const {
Real SubPeriodsPricer::swapletPrice() const {
QL_FAIL("SubPeriodsPricer::swapletPrice not implemented");
}

Expand Down Expand Up @@ -155,8 +155,8 @@ namespace QuantLib {
return coupon_->gearing() * rate + coupon_->spread();
}

SubPeriodsLeg::SubPeriodsLeg(const Schedule& schedule, ext::shared_ptr<IborIndex> i)
: schedule_(schedule), index_(std::move(i)), paymentCalendar_(schedule.calendar()) {
SubPeriodsLeg::SubPeriodsLeg(Schedule schedule, ext::shared_ptr<IborIndex> i)
: schedule_(std::move(schedule)), index_(std::move(i)), paymentCalendar_(schedule_.calendar()) {
QL_REQUIRE(index_, "no index provided");
}

Expand Down Expand Up @@ -306,4 +306,3 @@ namespace QuantLib {
return cashflows;
}
}

2 changes: 1 addition & 1 deletion ql/cashflows/subperiodcoupon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ namespace QuantLib {
//! helper class building a sequence of overnight coupons
class SubPeriodsLeg {
public:
SubPeriodsLeg(const Schedule &schedule, ext::shared_ptr<IborIndex> index);
SubPeriodsLeg(Schedule schedule, ext::shared_ptr<IborIndex> index);
SubPeriodsLeg& withNotionals(Real notional);
SubPeriodsLeg& withNotionals(const std::vector<Real>& notionals);
SubPeriodsLeg& withPaymentDayCounter(const DayCounter&);
Expand Down
20 changes: 10 additions & 10 deletions ql/experimental/averageois/arithmeticaverageois.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ namespace QuantLib {

ArithmeticAverageOIS::ArithmeticAverageOIS(Type type,
Real nominal,
const Schedule& fixedLegSchedule,
Schedule fixedLegSchedule,
Rate fixedRate,
DayCounter fixedDC,
ext::shared_ptr<OvernightIndex> overnightIndex,
const Schedule& overnightLegSchedule,
Schedule overnightLegSchedule,
Spread spread,
Real meanReversionSpeed,
Real volatility,
Expand All @@ -43,16 +43,16 @@ namespace QuantLib {
overnightIndex_(std::move(overnightIndex)), spread_(spread), byApprox_(byApprox),
mrs_(meanReversionSpeed), vol_(volatility) {

initialize(fixedLegSchedule, overnightLegSchedule);
initialize(std::move(fixedLegSchedule), std::move(overnightLegSchedule));
}

ArithmeticAverageOIS::ArithmeticAverageOIS(Type type,
std::vector<Real> nominals,
const Schedule& fixedLegSchedule,
Schedule fixedLegSchedule,
Rate fixedRate,
DayCounter fixedDC,
ext::shared_ptr<OvernightIndex> overnightIndex,
const Schedule& overnightLegSchedule,
Schedule overnightLegSchedule,
Spread spread,
Real meanReversionSpeed,
Real volatility,
Expand All @@ -64,18 +64,18 @@ namespace QuantLib {
overnightIndex_(std::move(overnightIndex)), spread_(spread), byApprox_(byApprox),
mrs_(meanReversionSpeed), vol_(volatility) {

initialize(fixedLegSchedule, overnightLegSchedule);
initialize(std::move(fixedLegSchedule), std::move(overnightLegSchedule));
}

void ArithmeticAverageOIS::initialize(const Schedule& fixedLegSchedule,
const Schedule& overnightLegSchedule) {
void ArithmeticAverageOIS::initialize(Schedule fixedLegSchedule,
Schedule overnightLegSchedule) {
if (fixedDC_==DayCounter())
fixedDC_ = overnightIndex_->dayCounter();
legs_[0] = FixedRateLeg(fixedLegSchedule)
legs_[0] = FixedRateLeg(std::move(fixedLegSchedule))
.withNotionals(nominals_)
.withCouponRates(fixedRate_, fixedDC_);

legs_[1] = OvernightLeg(overnightLegSchedule, overnightIndex_)
legs_[1] = OvernightLeg(std::move(overnightLegSchedule), overnightIndex_)
.withNotionals(nominals_)
.withSpreads(spread_);

Expand Down
11 changes: 5 additions & 6 deletions ql/experimental/averageois/arithmeticaverageois.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ namespace QuantLib {
public:
ArithmeticAverageOIS(Type type,
Real nominal,
const Schedule& fixedLegSchedule,
Schedule fixedLegSchedule,
Rate fixedRate,
DayCounter fixedDC,
ext::shared_ptr<OvernightIndex> overnightIndex,
const Schedule& overnightLegSchedule,
Schedule overnightLegSchedule,
Spread spread = 0.0,
Real meanReversionSpeed = 0.03,
Real volatility = 0.00, // NO convexity adjustment by default
bool byApprox = false); // TRUE to use Katsumi Takada approximation
ArithmeticAverageOIS(Type type,
std::vector<Real> nominals,
const Schedule& fixedLegSchedule,
Schedule fixedLegSchedule,
Rate fixedRate,
DayCounter fixedDC,
ext::shared_ptr<OvernightIndex> overnightIndex,
const Schedule& overnightLegSchedule,
Schedule overnightLegSchedule,
Spread spread = 0.0,
Real meanReversionSpeed = 0.03,
Real volatility = 0.00, // NO convexity adjustment by default
Expand Down Expand Up @@ -88,8 +88,7 @@ namespace QuantLib {
Spread fairSpread() const;
//@}
private:
void initialize(const Schedule& fixedLegSchedule,
const Schedule& overnightLegSchedule);
void initialize(Schedule fixedLegSchedule, Schedule overnightLegSchedule);
Type type_;
std::vector<Real> nominals_;

Expand Down
11 changes: 5 additions & 6 deletions ql/experimental/callablebonds/callablebond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ namespace QuantLib {
dayCounter,
compounding,
frequency);

if ( P == 0.0 )
return 0;
else
Expand Down Expand Up @@ -389,13 +389,13 @@ namespace QuantLib {
dayCounter,
compounding,
frequency);

if ( P == 0.0 )
return 0;
else
{
return (Ppp + Pmm - 2*P) / ( std::pow(bump,2) * P);
}
}

}

Expand Down Expand Up @@ -482,7 +482,7 @@ namespace QuantLib {
CallableFixedRateBond::CallableFixedRateBond(
Natural settlementDays,
Real faceAmount,
const Schedule& schedule,
Schedule schedule,
const std::vector<Rate>& coupons,
const DayCounter& accrualDayCounter,
BusinessDayConvention paymentConvention,
Expand All @@ -499,7 +499,7 @@ namespace QuantLib {
frequency_ = schedule.hasTenor() ? schedule.tenor().frequency() : NoFrequency;

cashflows_ =
FixedRateLeg(schedule)
FixedRateLeg(std::move(schedule))
.withNotionals(faceAmount)
.withCouponRates(coupons, accrualDayCounter)
.withPaymentAdjustment(paymentConvention)
Expand Down Expand Up @@ -533,4 +533,3 @@ namespace QuantLib {
}

}

2 changes: 1 addition & 1 deletion ql/experimental/callablebonds/callablebond.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ namespace QuantLib {
public:
CallableFixedRateBond(Natural settlementDays,
Real faceAmount,
const Schedule& schedule,
Schedule schedule,
const std::vector<Rate>& coupons,
const DayCounter& accrualDayCounter,
BusinessDayConvention paymentConvention = Following,
Expand Down
6 changes: 3 additions & 3 deletions ql/experimental/catbonds/catbond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace QuantLib {
arguments->notionalRisk = notionalRisk_;
arguments->startDate = issueDate();
}

void CatBond::fetchResults(const PricingEngine::results* r) const {
Bond::fetchResults(r);

Expand All @@ -59,7 +59,7 @@ namespace QuantLib {

FloatingCatBond::FloatingCatBond(Natural settlementDays,
Real faceAmount,
const Schedule& schedule,
Schedule schedule,
const ext::shared_ptr<IborIndex>& iborIndex,
const DayCounter& paymentDayCounter,
const ext::shared_ptr<NotionalRisk>& notionalRisk,
Expand All @@ -76,7 +76,7 @@ namespace QuantLib {

maturityDate_ = schedule.endDate();

cashflows_ = IborLeg(schedule, iborIndex)
cashflows_ = IborLeg(std::move(schedule), iborIndex)
.withNotionals(faceAmount)
.withPaymentDayCounter(paymentDayCounter)
.withPaymentAdjustment(paymentConvention)
Expand Down
2 changes: 1 addition & 1 deletion ql/experimental/catbonds/catbond.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace QuantLib {
public:
FloatingCatBond(Natural settlementDays,
Real faceAmount,
const Schedule& schedule,
Schedule schedule,
const ext::shared_ptr<IborIndex>& iborIndex,
const DayCounter& accrualDayCounter,
const ext::shared_ptr<NotionalRisk>& notionalRisk,
Expand Down
13 changes: 6 additions & 7 deletions ql/experimental/credit/nthtodefault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace QuantLib {
const ext::shared_ptr<Basket>& basket,
Size n,
Protection::Side side,
const Schedule& premiumSchedule,
Schedule premiumSchedule,
Rate upfrontRate,
Rate premiumRate,
const DayCounter& dayCounter,
Expand All @@ -41,19 +41,19 @@ namespace QuantLib {
)
: basket_(basket), n_(n),
side_(side), nominal_(nominal),
premiumSchedule_(premiumSchedule), premiumRate_(premiumRate),
upfrontRate_(upfrontRate),
premiumSchedule_(std::move(premiumSchedule)), premiumRate_(premiumRate),
upfrontRate_(upfrontRate),
dayCounter_(dayCounter), settlePremiumAccrual_(settlePremiumAccrual)
{
QL_REQUIRE(n_ <= basket_->size(),
QL_REQUIRE(n_ <= basket_->size(),
"NTD order provided is larger than the basket size.");

// Basket inception must lie before contract protection start.
QL_REQUIRE(basket->refDate() <= premiumSchedule.startDate(),
QL_REQUIRE(basket->refDate() <= premiumSchedule_.startDate(),
//using the start date of the schedule might be wrong, think of the CDS rule
"Basket did not exist before contract start.");

premiumLeg_ = FixedRateLeg(premiumSchedule)
premiumLeg_ = FixedRateLeg(premiumSchedule_)
.withNotionals(nominal)
.withCouponRates(premiumRate, dayCounter)
.withPaymentAdjustment(Unadjusted);
Expand Down Expand Up @@ -156,4 +156,3 @@ namespace QuantLib {
}

}

Loading
Loading