Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
legdata.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19#include <boost/test/unit_test.hpp>
21#include <oret/toplevelfixture.hpp>
22
23#include <boost/make_shared.hpp>
24
25using namespace QuantLib;
26using namespace ore::data;
27using namespace boost::unit_test_framework;
28
29BOOST_FIXTURE_TEST_SUITE(OREDataTestSuite, ore::test::TopLevelFixture)
30
31BOOST_AUTO_TEST_SUITE(LegDataTests)
32
33BOOST_AUTO_TEST_CASE(testLegDataNotionals) {
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}
68
69BOOST_AUTO_TEST_CASE(testLegDataCashflows) {
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}
90
91BOOST_AUTO_TEST_SUITE_END()
92
93BOOST_AUTO_TEST_SUITE_END()
Serializable object holding leg data.
Definition: legdata.hpp:844
Serializable object holding schedule Rules data.
Definition: schedule.hpp:37
Date parseDate(const string &s)
Convert std::string to QuantLib::Date.
Definition: parsers.cpp:51
leg data model and serialization
Leg makeSimpleLeg(const LegData &data)
Definition: legdata.cpp:934
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
BOOST_AUTO_TEST_CASE(testLegDataNotionals)
Definition: legdata.cpp:33