Skip to content

Commit

Permalink
Merge pull request #557.
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Oct 12, 2018
2 parents 6d08850 + 2b08913 commit e453ce9
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 31 deletions.
12 changes: 12 additions & 0 deletions .lgtm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

path_classifiers:
docs:
- Docs
- Examples
test:
- test-suite
library:
- tools
queries:
- exclude: cpp/fixme-comment

2 changes: 1 addition & 1 deletion ql/cashflows/cashflows.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ namespace QuantLib {
Rate guess = 0.05);

template <typename Solver>
static Rate yield(Solver solver,
static Rate yield(const Solver& solver,
const Leg& leg,
Real npv,
const DayCounter& dayCounter,
Expand Down
10 changes: 5 additions & 5 deletions ql/cashflows/conundrumpricer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,9 @@ namespace QuantLib {
Size n = fixedLeg.size();
accruals_.reserve(n);
for (Size i=0; i<n; ++i) {
ext::shared_ptr<Coupon> coupon =
ext::shared_ptr<Coupon> cpn =
ext::dynamic_pointer_cast<Coupon>(fixedLeg[i]);
accruals_.push_back(coupon->accrualPeriod());
accruals_.push_back(cpn->accrualPeriod());
}
}

Expand Down Expand Up @@ -711,10 +711,10 @@ namespace QuantLib {
shapedSwapPaymentTimes_.reserve(n);
swapPaymentDiscounts_.reserve(n);
for(Size i=0; i<n; ++i) {
ext::shared_ptr<Coupon> coupon =
ext::shared_ptr<Coupon> cpn =
ext::dynamic_pointer_cast<Coupon>(fixedLeg[i]);
accruals_.push_back(coupon->accrualPeriod());
const Date paymentDate(coupon->date());
accruals_.push_back(cpn->accrualPeriod());
const Date paymentDate(cpn->date());
const double swapPaymentTime(dc.yearFraction(rateCurve->referenceDate(), paymentDate));
shapedSwapPaymentTimes_.push_back(shapeOfShift(swapPaymentTime));
swapPaymentDiscounts_.push_back(rateCurve->discount(paymentDate));
Expand Down
4 changes: 2 additions & 2 deletions ql/experimental/credit/homogeneouspooldef.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ namespace QuantLib {
conditionalProbs.push_back(
copula_->conditionalDefaultProbabilityInvP(prob[iName], iName,
mkft));
Distribution d = bucktLDistBuff(lgd, conditionalProbs);
Distribution bld = bucktLDistBuff(lgd, conditionalProbs);
Real densitydm = delta_ * copula_->density(mkft);
// also, instead of calling the static method it could be wrapped
// through an inlined call in the latent model
for (Size j = 0; j < nBuckets_; j++)
dist.addDensity(j, d.density(j) * densitydm);
dist.addDensity(j, bld.density(j) * densitydm);
mkft[0] += delta_;
}
return dist;
Expand Down
4 changes: 2 additions & 2 deletions ql/experimental/credit/inhomogeneouspooldef.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ namespace QuantLib {
conditionalProbs.push_back(
copula_->conditionalDefaultProbabilityInvP(prob[iName], iName,
mkft));
Distribution d = bucktLDistBuff(lgd, conditionalProbs);
Distribution bld = bucktLDistBuff(lgd, conditionalProbs);
Real densitydm = delta_ * copula_->density(mkft);
// also, instead of calling the static method it could be wrapped
// through an inlined call in the latent model
for (Size j = 0; j < nBuckets_; j++)
dist.addDensity(j, d.density(j) * densitydm);
dist.addDensity(j, bld.density(j) * densitydm);
mkft[0] += delta_;
}
return dist;
Expand Down
2 changes: 1 addition & 1 deletion ql/experimental/credit/riskybond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ namespace QuantLib {
Currency ccy,
Real recoveryRate,
Handle<DefaultProbabilityTermStructure> defaultTS,
Schedule schedule,
const Schedule& schedule,
ext::shared_ptr<IborIndex> index,
Integer fixingDays,
Real spread,
Expand Down
2 changes: 1 addition & 1 deletion ql/experimental/credit/riskybond.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ namespace QuantLib {
Currency ccy,
Real recoveryRate,
Handle<DefaultProbabilityTermStructure> defaultTS,
Schedule schedule,
const Schedule& schedule,
ext::shared_ptr<IborIndex> index,
Integer fixingDays,
Real spread,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ namespace QuantLib {
QL_REQUIRE(d.size() > 1,
"must have at least two dates: " << d.size());

for (Size i = 0; i < d.size(); i++ ){
this->times_.push_back( this->timeFromReference(dates_[i]) );
this->data_.push_back(v[i]),
nodes_.push_back( std::make_pair( dates_[i], this->data_[i]) );
for (Size j = 0; j < d.size(); j++ ){
this->times_.push_back( this->timeFromReference(dates_[j]) );
this->data_.push_back(v[j]),
nodes_.push_back( std::make_pair( dates_[j], this->data_[j]) );
}

this->setupInterpolation();
Expand Down
28 changes: 28 additions & 0 deletions ql/experimental/math/hybridsimulatedannealingfunctors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ namespace QuantLib
SamplerLogNormal(const SamplerLogNormal& sampler) : generator_(sampler.gaussian_.engine()),
distribution_(sampler.gaussian_.distribution()),
gaussian_(generator_, distribution_) {};
SamplerLogNormal& operator=(const SamplerLogNormal& sampler) {
generator_ = sampler.gaussian_.engine();
distribution_ = sampler.gaussian_.distribution();
gaussian_ = normal_variate(generator_, distribution_);
return *this;
}

inline void operator()(Array &newPoint, const Array &currentPoint, const Array &temp) const {
QL_REQUIRE(newPoint.size() == currentPoint.size(), "Incompatible input");
Expand All @@ -99,6 +105,12 @@ namespace QuantLib
SamplerGaussian(const SamplerGaussian& sampler) : generator_(sampler.gaussian_.engine()),
distribution_(sampler.gaussian_.distribution()),
gaussian_(generator_, distribution_) {};
SamplerGaussian& operator=(const SamplerGaussian& sampler) {
generator_ = sampler.gaussian_.engine();
distribution_ = sampler.gaussian_.distribution();
gaussian_ = normal_variate(generator_, distribution_);
return *this;
}

inline void operator()(Array &newPoint, const Array &currentPoint, const Array &temp) const {
QL_REQUIRE(newPoint.size() == currentPoint.size(), "Incompatible input");
Expand Down Expand Up @@ -130,6 +142,14 @@ namespace QuantLib
distribution_(sampler.gaussian_.distribution()),
gaussian_(generator_, distribution_),
lower_(sampler.lower_), upper_(sampler.upper_) {};
SamplerRingGaussian& operator=(const SamplerRingGaussian& sampler) {
generator_ = sampler.gaussian_.engine();
distribution_ = sampler.gaussian_.distribution();
gaussian_ = normal_variate(generator_, distribution_);
lower_ = sampler.lower_;
upper_ = sampler.upper_;
return *this;
}

inline void operator()(Array &newPoint, const Array &currentPoint, const Array &temp) const {
QL_REQUIRE(newPoint.size() == currentPoint.size(), "Incompatible input");
Expand Down Expand Up @@ -170,6 +190,14 @@ namespace QuantLib
distribution_(sampler.gaussian_.distribution()),
gaussian_(generator_, distribution_),
lower_(sampler.lower_), upper_(sampler.upper_) {};
SamplerMirrorGaussian& operator=(const SamplerMirrorGaussian& sampler) {
generator_ = sampler.gaussian_.engine();
distribution_ = sampler.gaussian_.distribution();
gaussian_ = normal_variate(generator_, distribution_);
lower_ = sampler.lower_;
upper_ = sampler.upper_;
return *this;
}

inline void operator()(Array &newPoint, const Array &currentPoint, const Array &temp) const {
QL_REQUIRE(newPoint.size() == currentPoint.size(), "Incompatible input");
Expand Down
7 changes: 0 additions & 7 deletions ql/math/sampledcurve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ namespace QuantLib {
public:
SampledCurve(Size gridSize = 0);
SampledCurve(const Array &grid);
SampledCurve& operator=(const SampledCurve&);

//! \name inspectors
//@{
Expand Down Expand Up @@ -168,12 +167,6 @@ namespace QuantLib {
inline SampledCurve::SampledCurve(const Array& grid)
: grid_(grid), values_(grid.size()) {}

inline SampledCurve& SampledCurve::operator=(const SampledCurve& from) {
SampledCurve temp(from);
swap(temp);
return *this;
}

inline Array& SampledCurve::grid() {
return grid_;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@ namespace QuantLib {

const ext::shared_ptr<FdmLinearOpLayout> layout=mesher_->layout();
const FdmLinearOpIterator endIter = layout->end();
for (FdmLinearOpIterator iter = layout->begin(); iter != endIter;
++iter) {
const Size xn = iter.coordinates()[direction_];
for (FdmLinearOpIterator i = layout->begin(); i != endIter; ++i) {
const Size xn = i.coordinates()[direction_];
if (!initialized[xn]) {
initialized[xn] = true;
avgInnerValues_[xn] = avgInnerValueCalc(iter, t);
avgInnerValues_[xn] = avgInnerValueCalc(i, t);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ql/models/volatility/garch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ namespace QuantLib {
std::vector<std::size_t> idx;
std::size_t nCov = acf.size() - 1;
for (std::size_t i = 0; i <= nCov; ++i) {
if (i < 2 || (i > 1 && acf[i] > 0 && acf[i-1] > 0 && acf[i-1] > acf[i])) {
if (i < 2 || (acf[i] > 0 && acf[i-1] > 0 && acf[i-1] > acf[i])) {
idx.push_back(i);
}
}
Expand Down
2 changes: 1 addition & 1 deletion ql/pricingengines/bond/bondfunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ namespace QuantLib {
Size maxIterations = 100,
Rate guess = 0.05);
template <typename Solver>
static Rate yield(Solver solver,
static Rate yield(const Solver& solver,
const Bond& bond,
Real cleanPrice,
const DayCounter& dayCounter,
Expand Down
2 changes: 2 additions & 0 deletions ql/pricingengines/credit/isdacdsengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ namespace QuantLib {
yDates = castY3->dates();
} else if(ext::shared_ptr<FlatForward> castY4 =
ext::dynamic_pointer_cast<FlatForward>(*discountCurve_)) {
// no dates to extract
} else {
QL_FAIL("Yield curve must be flat forward interpolated");
}
Expand All @@ -134,6 +135,7 @@ namespace QuantLib {
} else if(
ext::shared_ptr<FlatHazardRate> castC3 =
ext::dynamic_pointer_cast<FlatHazardRate>(*probability_)) {
// no dates to extract
} else{
QL_FAIL("Credit curve must be flat forward interpolated");
}
Expand Down
3 changes: 2 additions & 1 deletion ql/termstructures/iterativebootstrap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ namespace QuantLib {
while (ts_->instruments_[firstAliveHelper_]->pillarDate() <= firstDate)
++firstAliveHelper_;
alive_ = n_-firstAliveHelper_;
QL_REQUIRE(alive_>=Interpolator::requiredPoints-1,
Size nodes = alive_+1;
QL_REQUIRE(nodes >= Interpolator::requiredPoints,
"not enough alive instruments: " << alive_ <<
" provided, " << Interpolator::requiredPoints-1 <<
" required");
Expand Down
2 changes: 1 addition & 1 deletion ql/termstructures/volatility/atmadjustedsmilesection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace QuantLib {
}

Real digitalOptionPrice(Rate strike, Option::Type type = Option::Call,
Real discount = 1.0, Real gap = 1.0E-8) const {
Real discount = 1.0, Real gap = 1.0e-5) const {
return source_->digitalOptionPrice(adjustedStrike(strike), type,
discount, gap);
}
Expand Down

0 comments on commit e453ce9

Please sign in to comment.