20#include <boost/test/unit_test.hpp>
24#include <ql/quotes/simplequote.hpp>
25#include <ql/time/calendars/nullcalendar.hpp>
27#include <boost/make_shared.hpp>
31using namespace boost::unit_test_framework;
35BOOST_AUTO_TEST_SUITE(CorrelationTermstructureTest)
39 QuantLib::ext::shared_ptr<SimpleQuote> q = QuantLib::ext::make_shared<SimpleQuote>(0.02);
41 Handle<FlatCorrelation> flatCorr(QuantLib::ext::make_shared<FlatCorrelation>(0, NullCalendar(), hq, Actual365Fixed()));
44 BOOST_CHECK_MESSAGE(flatCorr->correlation(1) == 0.02,
"unexpected correlation value: " << flatCorr->correlation(1));
49 BOOST_CHECK_MESSAGE(flatCorr->correlation(1) == 0.03,
"unexpected correlation value: " << flatCorr->correlation(1));
54 BOOST_CHECK_THROW(flatCorr->correlation(1), QuantLib::Error);
57 BOOST_CHECK_THROW(flatCorr->correlation(1), QuantLib::Error);
63 std::vector<Time> times;
64 std::vector<QuantLib::ext::shared_ptr<SimpleQuote> > simpleQuotes;
65 std::vector<Handle<Quote> > quotes;
68 for (Size i = 1; i < numYears; i++) {
72 simpleQuotes.push_back(QuantLib::ext::make_shared<SimpleQuote>(corr));
73 quotes.push_back(Handle<Quote>(simpleQuotes.back()));
75 times.push_back(
static_cast<Time
>(i));
78 Handle<PiecewiseLinearCorrelationCurve> interpCorr(
79 QuantLib::ext::make_shared<PiecewiseLinearCorrelationCurve>(times, quotes, Actual365Fixed(), NullCalendar()));
82 while (t < numYears) {
83 BOOST_CHECK_MESSAGE(interpCorr->correlation(t) == 0.1,
84 "unexpected correlation value: " << interpCorr->correlation(t));
89 for (Size i = 0; i < simpleQuotes.size(); ++i) {
90 simpleQuotes[i]->setValue(1);
94 while (t < numYears) {
95 BOOST_CHECK_MESSAGE(interpCorr->correlation(t) == 1,
96 "unexpected correlation value: " << interpCorr->correlation(t));
101 for (Size i = 0; i < simpleQuotes.size(); ++i) {
102 simpleQuotes[i]->setValue(0.1 + 0.01 * i);
106 BOOST_CHECK_CLOSE(interpCorr->correlation(1.5), 0.105, tol);
107 BOOST_CHECK_CLOSE(interpCorr->correlation(2.5), 0.115, tol);
108 BOOST_CHECK_CLOSE(interpCorr->correlation(3.5), 0.125, tol);
109 BOOST_CHECK_CLOSE(interpCorr->correlation(11), 0.18, tol);
112BOOST_AUTO_TEST_SUITE_END()
114BOOST_AUTO_TEST_SUITE_END()
Term structure of flat correlations.
interpolated correlation term structure
BOOST_AUTO_TEST_CASE(testFlatCorrelation)
Fixture that can be used at top level.