Skip to content

Commit

Permalink
Merge 24d0e23 into c0a8391
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Feb 13, 2021
2 parents c0a8391 + 24d0e23 commit bdba8e3
Show file tree
Hide file tree
Showing 31 changed files with 82 additions and 107 deletions.
4 changes: 3 additions & 1 deletion .clang-tidy
@@ -1,10 +1,12 @@
---
Checks: '-*,readability-*,bugprone-*,misc-*,performance-*,modernize-redundant-void-arg,modernize-deprecated-headers,modernize-use-override,modernize-use-auto,modernize-use-nullptr,modernize-use-default-member-init,modernize-use-equals-default,modernize-use-equals-delete,modernize-pass-by-value,modernize-loop-convert,-readability-else-after-return,-readability-named-parameter,-readability-braces-around-statements,-readability-inconsistent-declaration-parameter-name,-readability-isolate-declaration,-readability-magic-numbers,-readability-convert-member-functions-to-static,-bugprone-macro-parentheses,-bugprone-narrowing-conversions,-bugprone-branch-clone,-misc-non-private-member-variables-in-classes,-misc-unused-parameters'
Checks: '-*,readability-*,bugprone-*,misc-*,performance-*,modernize-redundant-void-arg,modernize-deprecated-headers,modernize-use-override,modernize-use-auto,modernize-use-nullptr,modernize-use-default-member-init,modernize-use-equals-default,modernize-use-equals-delete,modernize-pass-by-value,modernize-loop-convert,modernize-raw-string-literal,modernize-use-noexcept,modernize-return-braced-init-list,-readability-else-after-return,-readability-named-parameter,-readability-braces-around-statements,-readability-inconsistent-declaration-parameter-name,-readability-isolate-declaration,-readability-magic-numbers,-readability-convert-member-functions-to-static,-bugprone-macro-parentheses,-bugprone-narrowing-conversions,-bugprone-branch-clone,-misc-non-private-member-variables-in-classes,-misc-unused-parameters'
WarningsAsErrors: ''
HeaderFilterRegex: '.*'
AnalyzeTemporaryDtors: false
FormatStyle: file
CheckOptions:
- key: modernize-use-default-member-init.UseAssignment
value: 1
- key: modernize-use-noexcept.ReplacementString
value: QL_NOEXCEPT
...
2 changes: 1 addition & 1 deletion ql/cashflow.hpp
Expand Up @@ -57,7 +57,7 @@ namespace QuantLib {
*/
virtual Real amount() const = 0;
//! returns the date that the cash flow trades exCoupon
virtual Date exCouponDate() const {return Date();};
virtual Date exCouponDate() const { return {}; };
//! returns true if the cashflow is trading ex-coupon on the refDate
bool tradingExCoupon(const Date& refDate = Date()) const;

Expand Down
24 changes: 14 additions & 10 deletions ql/cashflows/cashflows.cpp
Expand Up @@ -123,7 +123,7 @@ namespace QuantLib {
cf = previousCashFlow(leg, includeSettlementDateFlows, settlementDate);

if (cf==leg.rend())
return Date();
return {};

return (*cf)->date();
}
Expand All @@ -135,7 +135,7 @@ namespace QuantLib {
cf = nextCashFlow(leg, includeSettlementDateFlows, settlementDate);

if (cf==leg.end())
return Date();
return {};

return (*cf)->date();
}
Expand Down Expand Up @@ -248,60 +248,64 @@ namespace QuantLib {
bool includeSettlementDateFlows,
Date settlementDate) {
auto cf = nextCashFlow(leg, includeSettlementDateFlows, settlementDate);
if (cf==leg.end()) return Date();
if (cf==leg.end())
return {};

Date paymentDate = (*cf)->date();
for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
if (cp != nullptr)
return cp->accrualStartDate();
}
return Date();
return {};
}

Date CashFlows::accrualEndDate(const Leg& leg,
bool includeSettlementDateFlows,
Date settlementDate) {
auto cf = nextCashFlow(leg, includeSettlementDateFlows, settlementDate);
if (cf==leg.end()) return Date();
if (cf==leg.end())
return {};

Date paymentDate = (*cf)->date();
for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
if (cp != nullptr)
return cp->accrualEndDate();
}
return Date();
return {};
}

Date CashFlows::referencePeriodStart(const Leg& leg,
bool includeSettlementDateFlows,
Date settlementDate) {
auto cf = nextCashFlow(leg, includeSettlementDateFlows, settlementDate);
if (cf==leg.end()) return Date();
if (cf==leg.end())
return {};

Date paymentDate = (*cf)->date();
for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
if (cp != nullptr)
return cp->referencePeriodStart();
}
return Date();
return {};
}

Date CashFlows::referencePeriodEnd(const Leg& leg,
bool includeSettlementDateFlows,
Date settlementDate) {
auto cf = nextCashFlow(leg, includeSettlementDateFlows, settlementDate);
if (cf==leg.end()) return Date();
if (cf==leg.end())
return {};

Date paymentDate = (*cf)->date();
for (; cf<leg.end() && (*cf)->date()==paymentDate; ++cf) {
ext::shared_ptr<Coupon> cp = ext::dynamic_pointer_cast<Coupon>(*cf);
if (cp != nullptr)
return cp->referencePeriodEnd();
}
return Date();
return {};
}

Time CashFlows::accrualPeriod(const Leg& leg,
Expand Down
5 changes: 1 addition & 4 deletions ql/errors.cpp
Expand Up @@ -97,9 +97,6 @@ namespace QuantLib {
format(file, line, function, message));
}

const char* Error::what() const throw () {
return message_->c_str();
}

const char* Error::what() const QL_NOEXCEPT { return message_->c_str(); }
}

2 changes: 1 addition & 1 deletion ql/errors.hpp
Expand Up @@ -52,7 +52,7 @@ namespace QuantLib {
~Error() throw() override {}
#endif
//! returns the error message.
const char* what() const throw() override;
const char* what() const QL_NOEXCEPT override;

private:
ext::shared_ptr<std::string> message_;
Expand Down
5 changes: 2 additions & 3 deletions ql/experimental/commodities/dateinterval.hpp
Expand Up @@ -65,9 +65,8 @@ namespace QuantLib {
DateInterval intersection(const DateInterval& di) const {
if ((startDate_ < di.startDate_ && endDate_ < di.startDate_) ||
(startDate_ > di.endDate_ && endDate_ > di.endDate_))
return DateInterval();
return DateInterval(std::max(startDate_, di.startDate_),
std::min(endDate_, di.endDate_));
return {};
return {std::max(startDate_, di.startDate_), std::min(endDate_, di.endDate_)};
}

bool operator==(const DateInterval& rhs) const {
Expand Down
3 changes: 1 addition & 2 deletions ql/experimental/credit/randomdefaultlatentmodel.hpp
Expand Up @@ -618,8 +618,7 @@ namespace QuantLib {
lowerPercentile = rankLosses[r];
upperPercentile = rankLosses[s];

return ext::tuple<Real, Real, Real>(quantileValue,
lowerPercentile, upperPercentile);
return {quantileValue, lowerPercentile, upperPercentile};
}


Expand Down
5 changes: 2 additions & 3 deletions ql/experimental/credit/saddlepointlossmodel.hpp
Expand Up @@ -817,8 +817,7 @@ namespace QuantLib {
(12.*suma1*suma1*suma2 -
6.*std::pow(suma1,4.)/suma0)/suma0)/suma0)/suma0;
}
return ext::tuple<Real, Real, Real, Real>(deriv0, deriv2,
deriv3, deriv4);
return {deriv0, deriv2, deriv3, deriv4};
}

template<class CP>
Expand Down Expand Up @@ -852,7 +851,7 @@ namespace QuantLib {
//deriv1 += suma1 / suma0;
deriv2 += suma2 / suma0 - std::pow(suma1 / suma0 , 2.);
}
return ext::tuple<Real, Real>(deriv0, deriv2);
return {deriv0, deriv2};
}

// ----- Saddle point search ----------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion ql/experimental/inflation/cpicapfloortermpricesurface.cpp
Expand Up @@ -110,7 +110,7 @@ namespace QuantLib {

Date CPICapFloorTermPriceSurface::cpiOptionDateFromTenor(const Period& p) const
{
return Date(calendar().adjust(referenceDate() + p, businessDayConvention()));
return calendar().adjust(referenceDate() + p, businessDayConvention());
}


Expand Down
2 changes: 1 addition & 1 deletion ql/experimental/inflation/yoycapfloortermpricesurface.cpp
Expand Up @@ -102,7 +102,7 @@ namespace QuantLib {

Date YoYCapFloorTermPriceSurface::yoyOptionDateFromTenor(const Period& p) const
{
return Date(referenceDate()+p);
return referenceDate() + p;
}

Real YoYCapFloorTermPriceSurface::price(const Period &d, const Rate k) const {
Expand Down
2 changes: 1 addition & 1 deletion ql/experimental/math/levyflightdistribution.hpp
Expand Up @@ -131,7 +131,7 @@ namespace QuantLib {
{ return QL_MAX_REAL; }

//! Returns the parameters of the distribution
param_type param() const { return param_type(xm_, alpha_); }
param_type param() const { return {xm_, alpha_}; }
//@}

//! Sets the parameters of the distribution
Expand Down
5 changes: 1 addition & 4 deletions ql/experimental/math/polarstudenttrng.hpp
Expand Up @@ -83,10 +83,7 @@ namespace QuantLib {
u = 2.* uniformGenerator_.next().value - 1.;
rSqr = v*v + u*u;
}while(rSqr >= 1.);
return sample_type(u *
std::sqrt(degFreedom_ * (std::pow(rSqr, -2./degFreedom_)-1.)
/ rSqr),
1.);
return {u * std::sqrt(degFreedom_ * (std::pow(rSqr, -2. / degFreedom_) - 1.) / rSqr), 1.};
}

}
Expand Down
5 changes: 2 additions & 3 deletions ql/experimental/math/zigguratrng.hpp
Expand Up @@ -53,9 +53,8 @@ namespace QuantLib {
public:
typedef Sample<Real> sample_type;
explicit ZigguratRng(unsigned long seed = 0);
sample_type next() const {
return sample_type(nextGaussian(),1.0);
}
sample_type next() const { return {nextGaussian(), 1.0}; }

private:
mutable MersenneTwisterUniformRng mt32_;
Real nextGaussian() const;
Expand Down
4 changes: 2 additions & 2 deletions ql/instruments/bond.cpp
Expand Up @@ -402,8 +402,8 @@ namespace QuantLib {
void Bond::arguments::validate() const {
QL_REQUIRE(settlementDate != Date(), "no settlement date provided");
QL_REQUIRE(!cashflows.empty(), "no cash flow provided");
for (Size i=0; i<cashflows.size(); ++i)
QL_REQUIRE(cashflows[i], "null cash flow provided");
for (const auto & cf: cashflows)
QL_REQUIRE(cf, "null cash flow provided");
}

}
4 changes: 2 additions & 2 deletions ql/math/initializers.hpp
Expand Up @@ -75,11 +75,11 @@ class MatrixProxy {
};

inline ArrayProxy operator<<(Array& a, const Real x) {
return ArrayProxy(a, x);
return {a, x};
}

inline MatrixProxy operator<<(Matrix& m, const Real x) {
return MatrixProxy(m, x);
return {m, x};
}

} // namespace initializers
Expand Down
4 changes: 2 additions & 2 deletions ql/math/randomnumbers/boxmullergaussianrng.hpp
Expand Up @@ -83,10 +83,10 @@ namespace QuantLib {
weight_ = firstWeight_*secondWeight_;

returnFirst_ = false;
return sample_type(firstValue_,weight_);
return {firstValue_, weight_};
} else {
returnFirst_ = true;
return sample_type(secondValue_,weight_);
return {secondValue_, weight_};
}
}

Expand Down
2 changes: 1 addition & 1 deletion ql/math/randomnumbers/centrallimitgaussianrng.hpp
Expand Up @@ -65,7 +65,7 @@ namespace QuantLib {
gaussPoint += sample.value;
gaussWeight *= sample.weight;
}
return sample_type(gaussPoint,gaussWeight);
return {gaussPoint, gaussWeight};
}

}
Expand Down
2 changes: 1 addition & 1 deletion ql/math/randomnumbers/knuthuniformrng.hpp
Expand Up @@ -69,7 +69,7 @@ namespace QuantLib {
double result = (ranf_arr_ptr != ranf_arr_sentinel ?
ranf_arr_buf[ranf_arr_ptr++] :
ranf_arr_cycle());
return sample_type(result,1.0);
return {result, 1.0};
}

inline double KnuthUniformRng::mod_sum(double x, double y) const {
Expand Down
2 changes: 1 addition & 1 deletion ql/math/randomnumbers/lecuyeruniformrng.cpp
Expand Up @@ -80,7 +80,7 @@ namespace QuantLib {
// users don't expect endpoint values
if (result > maxRandom)
result = (double) maxRandom;
return sample_type(result,1.0);
return {result, 1.0};
}

}
2 changes: 1 addition & 1 deletion ql/math/randomnumbers/mt19937uniformrng.hpp
Expand Up @@ -51,7 +51,7 @@ namespace QuantLib {
const std::vector<unsigned long>& seeds);
/*! returns a sample with weight 1.0 containing a random number
in the (0.0, 1.0) interval */
sample_type next() const { return sample_type(nextReal(),1.0); }
sample_type next() const { return {nextReal(), 1.0}; }
//! return a random number in the (0.0, 1.0)-interval
Real nextReal() const {
return (Real(nextInt32()) + 0.5)/4294967296.0;
Expand Down
8 changes: 2 additions & 6 deletions ql/math/randomnumbers/ranluxuniformrng.hpp
Expand Up @@ -49,9 +49,7 @@ namespace QuantLib {
explicit Ranlux3UniformRng(Size seed = 19780503U)
: ranlux3_(boost::random::ranlux64_base_01(seed)) {}

sample_type next() const {
return sample_type(ranlux3_(), 1.0);
}
sample_type next() const { return {ranlux3_(), 1.0}; }

private:
mutable boost::ranlux64_3_01 ranlux3_;
Expand All @@ -64,9 +62,7 @@ namespace QuantLib {
explicit Ranlux4UniformRng(Size seed = 19780503U)
: ranlux4_(boost::random::ranlux64_base_01(seed)) {}

sample_type next() const {
return sample_type(ranlux4_(), 1.0);
}
sample_type next() const { return {ranlux4_(), 1.0}; }

private:
mutable boost::ranlux64_4_01 ranlux4_;
Expand Down
36 changes: 13 additions & 23 deletions ql/methods/finitedifferences/solvers/fdmbackwardsolver.cpp
Expand Up @@ -43,49 +43,39 @@ namespace QuantLib {
FdmSchemeDesc::FdmSchemeDesc(FdmSchemeType aType, Real aTheta, Real aMu)
: type(aType), theta(aTheta), mu(aMu) { }

FdmSchemeDesc FdmSchemeDesc::Douglas() {
return FdmSchemeDesc(FdmSchemeDesc::DouglasType, 0.5, 0.0);
}

FdmSchemeDesc FdmSchemeDesc::Douglas() { return {FdmSchemeDesc::DouglasType, 0.5, 0.0}; }

FdmSchemeDesc FdmSchemeDesc::CrankNicolson() {
return FdmSchemeDesc(FdmSchemeDesc::CrankNicolsonType, 0.5, 0.0);
return {FdmSchemeDesc::CrankNicolsonType, 0.5, 0.0};
}

FdmSchemeDesc FdmSchemeDesc::CraigSneyd() {
return FdmSchemeDesc(FdmSchemeDesc::CraigSneydType,0.5, 0.5);
}

FdmSchemeDesc FdmSchemeDesc::ModifiedCraigSneyd() {
return FdmSchemeDesc(FdmSchemeDesc::ModifiedCraigSneydType,
1.0/3.0, 1.0/3.0);
FdmSchemeDesc FdmSchemeDesc::CraigSneyd() { return {FdmSchemeDesc::CraigSneydType, 0.5, 0.5}; }

FdmSchemeDesc FdmSchemeDesc::ModifiedCraigSneyd() {
return {FdmSchemeDesc::ModifiedCraigSneydType, 1.0 / 3.0, 1.0 / 3.0};
}

FdmSchemeDesc FdmSchemeDesc::Hundsdorfer() {
return FdmSchemeDesc(FdmSchemeDesc::HundsdorferType,
0.5+std::sqrt(3.0)/6, 0.5);
return {FdmSchemeDesc::HundsdorferType, 0.5 + std::sqrt(3.0) / 6, 0.5};
}

FdmSchemeDesc FdmSchemeDesc::ModifiedHundsdorfer() {
return FdmSchemeDesc(FdmSchemeDesc::HundsdorferType,
1.0-std::sqrt(2.0)/2, 0.5);
return {FdmSchemeDesc::HundsdorferType, 1.0 - std::sqrt(2.0) / 2, 0.5};
}

FdmSchemeDesc FdmSchemeDesc::ExplicitEuler() {
return FdmSchemeDesc(FdmSchemeDesc::ExplicitEulerType, 0.0, 0.0);
return {FdmSchemeDesc::ExplicitEulerType, 0.0, 0.0};
}

FdmSchemeDesc FdmSchemeDesc::ImplicitEuler() {
return FdmSchemeDesc(FdmSchemeDesc::ImplicitEulerType, 0.0, 0.0);
return {FdmSchemeDesc::ImplicitEulerType, 0.0, 0.0};
}

FdmSchemeDesc FdmSchemeDesc::MethodOfLines(Real eps, Real relInitStepSize) {
return FdmSchemeDesc(
FdmSchemeDesc::MethodOfLinesType, eps, relInitStepSize);
return {FdmSchemeDesc::MethodOfLinesType, eps, relInitStepSize};
}

FdmSchemeDesc FdmSchemeDesc::TrBDF2() {
return FdmSchemeDesc(FdmSchemeDesc::TrBDF2Type, 2 - M_SQRT2, 1e-8);
}
FdmSchemeDesc FdmSchemeDesc::TrBDF2() { return {FdmSchemeDesc::TrBDF2Type, 2 - M_SQRT2, 1e-8}; }

FdmBackwardSolver::FdmBackwardSolver(
ext::shared_ptr<FdmLinearOpComposite> map,
Expand Down
2 changes: 1 addition & 1 deletion ql/prices.hpp
Expand Up @@ -106,7 +106,7 @@ namespace QuantLib {
{
public:
Null() = default;
operator IntervalPrice() const { return IntervalPrice(); }
operator IntervalPrice() const { return {}; }
};

}
Expand Down

0 comments on commit bdba8e3

Please sign in to comment.