Skip to content

Commit

Permalink
Remove unnecessary anonymous namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Dec 17, 2023
1 parent 6171c00 commit 98822d7
Show file tree
Hide file tree
Showing 123 changed files with 11,946 additions and 12,355 deletions.
414 changes: 201 additions & 213 deletions test-suite/americanoption.cpp

Large diffs are not rendered by default.

431 changes: 214 additions & 217 deletions test-suite/andreasenhugevolatilityinterpl.cpp

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions test-suite/array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ BOOST_FIXTURE_TEST_SUITE(QuantLibTests, TopLevelFixture)

BOOST_AUTO_TEST_SUITE(ArrayTests)

namespace {
class FSquared {
public:
Real operator()(Real x) const { return x*x; }
};
}
class FSquared {
public:
Real operator()(Real x) const { return x*x; }
};

BOOST_AUTO_TEST_CASE(testConstruction) {

Expand Down
117 changes: 58 additions & 59 deletions test-suite/asianoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,69 +82,68 @@ BOOST_AUTO_TEST_SUITE(AsianOptionTests)
<< "\n" \
<< " tolerance: " << tolerance);

namespace {

std::string averageTypeToString(Average::Type averageType) {
std::string averageTypeToString(Average::Type averageType) {

if (averageType == Average::Geometric)
return "Geometric Averaging";
else if (averageType == Average::Arithmetic)
return "Arithmetic Averaging";
else
QL_FAIL("unknown averaging");
}

struct DiscreteAverageData {
Option::Type type;
Real underlying;
Real strike;
Rate dividendYield;
Rate riskFreeRate;
Time first;
Time length;
Size fixings;
Volatility volatility;
bool controlVariate;
Real result;
};

struct ContinuousAverageData {
Option::Type type;
Real spot;
Real currentAverage;
Real strike;
Rate dividendYield;
Rate riskFreeRate;
Volatility volatility;
Natural length;
Natural elapsed;
Real result;
};
if (averageType == Average::Geometric)
return "Geometric Averaging";
else if (averageType == Average::Arithmetic)
return "Arithmetic Averaging";
else
QL_FAIL("unknown averaging");
}

struct DiscreteAverageDataTermStructure {
Option::Type type;
Real underlying;
Real strike;
Rate b;
Rate riskFreeRate;
Time first; // t1
Time expiry;
Size fixings;
Volatility volatility;
std::string slope;
Real result;
};
struct DiscreteAverageData {
Option::Type type;
Real underlying;
Real strike;
Rate dividendYield;
Rate riskFreeRate;
Time first;
Time length;
Size fixings;
Volatility volatility;
bool controlVariate;
Real result;
};

struct ContinuousAverageData {
Option::Type type;
Real spot;
Real currentAverage;
Real strike;
Rate dividendYield;
Rate riskFreeRate;
Volatility volatility;
Natural length;
Natural elapsed;
Real result;
};

struct DiscreteAverageDataTermStructure {
Option::Type type;
Real underlying;
Real strike;
Rate b;
Rate riskFreeRate;
Time first; // t1
Time expiry;
Size fixings;
Volatility volatility;
std::string slope;
Real result;
};

struct VecerData {
Real spot;
Rate riskFreeRate;
Volatility volatility;
Real strike;
Natural length;
Real result;
Real tolerance;
};

struct VecerData {
Real spot;
Rate riskFreeRate;
Volatility volatility;
Real strike;
Natural length;
Real result;
Real tolerance;
};
}

BOOST_AUTO_TEST_CASE(testAnalyticContinuousGeometricAveragePrice) {

Expand Down
77 changes: 35 additions & 42 deletions test-suite/assetswap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,60 +61,53 @@ BOOST_FIXTURE_TEST_SUITE(QuantLibTests, TopLevelFixture)

BOOST_AUTO_TEST_SUITE(AssetSwapTests)

namespace {

struct CommonVars {
// common data
ext::shared_ptr<IborIndex> iborIndex;
ext::shared_ptr<SwapIndex> swapIndex;
ext::shared_ptr<IborCouponPricer> pricer;
ext::shared_ptr<CmsCouponPricer> cmspricer;
Spread spread;
Spread nonnullspread;
Real faceAmount;
Compounding compounding;
RelinkableHandle<YieldTermStructure> termStructure;

// initial setup
CommonVars() {
Natural swapSettlementDays = 2;
faceAmount = 100.0;
BusinessDayConvention fixedConvention = Unadjusted;
compounding = Continuous;
Frequency fixedFrequency = Annual;
Frequency floatingFrequency = Semiannual;
iborIndex = ext::shared_ptr<IborIndex>(
struct CommonVars {
// common data
ext::shared_ptr<IborIndex> iborIndex;
ext::shared_ptr<SwapIndex> swapIndex;
ext::shared_ptr<IborCouponPricer> pricer;
ext::shared_ptr<CmsCouponPricer> cmspricer;
Spread spread;
Spread nonnullspread;
Real faceAmount;
Compounding compounding;
RelinkableHandle<YieldTermStructure> termStructure;

// initial setup
CommonVars() {
Natural swapSettlementDays = 2;
faceAmount = 100.0;
BusinessDayConvention fixedConvention = Unadjusted;
compounding = Continuous;
Frequency fixedFrequency = Annual;
Frequency floatingFrequency = Semiannual;
iborIndex = ext::shared_ptr<IborIndex>(
new Euribor(Period(floatingFrequency), termStructure));
Calendar calendar = iborIndex->fixingCalendar();
swapIndex= ext::make_shared<SwapIndex>(
Calendar calendar = iborIndex->fixingCalendar();
swapIndex = ext::make_shared<SwapIndex>(
"EuriborSwapIsdaFixA", 10*Years, swapSettlementDays,
iborIndex->currency(), calendar,
Period(fixedFrequency), fixedConvention,
iborIndex->dayCounter(), iborIndex);
spread = 0.0;
nonnullspread = 0.003;
Date today(24,April,2007);
Settings::instance().evaluationDate() = today;

//Date today = Settings::instance().evaluationDate();

termStructure.linkTo(flatRate(today, 0.05, Actual365Fixed()));
pricer = ext::shared_ptr<IborCouponPricer>(new
BlackIborCouponPricer);
Handle<SwaptionVolatilityStructure> swaptionVolatilityStructure(
spread = 0.0;
nonnullspread = 0.003;
Date today(24,April,2007);
Settings::instance().evaluationDate() = today;

termStructure.linkTo(flatRate(today, 0.05, Actual365Fixed()));
pricer = ext::shared_ptr<IborCouponPricer>(new BlackIborCouponPricer);
Handle<SwaptionVolatilityStructure> swaptionVolatilityStructure(
ext::shared_ptr<SwaptionVolatilityStructure>(new
ConstantSwaptionVolatility(today, NullCalendar(),Following,
0.2, Actual365Fixed())));
Handle<Quote> meanReversionQuote(ext::shared_ptr<Quote>(new
Handle<Quote> meanReversionQuote(ext::shared_ptr<Quote>(new
SimpleQuote(0.01)));
cmspricer = ext::shared_ptr<CmsCouponPricer>(new
cmspricer = ext::shared_ptr<CmsCouponPricer>(new
AnalyticHaganPricer(swaptionVolatilityStructure,
GFunctionFactory::Standard,
meanReversionQuote));
}
};

}
}
};


BOOST_AUTO_TEST_CASE(testConsistency) {
Expand Down
114 changes: 55 additions & 59 deletions test-suite/barrieroption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,68 +104,64 @@ BOOST_AUTO_TEST_SUITE(BarrierOptionTests)
<< " tolerance: " << tolerance);


namespace {

std::string barrierTypeToString(Barrier::Type type) {
switch(type){
case Barrier::DownIn:
return std::string("Down-and-in");
case Barrier::UpIn:
return std::string("Up-and-in");
case Barrier::DownOut:
return std::string("Down-and-out");
case Barrier::UpOut:
return std::string("Up-and-out");
default:
QL_FAIL("unknown exercise type");
}
std::string barrierTypeToString(Barrier::Type type) {
switch(type){
case Barrier::DownIn:
return std::string("Down-and-in");
case Barrier::UpIn:
return std::string("Up-and-in");
case Barrier::DownOut:
return std::string("Down-and-out");
case Barrier::UpOut:
return std::string("Up-and-out");
default:
QL_FAIL("unknown exercise type");
}

struct BarrierOptionData {
Barrier::Type type;
Volatility volatility;
Real strike;
Real barrier;
Real callValue;
Real putValue;
};

struct NewBarrierOptionData {
Barrier::Type barrierType;
Real barrier;
Real rebate;
Option::Type type;
Exercise::Type exType;
Real strike;
Real s; // spot
Rate q; // dividend
Rate r; // risk-free rate
Time t; // time to maturity
Volatility v; // volatility
Real result; // result
Real tol; // tolerance
};

struct BarrierFxOptionData {
Barrier::Type barrierType;
Real barrier;
Real rebate;
Option::Type type;
Real strike;
Real s; // spot
Rate q; // dividend
Rate r; // risk-free rate
Time t; // time to maturity
Volatility vol25Put; // 25 delta put vol
Volatility volAtm; // atm vol
Volatility vol25Call; // 25 delta call vol
Volatility v; // volatility at strike
Real result; // result
Real tol; // tolerance
};

}

struct BarrierOptionData {
Barrier::Type type;
Volatility volatility;
Real strike;
Real barrier;
Real callValue;
Real putValue;
};

struct NewBarrierOptionData {
Barrier::Type barrierType;
Real barrier;
Real rebate;
Option::Type type;
Exercise::Type exType;
Real strike;
Real s; // spot
Rate q; // dividend
Rate r; // risk-free rate
Time t; // time to maturity
Volatility v; // volatility
Real result; // result
Real tol; // tolerance
};

struct BarrierFxOptionData {
Barrier::Type barrierType;
Real barrier;
Real rebate;
Option::Type type;
Real strike;
Real s; // spot
Rate q; // dividend
Rate r; // risk-free rate
Time t; // time to maturity
Volatility vol25Put; // 25 delta put vol
Volatility volAtm; // atm vol
Volatility vol25Call; // 25 delta call vol
Volatility v; // volatility at strike
Real result; // result
Real tol; // tolerance
};

#define QL_ASSERT_EXCEPTION_THROWN(statement) \
auto exception_thrown = false; \
try { \
Expand Down
Loading

0 comments on commit 98822d7

Please sign in to comment.