Skip to content

Commit

Permalink
Merge 6b150a7 into 8773f58
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Jun 6, 2020
2 parents 8773f58 + 6b150a7 commit 9ac9d50
Show file tree
Hide file tree
Showing 39 changed files with 165 additions and 201 deletions.
4 changes: 2 additions & 2 deletions Examples/GlobalOptimizer/GlobalOptimizer.cpp
Expand Up @@ -143,8 +143,8 @@ class TestFunction : public CostFunction {
public:
typedef ext::function<Real(const Array&)> RealFunc;
typedef ext::function<Disposable<Array>(const Array&)> ArrayFunc;
TestFunction(const RealFunc & f, const ArrayFunc & fs = ArrayFunc()) : f_(f), fs_(fs) {}
TestFunction(Real(*f)(const Array&), Disposable<Array>(*fs)(const Array&) = NULL) : f_(f), fs_(fs) {}
explicit TestFunction(const RealFunc & f, const ArrayFunc & fs = ArrayFunc()) : f_(f), fs_(fs) {}
explicit TestFunction(Real(*f)(const Array&), Disposable<Array>(*fs)(const Array&) = NULL) : f_(f), fs_(fs) {}
virtual ~TestFunction(){}
virtual Real value(const Array& x) const {
return f_(x);
Expand Down
136 changes: 60 additions & 76 deletions Examples/MarketModels/MarketModels.cpp
Expand Up @@ -403,66 +403,58 @@ int Bermudan()
std::cout << " total Vega, " << totalVega << "\n";
}

bool doUpperBound = true;
// upper bound

if (doUpperBound)
{

// upper bound

MTBrownianGeneratorFactory uFactory(seed+142);
MTBrownianGeneratorFactory uFactory(seed+142);


ext::shared_ptr<MarketModelEvolver> upperEvolver(new LogNormalFwdRatePc( ext::shared_ptr<MarketModel>(new FlatVol(calibration)),
ext::shared_ptr<MarketModelEvolver> upperEvolver(new LogNormalFwdRatePc( ext::shared_ptr<MarketModel>(new FlatVol(calibration)),
uFactory,
numeraires // numeraires for each step
));

std::vector<ext::shared_ptr<MarketModelEvolver> > innerEvolvers;
std::vector<ext::shared_ptr<MarketModelEvolver> > innerEvolvers;

std::valarray<bool> isExerciseTime = isInSubset(evolution.evolutionTimes(), exerciseStrategy.exerciseTimes());
std::valarray<bool> isExerciseTime = isInSubset(evolution.evolutionTimes(), exerciseStrategy.exerciseTimes());

for (Size s=0; s < isExerciseTime.size(); ++s)
for (Size s=0; s < isExerciseTime.size(); ++s)
{
if (isExerciseTime[s])
{
if (isExerciseTime[s])
{
MTBrownianGeneratorFactory iFactory(seed+s);
ext::shared_ptr<MarketModelEvolver> e =ext::shared_ptr<MarketModelEvolver> (static_cast<MarketModelEvolver*>(new LogNormalFwdRatePc(ext::shared_ptr<MarketModel>(new FlatVol(calibration)),
MTBrownianGeneratorFactory iFactory(seed+s);
ext::shared_ptr<MarketModelEvolver> e =ext::shared_ptr<MarketModelEvolver> (static_cast<MarketModelEvolver*>(new LogNormalFwdRatePc(ext::shared_ptr<MarketModel>(new FlatVol(calibration)),
uFactory,
numeraires , // numeraires for each step
s)));

innerEvolvers.push_back(e);
}
innerEvolvers.push_back(e);
}
}



UpperBoundEngine uEngine(upperEvolver, // does outer paths
innerEvolvers, // for sub-simulations that do continuation values
receiverSwap,
nullRebate,
receiverSwap,
nullRebate,
exerciseStrategy,
initialNumeraireValue);

Statistics uStats;
Size innerPaths = 255;
Size outerPaths =256;
UpperBoundEngine uEngine(upperEvolver, // does outer paths
innerEvolvers, // for sub-simulations that do continuation values
receiverSwap,
nullRebate,
receiverSwap,
nullRebate,
exerciseStrategy,
initialNumeraireValue);

int t4 = clock();
Statistics uStats;
Size innerPaths = 255;
Size outerPaths =256;

uEngine.multiplePathValues(uStats,outerPaths,innerPaths);
Real upperBound = uStats.mean();
Real upperSE = uStats.errorEstimate();
int t4 = clock();

int t5=clock();
uEngine.multiplePathValues(uStats,outerPaths,innerPaths);
Real upperBound = uStats.mean();
Real upperSE = uStats.errorEstimate();

std::cout << " Upper - lower is, " << upperBound << ", with standard error " << upperSE << "\n";
std::cout << " time to compute upper bound is, " << (t5-t4)/static_cast<Real>(CLOCKS_PER_SEC) << ", seconds.\n";
int t5=clock();

}
std::cout << " Upper - lower is, " << upperBound << ", with standard error " << upperSE << "\n";
std::cout << " time to compute upper bound is, " << (t5-t4)/static_cast<Real>(CLOCKS_PER_SEC) << ", seconds.\n";

return 0;
}
Expand Down Expand Up @@ -748,67 +740,59 @@ int InverseFloater(Real rateLevel)
std::cout << " total Vega, " << totalVega << "\n";
}

bool doUpperBound = true;
// upper bound

if (doUpperBound)
{

// upper bound

MTBrownianGeneratorFactory uFactory(seed+142);
MTBrownianGeneratorFactory uFactory(seed+142);


ext::shared_ptr<MarketModelEvolver> upperEvolver(new LogNormalFwdRatePc( ext::shared_ptr<MarketModel>(new FlatVol(calibration)),
ext::shared_ptr<MarketModelEvolver> upperEvolver(new LogNormalFwdRatePc( ext::shared_ptr<MarketModel>(new FlatVol(calibration)),
uFactory,
numeraires // numeraires for each step
));

std::vector<ext::shared_ptr<MarketModelEvolver> > innerEvolvers;
std::vector<ext::shared_ptr<MarketModelEvolver> > innerEvolvers;

std::valarray<bool> isExerciseTime = isInSubset(evolution.evolutionTimes(), exerciseStrategy.exerciseTimes());
std::valarray<bool> isExerciseTime = isInSubset(evolution.evolutionTimes(), exerciseStrategy.exerciseTimes());

for (Size s=0; s < isExerciseTime.size(); ++s)
for (Size s=0; s < isExerciseTime.size(); ++s)
{
if (isExerciseTime[s])
{
if (isExerciseTime[s])
{
MTBrownianGeneratorFactory iFactory(seed+s);
ext::shared_ptr<MarketModelEvolver> e =ext::shared_ptr<MarketModelEvolver> (static_cast<MarketModelEvolver*>(new LogNormalFwdRatePc(ext::shared_ptr<MarketModel>(new FlatVol(calibration)),
MTBrownianGeneratorFactory iFactory(seed+s);
ext::shared_ptr<MarketModelEvolver> e =ext::shared_ptr<MarketModelEvolver> (static_cast<MarketModelEvolver*>(new LogNormalFwdRatePc(ext::shared_ptr<MarketModel>(new FlatVol(calibration)),
uFactory,
numeraires , // numeraires for each step
s)));

innerEvolvers.push_back(e);
}
innerEvolvers.push_back(e);
}
}



UpperBoundEngine uEngine(upperEvolver, // does outer paths
innerEvolvers, // for sub-simulations that do continuation values
inverseFloater,
nullRebate,
inverseFloater,
nullRebate,
exerciseStrategy,
initialNumeraireValue);

Statistics uStats;
Size innerPaths = 255;
Size outerPaths =256;

int t4 = clock();
UpperBoundEngine uEngine(upperEvolver, // does outer paths
innerEvolvers, // for sub-simulations that do continuation values
inverseFloater,
nullRebate,
inverseFloater,
nullRebate,
exerciseStrategy,
initialNumeraireValue);

uEngine.multiplePathValues(uStats,outerPaths,innerPaths);
Real upperBound = uStats.mean();
Real upperSE = uStats.errorEstimate();
Statistics uStats;
Size innerPaths = 255;
Size outerPaths =256;

int t5=clock();
int t4 = clock();

std::cout << " Upper - lower is, " << upperBound << ", with standard error " << upperSE << "\n";
std::cout << " time to compute upper bound is, " << (t5-t4)/static_cast<Real>(CLOCKS_PER_SEC) << ", seconds.\n";
uEngine.multiplePathValues(uStats,outerPaths,innerPaths);
Real upperBound = uStats.mean();
Real upperSE = uStats.errorEstimate();

}
int t5=clock();

std::cout << " Upper - lower is, " << upperBound << ", with standard error " << upperSE << "\n";
std::cout << " time to compute upper bound is, " << (t5-t4)/static_cast<Real>(CLOCKS_PER_SEC) << ", seconds.\n";


return 0;
Expand Down
Expand Up @@ -48,7 +48,7 @@ namespace QuantLib {
*/
class AnalyticDoubleBarrierEngine : public DoubleBarrierOption::engine {
public:
AnalyticDoubleBarrierEngine(
explicit AnalyticDoubleBarrierEngine(
const ext::shared_ptr<GeneralizedBlackScholesProcess>& process,
int series = 5);
void calculate() const;
Expand Down
Expand Up @@ -39,7 +39,7 @@ namespace QuantLib {
*/
class PerturbativeBarrierOptionEngine : public BarrierOption::engine {
public:
PerturbativeBarrierOptionEngine(
explicit PerturbativeBarrierOptionEngine(
const ext::shared_ptr<GeneralizedBlackScholesProcess>&,
Natural order = 1,
bool zeroGamma = false);
Expand Down
Expand Up @@ -41,7 +41,7 @@ namespace QuantLib {
*/
class WulinYongDoubleBarrierEngine : public DoubleBarrierOption::engine {
public:
WulinYongDoubleBarrierEngine(
explicit WulinYongDoubleBarrierEngine(
const ext::shared_ptr<GeneralizedBlackScholesProcess>& process,
int series = 5);
void calculate() const;
Expand Down
6 changes: 2 additions & 4 deletions ql/experimental/basismodels/tenoroptionletvts.hpp
Expand Up @@ -86,10 +86,8 @@ namespace QuantLib {

public:
TwoParameterCorrelation(const ext::shared_ptr<Interpolation>& rhoInf,
const ext::shared_ptr<Interpolation>& beta) {
rhoInf_ = rhoInf;
beta_ = beta;
}
const ext::shared_ptr<Interpolation>& beta)
: rhoInf_(rhoInf), beta_(beta) {}
Real operator()(const Time& start1, const Time& start2) const {
Real rhoInf = (*rhoInf_)(start1);
Real beta = (*beta_)(start1);
Expand Down
2 changes: 1 addition & 1 deletion ql/experimental/catbonds/montecarlocatbondengine.hpp
Expand Up @@ -32,7 +32,7 @@ namespace QuantLib {
public CatBond::engine
{
public:
MonteCarloCatBondEngine(
explicit MonteCarloCatBondEngine(
const ext::shared_ptr<CatRisk>& catRisk,
const Handle<YieldTermStructure>& discountCurve = Handle<YieldTermStructure>(),
const boost::optional<bool>& includeSettlementDateFlows = boost::none);
Expand Down
2 changes: 1 addition & 1 deletion ql/experimental/coupons/digitalcmsspreadcoupon.hpp
Expand Up @@ -33,7 +33,7 @@ namespace QuantLib {
//! Cms-spread-rate coupon with digital digital call/put option
class DigitalCmsSpreadCoupon : public DigitalCoupon {
public:
DigitalCmsSpreadCoupon(
explicit DigitalCmsSpreadCoupon(
const ext::shared_ptr<CmsSpreadCoupon> &underlying,
Rate callStrike = Null<Rate>(),
Position::Type callPosition = Position::Long,
Expand Down
3 changes: 1 addition & 2 deletions ql/experimental/credit/cdsoption.cpp
Expand Up @@ -39,9 +39,8 @@ namespace QuantLib {
Real recoveryRate,
const Handle<YieldTermStructure>& termStructure,
Real targetValue)
: targetValue_(targetValue) {
: targetValue_(targetValue), vol_(ext::make_shared<SimpleQuote>(0.0)) {

vol_ = ext::make_shared<SimpleQuote>(0.0);
Handle<Quote> h(vol_);
engine_ = ext::shared_ptr<PricingEngine>(
new BlackCdsOptionEngine(probability, recoveryRate,
Expand Down
4 changes: 2 additions & 2 deletions ql/experimental/credit/defaulttype.hpp
Expand Up @@ -167,8 +167,8 @@ namespace QuantLib {
// Only atomic construction.
// Amount contract by default is in dollars as per ISDA doc and not
// the contract curr. Theres an issue here...... FIX ME
FailureToPay(const Period& grace,
Real amount = 1.e+6)
explicit FailureToPay(const Period& grace,
Real amount = 1.e+6)
: DefaultType(AtomicDefault::FailureToPay, Restructuring::XR),
gracePeriod_(grace), amountRequired_(amount) {}

Expand Down
4 changes: 2 additions & 2 deletions ql/experimental/credit/integralcdoengine.hpp
Expand Up @@ -34,8 +34,8 @@ namespace QuantLib {

class IntegralCDOEngine : public SyntheticCDO::engine {
public:
IntegralCDOEngine(const Handle<YieldTermStructure>& discountCurve,
Period stepSize = 3*Months)
explicit IntegralCDOEngine(const Handle<YieldTermStructure>& discountCurve,
Period stepSize = 3*Months)
: stepSize_(stepSize), discountCurve_(discountCurve) {}
void calculate() const;
protected:
Expand Down
2 changes: 1 addition & 1 deletion ql/experimental/credit/onefactoraffinesurvival.hpp
Expand Up @@ -41,7 +41,7 @@ namespace QuantLib {
: public HazardRateStructure {
public:
// implement remaining constructors.....
OneFactorAffineSurvivalStructure(
explicit OneFactorAffineSurvivalStructure(
const ext::shared_ptr<OneFactorAffineModel>& model,
const DayCounter& dayCounter = DayCounter(),
const std::vector<Handle<Quote> >& jumps = std::vector<Handle<Quote> >(),
Expand Down
4 changes: 2 additions & 2 deletions ql/experimental/credit/onefactorgaussiancopula.hpp
Expand Up @@ -39,8 +39,8 @@ namespace QuantLib {
*/
class OneFactorGaussianCopula : public OneFactorCopula {
public:
OneFactorGaussianCopula (const Handle<Quote>& correlation,
Real maximum = 5, Size integrationSteps = 50)
explicit OneFactorGaussianCopula(const Handle<Quote>& correlation,
Real maximum = 5, Size integrationSteps = 50)
: OneFactorCopula (correlation, maximum, integrationSteps) {
registerWith(correlation_);
}
Expand Down
5 changes: 2 additions & 3 deletions ql/experimental/credit/randomdefaultlatentmodel.hpp
Expand Up @@ -842,9 +842,8 @@ namespace QuantLib {
this->registerWith(Settings::instance().evaluationDate());
this->registerWith(model_);
}
RandomDefaultLM(
const ext::shared_ptr<ConstantLossLatentmodel<copulaPolicy> >&
model,
explicit RandomDefaultLM(
const ext::shared_ptr<ConstantLossLatentmodel<copulaPolicy> >& model,
Size nSims = 0,// stats will crash on div by zero, FIX ME.
Real accuracy = 1.e-6,
BigNatural seed = 2863311530UL)
Expand Down
2 changes: 1 addition & 1 deletion ql/experimental/credit/randomlosslatentmodel.hpp
Expand Up @@ -78,7 +78,7 @@ namespace QuantLib {
// for time inversion:
Real accuracy_;
public:
RandomLossLM(
explicit RandomLossLM(
const ext::shared_ptr<SpotRecoveryLatentModel<copulaPolicy> >&
copula,
Size nSims = 0,
Expand Down
7 changes: 4 additions & 3 deletions ql/experimental/credit/recursivelossmodel.hpp
Expand Up @@ -47,9 +47,10 @@ namespace QuantLib {
template<class copulaPolicy>
class RecursiveLossModel : public DefaultLossModel {
public:
RecursiveLossModel(const ext::shared_ptr<ConstantLossLatentmodel<copulaPolicy> >& m,
// nope! use max common divisor. See O'Kane. Or give both options at least.
Size nbuckets = 1)
explicit RecursiveLossModel(
const ext::shared_ptr<ConstantLossLatentmodel<copulaPolicy> >& m,
// nope! use max common divisor. See O'Kane. Or give both options at least.
Size nbuckets = 1)
: copula_(m), nBuckets_(nbuckets) {}

private:
Expand Down
Expand Up @@ -111,12 +111,10 @@ namespace QuantLib {
const ext::shared_ptr<YoYInflationCapFloorEngine>& p,
Real priceToMatch)
: slope_(slope), K_(K), frequency_(anIndex->frequency()),
indexIsInterpolated_(anIndex->interpolated()), priceToMatch_(priceToMatch), surf_(surf),
p_(p) {
indexIsInterpolated_(anIndex->interpolated()),
tvec_(std::vector<Time>(2)), dvec_(std::vector<Date>(2)),
vvec_(std::vector<Volatility>(2)), priceToMatch_(priceToMatch), surf_(surf), p_(p) {

tvec_ = std::vector<Time>(2);
vvec_ = std::vector<Volatility>(2);
dvec_ = std::vector<Date>(2);
lag_ = surf_->observationLag();
capfloor_ =
MakeYoYInflationCapFloor(type, anIndex,
Expand Down
9 changes: 3 additions & 6 deletions ql/experimental/lattices/extendedbinomialtree.hpp
Expand Up @@ -43,11 +43,8 @@ namespace QuantLib {
const ext::shared_ptr<StochasticProcess1D>& process,
Time end,
Size steps)
: Tree<T>(steps+1), treeProcess_(process) {
x0_ = process->x0();
dt_ = end/steps;
driftPerStep_ = process->drift(0.0, x0_) * dt_;
}
: Tree<T>(steps+1), x0_(process->x0()), dt_(end/steps),
treeProcess_(process) {}
Size size(Size i) const {
return i+1;
}
Expand All @@ -60,7 +57,7 @@ namespace QuantLib {
return this->treeProcess_->drift(driftTime, x0_) * dt_;
}

Real x0_, driftPerStep_;
Real x0_;
Time dt_;

protected:
Expand Down

0 comments on commit 9ac9d50

Please sign in to comment.