Skip to content

Commit

Permalink
Merge afbb15e into 5143ca6
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Feb 21, 2021
2 parents 5143ca6 + afbb15e commit a57cf08
Show file tree
Hide file tree
Showing 69 changed files with 1,441 additions and 2,044 deletions.
12 changes: 3 additions & 9 deletions Examples/BasketLosses/BasketLosses.cpp
Expand Up @@ -32,16 +32,12 @@
#include <ql/time/daycounters/actual365fixed.hpp>
#include <ql/time/calendars/target.hpp>
#include <ql/currencies/europe.hpp>

#include <boost/assign/std/vector.hpp>

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;
using namespace QuantLib;
using namespace boost::assign;

#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {
Expand All @@ -67,11 +63,9 @@ int main(int, char* []) {
SET UP BASKET PORTFOLIO
-------------------------------------------------------------- */
// build curves and issuers into a basket of ten names
std::vector<Real> hazardRates;
hazardRates +=
// 0.01, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9;
0.001, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09;
// 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01;
std::vector<Real> hazardRates = {
0.001, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09
};
std::vector<std::string> names;
for(Size i=0; i<hazardRates.size(); i++)
names.push_back(std::string("Acme") +
Expand Down
30 changes: 15 additions & 15 deletions ql/experimental/models/hestonslvfdmmodel.cpp
Expand Up @@ -43,13 +43,10 @@
#include <ql/termstructures/volatility/equityfx/fixedlocalvolsurface.hpp>
#include <ql/termstructures/volatility/equityfx/localvoltermstructure.hpp>
#include <ql/timegrid.hpp>
#include <boost/assign/std/vector.hpp>
#include <boost/scoped_ptr.hpp>
#include <functional>
#include <utility>

using namespace boost::assign;

namespace QuantLib {

namespace {
Expand Down Expand Up @@ -83,10 +80,11 @@ namespace QuantLib {

const Real v0Center = std::log(v0);

cPoints +=
ext::make_tuple(lowerBound, lowerBoundDensity, false),
ext::make_tuple(v0Center, v0Density, true),
ext::make_tuple(upperBound, upperBoundDensity, false);
cPoints = {
{lowerBound, lowerBoundDensity, false},
{v0Center, v0Density, true},
{upperBound, upperBoundDensity, false}
};

return ext::make_shared<Concentrating1dMesher>(
lowerBound, upperBound, vGrid, cPoints, 1e-8);
Expand All @@ -96,10 +94,11 @@ namespace QuantLib {
{
const Real v0Center = v0;

cPoints +=
ext::make_tuple(lowerBound, lowerBoundDensity, false),
ext::make_tuple(v0Center, v0Density, true),
ext::make_tuple(upperBound, upperBoundDensity, false);
cPoints = {
{lowerBound, lowerBoundDensity, false},
{v0Center, v0Density, true},
{upperBound, upperBoundDensity, false}
};

return ext::make_shared<Concentrating1dMesher>(
lowerBound, upperBound, vGrid, cPoints, 1e-8);
Expand All @@ -109,10 +108,11 @@ namespace QuantLib {
{
const Real v0Center = v0;

cPoints +=
ext::make_tuple(lowerBound, lowerBoundDensity, false),
ext::make_tuple(v0Center, v0Density, true),
ext::make_tuple(upperBound, upperBoundDensity, false);
cPoints = {
{lowerBound, lowerBoundDensity, false},
{v0Center, v0Density, true},
{upperBound, upperBoundDensity, false}
};

return ext::make_shared<Concentrating1dMesher>(
lowerBound, upperBound, vGrid, cPoints, 1e-8);
Expand Down
21 changes: 11 additions & 10 deletions ql/experimental/volatility/noarbsabr.cpp
Expand Up @@ -22,7 +22,6 @@
#include <ql/math/solvers1d/brent.hpp>
#include <ql/math/modifiedbessel.hpp>
#include <boost/math/special_functions/gamma.hpp>
#include <boost/assign/std/vector.hpp>
#include <boost/functional/hash.hpp>

namespace QuantLib {
Expand Down Expand Up @@ -184,8 +183,6 @@ Real NoArbSabrModel::p(const Real f) const {

namespace detail {

using namespace boost::assign;

D0Interpolator::D0Interpolator(const Real forward, const Real expiryTime,
const Real alpha, const Real beta, const Real nu,
const Real rho)
Expand All @@ -194,7 +191,8 @@ D0Interpolator::D0Interpolator(const Real forward, const Real expiryTime,

sigmaI_ = alpha_ * std::pow(forward_, beta_ - 1.0);

tauG_ += 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5, 2.75, 3.0,
tauG_ = {
0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25, 2.5, 2.75, 3.0,
3.25, 3.5, 3.75, 4.0, 4.25, 4.5, 4.75, 5.0, 5.25, 5.5, 5.75, 6.0, 6.25,
6.5, 6.75, 7.0, 7.25, 7.5, 7.75, 8.0, 8.25, 8.5, 8.75, 9.0, 9.25, 9.5,
9.75, 10.0, 10.25, 10.5, 10.75, 11.0, 11.25, 11.5, 11.75, 12.0, 12.25,
Expand All @@ -204,16 +202,19 @@ D0Interpolator::D0Interpolator(const Real forward, const Real expiryTime,
20.75, 21.0, 21.25, 21.5, 21.75, 22.0, 22.25, 22.5, 22.75, 23.0, 23.25,
23.5, 23.75, 24.0, 24.25, 24.5, 24.75, 25.0, 25.25, 25.5, 25.75, 26.0,
26.25, 26.5, 26.75, 27.0, 27.25, 27.5, 27.75, 28.0, 28.25, 28.5, 28.75,
29.0, 29.25, 29.5, 29.75, 30.0;
29.0, 29.25, 29.5, 29.75, 30.0
};

sigmaIG_ += 1.0, 0.8, 0.7, 0.6, 0.5, 0.45, 0.4, 0.35, 0.3, 0.27, 0.24, 0.21,
0.18, 0.15, 0.125, 0.1, 0.075, 0.05;
sigmaIG_ = {
1.0, 0.8, 0.7, 0.6, 0.5, 0.45, 0.4, 0.35, 0.3, 0.27, 0.24, 0.21,
0.18, 0.15, 0.125, 0.1, 0.075, 0.05
};

rhoG_ += 0.75, 0.50, 0.25, 0.00, -0.25, -0.50, -0.75;
rhoG_ = { 0.75, 0.50, 0.25, 0.00, -0.25, -0.50, -0.75 };

nuG_ += 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8;
nuG_ = { 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8 };

betaG_ += 0.01, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9;
betaG_ = { 0.01, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9 };
}

Real D0Interpolator::operator()() const {
Expand Down
6 changes: 2 additions & 4 deletions ql/experimental/volatility/noarbsabrinterpolation.hpp
Expand Up @@ -26,7 +26,6 @@

#include <ql/experimental/volatility/noarbsabrsmilesection.hpp>
#include <ql/math/interpolations/sabrinterpolation.hpp>
#include <boost/assign/list_of.hpp>
#include <utility>

namespace QuantLib {
Expand Down Expand Up @@ -214,9 +213,8 @@ class NoArbSabrInterpolation : public Interpolation {
impl_ = ext::shared_ptr<Interpolation::Impl>(
new detail::XABRInterpolationImpl<I1, I2, detail::NoArbSabrSpecs>(
xBegin, xEnd, yBegin, t, forward,
boost::assign::list_of(alpha)(beta)(nu)(rho),
boost::assign::list_of(alphaIsFixed)(betaIsFixed)(nuIsFixed)(
rhoIsFixed),
{alpha, beta, nu, rho},
{alphaIsFixed, betaIsFixed, nuIsFixed, rhoIsFixed},
vegaWeighted, endCriteria, optMethod, errorAccept, useMaxError,
maxGuesses));
coeffs_ = ext::dynamic_pointer_cast<
Expand Down
6 changes: 2 additions & 4 deletions ql/experimental/volatility/sviinterpolation.hpp
Expand Up @@ -26,7 +26,6 @@

#include <ql/experimental/volatility/svismilesection.hpp>
#include <ql/math/interpolations/xabrinterpolation.hpp>
#include <boost/assign/list_of.hpp>
#include <utility>

namespace QuantLib {
Expand Down Expand Up @@ -162,9 +161,8 @@ class SviInterpolation : public Interpolation {
impl_ = ext::shared_ptr<Interpolation::Impl>(
new detail::XABRInterpolationImpl<I1, I2, detail::SviSpecs>(
xBegin, xEnd, yBegin, t, forward,
boost::assign::list_of(a)(b)(sigma)(rho)(m),
boost::assign::list_of(aIsFixed)(bIsFixed)(sigmaIsFixed)(
rhoIsFixed)(mIsFixed),
{a, b, sigma, rho, m},
{aIsFixed, bIsFixed, sigmaIsFixed, rhoIsFixed, mIsFixed},
vegaWeighted, endCriteria, optMethod, errorAccept, useMaxError,
maxGuesses));
coeffs_ = ext::dynamic_pointer_cast<
Expand Down
6 changes: 2 additions & 4 deletions ql/experimental/volatility/zabrinterpolation.hpp
Expand Up @@ -26,7 +26,6 @@

#include <ql/experimental/volatility/zabrsmilesection.hpp>
#include <ql/math/interpolations/xabrinterpolation.hpp>
#include <boost/assign/list_of.hpp>
#include <utility>

namespace QuantLib {
Expand Down Expand Up @@ -140,9 +139,8 @@ template <class Evaluation> class ZabrInterpolation : public Interpolation {
I1, I2,
detail::ZabrSpecs<Evaluation> >(
xBegin, xEnd, yBegin, t, forward,
boost::assign::list_of(alpha)(beta)(nu)(rho)(gamma),
boost::assign::list_of(alphaIsFixed)(betaIsFixed)(nuIsFixed)(
rhoIsFixed)(gammaIsFixed),
{alpha, beta, nu, rho, gamma},
{alphaIsFixed, betaIsFixed, nuIsFixed, rhoIsFixed, gammaIsFixed},
vegaWeighted, endCriteria, optMethod, errorAccept, useMaxError,
maxGuesses));
coeffs_ = ext::dynamic_pointer_cast<detail::XABRCoeffHolder<
Expand Down
8 changes: 3 additions & 5 deletions ql/math/interpolations/sabrinterpolation.hpp
Expand Up @@ -32,7 +32,6 @@

#include <ql/math/interpolations/xabrinterpolation.hpp>
#include <ql/termstructures/volatility/sabr.hpp>
#include <boost/assign/list_of.hpp>
#include <utility>

namespace QuantLib {
Expand Down Expand Up @@ -169,11 +168,10 @@ class SABRInterpolation : public Interpolation {
impl_ = ext::shared_ptr<Interpolation::Impl>(
new detail::XABRInterpolationImpl<I1, I2, detail::SABRSpecs>(
xBegin, xEnd, yBegin, t, forward,
boost::assign::list_of(alpha)(beta)(nu)(rho),
boost::assign::list_of(alphaIsFixed)(betaIsFixed)(nuIsFixed)(
rhoIsFixed),
{alpha, beta, nu, rho},
{alphaIsFixed, betaIsFixed, nuIsFixed, rhoIsFixed},
vegaWeighted, endCriteria, optMethod, errorAccept, useMaxError,
maxGuesses, boost::assign::list_of(shift)));
maxGuesses, {shift}));
coeffs_ = ext::dynamic_pointer_cast<
detail::XABRCoeffHolder<detail::SABRSpecs> >(impl_);
}
Expand Down
48 changes: 9 additions & 39 deletions ql/methods/finitedifferences/meshers/fdmmeshercomposite.cpp
Expand Up @@ -21,43 +21,12 @@

#include <ql/methods/finitedifferences/operators/fdmlinearoplayout.hpp>
#include <ql/methods/finitedifferences/meshers/fdmmeshercomposite.hpp>
#if defined(__GNUC__) && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)) || (__GNUC__ > 4))
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#endif
#include <boost/assign/list_of.hpp>
#if defined(__GNUC__) && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)) || (__GNUC__ > 4))
#pragma GCC diagnostic pop
#endif

namespace QuantLib {

namespace {
typedef ext::shared_ptr<Fdm1dMesher> T;

std::vector<T> build_vector(const T& m1) {
return std::vector<T>(1, m1);
}

std::vector<T> build_vector(const T& m1, const T& m2) {
std::vector<ext::shared_ptr<Fdm1dMesher> > retVal
= boost::assign::list_of(m1)(m2);
return retVal;
}

std::vector<T> build_vector(const T& m1, const T& m2, const T& m3) {
std::vector<ext::shared_ptr<Fdm1dMesher> > retVal
= boost::assign::list_of(m1)(m2)(m3);
return retVal;
}

std::vector<T> build_vector(const T& m1, const T& m2,
const T& m3, const T& m4) {
std::vector<ext::shared_ptr<Fdm1dMesher> > retVal
= boost::assign::list_of(m1)(m2)(m3)(m4);
return retVal;
}

ext::shared_ptr<FdmLinearOpLayout> getLayoutFromMeshers(
const std::vector<ext::shared_ptr<Fdm1dMesher> > & meshers) {
std::vector<Size> dim(meshers.size());
Expand All @@ -70,34 +39,35 @@ namespace QuantLib {

FdmMesherComposite::FdmMesherComposite(
const ext::shared_ptr<Fdm1dMesher>& mesher)
: FdmMesher(getLayoutFromMeshers(build_vector(mesher))),
mesher_(build_vector(mesher)) {
: FdmMesher(getLayoutFromMeshers({mesher})),
mesher_({mesher}) {
}


FdmMesherComposite::FdmMesherComposite(
const ext::shared_ptr<Fdm1dMesher>& m1,
const ext::shared_ptr<Fdm1dMesher>& m2)
: FdmMesher(getLayoutFromMeshers(build_vector(m1, m2))),
mesher_(build_vector(m1, m2)) {
: FdmMesher(getLayoutFromMeshers({m1, m2})),
mesher_({m1, m2}) {
}

FdmMesherComposite::FdmMesherComposite(
const ext::shared_ptr<Fdm1dMesher>& m1,
const ext::shared_ptr<Fdm1dMesher>& m2,
const ext::shared_ptr<Fdm1dMesher>& m3)
: FdmMesher(getLayoutFromMeshers(build_vector(m1, m2, m3))),
mesher_(build_vector(m1, m2, m3)) {
: FdmMesher(getLayoutFromMeshers({m1, m2, m3})),
mesher_({m1, m2, m3}) {
}

FdmMesherComposite::FdmMesherComposite(
const ext::shared_ptr<Fdm1dMesher>& m1,
const ext::shared_ptr<Fdm1dMesher>& m2,
const ext::shared_ptr<Fdm1dMesher>& m3,
const ext::shared_ptr<Fdm1dMesher>& m4)
: FdmMesher(getLayoutFromMeshers(build_vector(m1, m2, m3, m4))),
mesher_(build_vector(m1, m2, m3, m4)) {
: FdmMesher(getLayoutFromMeshers({m1, m2, m3, m4})),
mesher_({m1, m2, m3, m4}) {
}

FdmMesherComposite::FdmMesherComposite(
const std::vector<ext::shared_ptr<Fdm1dMesher> > & mesher)
: FdmMesher(getLayoutFromMeshers(mesher)), mesher_(mesher) {
Expand Down

0 comments on commit a57cf08

Please sign in to comment.