Skip to content

Instantly share code, notes, and snippets.

@tdsmith
Last active August 29, 2015 14:09
Show Gist options
  • Save tdsmith/b2d5909db67b3173db02 to your computer and use it in GitHub Desktop.
Save tdsmith/b2d5909db67b3173db02 to your computer and use it in GitHub Desktop.
diff --git a/ql/experimental/processes/extendedornsteinuhlenbeckprocess.cpp b/ql/experimental/processes/extendedornsteinuhlenbeckprocess.cpp
index 9e58905..b01dc5e 100644
--- a/ql/experimental/processes/extendedornsteinuhlenbeckprocess.cpp
+++ b/ql/experimental/processes/extendedornsteinuhlenbeckprocess.cpp
@@ -21,12 +21,22 @@
#include <ql/processes/ornsteinuhlenbeckprocess.hpp>
#include <ql/experimental/processes/extendedornsteinuhlenbeckprocess.hpp>
-#include <boost/lambda/bind.hpp>
-#include <boost/lambda/lambda.hpp>
+namespace QuantLib {
-using namespace boost::lambda;
+ namespace {
-namespace QuantLib {
+ class integrand {
+ boost::function<Real (Real)> b;
+ Real speed;
+ public:
+ integrand(const boost::function<Real (Real)>& b, Real speed)
+ : b(b), speed(speed) {}
+ Real operator()(Real x) const {
+ return b(x) * std::exp(speed*x);
+ }
+ };
+
+ }
ExtendedOrnsteinUhlenbeckProcess::ExtendedOrnsteinUhlenbeckProcess(
Real speed, Volatility vol, Real x0,
@@ -95,10 +105,8 @@ namespace QuantLib {
case GaussLobatto:
return ouProcess_->expectation(t0, x0, dt)
+ speed_*std::exp(-speed_*(t0+dt))
- * GaussLobattoIntegral(100000, intEps_)(
- boost::lambda::bind(b_, boost::lambda::_1)
- *boost::lambda::bind(std::ptr_fun<Real, Real>(std::exp),
- speed_*boost::lambda::_1), t0, t0+dt);
+ * GaussLobattoIntegral(100000, intEps_)(integrand(b_, speed_),
+ t0, t0+dt);
break;
default:
QL_FAIL("unknown discretization scheme");
diff --git a/ql/pricingengines/vanilla/analytichestonengine.cpp b/ql/pricingengines/vanilla/analytichestonengine.cpp
index fc38c85..18e44a5 100644
--- a/ql/pricingengines/vanilla/analytichestonengine.cpp
+++ b/ql/pricingengines/vanilla/analytichestonengine.cpp
@@ -36,13 +36,45 @@
#pragma warning(disable: 4180)
#endif
-#include <boost/lambda/if.hpp>
-#include <boost/lambda/bind.hpp>
-#include <boost/lambda/lambda.hpp>
+namespace QuantLib {
-using namespace boost::lambda;
+ namespace {
+
+ class integrand1 {
+ private:
+ Real c_inf;
+ boost::function<Real(Real)> f;
+ public:
+ integrand1(Real c_inf,
+ boost::function<Real(Real)> f)
+ : c_inf(c_inf), f(f) {}
+ Real operator()(Real x) const {
+ if ((x+1.0)*c_inf > QL_EPSILON) {
+ return f(-std::log(0.5*x+0.5)/c_inf)/((x+1.0)*c_inf);
+ } else {
+ return 0.0;
+ }
+ }
+ };
+
+ class integrand2 {
+ private:
+ Real c_inf;
+ boost::function<Real(Real)> f;
+ public:
+ integrand2(Real c_inf,
+ boost::function<Real(Real)> f)
+ : c_inf(c_inf), f(f) {}
+ Real operator()(Real x) const {
+ if (x*c_inf > QL_EPSILON) {
+ return f(-std::log(x)/c_inf)/(x*c_inf);
+ } else {
+ return 0.0;
+ }
+ }
+ };
-namespace QuantLib {
+ }
// helper class for integration
class AnalyticHestonEngine::Fj_Helper
@@ -526,35 +558,19 @@ namespace QuantLib {
switch(intAlgo_) {
case GaussLaguerre:
- retVal = gaussianQuadrature_->operator()(f);
+ retVal = (*gaussianQuadrature_)(f);
break;
case GaussLegendre:
case GaussChebyshev:
case GaussChebyshev2nd:
- retVal = gaussianQuadrature_->operator()(
- boost::function1<Real, Real>(
- if_then_else_return ( (boost::lambda::_1+1.0)*c_inf
- > QL_EPSILON,
- boost::lambda::bind(f, -boost::lambda::bind(
- std::ptr_fun<Real,Real>(std::log),
- 0.5*boost::lambda::_1+0.5 )/c_inf )
- /((boost::lambda::_1+1.0)*c_inf),
- boost::lambda::bind(constant<Real, Real>(0.0),
- boost::lambda::_1))));
+ retVal = (*gaussianQuadrature_)(integrand1(c_inf, f));
break;
case Simpson:
case Trapezoid:
case GaussLobatto:
case GaussKronrod:
- retVal = integrator_->operator()(
- boost::function1<Real, Real>(
- if_then_else_return ( boost::lambda::_1*c_inf > QL_EPSILON,
- boost::lambda::bind(f,-boost::lambda::bind(
- std::ptr_fun<Real,Real>(std::log),
- boost::lambda::_1)/c_inf) /(boost::lambda::_1*c_inf),
- boost::lambda::bind(constant<Real, Real>(0.0),
- boost::lambda::_1))),
- 0.0, 1.0);
+ retVal = (*integrator_)(integrand2(c_inf, f),
+ 0.0, 1.0);
break;
default:
QL_FAIL("unknwon integration algorithm");
diff --git a/ql/processes/hestonprocess.cpp b/ql/processes/hestonprocess.cpp
index f9e51c7..24d3949 100644
--- a/ql/processes/hestonprocess.cpp
+++ b/ql/processes/hestonprocess.cpp
@@ -161,11 +161,19 @@ namespace QuantLib {
);
}
- Real ch(const HestonProcess& process,
- Real x, Real u, Real nu_0, Real nu_t, Time dt) {
- return M_2_PI*std::sin(u*x)/u
+ class ch {
+ const HestonProcess& process;
+ Real x, nu_0, nu_t;
+ Time dt;
+ public:
+ ch(const HestonProcess& process,
+ Real x, Real nu_0, Real nu_t, Time dt)
+ : process(process), x(x), nu_0(nu_0), nu_t(nu_t), dt(dt) {}
+ Real operator()(Real u) const {
+ return M_2_PI*std::sin(u*x)/u
* Phi(process, u, nu_0, nu_t, dt).real();
- }
+ }
+ };
Real pade(Real x, const Real* nominator, const Real* denominator, Size m) {
Real n=0.0, d=0.0;
@@ -278,9 +286,8 @@ namespace QuantLib {
return (x < upper)
? std::max(0.0, std::min(1.0,
- GaussLaguerreIntegration(128)(
- boost::lambda::bind(&ch, process, x,
- boost::lambda::_1, nu_0, nu_t, dt))))
+ GaussLaguerreIntegration(128)(ch(process, x,
+ nu_0, nu_t, dt))))
: 1.0;
}
case HestonProcess::BroadieKayaExactSchemeLobatto:
@@ -290,11 +297,10 @@ namespace QuantLib {
while (std::abs(Phi(process,upper,nu_0,nu_t,dt))
> eps) upper*=2.0;
- return (x < upper)
- ? std::max(0.0, std::min(1.0,
+ return x < upper ?
+ std::max(0.0, std::min(1.0,
GaussLobattoIntegral(Null<Size>(), eps)(
- boost::lambda::bind(&ch, process, x,
- boost::lambda::_1, nu_0, nu_t, dt),
+ ch(process, x, nu_0, nu_t, dt),
1e-6, upper)))
: 1.0;
}
diff --git a/test-suite/vpp.cpp b/test-suite/vpp.cpp
index adc15a2..6929de5 100644
--- a/test-suite/vpp.cpp
+++ b/test-suite/vpp.cpp
@@ -53,7 +53,6 @@
#include <ql/methods/finitedifferences/utilities/fdminnervaluecalculator.hpp>
#include <ql/experimental/finitedifferences/fdmspreadpayoffinnervalue.hpp>
-#include <boost/lambda/lambda.hpp>
#include <deque>
using namespace QuantLib;
@@ -77,6 +76,16 @@ namespace {
new ExtOUWithJumpsProcess(ouProcess, x0[1], beta,
jumpIntensity, eta));
}
+
+ class linear {
+ Real alpha, beta;
+ public:
+ linear(Real alpha, Real beta) : alpha(alpha), beta(beta) {}
+ Real operator()(Real x) const {
+ return alpha + beta*x;
+ }
+ };
+
}
@@ -129,7 +138,7 @@ void VPPTest::testGemanRoncoroniProcess() {
const Real alphaG = 1.0;
const Real x0G = 1.1;
- boost::function<Real (Real)> f = alphaG + betaG*boost::lambda::_1;
+ boost::function<Real (Real)> f = linear(alphaG, betaG);
boost::shared_ptr<StochasticProcess1D> eouProcess(
new ExtendedOrnsteinUhlenbeckProcess(speed, vol, x0G, f,
@@ -278,7 +287,7 @@ void VPPTest::testKlugeExtOUSpreadOption() {
boost::shared_ptr<ExtOUWithJumpsProcess>
klugeProcess = createKlugeProcess();
- boost::function<Real (Real)> f = alphaG + betaG*boost::lambda::_1;
+ boost::function<Real (Real)> f = linear(alphaG, betaG);
boost::shared_ptr<ExtendedOrnsteinUhlenbeckProcess> extOUProcess(
new ExtendedOrnsteinUhlenbeckProcess(speed, vol, x0G, f,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment