Skip to content

Commit

Permalink
Allow passing optimizer and end criteria to GlobalBootstrap (#675)
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio authored Oct 3, 2024
2 parents feeb392 + fa2c321 commit b351410
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
3 changes: 3 additions & 0 deletions SWIG/optimizers.i
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,16 @@ class EndCriteria {
StationaryFunctionValue,
StationaryFunctionAccuracy,
ZeroGradientNorm,
FunctionEpsilonTooSmall,
Unknown
};
EndCriteria(Size maxIteration,
Size maxStationaryStateIterations,
Real rootEpsilon,
Real functionEpsilon,
Real gradientNormEpsilon);

static bool succeeded(EndCriteria::Type ecType);
};


Expand Down
32 changes: 22 additions & 10 deletions SWIG/piecewiseyieldcurve.i
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
%include termstructures.i
%include ratehelpers.i
%include interpolation.i
%include optimizers.i
%include null.i

// bootstrap traits
Expand Down Expand Up @@ -211,21 +212,32 @@ struct _GlobalBootstrap {
std::vector<ext::shared_ptr<RateHelper> > additionalHelpers;
std::vector<Date> additionalDates;
double accuracy;
_GlobalBootstrap(double accuracy = Null<double>())
: accuracy(accuracy) {}
ext::shared_ptr<OptimizationMethod> optimizer;
ext::shared_ptr<EndCriteria> endCriteria;
_GlobalBootstrap(double accuracy = Null<double>(),
ext::shared_ptr<OptimizationMethod> optimizer = nullptr,
ext::shared_ptr<EndCriteria> endCriteria = nullptr)
: accuracy(accuracy), optimizer(optimizer), endCriteria(endCriteria) {}
_GlobalBootstrap(const std::vector<ext::shared_ptr<RateHelper> >& additionalHelpers,
const std::vector<Date>& additionalDates,
double accuracy = Null<double>())
: additionalHelpers(additionalHelpers), additionalDates(additionalDates), accuracy(accuracy) {}
const std::vector<Date>& additionalDates,
double accuracy = Null<double>(),
ext::shared_ptr<OptimizationMethod> optimizer = nullptr,
ext::shared_ptr<EndCriteria> endCriteria = nullptr)
: additionalHelpers(additionalHelpers), additionalDates(additionalDates), accuracy(accuracy),
optimizer(optimizer), endCriteria(endCriteria) {}
};
%}

%rename(GlobalBootstrap) _GlobalBootstrap;
struct _GlobalBootstrap {
_GlobalBootstrap(doubleOrNull accuracy = Null<double>());
_GlobalBootstrap(doubleOrNull accuracy = Null<double>(),
ext::shared_ptr<OptimizationMethod> optimizer = nullptr,
ext::shared_ptr<EndCriteria> endCriteria = nullptr);
_GlobalBootstrap(const std::vector<ext::shared_ptr<RateHelper> >& additionalHelpers,
const std::vector<Date>& additionalDates,
doubleOrNull accuracy = Null<double>());
doubleOrNull accuracy = Null<double>(),
ext::shared_ptr<OptimizationMethod> optimizer = nullptr,
ext::shared_ptr<EndCriteria> endCriteria = nullptr);
};


Expand All @@ -247,14 +259,14 @@ class GlobalLinearSimpleZeroCurve : public YieldTermStructure {
if (b.additionalHelpers.empty()) {
return new GlobalLinearSimpleZeroCurve(
referenceDate, instruments, dayCounter, Linear(),
GlobalLinearSimpleZeroCurve::bootstrap_type(b.accuracy));
GlobalLinearSimpleZeroCurve::bootstrap_type(b.accuracy, b.optimizer, b.endCriteria));
} else {
return new GlobalLinearSimpleZeroCurve(
referenceDate, instruments, dayCounter, Linear(),
GlobalLinearSimpleZeroCurve::bootstrap_type(b.additionalHelpers,
AdditionalDates(b.additionalDates),
AdditionalErrors(b.additionalHelpers),
b.accuracy));
b.accuracy, b.optimizer, b.endCriteria));
}
}
}
Expand All @@ -266,4 +278,4 @@ class GlobalLinearSimpleZeroCurve : public YieldTermStructure {
};


#endif
#endif

0 comments on commit b351410

Please sign in to comment.