Skip to content

Commit

Permalink
Merge 89405c7 into b6348dc
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Feb 12, 2021
2 parents b6348dc + 89405c7 commit 61ec7a1
Show file tree
Hide file tree
Showing 254 changed files with 6,415 additions and 7,784 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
@@ -1,5 +1,5 @@
---
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,-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,-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
Expand Down
5 changes: 2 additions & 3 deletions Examples/BasketLosses/BasketLosses.cpp
Expand Up @@ -77,10 +77,9 @@ int main(int, char* []) {
names.push_back(std::string("Acme") +
boost::lexical_cast<std::string>(i));
std::vector<Handle<DefaultProbabilityTermStructure> > defTS;
for(Size i=0; i<hazardRates.size(); i++) {
for (double& hazardRate : hazardRates) {
defTS.push_back(Handle<DefaultProbabilityTermStructure>(
ext::make_shared<FlatHazardRate>(0, TARGET(), hazardRates[i],
Actual365Fixed())));
ext::make_shared<FlatHazardRate>(0, TARGET(), hazardRate, Actual365Fixed())));
defTS.back()->enableExtrapolation();
}
std::vector<Issuer> issuers;
Expand Down
4 changes: 2 additions & 2 deletions Examples/Bonds/Bonds.cpp
Expand Up @@ -163,8 +163,8 @@ int main(int, char* []) {
};

std::vector< ext::shared_ptr<SimpleQuote> > quote;
for (Size i=0; i<numberOfBonds; i++) {
ext::shared_ptr<SimpleQuote> cp(new SimpleQuote(marketQuotes[i]));
for (double marketQuote : marketQuotes) {
ext::shared_ptr<SimpleQuote> cp(new SimpleQuote(marketQuote));
quote.push_back(cp);
}

Expand Down
22 changes: 10 additions & 12 deletions Examples/CDS/CDS.cpp
Expand Up @@ -119,9 +119,8 @@ void example01() {
vector<pair<Date, Real> > hr_curve_data = hazardRateStructure->nodes();

cout << "Calibrated hazard rate values: " << endl;
for (Size i = 0; i < hr_curve_data.size(); i++) {
cout << "hazard rate on " << hr_curve_data[i].first << " is "
<< hr_curve_data[i].second << endl;
for (auto& i : hr_curve_data) {
cout << "hazard rate on " << i.first << " is " << i.second << endl;
}
cout << endl;

Expand Down Expand Up @@ -345,8 +344,8 @@ std::copy(cdsSchedule.begin(), cdsSchedule.end(),

// output rate curve
std::cout << "ISDA rate curve: " << std::endl;
for(Size i=0;i<isdaRateHelper.size(); i++) {
Date d = isdaRateHelper[i]->latestDate();
for (auto& i : isdaRateHelper) {
Date d = i->latestDate();
std::cout << d << "\t" << setprecision(6) <<
rateTs->zeroRate(d,Actual365Fixed(),Continuous).rate() << "\t" <<
rateTs->discount(d) << std::endl;
Expand Down Expand Up @@ -395,16 +394,15 @@ std::copy(cdsSchedule.begin(), cdsSchedule.end(),
0, WeekendsOnly(), isdaCdsHelper, Actual365Fixed()));

std::cout << "ISDA credit curve: " << std::endl;
for(Size i=0;i<isdaCdsHelper.size();i++) {
Date d = isdaCdsHelper[i]->latestDate();
for (auto& i : isdaCdsHelper) {
Date d = i->latestDate();
Real pd = defaultTs->defaultProbability(d);
Real t = defaultTs->timeFromReference(d);
std::cout << d << ";" << pd << ";" << 1.0 - pd << ";" <<
-std::log(1.0-pd)/t << std::endl;
}



// // set up sample CDS trade

// ext::shared_ptr<CreditDefaultSwap> trade =
Expand Down Expand Up @@ -613,8 +611,8 @@ void example03() {
// check the curves
std::cout << "ISDA yield curve:" << std::endl;
std::cout << "date;time;zeroyield" << std::endl;
for (Size i = 0; i < isdaYieldHelpers.size(); i++) {
Date d = isdaYieldHelpers[i]->latestDate();
for (auto& isdaYieldHelper : isdaYieldHelpers) {
Date d = isdaYieldHelper->latestDate();
Real t = isdaYts->timeFromReference(d);
std::cout << d << ";" << t << ";"
<< isdaYts->zeroRate(d, Actual365Fixed(), Continuous).rate()
Expand All @@ -623,8 +621,8 @@ void example03() {

std::cout << "ISDA credit curve:" << std::endl;
std::cout << "date;time;survivalprob" << std::endl;
for (Size i = 0; i < isdaCdsHelpers.size(); i++) {
Date d = isdaCdsHelpers[i]->latestDate();
for (auto& isdaCdsHelper : isdaCdsHelpers) {
Date d = isdaCdsHelper->latestDate();
Real t = isdaCts->timeFromReference(d);
std::cout << d << ";" << t << ";" << isdaCts->survivalProbability(d)
<< std::endl;
Expand Down
12 changes: 6 additions & 6 deletions Examples/FittedBondCurve/FittedBondCurve.cpp
Expand Up @@ -89,13 +89,13 @@ int main(int, char* []) {
const Size numberOfBonds = 15;
Real cleanPrice[numberOfBonds];

for (Size i=0; i<numberOfBonds; i++) {
cleanPrice[i]=100.0;
for (double& i : cleanPrice) {
i = 100.0;
}

std::vector< ext::shared_ptr<SimpleQuote> > quote;
for (Size i=0; i<numberOfBonds; i++) {
ext::shared_ptr<SimpleQuote> cp(new SimpleQuote(cleanPrice[i]));
for (double i : cleanPrice) {
ext::shared_ptr<SimpleQuote> cp(new SimpleQuote(i));
quote.push_back(cp);
}

Expand Down Expand Up @@ -227,8 +227,8 @@ int main(int, char* []) {
20.0, 25.0, 30.0, 40.0, 50.0 };

std::vector<Time> knotVector;
for (Size i=0; i< LENGTH(knots); i++) {
knotVector.push_back(knots[i]);
for (double& knot : knots) {
knotVector.push_back(knot);
}

CubicBSplinesFitting cubicBSplines(knotVector, constrainAtZero);
Expand Down
37 changes: 18 additions & 19 deletions Examples/Gaussian1dModels/Gaussian1dModels.cpp
Expand Up @@ -70,9 +70,8 @@ void printBasket(
"===================="
"===================="
"==================" << std::endl;
for (Size j = 0; j < basket.size(); ++j) {
ext::shared_ptr<SwaptionHelper> helper =
ext::dynamic_pointer_cast<SwaptionHelper>(basket[j]);
for (const auto& j : basket) {
ext::shared_ptr<SwaptionHelper> helper = ext::dynamic_pointer_cast<SwaptionHelper>(j);
Date endDate = helper->underlyingSwap()->fixedSchedule().dates().back();
Real nominal = helper->underlyingSwap()->nominal();
Real vol = helper->volatility()->value();
Expand Down Expand Up @@ -266,8 +265,8 @@ int main(int argc, char *argv[]) {
"\nthe calibrating vanilla swaptions. The result of this is as "
"follows:" << std::endl;

for (Size i = 0; i < basket.size(); ++i)
basket[i]->setPricingEngine(swaptionEngine);
for (auto& i : basket)
i->setPricingEngine(swaptionEngine);

LevenbergMarquardt method;
EndCriteria ec(1000, 10, 1E-8, 1E-8,
Expand Down Expand Up @@ -318,10 +317,10 @@ int main(int argc, char *argv[]) {
std::cout << "\nLet's see how this affects the exotics npv. The "
"\nrecalibrated model is:" << std::endl;

for (Size i = 0; i < basket.size(); ++i)
basket[i]->setPricingEngine(swaptionEngine);
for (auto& i : basket)
i->setPricingEngine(swaptionEngine);



gsr->calibrateVolatilitiesIterative(basket, method, ec);


Expand Down Expand Up @@ -434,10 +433,10 @@ int main(int argc, char *argv[]) {
<< "\nThe npv of the call right is (after recalibrating the model)"
<< std::endl;

for (Size i = 0; i < basket.size(); i++)
basket[i]->setPricingEngine(swaptionEngine);
for (auto& i : basket)
i->setPricingEngine(swaptionEngine);



gsr->calibrateVolatilitiesIterative(basket, method, ec);
Real npv3 = swaption3->NPV();

Expand Down Expand Up @@ -469,10 +468,10 @@ int main(int argc, char *argv[]) {

std::cout << "\nThe npv becomes:" << std::endl;

for (Size i = 0; i < basket.size(); i++)
basket[i]->setPricingEngine(swaptionEngine);
for (auto& i : basket)
i->setPricingEngine(swaptionEngine);



gsr->calibrateVolatilitiesIterative(basket, method, ec);
Real npv4 = swaption3->NPV();

Expand Down Expand Up @@ -541,8 +540,8 @@ int main(int argc, char *argv[]) {

basket = swaption4->calibrationBasket(swapBase, *swaptionVol,
BasketGeneratingEngine::Naive);
for (Size i = 0; i < basket.size(); ++i)
basket[i]->setPricingEngine(swaptionEngine);
for (auto& i : basket)
i->setPricingEngine(swaptionEngine);
gsr->calibrateVolatilitiesIterative(basket, method, ec);


Expand Down Expand Up @@ -637,10 +636,10 @@ int main(int argc, char *argv[]) {
"\ndepending on your machine, this may take a"
"\nwhile now..." << std::endl;

for (Size i = 0; i < basket.size(); ++i)
basket[i]->setPricingEngine(swaptionEngineMarkov);
for (auto& i : basket)
i->setPricingEngine(swaptionEngineMarkov);



markov->calibrate(basket, method, ec);


Expand Down
12 changes: 6 additions & 6 deletions Examples/GlobalOptimizer/GlobalOptimizer.cpp
Expand Up @@ -56,9 +56,9 @@ Real ackley(const Array& x) {
//Minimum is found at 0
Real p1 = 0.0, p2 = 0.0;

for (Size i = 0; i < x.size(); i++) {
p1 += x[i] * x[i];
p2 += std::cos(M_TWOPI*x[i]);
for (double i : x) {
p1 += i * i;
p2 += std::cos(M_TWOPI * i);
}
p1 = -0.2*std::sqrt(0.5*p1);
p2 *= 0.5;
Expand Down Expand Up @@ -103,9 +103,9 @@ Real rosenbrock(const Array& x) {
Real easom(const Array& x) {
//Minimum is found at f(\pi, \pi, ...)
Real p1 = 1.0, p2 = 0.0;
for (Size i = 0; i < x.size(); i++) {
p1 *= std::cos(x[i]);
p2 += (x[i] - M_PI)*(x[i] - M_PI);
for (double i : x) {
p1 *= std::cos(i);
p2 += (i - M_PI) * (i - M_PI);
}
return -p1*std::exp(-p2);
}
Expand Down
6 changes: 3 additions & 3 deletions Examples/LatentModel/LatentModel.cpp
Expand Up @@ -71,10 +71,10 @@ int main(int, char* []) {
names.push_back(std::string("Acme") +
boost::lexical_cast<std::string>(i));
std::vector<Handle<DefaultProbabilityTermStructure> > defTS;
for(Size i=0; i<hazardRates.size(); i++)
defTS.reserve(hazardRates.size());
for (double& hazardRate : hazardRates)
defTS.push_back(Handle<DefaultProbabilityTermStructure>(
ext::make_shared<FlatHazardRate>(0, TARGET(), hazardRates[i],
Actual365Fixed())));
ext::make_shared<FlatHazardRate>(0, TARGET(), hazardRate, Actual365Fixed())));
std::vector<Issuer> issuers;
for(Size i=0; i<hazardRates.size(); i++) {
std::vector<QuantLib::Issuer::key_curve_pair> curves(1,
Expand Down
8 changes: 4 additions & 4 deletions Examples/MarketModels/MarketModels.cpp
Expand Up @@ -323,8 +323,8 @@ int Bermudan()

std::vector<Real> means(stats.mean());

for (Size i=0; i < means.size(); ++i)
std::cout << means[i] << "\n";
for (double mean : means)
std::cout << mean << "\n";

std::cout << " time to build strategy, " << (t2-t1)/static_cast<Real>(CLOCKS_PER_SEC)<< ", seconds.\n";
std::cout << " time to price, " << (t3-t2)/static_cast<Real>(CLOCKS_PER_SEC)<< ", seconds.\n";
Expand Down Expand Up @@ -656,8 +656,8 @@ int InverseFloater(Real rateLevel)

std::vector<Real> means(stats.mean());

for (Size i=0; i < means.size(); ++i)
std::cout << means[i] << "\n";
for (double mean : means)
std::cout << mean << "\n";

std::cout << " time to build strategy, " << (t2-t1)/static_cast<Real>(CLOCKS_PER_SEC)<< ", seconds.\n";
std::cout << " time to price, " << (t3-t2)/static_cast<Real>(CLOCKS_PER_SEC)<< ", seconds.\n";
Expand Down
4 changes: 2 additions & 2 deletions Examples/MultidimIntegral/MultidimIntegral.cpp
Expand Up @@ -46,8 +46,8 @@ namespace QuantLib {
struct integrand {
Real operator()(const std::vector<Real>& arg) const {
Real sum = 1.;
for(Size i=0; i<arg.size(); i++)
sum *= std::exp(-arg[i]*arg[i]) * std::cos(arg[i]);
for (double i : arg)
sum *= std::exp(-i * i) * std::cos(i);
return sum;
}
};
Expand Down

0 comments on commit 61ec7a1

Please sign in to comment.