Skip to content

Commit

Permalink
Merge pull request #8
Browse files Browse the repository at this point in the history
automated-test-registration
  • Loading branch information
Sidsky authored Nov 3, 2023
2 parents 8796522 + 3c3230f commit 589b56c
Show file tree
Hide file tree
Showing 45 changed files with 875 additions and 1,936 deletions.
24 changes: 3 additions & 21 deletions test-suite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,24 +174,6 @@ set(QL_TEST_SOURCES
)

set(QL_TEST_HEADERS
dates.hpp
daycounters.hpp
defaultprobabilitycurves.hpp
digitalcoupon.hpp
digitaloption.hpp
distributions.hpp
dividendoption.hpp
doublebarrieroption.hpp
doublebinaryoption.hpp
equityindex.hpp
equitycashflow.hpp
equitytotalreturnswap.hpp
europeanoption.hpp
everestoption.hpp
exchangerate.hpp
extendedtrees.hpp
extensibleoptions.hpp
fastfouriertransform.hpp
fdcev.hpp
fdcir.hpp
fdheston.hpp
Expand Down Expand Up @@ -315,9 +297,9 @@ set(QL_BENCHMARK_SOURCES
basketoption.cpp
batesmodel.cpp
convertiblebonds.cpp
digitaloption.cpp digitaloption.hpp
dividendoption.cpp dividendoption.hpp
europeanoption.cpp europeanoption.hpp
digitaloption.cpp
dividendoption.cpp
europeanoption.cpp
fdheston.cpp fdheston.hpp
hestonmodel.cpp hestonmodel.hpp
interpolations.cpp interpolations.hpp
Expand Down
22 changes: 0 additions & 22 deletions test-suite/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -174,24 +174,6 @@ QL_TEST_SRCS = \
zerocouponswap.cpp

QL_TEST_HDRS = \
dates.hpp \
daycounters.hpp \
defaultprobabilitycurves.hpp \
digitalcoupon.hpp \
digitaloption.hpp \
distributions.hpp \
dividendoption.hpp \
doublebarrieroption.hpp \
doublebinaryoption.hpp \
equityindex.hpp \
equitycashflow.hpp \
equitytotalreturnswap.hpp \
europeanoption.hpp \
everestoption.hpp \
exchangerate.hpp \
extendedtrees.hpp \
extensibleoptions.hpp \
fastfouriertransform.hpp \
fdheston.hpp \
fdcir.hpp \
fdmlinearop.hpp \
Expand Down Expand Up @@ -333,10 +315,6 @@ QL_BENCHMARK_SRCS = \
utilities.cpp

QL_BENCHMARK_HDRS = \
doublebarrieroption.hpp \
digitaloption.hpp \
dividendoption.hpp \
europeanoption.hpp \
fdheston.hpp \
hestonmodel.hpp \
interpolations.hpp \
Expand Down
129 changes: 67 additions & 62 deletions test-suite/basketoption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,85 +741,90 @@ BOOST_AUTO_TEST_CASE(testTavellaValues) {
}
}

BOOST_AUTO_TEST_CASE(testOneDAmericanValues) {
std::size_t from{0}, to{5};
struct sliceOne { static const int from{0}, to{5}; };
struct sliceTwo { static const int from{5}, to{11}; };
struct sliceThree { static const int from{11}, to{17}; };
struct sliceFour { static const int from{17}, to{23}; };
struct sliceFive { static const int from{23}, to{29}; };

for (int iter{0}; iter < 5; iter++) {
using slices = boost::mpl::vector<sliceOne, sliceTwo, sliceThree, sliceFour, sliceFive>;

BOOST_TEST_MESSAGE("Testing basket American options against 1-D case "
"from " << from << " to " << to - 1 << "...");
BOOST_AUTO_TEST_CASE_TEMPLATE(testOneDAmericanValues, T, slices) {
const int from = T::from;
const int to = T::to;

DayCounter dc = Actual360();
Date today = Date::todaysDate();
BOOST_TEST_MESSAGE("Testing basket American options against 1-D case "
"from " << from << " to " << to - 1 << "...");

ext::shared_ptr<SimpleQuote> spot1(new SimpleQuote(0.0));
DayCounter dc = Actual360();
Date today = Date::todaysDate();

ext::shared_ptr<SimpleQuote> qRate(new SimpleQuote(0.0));
ext::shared_ptr<YieldTermStructure> qTS = flatRate(today, qRate, dc);
ext::shared_ptr<SimpleQuote> spot1(new SimpleQuote(0.0));

ext::shared_ptr<SimpleQuote> rRate(new SimpleQuote(0.05));
ext::shared_ptr<YieldTermStructure> rTS = flatRate(today, rRate, dc);
ext::shared_ptr<SimpleQuote> qRate(new SimpleQuote(0.0));
ext::shared_ptr<YieldTermStructure> qTS = flatRate(today, qRate, dc);

ext::shared_ptr<SimpleQuote> vol1(new SimpleQuote(0.0));
ext::shared_ptr<BlackVolTermStructure> volTS1 = flatVol(today, vol1, dc);
ext::shared_ptr<SimpleQuote> rRate(new SimpleQuote(0.05));
ext::shared_ptr<YieldTermStructure> rTS = flatRate(today, rRate, dc);

Size requiredSamples = 10000;
Size timeSteps = 52;
BigNatural seed = 0;
ext::shared_ptr<SimpleQuote> vol1(new SimpleQuote(0.0));
ext::shared_ptr<BlackVolTermStructure> volTS1 = flatVol(today, vol1, dc);

ext::shared_ptr<StochasticProcess1D> stochProcess1(new
BlackScholesMertonProcess(Handle<Quote>(spot1),
Handle<YieldTermStructure>(qTS),
Handle<YieldTermStructure>(rTS),
Handle<BlackVolTermStructure>(volTS1)));
Size requiredSamples = 10000;
Size timeSteps = 52;
BigNatural seed = 0;

std::vector<ext::shared_ptr<StochasticProcess1D>> procs = {stochProcess1};
ext::shared_ptr<StochasticProcess1D> stochProcess1(new
BlackScholesMertonProcess(Handle<Quote>(spot1),
Handle<YieldTermStructure>(qTS),
Handle<YieldTermStructure>(rTS),
Handle<BlackVolTermStructure>(volTS1)));

Matrix correlation(1, 1, 1.0);
std::vector<ext::shared_ptr<StochasticProcess1D>> procs = {stochProcess1};

ext::shared_ptr<StochasticProcessArray> process(
new StochasticProcessArray(procs, correlation));
Matrix correlation(1, 1, 1.0);

ext::shared_ptr<PricingEngine> mcLSMCEngine =
MakeMCAmericanBasketEngine<>(process)
.withSteps(timeSteps)
.withAntitheticVariate()
.withSamples(requiredSamples)
.withCalibrationSamples(requiredSamples / 4)
.withSeed(seed);

for (Size i = from; i < to; i++) {
ext::shared_ptr<PlainVanillaPayoff> payoff(
new PlainVanillaPayoff(oneDataValues[i].type, oneDataValues[i].strike));

Date exDate = today + timeToDays(oneDataValues[i].t);
ext::shared_ptr<Exercise> exercise(new AmericanExercise(today, exDate));

spot1 ->setValue(oneDataValues[i].s);
vol1 ->setValue(oneDataValues[i].v);
rRate ->setValue(oneDataValues[i].r);
qRate ->setValue(oneDataValues[i].q);

BasketOption basketOption( // process,
basketTypeToPayoff(MaxBasket, payoff), exercise);
basketOption.setPricingEngine(mcLSMCEngine);

Real calculated = basketOption.NPV();
Real expected = oneDataValues[i].result;
// Real errorEstimate = basketOption.errorEstimate();
Real relError = relativeError(calculated, expected, oneDataValues[i].s);
// Real error = std::fabs(calculated-expected);

if (relError > oneDataValues[i].tol) {
BOOST_FAIL("expected value: " << oneDataValues[i].result << "\n"
<< "calculated: " << calculated);
}
ext::shared_ptr<StochasticProcessArray> process(
new StochasticProcessArray(procs, correlation));

ext::shared_ptr<PricingEngine> mcLSMCEngine =
MakeMCAmericanBasketEngine<>(process)
.withSteps(timeSteps)
.withAntitheticVariate()
.withSamples(requiredSamples)
.withCalibrationSamples(requiredSamples / 4)
.withSeed(seed);

for (Size i = from; i < to; i++) {
ext::shared_ptr<PlainVanillaPayoff> payoff(
new PlainVanillaPayoff(oneDataValues[i].type, oneDataValues[i].strike));

Date exDate = today + timeToDays(oneDataValues[i].t);
ext::shared_ptr<Exercise> exercise(new AmericanExercise(today, exDate));

spot1 ->setValue(oneDataValues[i].s);
vol1 ->setValue(oneDataValues[i].v);
rRate ->setValue(oneDataValues[i].r);
qRate ->setValue(oneDataValues[i].q);

BasketOption basketOption( // process,
basketTypeToPayoff(MaxBasket, payoff), exercise);
basketOption.setPricingEngine(mcLSMCEngine);

Real calculated = basketOption.NPV();
Real expected = oneDataValues[i].result;
// Real errorEstimate = basketOption.errorEstimate();
Real relError = relativeError(calculated, expected, oneDataValues[i].s);
// Real error = std::fabs(calculated-expected);

if (relError > oneDataValues[i].tol) {
BOOST_FAIL("expected value: " << oneDataValues[i].result << "\n"
<< "calculated: " << calculated);
}
from = to; to += 6;
}
}

/* This unit test is a a regression test to check for a crash in
/* This unit test is a regression test to check for a crash in
monte carlo if the required sample is odd. The crash occurred
because the samples array size was off by one when antithetic
paths were added.
Expand Down
Loading

0 comments on commit 589b56c

Please sign in to comment.