Skip to content

Commit c662035

Browse files
Consistent use of Real and testing macros
1 parent 6cf1ac8 commit c662035

4 files changed

Lines changed: 21 additions & 20 deletions

File tree

ql/math/comparison.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ namespace QuantLib {
6666
return true;
6767

6868
Real diff = std::fabs(x-y);
69-
constexpr Real tolerance = 42 * QL_EPSILON;
69+
constexpr double tolerance = 42 * QL_EPSILON;
7070

7171
if (x == 0.0 || y == 0.0)
7272
return diff < (tolerance * tolerance);
@@ -97,7 +97,7 @@ namespace QuantLib {
9797
return true;
9898

9999
Real diff = std::fabs(x-y);
100-
constexpr Real tolerance = 42 * QL_EPSILON;
100+
constexpr double tolerance = 42 * QL_EPSILON;
101101

102102
if (x == 0.0 || y == 0.0) // x or y = 0.0
103103
return diff < (tolerance * tolerance);

ql/termstructures/defaulttermstructure.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ namespace QuantLib {
219219
inline
220220
Rate DefaultProbabilityTermStructure::hazardRateImpl(Time t) const {
221221
Probability S = survivalProbability(t, true);
222-
return S == 0.0 ? 0.0 : defaultDensity(t, true)/S;
222+
return S == 0.0 ? Rate(0.0) : defaultDensity(t, true)/S;
223223
}
224224

225225
inline Rate DefaultProbabilityTermStructure::hazardRate(Time t,

ql/termstructures/inflation/inflationtraits.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
namespace QuantLib {
3434

3535
namespace detail {
36-
constexpr Rate avgInflation = 0.02;
37-
constexpr Rate maxInflation = 0.5;
36+
constexpr double avgInflation = 0.02;
37+
constexpr double maxInflation = 0.5;
3838
}
3939

4040
//! Bootstrap traits to use for PiecewiseZeroInflationCurve

test-suite/creditdefaultswap.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ void CreditDefaultSwapTest::testIsdaEngine() {
712712
.withSide(Protection::Buyer)
713713
.withPricingEngine(engine);
714714

715-
BOOST_CHECK_SMALL(conventionalTradeBuy->NPV(), tolerance);
715+
QL_CHECK_SMALL(conventionalTradeBuy->NPV(), tolerance);
716716

717717
ext::shared_ptr<CreditDefaultSwap> conventionalTradeSell =
718718
MakeCreditDefaultSwap(termDate, 0.01)
@@ -721,7 +721,7 @@ void CreditDefaultSwapTest::testIsdaEngine() {
721721
.withSide(Protection::Seller)
722722
.withPricingEngine(engine);
723723

724-
BOOST_CHECK_SMALL(conventionalTradeSell->NPV(), tolerance);
724+
QL_CHECK_SMALL(conventionalTradeSell->NPV(), tolerance);
725725

726726
l++;
727727
}
@@ -848,24 +848,25 @@ void CreditDefaultSwapTest::testIsdaCalculatorReconcileSingleQuote ()
848848
.withPricingEngine(engine);
849849

850850

851-
double npv = conventionalTrade->NPV();
852-
double calculated_upfront = conventionalTrade->notional() * conventionalTrade->fairUpfront();
853-
double df = calculated_upfront / npv; //to take into account of the discount to cash settlement
854-
double derived_accrual = df * (npv -
851+
Real npv = conventionalTrade->NPV();
852+
Real calculated_upfront = conventionalTrade->notional() * conventionalTrade->fairUpfront();
853+
Real df = calculated_upfront / npv; // to take into account of the discount to cash settlement
854+
Real derived_accrual =
855+
df * (npv -
855856
conventionalTrade->defaultLegNPV() -
856857
conventionalTrade->couponLegNPV());
857858

858-
double calculated_accrual = conventionalTrade->accrualRebate()->amount();
859+
Real calculated_accrual = conventionalTrade->accrualRebate()->amount();
859860

860861
auto settlement_date = conventionalTrade->accrualRebate()->date();
861862

862-
BOOST_CHECK_CLOSE(npv, markitValue, tolerance);
863+
QL_CHECK_CLOSE(npv, markitValue, tolerance);
863864

864-
BOOST_CHECK_CLOSE(calculated_upfront, df*markitValue, tolerance);
865+
QL_CHECK_CLOSE(calculated_upfront, df * markitValue, tolerance);
865866

866-
BOOST_CHECK_CLOSE(derived_accrual, expected_accrual, tolerance);
867+
QL_CHECK_CLOSE(derived_accrual, expected_accrual, tolerance);
867868

868-
BOOST_CHECK_CLOSE(calculated_accrual, expected_accrual, tolerance);
869+
QL_CHECK_CLOSE(calculated_accrual, expected_accrual, tolerance);
869870

870871
BOOST_CHECK_EQUAL(settlement_date, WeekendsOnly().advance(tradeDate,3, TimeUnit::Days));
871872

@@ -962,14 +963,14 @@ void CreditDefaultSwapTest::testIsdaCalculatorReconcileSingleWithIssueDateInTheP
962963
.withTradeDate(tradeDate);
963964

964965

965-
double npv = conventionalTrade->NPV();
966-
double calculated_accrual = npv -
966+
Real npv = conventionalTrade->NPV();
967+
Real calculated_accrual = npv -
967968
conventionalTrade->defaultLegNPV() -
968969
conventionalTrade->couponLegNPV();
969970

970-
BOOST_CHECK_CLOSE(npv, markitValue, tolerance);
971+
QL_CHECK_CLOSE(npv, markitValue, tolerance);
971972

972-
BOOST_CHECK_CLOSE(calculated_accrual, expected_accrual, tolerance);
973+
QL_CHECK_CLOSE(calculated_accrual, expected_accrual, tolerance);
973974
}
974975

975976
test_suite* CreditDefaultSwapTest::suite() {

0 commit comments

Comments
 (0)