Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
indices.cpp File Reference
#include <boost/test/unit_test.hpp>
#include <ored/configuration/conventions.hpp>
#include <ored/utilities/indexparser.hpp>
#include <oret/toplevelfixture.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testIborIndexParsing)
 
 BOOST_AUTO_TEST_CASE (testIborIndexParsingFails)
 
 BOOST_AUTO_TEST_CASE (testSwapIndexParsing)
 
 BOOST_AUTO_TEST_CASE (testInflationIndexParsing)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/4]

BOOST_AUTO_TEST_CASE ( testIborIndexParsing  )

Definition at line 386 of file indices.cpp.

386 {
387
388 BOOST_TEST_MESSAGE("Testing Ibor Index name parsing...");
389
390 Size len = sizeof(index_data) / sizeof(index_data[0]);
391 for (Size i = 0; i < len; ++i) {
392 string str(ore::data::internalIndexName(index_data[i].str));
393 string index_name(index_data[i].index_name);
394 Period tenor(index_data[i].tenor);
395
396 QuantLib::ext::shared_ptr<IborIndex> ibor;
397 try {
398 ibor = ore::data::parseIborIndex(str);
399 } catch (std::exception& e) {
400 BOOST_FAIL("Ibor Parser failed to parse \"" << str << "\" [exception:" << e.what() << "]");
401 } catch (...) {
402 BOOST_FAIL("Ibor Parser failed to parse \"" << str << "\" [unhandled]");
403 }
404 if (ibor) {
405 BOOST_CHECK_EQUAL(ibor->name(), index_name);
406 BOOST_CHECK_EQUAL(ibor->tenor(), tenor);
407
408 BOOST_TEST_MESSAGE("Parsed \"" << str << "\" and got " << ibor->name());
409 } else
410 BOOST_FAIL("Ibor Parser(" << str << ") returned null pointer");
411 }
412}
QuantLib::ext::shared_ptr< IborIndex > parseIborIndex(const string &s, const Handle< YieldTermStructure > &h)
Convert std::string to QuantLib::IborIndex.
string internalIndexName(const string &indexName)
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [2/4]

BOOST_AUTO_TEST_CASE ( testIborIndexParsingFails  )

Definition at line 414 of file indices.cpp.

414 {
415
416 BOOST_TEST_MESSAGE("Testing Ibor Index parsing fails...");
417
418 // Test invalid strings
419 BOOST_CHECK_THROW(ore::data::parseIborIndex("EUR-EONIA-1M"), QuantLib::Error);
420 BOOST_CHECK_THROW(ore::data::parseIborIndex("EUR-FALSE-6M"), QuantLib::Error);
421 BOOST_CHECK_THROW(ore::data::parseIborIndex("It's a trap!"), QuantLib::Error);
422}
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [3/4]

BOOST_AUTO_TEST_CASE ( testSwapIndexParsing  )

Definition at line 424 of file indices.cpp.

424 {
425
426 BOOST_TEST_MESSAGE("Testing Swap Index name parsing...");
427
428 Handle<YieldTermStructure> h; // dummy
429
430 Size len = sizeof(swap_index_data) / sizeof(swap_index_data[0]);
431
432 for (Size i = 0; i < len; ++i) {
433 string str(swap_index_data[i].str);
434 string index_name(swap_index_data[i].index_name);
435 Period tenor(swap_index_data[i].tenor);
436 ore::data::InstrumentConventions::instance().setConventions(convs());
437 QuantLib::ext::shared_ptr<SwapIndex> swap;
438 try {
439 swap = ore::data::parseSwapIndex(str, h, h);
440 } catch (std::exception& e) {
441 BOOST_FAIL("Swap Parser failed to parse \"" << str << "\" [exception:" << e.what() << "]");
442 } catch (...) {
443 BOOST_FAIL("Swap Parser failed to parse \"" << str << "\" [unhandled]");
444 }
445 if (swap) {
446 BOOST_CHECK_EQUAL(swap->name(), index_name);
447 BOOST_CHECK_EQUAL(swap->tenor(), tenor);
448
449 BOOST_TEST_MESSAGE("Parsed \"" << str << "\" and got " << swap->name());
450 } else
451 BOOST_FAIL("Swap Parser(" << str << ") returned null pointer");
452 }
453}
QuantLib::ext::shared_ptr< SwapIndex > parseSwapIndex(const string &s, const Handle< YieldTermStructure > &f, const Handle< YieldTermStructure > &d)
Convert std::string to QuantLib::SwapIndex.
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [4/4]

BOOST_AUTO_TEST_CASE ( testInflationIndexParsing  )

Definition at line 455 of file indices.cpp.

455 {
456
457 BOOST_TEST_MESSAGE("Testing Inflation Index name parsing...");
458
459 Size len = sizeof(inflation_index_data) / sizeof(inflation_index_data[0]);
460 for (Size i = 0; i < len; ++i) {
461 string str(inflation_index_data[i].str);
462 string index_name(inflation_index_data[i].index_name);
463 Frequency frequency(inflation_index_data[i].frequency);
464
465 QuantLib::ext::shared_ptr<ZeroInflationIndex> cpi;
466 try {
468 } catch (std::exception& e) {
469 BOOST_FAIL("Inflation Index Parser failed to parse \"" << str << "\" [exception:" << e.what() << "]");
470 } catch (...) {
471 BOOST_FAIL("Inflation Index Parser failed to parse \"" << str << "\" [unhandled]");
472 }
473 if (cpi) {
474 BOOST_CHECK_EQUAL(cpi->name(), index_name);
475 BOOST_CHECK_EQUAL(cpi->frequency(), frequency);
476 // Frequency
477 //Availability lag?
478
479 BOOST_TEST_MESSAGE("Parsed \"" << str << "\" and got " << cpi->name());
480 } else
481 BOOST_FAIL("Inflation Index Parser(" << str << ") returned null pointer");
482 }
483}
QuantLib::ext::shared_ptr< ZeroInflationIndex > parseZeroInflationIndex(const string &s, const Handle< ZeroInflationTermStructure > &h)
Convert std::string to QuantLib::ZeroInflationIndex.
+ Here is the call graph for this function: