Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
legdata.cpp File Reference
#include <boost/test/unit_test.hpp>
#include <ored/portfolio/legdata.hpp>
#include <oret/toplevelfixture.hpp>
#include <boost/make_shared.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testLegDataNotionals)
 
 BOOST_AUTO_TEST_CASE (testLegDataCashflows)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/2]

BOOST_AUTO_TEST_CASE ( testLegDataNotionals  )

Definition at line 33 of file legdata.cpp.

33 {
34
35 BOOST_TEST_MESSAGE("Testing LegData Notionals...");
36
37 vector<double> notionals = {100, 200, 300};
38 vector<string> dates = {"", "2015-01-01", "2016-01-01"};
39
40 ScheduleRules sr("2014-06-01", "2016-12-01", "6M", "TARGET", "F", "F", "Forward");
41 Schedule s = makeSchedule(sr);
42 BOOST_CHECK_EQUAL(s.size(), 6UL);
43
44 vector<double> notionalsOut = buildScheduledVector(notionals, dates, s);
45
46 // Expect 100, 100, 200, 200, 300
47 BOOST_CHECK_EQUAL(notionalsOut.size(), 5UL);
48 BOOST_CHECK_EQUAL(notionalsOut[0], 100);
49 BOOST_CHECK_EQUAL(notionalsOut[1], 100);
50 BOOST_CHECK_EQUAL(notionalsOut[2], 200);
51 BOOST_CHECK_EQUAL(notionalsOut[3], 200);
52 BOOST_CHECK_EQUAL(notionalsOut[4], 300);
53
54 // Now check single value
55 notionals = vector<double>(1, 123);
56 notionalsOut = buildScheduledVector(notionals, {}, s);
57 BOOST_CHECK_EQUAL(notionalsOut.size(), 1UL);
58 BOOST_CHECK_EQUAL(notionalsOut[0], 123);
59
60 // Now check long value with no "dates" is unaffected
61 notionals = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
62 notionalsOut = buildScheduledVector(notionals, {}, s);
63 BOOST_CHECK_EQUAL(notionalsOut.size(), 10UL);
64 for (Size i = 0; i < notionalsOut.size(); i++) {
65 BOOST_CHECK_EQUAL(notionalsOut[i], (double)i);
66 }
67}
Serializable object holding schedule Rules data.
Definition: schedule.hpp:37
vector< T > buildScheduledVector(const vector< T > &values, const vector< string > &dates, const Schedule &schedule, const bool checkAllValuesAppearInResult=false)
Definition: legdata.hpp:1061
Schedule makeSchedule(const ScheduleDates &data)
Definition: schedule.cpp:263
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [2/2]

BOOST_AUTO_TEST_CASE ( testLegDataCashflows  )

Definition at line 69 of file legdata.cpp.

69 {
70
71 BOOST_TEST_MESSAGE("Testing LegData Cashflows...");
72
73 vector<double> amounts = {1000000, 2000000, 3000000};
74 vector<string> dates = {"2015-01-01", "2016-01-01", "2017-01-01"};
75
76 LegData legData(QuantLib::ext::make_shared<CashflowData>(amounts, dates), true, "EUR");
77 Leg leg = makeSimpleLeg(legData);
78
79 // Expect 100000, 200000, 300000
80 BOOST_CHECK_EQUAL(leg.size(), 3);
81
82 BOOST_CHECK_EQUAL(leg[0]->amount(), 1000000);
83 BOOST_CHECK_EQUAL(leg[1]->amount(), 2000000);
84 BOOST_CHECK_EQUAL(leg[2]->amount(), 3000000);
85
86 BOOST_CHECK_EQUAL(leg[0]->date(), parseDate("2015-01-01"));
87 BOOST_CHECK_EQUAL(leg[1]->date(), parseDate("2016-01-01"));
88 BOOST_CHECK_EQUAL(leg[2]->date(), parseDate("2017-01-01"));
89}
Serializable object holding leg data.
Definition: legdata.hpp:844
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Definition: parsers.cpp:51
Leg makeSimpleLeg(const LegData &data)
Definition: legdata.cpp:934
+ Here is the call graph for this function: