Skip to content

Commit

Permalink
Consistently using QL_CHECK_XXX macros
Browse files Browse the repository at this point in the history
  • Loading branch information
auto-differentiation-dev committed Jan 9, 2024
1 parent bf4b0be commit d860bf0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
18 changes: 9 additions & 9 deletions test-suite/americanoption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1944,15 +1944,15 @@ BOOST_AUTO_TEST_CASE(testBjerksundStenslandEuropeanGreeks) {

constexpr double tol = 1000*QL_EPSILON;

BOOST_CHECK_CLOSE(europeanOption.NPV(), americanOption.NPV(), tol);
BOOST_CHECK_CLOSE(europeanOption.delta(), americanOption.delta(), tol);
BOOST_CHECK_CLOSE(europeanOption.strikeSensitivity(), americanOption.strikeSensitivity(), tol);
BOOST_CHECK_CLOSE(europeanOption.gamma(), americanOption.gamma(), tol);
BOOST_CHECK_CLOSE(europeanOption.vega(), americanOption.vega(), tol);
BOOST_CHECK_CLOSE(europeanOption.theta(), americanOption.theta(), tol);
BOOST_CHECK_CLOSE(europeanOption.thetaPerDay(), americanOption.thetaPerDay(), tol);
BOOST_CHECK_CLOSE(europeanOption.rho(), americanOption.rho(), tol);
BOOST_CHECK_CLOSE(europeanOption.dividendRho(), americanOption.dividendRho(), tol);
QL_CHECK_CLOSE(europeanOption.NPV(), americanOption.NPV(), tol);
QL_CHECK_CLOSE(europeanOption.delta(), americanOption.delta(), tol);
QL_CHECK_CLOSE(europeanOption.strikeSensitivity(), americanOption.strikeSensitivity(), tol);
QL_CHECK_CLOSE(europeanOption.gamma(), americanOption.gamma(), tol);
QL_CHECK_CLOSE(europeanOption.vega(), americanOption.vega(), tol);
QL_CHECK_CLOSE(europeanOption.theta(), americanOption.theta(), tol);
QL_CHECK_CLOSE(europeanOption.thetaPerDay(), americanOption.thetaPerDay(), tol);
QL_CHECK_CLOSE(europeanOption.rho(), americanOption.rho(), tol);
QL_CHECK_CLOSE(europeanOption.dividendRho(), americanOption.dividendRho(), tol);
}
}

Expand Down
12 changes: 6 additions & 6 deletions test-suite/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,28 +299,28 @@ BOOST_AUTO_TEST_CASE(testExpm1) {
BOOST_TEST_MESSAGE("Testing complex valued expm1...");

const std::complex<Real> z = std::complex<Real>(1.2, 0.5);
BOOST_CHECK_SMALL(std::abs(std::exp(z) - 1.0 - expm1(z)), 10*QL_EPSILON);
QL_CHECK_SMALL(std::abs(std::exp(z) - 1.0 - expm1(z)), 10*QL_EPSILON);

const std::complex<Real> calculated = expm1(std::complex<Real>(5e-6, 5e-5));
//scipy reference value
const std::complex<Real> expected(4.998762493771078e-06,5.000024997979157e-05);
const Real tol = std::max(2.2e-14, 100*QL_EPSILON);
BOOST_CHECK_CLOSE_FRACTION(calculated.real(), expected.real(), tol);
BOOST_CHECK_CLOSE_FRACTION(calculated.imag(), expected.imag(), tol);
QL_CHECK_CLOSE_FRACTION(calculated.real(), expected.real(), tol);
QL_CHECK_CLOSE_FRACTION(calculated.imag(), expected.imag(), tol);
}

BOOST_AUTO_TEST_CASE(testLog1p) {
BOOST_TEST_MESSAGE("Testing complex valued log1p...");

const std::complex<Real> z = std::complex<Real>(1.2, 0.57);
BOOST_CHECK_SMALL(std::abs(std::log(1.0+z) - log1p(z)), 10*QL_EPSILON);
QL_CHECK_SMALL(std::abs(std::log(1.0+z) - log1p(z)), 10*QL_EPSILON);

const std::complex<Real> calculated = log1p(std::complex<Real>(5e-6, 5e-5));
//scipy reference value
const std::complex<Real> expected(5.0012374875401984e-06, 4.999974995958395e-05);
const Real tol = std::max(2.2e-14, 100*QL_EPSILON);
BOOST_CHECK_CLOSE_FRACTION(calculated.real(), expected.real(), tol);
BOOST_CHECK_CLOSE_FRACTION(calculated.imag(), expected.imag(), tol);
QL_CHECK_CLOSE_FRACTION(calculated.real(), expected.real(), tol);
QL_CHECK_CLOSE_FRACTION(calculated.imag(), expected.imag(), tol);
}

BOOST_AUTO_TEST_SUITE_END()
Expand Down
10 changes: 5 additions & 5 deletions test-suite/hestonmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3288,7 +3288,7 @@ BOOST_AUTO_TEST_CASE(testOptimalAlphaKmin) {
const Real alphaStar = AnalyticHestonEngine::OptimalAlpha(1.0, engine.get())
.alphaSmallerMinusOne(strike).first;

BOOST_CHECK_SMALL(alphaStar+3.71, 0.0051);
QL_CHECK_SMALL(alphaStar+3.71, 0.0051);

const Date maturityDate = todaysDate + Period(15, Months);

Expand Down Expand Up @@ -3345,31 +3345,31 @@ BOOST_AUTO_TEST_CASE(testOptimalAlphaKmax) {
auto engine = ext::make_shared<AnalyticHestonEngine>(model);
Real alphaStar = AnalyticHestonEngine::OptimalAlpha(T, engine.get())
.alphaGreaterZero(strike).first;
BOOST_CHECK_SMALL(alphaStar - 3.22615, 1e-4);
QL_CHECK_SMALL(alphaStar - 3.22615, 1e-4);

// case 2: kappa - sigma*rho < 0, T < t_cut
model = ext::make_shared<HestonModel>(
ext::make_shared<HestonProcess>(yTS, yTS, spot, 0.1, 1.2, 0.2, 1.5, 0.9));
engine = ext::make_shared<AnalyticHestonEngine>(model);
alphaStar = AnalyticHestonEngine::OptimalAlpha(T, engine.get())
.alphaGreaterZero(strike).first;
BOOST_CHECK_SMALL(alphaStar - 0.31137, 1e-4);
QL_CHECK_SMALL(alphaStar - 0.31137, 1e-4);

// case 3: kappa - sigma*rho < 0, T >= t_cut
model = ext::make_shared<HestonModel>(
ext::make_shared<HestonProcess>(yTS, yTS, spot, 0.1, 1.2, 0.2, 2.25, 0.9));
engine = ext::make_shared<AnalyticHestonEngine>(model);
alphaStar = AnalyticHestonEngine::OptimalAlpha(T, engine.get())
.alphaGreaterZero(strike).first;
BOOST_CHECK_SMALL(alphaStar - 0.11940, 1e-4);
QL_CHECK_SMALL(alphaStar - 0.11940, 1e-4);

// case 4: kappa - sigma*rho == 0
model = ext::make_shared<HestonModel>(
ext::make_shared<HestonProcess>(yTS, yTS, spot, 0.1, 1.0, 0.2, 2.0, 0.5));
engine = ext::make_shared<AnalyticHestonEngine>(model);
alphaStar = AnalyticHestonEngine::OptimalAlpha(T, engine.get())
.alphaGreaterZero(strike).first;
BOOST_CHECK_SMALL(alphaStar - 0.28006, 1e-4);
QL_CHECK_SMALL(alphaStar - 0.28006, 1e-4);
}
BOOST_AUTO_TEST_SUITE_END()

Expand Down
14 changes: 7 additions & 7 deletions test-suite/integrals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,16 +588,16 @@ BOOST_AUTO_TEST_CASE(testExponentialIntegralLimits) {

const Real tol = 1000*QL_EPSILON;

BOOST_CHECK_CLOSE(largeValuePosImag.imag(), M_PI, tol);
QL_CHECK_CLOSE(largeValuePosImag.imag(), M_PI, tol);

BOOST_CHECK_CLOSE(
QL_CHECK_CLOSE(
largeValuePosImag.real(), std::exp(largeValue)/largeValue, 1e3/largeValue);

const std::complex<Real> largeValueNegImag =
Ei(std::complex<Real>(largeValue, -std::numeric_limits<Real>::min()));

BOOST_CHECK_CLOSE(largeValueNegImag.imag(), -M_PI, tol);
BOOST_CHECK_CLOSE(
QL_CHECK_CLOSE(largeValueNegImag.imag(), -M_PI, tol);
QL_CHECK_CLOSE(
largeValueNegImag.real(), std::exp(largeValue)/largeValue, 1e3/largeValue);

const std::complex<Real> largeValueZeroImag =
Expand All @@ -619,8 +619,8 @@ BOOST_AUTO_TEST_CASE(testExponentialIntegralLimits) {
// principal branch
const std::complex<Real> limit_ei = M_EULER_MASCHERONI + std::log(z);

BOOST_CHECK_CLOSE(ei.real(), limit_ei.real(), tol);
BOOST_CHECK_CLOSE(ei.imag(), limit_ei.imag(), tol);
QL_CHECK_CLOSE(ei.real(), limit_ei.real(), tol);
QL_CHECK_CLOSE(ei.imag(), limit_ei.imag(), tol);
}

const Real largeR = largeValue;
Expand All @@ -632,7 +632,7 @@ BOOST_AUTO_TEST_CASE(testExponentialIntegralLimits) {

const Real limit_ei_imag = boost::math::sign(z.imag())*M_PI;
BOOST_CHECK(close_enough(ei.real(), 0.0));
BOOST_CHECK_CLOSE(ei.imag(), limit_ei_imag, tol);
QL_CHECK_CLOSE(ei.imag(), limit_ei_imag, tol);
}
}
}
Expand Down

0 comments on commit d860bf0

Please sign in to comment.