Skip to content

Commit

Permalink
Merge 020c28c into 4f52945
Browse files Browse the repository at this point in the history
  • Loading branch information
klausspanderen committed May 26, 2020
2 parents 4f52945 + 020c28c commit b654953
Show file tree
Hide file tree
Showing 7 changed files with 245 additions and 229 deletions.
38 changes: 26 additions & 12 deletions ql/pricingengines/vanilla/analytichestonengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
based on fourier transformation
*/

#include <ql/functional.hpp>
#include <ql/math/solvers1d/brent.hpp>
#include <ql/math/functional.hpp>
#include <ql/math/integrals/simpsonintegral.hpp>
#include <ql/math/integrals/kronrodintegral.hpp>
#include <ql/math/integrals/trapezoidintegral.hpp>
Expand All @@ -34,7 +36,6 @@
#include <ql/pricingengines/blackcalculator.hpp>
#include <ql/pricingengines/vanilla/analytichestonengine.hpp>


#if defined(QL_PATCH_MSVC)
#pragma warning(disable: 4180)
#endif
Expand Down Expand Up @@ -577,8 +578,9 @@ namespace QuantLib {
const Real epsilon = enginePtr->andersenPiterbargEpsilon_
*M_PI/(std::sqrt(strikePrice*fwdPrice)*riskFreeDiscount);

const Real uM = Integration::andersenPiterbargIntegrationLimit(
c_inf, epsilon, v0, term);
const ext::function<Real()> uM = ext::bind(
Integration::andersenPiterbargIntegrationLimit,
c_inf, epsilon, v0, term);

const Real vAvg = (cpxLog == AndersenPiterbarg)
? (1-std::exp(-kappa*term))*(v0-theta)/(kappa*term) + theta
Expand Down Expand Up @@ -772,9 +774,10 @@ namespace QuantLib {
}

Real AnalyticHestonEngine::Integration::calculate(
Real c_inf,
const ext::function<Real(Real)>& f,
Real maxBound) const {
Real c_inf,
const ext::function<Real(Real)>& f,
const ext::function<Real()>& maxBound) const {

Real retVal;

switch(intAlgo_) {
Expand All @@ -790,17 +793,17 @@ namespace QuantLib {
case Trapezoid:
case GaussLobatto:
case GaussKronrod:
if (maxBound == Null<Real>())
retVal = (*integrator_)(integrand2(c_inf, f), 0.0, 1.0);
if (maxBound && maxBound() != Null<Real>())
retVal = (*integrator_)(f, 0.0, maxBound());
else
retVal = (*integrator_)(f, 0.0, maxBound);
retVal = (*integrator_)(integrand2(c_inf, f), 0.0, 1.0);
break;
case DiscreteTrapezoid:
case DiscreteSimpson:
if (maxBound == Null<Real>())
retVal = (*integrator_)(integrand3(c_inf, f), 0.0, 1.0);
if (maxBound && maxBound() != Null<Real>())
retVal = (*integrator_)(f, 0.0, maxBound());
else
retVal = (*integrator_)(f, 0.0, maxBound);
retVal = (*integrator_)(integrand3(c_inf, f), 0.0, 1.0);
break;
default:
QL_FAIL("unknwon integration algorithm");
Expand All @@ -809,6 +812,17 @@ namespace QuantLib {
return retVal;
}

Real AnalyticHestonEngine::Integration::calculate(
Real c_inf,
const ext::function<Real(Real)>& f,
Real maxBound) const {

return AnalyticHestonEngine::Integration::calculate(
c_inf, f,
ext::bind(&constant<Real, Real>::operator(),
constant<Real, Real>(maxBound), 1.0));
}

Real AnalyticHestonEngine::Integration::andersenPiterbargIntegrationLimit(
Real c_inf, Real epsilon, Real v0, Real t) {

Expand Down
6 changes: 5 additions & 1 deletion ql/pricingengines/vanilla/analytichestonengine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ namespace QuantLib {

Real calculate(Real c_inf,
const ext::function<Real(Real)>& f,
Real maxBound = Null<Real>()) const;
const ext::function<Real()>& maxBound =
ext::function<Real()>()) const;

Real calculate(Real c_inf,
const boost::function<Real(Real)>& f, Real maxBound) const;

Size numberOfEvaluations() const;
bool isAdaptiveIntegration() const;
Expand Down
5 changes: 3 additions & 2 deletions ql/pricingengines/vanilla/analyticptdhestonengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,9 @@ namespace QuantLib {

const Real c_inf = -(C_u_inf + D_u_inf*v0).real();

const Real uM = Integration::andersenPiterbargIntegrationLimit(
c_inf, epsilon, v0, term);
const ext::function<Real()> uM = ext::bind(
Integration::andersenPiterbargIntegrationLimit,
c_inf, epsilon, v0, term);

const Real vAvg
= (1-std::exp(-kappaAvg*term))*(v0-thetaAvg)
Expand Down

0 comments on commit b654953

Please sign in to comment.