Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
pricecurve.cpp File Reference
#include "toplevelfixture.hpp"
#include <boost/assign/list_of.hpp>
#include <boost/make_shared.hpp>
#include <boost/test/unit_test.hpp>
#include <ql/currencies/america.hpp>
#include <ql/math/interpolations/all.hpp>
#include <ql/quotes/simplequote.hpp>
#include <ql/time/daycounters/actual365fixed.hpp>
#include <qle/termstructures/pricecurve.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testPeriodsAndPricesCurve)
 
 BOOST_AUTO_TEST_CASE (testPeriodsAndQuotesCurve)
 
 BOOST_AUTO_TEST_CASE (testDatesAndPricesCurve)
 
 BOOST_AUTO_TEST_CASE (testDatesAndQuotesCurve)
 
 BOOST_AUTO_TEST_CASE (testNoTimeZeroWorks)
 
 BOOST_AUTO_TEST_CASE (testNegativeTimeRequestThrows)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/6]

BOOST_AUTO_TEST_CASE ( testPeriodsAndPricesCurve  )

Definition at line 185 of file pricecurve.cpp.

185 {
186
187 BOOST_TEST_MESSAGE("Testing interpolated price curve built from periods and prices");
188
189 CommonData td;
190
191 // Look at the first test date
192 Settings::instance().evaluationDate() = td.testDates[0];
193
194 // Create a linearly interpolated price curve
195 InterpolatedPriceCurve<Linear> priceCurve(td.curveTenors, td.prices, td.curveDayCounter, td.currency);
196
197 // Common checks on curve
198 commonChecks(td, priceCurve, false);
199
200 // Create a loglinearly interpolated price curve
201 InterpolatedPriceCurve<LogLinear> logPriceCurve(td.curveTenors, td.prices, td.curveDayCounter, td.currency);
202
203 // Common checks on curve
204 commonChecks(td, logPriceCurve, true);
205
206 // Check linearly interpolated price curve after moving reference date
207 Settings::instance().evaluationDate() = td.testDates[1];
208
209 // Check curve reference date is now second test date
210 BOOST_CHECK_EQUAL(priceCurve.referenceDate(), td.testDates[1]);
211
212 // Requesting price by time should give the same results as previously
213 // Requesting by date should give new results (floating reference date curve)
214 for (Size i = 0; i < td.interpolationTimes.size(); i++) {
215 BOOST_CHECK_CLOSE(td.baseExpInterpResults[i], priceCurve.price(td.interpolationTimes[i], td.extrapolate),
216 td.tolerance);
217 BOOST_CHECK_CLOSE(td.afterExpInterpResults[i], priceCurve.price(td.interpolationDates[i], td.extrapolate),
218 td.tolerance);
219 }
220}
Interpolated price curve.
Definition: pricecurve.hpp:50
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [2/6]

BOOST_AUTO_TEST_CASE ( testPeriodsAndQuotesCurve  )

Definition at line 222 of file pricecurve.cpp.

222 {
223
224 BOOST_TEST_MESSAGE("Testing interpolated price curve built from periods and quotes");
225
226 CommonData td;
227
228 // Look at the first test date
229 Settings::instance().evaluationDate() = td.testDates[0];
230
231 // Create a linearly interpolated price curve
232 InterpolatedPriceCurve<Linear> priceCurve(td.curveTenors, td.quotes, td.curveDayCounter, td.currency);
233
234 // Common checks on curve
235 commonChecks(td, priceCurve, false);
236
237 // Create a loglinearly interpolated price curve
238 InterpolatedPriceCurve<LogLinear> logPriceCurve(td.curveTenors, td.quotes, td.curveDayCounter, td.currency);
239
240 // Common checks on curve
241 commonChecks(td, logPriceCurve, true);
242
243 // Check linearly interpolated price curve after moving reference date
244 Settings::instance().evaluationDate() = td.testDates[1];
245
246 // Check curve reference date is now second test date
247 BOOST_CHECK_EQUAL(priceCurve.referenceDate(), td.testDates[1]);
248
249 // Requesting price by time should give the same results as previously
250 // Requesting by date should give new results (floating reference date curve)
251 for (Size i = 0; i < td.interpolationTimes.size(); i++) {
252 BOOST_CHECK_CLOSE(td.baseExpInterpResults[i], priceCurve.price(td.interpolationTimes[i], td.extrapolate),
253 td.tolerance);
254 BOOST_CHECK_CLOSE(td.afterExpInterpResults[i], priceCurve.price(td.interpolationDates[i], td.extrapolate),
255 td.tolerance);
256 }
257
258 // Update quotes and check interpolations again (on this second test date)
259 td.updateQuotes();
260 for (Size i = 0; i < td.interpolationTimes.size(); i++) {
261 BOOST_CHECK_CLOSE(td.baseNewInterpResults[i], priceCurve.price(td.interpolationTimes[i], td.extrapolate),
262 td.tolerance);
263 BOOST_CHECK_CLOSE(td.afterNewInterpResults[i], priceCurve.price(td.interpolationDates[i], td.extrapolate),
264 td.tolerance);
265 }
266
267 // Move date back to first test date
268 Settings::instance().evaluationDate() = td.testDates[0];
269
270 // Check interpolations again with the new quotes
271 for (Size i = 0; i < td.interpolationTimes.size(); i++) {
272 BOOST_CHECK_CLOSE(td.baseNewInterpResults[i], priceCurve.price(td.interpolationTimes[i], td.extrapolate),
273 td.tolerance);
274 BOOST_CHECK_CLOSE(td.baseNewInterpResults[i], priceCurve.price(td.interpolationDates[i], td.extrapolate),
275 td.tolerance);
276 }
277}
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [3/6]

BOOST_AUTO_TEST_CASE ( testDatesAndPricesCurve  )

Definition at line 279 of file pricecurve.cpp.

279 {
280
281 BOOST_TEST_MESSAGE("Testing interpolated price curve built from dates and prices");
282
283 CommonData td;
284
285 // Look at the first test date
286 Settings::instance().evaluationDate() = td.testDates[0];
287
288 // Create a linearly interpolated price curve
289 vector<Date> dates = td.dates(0);
290 InterpolatedPriceCurve<Linear> priceCurve(dates[0], dates, td.prices, td.curveDayCounter, td.currency);
291
292 // Common checks on curve
293 commonChecks(td, priceCurve, false);
294
295 // Create a loglinearly interpolated price curve
296 InterpolatedPriceCurve<LogLinear> logPriceCurve(dates[0], dates, td.prices, td.curveDayCounter, td.currency);
297
298 // Common checks on curve
299 commonChecks(td, logPriceCurve, true);
300
301 // Check linearly interpolated price curve after moving reference date
302 Settings::instance().evaluationDate() = td.testDates[1];
303
304 // Check curve reference date is still first test date
305 BOOST_CHECK_EQUAL(priceCurve.referenceDate(), td.testDates[0]);
306
307 // Requesting price by time or date should give the same results as previously
308 // because this is a fixed reference date curve
309 for (Size i = 0; i < td.interpolationTimes.size(); i++) {
310 BOOST_CHECK_CLOSE(td.baseExpInterpResults[i], priceCurve.price(td.interpolationTimes[i], td.extrapolate),
311 td.tolerance);
312 BOOST_CHECK_CLOSE(td.baseExpInterpResults[i], priceCurve.price(td.interpolationDates[i], td.extrapolate),
313 td.tolerance);
314 }
315}
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [4/6]

BOOST_AUTO_TEST_CASE ( testDatesAndQuotesCurve  )

Definition at line 317 of file pricecurve.cpp.

317 {
318
319 BOOST_TEST_MESSAGE("Testing interpolated price curve built from dates and quotes");
320
321 CommonData td;
322
323 // Look at the first test date
324 Settings::instance().evaluationDate() = td.testDates[0];
325
326 // Create a linearly interpolated price curve
327 vector<Date> dates = td.dates(0);
328 InterpolatedPriceCurve<Linear> priceCurve(dates[0], dates, td.quotes, td.curveDayCounter, td.currency);
329
330 // Common checks on curve
331 commonChecks(td, priceCurve, false);
332
333 // Create a loglinearly interpolated price curve
334 InterpolatedPriceCurve<LogLinear> logPriceCurve(dates[0], dates, td.quotes, td.curveDayCounter, td.currency);
335
336 // Common checks on curve
337 commonChecks(td, logPriceCurve, true);
338
339 // Check linearly interpolated price curve after moving reference date
340 Settings::instance().evaluationDate() = td.testDates[1];
341
342 // Check curve reference date is still first test date
343 BOOST_CHECK_EQUAL(priceCurve.referenceDate(), td.testDates[0]);
344
345 // Requesting price by time or date should give the same results as previously
346 // because this is a fixed reference date curve
347 for (Size i = 0; i < td.interpolationTimes.size(); i++) {
348 BOOST_CHECK_CLOSE(td.baseExpInterpResults[i], priceCurve.price(td.interpolationTimes[i], td.extrapolate),
349 td.tolerance);
350 BOOST_CHECK_CLOSE(td.baseExpInterpResults[i], priceCurve.price(td.interpolationDates[i], td.extrapolate),
351 td.tolerance);
352 }
353
354 // Update quotes and check the new interpolated values
355 td.updateQuotes();
356 for (Size i = 0; i < td.interpolationTimes.size(); i++) {
357 BOOST_CHECK_CLOSE(td.baseNewInterpResults[i], priceCurve.price(td.interpolationTimes[i], td.extrapolate),
358 td.tolerance);
359 BOOST_CHECK_CLOSE(td.baseNewInterpResults[i], priceCurve.price(td.interpolationDates[i], td.extrapolate),
360 td.tolerance);
361 }
362}
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [5/6]

BOOST_AUTO_TEST_CASE ( testNoTimeZeroWorks  )

Definition at line 364 of file pricecurve.cpp.

364 {
365
366 BOOST_TEST_MESSAGE("Test building with periods without a time 0 works with extrapolation on");
367
368 CommonData td;
369
370 // Look at the first test date
371 Settings::instance().evaluationDate() = td.testDates[0];
372
373 // Create the price curve after removing the time 0 pillar
374 vector<Period> tenors = td.curveTenors;
375 tenors.erase(tenors.begin());
376 td.prices.erase(td.prices.begin());
377 InterpolatedPriceCurve<Linear> priceCurve(tenors, td.prices, td.curveDayCounter, td.currency);
378
379 // Check requests for prices between first curve time ~0.5 and 0
380 BOOST_CHECK_CLOSE(15.1391304347826, priceCurve.price(0.25, td.extrapolate), td.tolerance);
381 BOOST_CHECK_CLOSE(13.5521739130435, priceCurve.price(0.0, td.extrapolate), td.tolerance);
382
383 // Test log-linear interpolation also
384 InterpolatedPriceCurve<LogLinear> logPriceCurve(tenors, td.prices, td.curveDayCounter, td.currency);
385 BOOST_CHECK_CLOSE(15.331307232214800, logPriceCurve.price(0.25, td.extrapolate), td.tolerance);
386 BOOST_CHECK_CLOSE(14.054688467053400, logPriceCurve.price(0.0, td.extrapolate), td.tolerance);
387
388 // Test that an exception is thrown when extrapolation is off
389 BOOST_CHECK_THROW(priceCurve.price(0.25, false), QuantLib::Error);
390}
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [6/6]

BOOST_AUTO_TEST_CASE ( testNegativeTimeRequestThrows  )

Definition at line 392 of file pricecurve.cpp.

392 {
393
394 BOOST_TEST_MESSAGE("Test that requesting a price at a time before zero throws");
395
396 CommonData td;
397
398 // Look at the first test date
399 Date today = td.testDates[0];
400 Settings::instance().evaluationDate() = today;
401
402 // Create the price curve
403 InterpolatedPriceCurve<Linear> priceCurve(td.curveTenors, td.prices, td.curveDayCounter, td.currency);
404
405 // Check requests for prices at times < 0
406 Time t = -0.5;
407 Date d = today - 1 * Weeks;
408 BOOST_CHECK_THROW(priceCurve.price(t, td.extrapolate), QuantLib::Error);
409 BOOST_CHECK_THROW(priceCurve.price(d, td.extrapolate), QuantLib::Error);
410
411 // Update evaluation date and request on today should throw similarly
412 Settings::instance().evaluationDate() = today + 1 * Weeks;
413 BOOST_CHECK_THROW(priceCurve.price(today, td.extrapolate), QuantLib::Error);
414}
+ Here is the call graph for this function: