Skip to content

Commit

Permalink
Merge 7067ec8 into 256cc86
Browse files Browse the repository at this point in the history
  • Loading branch information
auto-differentiation-dev authored Jun 8, 2022
2 parents 256cc86 + 7067ec8 commit 00bf064
Show file tree
Hide file tree
Showing 147 changed files with 486 additions and 476 deletions.
2 changes: 1 addition & 1 deletion Examples/BasketLosses/BasketLosses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int main(int, char* []) {
for(Size i=0; i<hazardRates.size(); i++)
names.push_back(std::string("Acme") + std::to_string(i));
std::vector<Handle<DefaultProbabilityTermStructure> > defTS;
for (double& hazardRate : hazardRates) {
for (Real& hazardRate : hazardRates) {
defTS.emplace_back(
ext::make_shared<FlatHazardRate>(0, TARGET(), hazardRate, Actual365Fixed()));
defTS.back()->enableExtrapolation();
Expand Down
2 changes: 1 addition & 1 deletion Examples/Bonds/Bonds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ int main(int, char* []) {
};

std::vector< ext::shared_ptr<SimpleQuote> > quote;
for (double marketQuote : marketQuotes) {
for (Real marketQuote : marketQuotes) {
ext::shared_ptr<SimpleQuote> cp(new SimpleQuote(marketQuote));
quote.push_back(cp);
}
Expand Down
6 changes: 3 additions & 3 deletions Examples/FittedBondCurve/FittedBondCurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ int main(int, char* []) {
const Size numberOfBonds = 15;
Real cleanPrice[numberOfBonds];

for (double& i : cleanPrice) {
for (Real& i : cleanPrice) {
i = 100.0;
}

std::vector< ext::shared_ptr<SimpleQuote> > quote;
for (double i : cleanPrice) {
for (Real i : cleanPrice) {
ext::shared_ptr<SimpleQuote> cp(new SimpleQuote(i));
quote.push_back(cp);
}
Expand Down Expand Up @@ -227,7 +227,7 @@ int main(int, char* []) {
20.0, 25.0, 30.0, 40.0, 50.0 };

std::vector<Time> knotVector;
for (double& knot : knots) {
for (Real& knot : knots) {
knotVector.push_back(knot);
}

Expand Down
4 changes: 2 additions & 2 deletions Examples/GlobalOptimizer/GlobalOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Real ackley(const Array& x) {
//Minimum is found at 0
Real p1 = 0.0, p2 = 0.0;

for (double i : x) {
for (Real i : x) {
p1 += i * i;
p2 += std::cos(M_TWOPI * i);
}
Expand Down Expand Up @@ -103,7 +103,7 @@ 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 (double i : x) {
for (Real i : x) {
p1 *= std::cos(i);
p2 += (i - M_PI) * (i - M_PI);
}
Expand Down
2 changes: 1 addition & 1 deletion Examples/LatentModel/LatentModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int main(int, char* []) {
names.push_back(std::string("Acme") + std::to_string(i));
std::vector<Handle<DefaultProbabilityTermStructure> > defTS;
defTS.reserve(hazardRates.size());
for (double& hazardRate : hazardRates)
for (Real& hazardRate : hazardRates)
defTS.emplace_back(
ext::make_shared<FlatHazardRate>(0, TARGET(), hazardRate, Actual365Fixed()));
std::vector<Issuer> issuers;
Expand Down
4 changes: 2 additions & 2 deletions Examples/MarketModels/MarketModels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ int Bermudan()

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

for (double mean : means)
for (Real mean : means)
std::cout << mean << "\n";

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

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

for (double mean : means)
for (Real mean : means)
std::cout << mean << "\n";

std::cout << " time to build strategy, " << (t2-t1)/static_cast<Real>(CLOCKS_PER_SEC)<< ", seconds.\n";
Expand Down
2 changes: 1 addition & 1 deletion Examples/MultidimIntegral/MultidimIntegral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace QuantLib {
struct integrand {
Real operator()(const std::vector<Real>& arg) const {
Real sum = 1.;
for (double i : arg)
for (Real i : arg)
sum *= std::exp(-i * i) * std::cos(i);
return sum;
}
Expand Down
8 changes: 4 additions & 4 deletions ql/cashflows/conundrumpricer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ namespace QuantLib {

Real GFunctionFactory::GFunctionExactYield::operator()(Real x) {
Real product = 1.;
for (double accrual : accruals_) {
for (Real accrual : accruals_) {
product *= 1. / (1. + accrual * x);
}
return x*std::pow(1.+ accruals_[0]*x,-delta_)*(1./(1.-product));
Expand All @@ -612,7 +612,7 @@ namespace QuantLib {
Real derC = 0.;
std::vector<Real> b;
b.reserve(accruals_.size());
for (double accrual : accruals_) {
for (Real accrual : accruals_) {
Real temp = 1.0 / (1.0 + accrual * x);
b.push_back(temp);
c *= temp;
Expand All @@ -634,7 +634,7 @@ namespace QuantLib {
Real sumOfSquare = 0.;
std::vector<Real> b;
b.reserve(accruals_.size());
for (double accrual : accruals_) {
for (Real accrual : accruals_) {
Real temp = 1.0 / (1.0 + accrual * x);
b.push_back(temp);
c *= temp;
Expand Down Expand Up @@ -699,7 +699,7 @@ namespace QuantLib {
ext::dynamic_pointer_cast<Coupon>(fixedLeg[i]);
accruals_.push_back(cpn->accrualPeriod());
const Date paymentDate(cpn->date());
const double swapPaymentTime(dc.yearFraction(rateCurve->referenceDate(), paymentDate));
const Real swapPaymentTime(dc.yearFraction(rateCurve->referenceDate(), paymentDate));
shapedSwapPaymentTimes_.push_back(shapeOfShift(swapPaymentTime));
swapPaymentDiscounts_.push_back(rateCurve->discount(paymentDate));
}
Expand Down
10 changes: 5 additions & 5 deletions ql/experimental/asian/analytic_cont_geom_av_price_heston.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ namespace QuantLib {
Real xiRightLimit) : t_(0.0), T_(T), K_(K), logK_(std::log(K)), cutoff_(cutoff),
parent_(parent), xiRightLimit_(xiRightLimit), i_(std::complex<Real>(0.0, 1.0)) {}

double operator()(double xi) const {
double xiDash = (0.5+1e-8+0.5*xi) * xiRightLimit_; // Map xi to full range
Real operator()(Real xi) const {
Real xiDash = (0.5+1e-8+0.5*xi) * xiRightLimit_; // Map xi to full range

std::complex<Real> inner1 = parent_->Phi(1.0 + xiDash*i_, 0, T_, t_, cutoff_);
std::complex<Real> inner2 = - K_*parent_->Phi(xiDash*i_, 0, T_, t_, cutoff_);
Expand All @@ -63,8 +63,8 @@ namespace QuantLib {
denominator_ = std::log(riskFreeRate_->discount(t_)) - std::log(dividendYield_->discount(t_));
}

double operator()(double u) const {
double uDash = (0.5+1e-8+0.5*u) * (T_ - t_) + t_; // Map u to full range
Real operator()(Real u) const {
Real uDash = (0.5+1e-8+0.5*u) * (T_ - t_) + t_; // Map u to full range
return 0.5*(T_ - t_)*(-std::log(riskFreeRate_->discount(uDash))
+ std::log(dividendYield_->discount(uDash)) + denominator_);
}
Expand Down Expand Up @@ -172,7 +172,7 @@ namespace QuantLib {
for (Size i=0; i<cutoff; i++) {
temp = f(z1, z2, z3, z4, i, tau);
runningSum1 += temp;
runningSum2 += temp*double(i)/tau;
runningSum2 += temp*Real(i)/tau;
}

std::pair<std::complex<Real>, std::complex<Real> > result(runningSum1, runningSum2);
Expand Down
14 changes: 7 additions & 7 deletions ql/experimental/asian/analytic_discr_geom_av_price_heston.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ namespace QuantLib {
tauK_(std::move(tauK)), parent_(parent), xiRightLimit_(xiRightLimit),
i_(std::complex<Real>(0.0, 1.0)) {}

double operator()(double xi) const {
double xiDash = (0.5+1e-8+0.5*xi) * xiRightLimit_; // Map xi to full range
Real operator()(Real xi) const {
Real xiDash = (0.5+1e-8+0.5*xi) * xiRightLimit_; // Map xi to full range

std::complex<Real> inner1 = parent_->Phi(1.0 + xiDash*i_, 0, t_, T_, kStar_, t_n_, tauK_);
std::complex<Real> inner2 = -K_*parent_->Phi(xiDash*i_, 0, t_, T_, kStar_, t_n_, tauK_);
Expand Down Expand Up @@ -96,8 +96,8 @@ namespace QuantLib {

std::complex<Real> AnalyticDiscreteGeometricAveragePriceAsianHestonEngine::z(
const std::complex<Real>& s, const std::complex<Real>& w, Size k, Size n) const {
auto k_ = double(k);
auto n_ = double(n);
auto k_ = Real(k);
auto n_ = Real(n);
std::complex<Real> term1 = (2*rho_*kappa_ - sigma_)*((n_-k_+1)*s + n_*w)/(2*sigma_*n_);
std::complex<Real> term2 = (1-rho_*rho_)*pow(((n_-k_+1)*s + n_*w), 2)/(2*n_*n_);

Expand All @@ -120,8 +120,8 @@ namespace QuantLib {
const std::complex<Real>& w,
Time t, Time T, Size kStar,
const std::vector<Time>& t_n) const {
auto kStar_ = double(kStar);
auto n_ = double(t_n.size());
auto kStar_ = Real(kStar);
auto n_ = Real(t_n.size());
Real temp = -rho_*kappa_*theta_/sigma_;

Time summation = 0.0;
Expand Down Expand Up @@ -262,7 +262,7 @@ namespace QuantLib {
tkr_tk_ = std::vector<Real>();
tr_t_ = -std::log(riskFreeRate_->discount(startTime) / dividendYield_->discount(startTime));
Tr_T_ = -std::log(riskFreeRate_->discount(expiryTime) / dividendYield_->discount(expiryTime));
for (double fixingTime : fixingTimes) {
for (Real fixingTime : fixingTimes) {
if (fixingTime < 0) {
tkr_tk_.push_back(1.0);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace QuantLib {
stoppingTime = true;
break;
case Exercise::Bermudan:
for (double i : stoppingTimes_) {
for (Real i : stoppingTimes_) {
if (isOnTime(i)) {
stoppingTime = true;
break;
Expand Down
2 changes: 1 addition & 1 deletion ql/experimental/basismodels/tenoroptionletvts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace QuantLib {

Volatility TenorOptionletVTS::TenorOptionletSmileSection::volatilityImpl(Rate strike) const {
Real sum_v = 0.0;
for (double k : v_)
for (Real k : v_)
sum_v += k;
std::vector<Real> volBase(v_.size());
for (Size k = 0; k < fraRateBase_.size(); ++k) {
Expand Down
4 changes: 2 additions & 2 deletions ql/experimental/basismodels/tenorswaptionvts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ namespace QuantLib {
// calculate affine TSR model u and v
// Sum tau_j (fixed leg)
Real sumTauj = 0.0;
for (double k : cfs.annuityWeights())
for (Real k : cfs.annuityWeights())
sumTauj += k;
// Sum tau_j (T_M - T_j) (fixed leg)
Real sumTaujDeltaT = 0.0;
Expand All @@ -100,7 +100,7 @@ namespace QuantLib {
cfs.annuityWeights()[k] * (cfs.fixedTimes().back() - cfs.fixedTimes()[k]);
// Sum w_i (float leg)
Real sumWi = 0.0;
for (double k : cfs.floatWeights())
for (Real k : cfs.floatWeights())
sumWi += k;
// Sum w_i (T_N - T_i) (float leg)
Real sumWiDeltaT = 0.0;
Expand Down
56 changes: 28 additions & 28 deletions ql/experimental/callablebonds/callablebond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ namespace QuantLib {
Compounding compounding,
Frequency frequency)
{
double zz=yts->zeroRate(b.maturityDate(),
dayCounter,
Continuous,
NoFrequency);
Real zz=yts->zeroRate(b.maturityDate(),
dayCounter,
Continuous,
NoFrequency);
InterestRate baseRate(zz,
dayCounter,
Continuous,
Expand All @@ -166,16 +166,16 @@ namespace QuantLib {
dayCounter,
Continuous,
NoFrequency);
double br=baseRate.equivalentRate(dayCounter,
compounding,
frequency,
yts->referenceDate(),
b.maturityDate()).rate();
double sr=spreadedRate.equivalentRate(dayCounter,
compounding,
frequency,
yts->referenceDate(),
b.maturityDate()).rate();
Real br=baseRate.equivalentRate(dayCounter,
compounding,
frequency,
yts->referenceDate(),
b.maturityDate()).rate();
Real sr=spreadedRate.equivalentRate(dayCounter,
compounding,
frequency,
yts->referenceDate(),
b.maturityDate()).rate();
// Return the spread
return sr-br;
}
Expand All @@ -190,10 +190,10 @@ namespace QuantLib {
Compounding compounding,
Frequency frequency)
{
double zz=yts->zeroRate(b.maturityDate(),
dayCounter,
compounding,
frequency);
Real zz=yts->zeroRate(b.maturityDate(),
dayCounter,
compounding,
frequency);
InterestRate baseRate(zz,
dayCounter,
compounding,
Expand All @@ -203,16 +203,16 @@ namespace QuantLib {
dayCounter,
compounding,
frequency);
double br=baseRate.equivalentRate(dayCounter,
Continuous,
NoFrequency,
yts->referenceDate(),
b.maturityDate()).rate();
double sr=spreadedRate.equivalentRate(dayCounter,
Continuous,
NoFrequency,
yts->referenceDate(),
b.maturityDate()).rate();
Real br=baseRate.equivalentRate(dayCounter,
Continuous,
NoFrequency,
yts->referenceDate(),
b.maturityDate()).rate();
Real sr=spreadedRate.equivalentRate(dayCounter,
Continuous,
NoFrequency,
yts->referenceDate(),
b.maturityDate()).rate();
// Return the spread
return sr-br;
}
Expand Down
4 changes: 2 additions & 2 deletions ql/experimental/credit/basket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace QuantLib {
// probability term structures for the defultKeys(eventType+
// currency+seniority) entering in this basket. This is not
// necessarily a problem.
for (double notional : notionals_) {
for (Real notional : notionals_) {
basketNotional_ += notional;
attachmentAmount_ += notional * attachmentRatio_;
detachmentAmount_ += notional * detachmentRatio_;
Expand Down Expand Up @@ -103,7 +103,7 @@ namespace QuantLib {
}

Real Basket::notional() const {
return std::accumulate(notionals_.begin(), notionals_.end(), 0.0);
return std::accumulate(notionals_.begin(), notionals_.end(), Real(0.0));
}

vector<Real> Basket::probabilities(const Date& d) const {
Expand Down
4 changes: 2 additions & 2 deletions ql/experimental/credit/binomiallossmodel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ namespace QuantLib {
// of full portfolio:
Real avgProb = avgLgd <= QL_EPSILON ? 0. : // only if all are 0
std::inner_product(condDefProb.begin(),
condDefProb.end(), lgdsLeft.begin(), 0.)
condDefProb.end(), lgdsLeft.begin(), Real(0.))
/ (avgLgd * bsktSize);
// model parameters:
Real m = avgProb * bsktSize;
Expand All @@ -200,7 +200,7 @@ namespace QuantLib {
std::transform(lgdsLeft.begin(), lgdsLeft.end(),
lgdsLeft.begin(), lgdsLeft.begin(), std::multiplies<Real>());
Real variance = std::inner_product(condDefProb.begin(),
condDefProb.end(), lgdsLeft.begin(), 0.);
condDefProb.end(), lgdsLeft.begin(), Real(0.));

variance = avgLgd <= QL_EPSILON ? 0. :
variance / (bsktSize * bsktSize * avgLgd * avgLgd );
Expand Down
2 changes: 1 addition & 1 deletion ql/experimental/credit/distribution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ namespace QuantLib {
dx_.erase(dx_.begin() + size_, dx_.end());

// truncate
for (double& i : x_) {
for (Real& i : x_) {
i = std::min(std::max(i - attachmentPoint, 0.), detachmentPoint - attachmentPoint);
}

Expand Down
4 changes: 2 additions & 2 deletions ql/experimental/credit/gaussianlhplossmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace QuantLib {
beta_(sqrt(correlation)),
biphi_(-sqrt(correlation))
{
for (double recoverie : recoveries)
for (Real recoverie : recoveries)
rrQuotes_.emplace_back(ext::make_shared<RecoveryRateQuote>(recoverie));
}

Expand All @@ -77,7 +77,7 @@ namespace QuantLib {
biphi_(-sqrt(correlQuote->value()))
{
registerWith(correl_);
for (double recoverie : recoveries)
for (Real recoverie : recoveries)
rrQuotes_.emplace_back(ext::make_shared<RecoveryRateQuote>(recoverie));
}

Expand Down
Loading

0 comments on commit 00bf064

Please sign in to comment.