60 {
61
62
63 std::vector<Time> times;
64 std::vector<QuantLib::ext::shared_ptr<SimpleQuote> > simpleQuotes;
65 std::vector<Handle<Quote> > quotes;
66
67 Size numYears = 10;
68 for (Size i = 1; i < numYears; i++) {
69
70 Real corr = 0.1;
71
72 simpleQuotes.push_back(QuantLib::ext::make_shared<SimpleQuote>(corr));
73 quotes.push_back(Handle<Quote>(simpleQuotes.back()));
74
75 times.push_back(static_cast<Time>(i));
76 }
77
78 Handle<PiecewiseLinearCorrelationCurve> interpCorr(
79 QuantLib::ext::make_shared<PiecewiseLinearCorrelationCurve>(times, quotes, Actual365Fixed(), NullCalendar()));
80
81 Time t = 1;
82 while (t < numYears) {
83 BOOST_CHECK_MESSAGE(interpCorr->correlation(t) == 0.1,
84 "unexpected correlation value: " << interpCorr->correlation(t));
85 t += 0.5;
86 }
87
88
89 for (Size i = 0; i < simpleQuotes.size(); ++i) {
90 simpleQuotes[i]->setValue(1);
91 }
92
93 t = 1;
94 while (t < numYears) {
95 BOOST_CHECK_MESSAGE(interpCorr->correlation(t) == 1,
96 "unexpected correlation value: " << interpCorr->correlation(t));
97 t += 0.5;
98 }
99
100
101 for (Size i = 0; i < simpleQuotes.size(); ++i) {
102 simpleQuotes[i]->setValue(0.1 + 0.01 * i);
103 }
104
105 Real tol = 1.0E-8;
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);
110}