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

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testAddTrades)
 
 BOOST_AUTO_TEST_CASE (testAddTradeWithExistingId)
 
 BOOST_AUTO_TEST_CASE (testClear)
 
 BOOST_AUTO_TEST_CASE (testSize)
 
 BOOST_AUTO_TEST_CASE (testRemove)
 
 BOOST_AUTO_TEST_CASE (testTrades)
 
 BOOST_AUTO_TEST_CASE (testIds)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/7]

BOOST_AUTO_TEST_CASE ( testAddTrades  )

Definition at line 34 of file portfolio.cpp.

34 {
35 QuantLib::ext::shared_ptr<Portfolio> portfolio = QuantLib::ext::make_shared<Portfolio>();
36 QuantLib::ext::shared_ptr<FxForward> trade1 = QuantLib::ext::make_shared<FxForward>();
37 QuantLib::ext::shared_ptr<FxForward> trade2 = QuantLib::ext::make_shared<FxForward>();
38 trade1->id() = "1";
39 trade2->id() = "2";
40 BOOST_CHECK_EQUAL(portfolio->has(trade1->id()), false);
41 BOOST_CHECK_EQUAL(portfolio->size(), 0);
42 portfolio->add(trade1);
43 BOOST_CHECK_EQUAL(portfolio->has(trade1->id()), true);
44 BOOST_CHECK_EQUAL(portfolio->size(), 1);
45 portfolio->add(trade2);
46 BOOST_CHECK_EQUAL(portfolio->has(trade2->id()), true);
47 BOOST_CHECK_EQUAL(portfolio->size(), 2);
48}

◆ BOOST_AUTO_TEST_CASE() [2/7]

BOOST_AUTO_TEST_CASE ( testAddTradeWithExistingId  )

Definition at line 50 of file portfolio.cpp.

50 {
51 QuantLib::ext::shared_ptr<Portfolio> portfolio = QuantLib::ext::make_shared<Portfolio>();
52 QuantLib::ext::shared_ptr<FxForward> trade1 = QuantLib::ext::make_shared<FxForward>();
53 QuantLib::ext::shared_ptr<FxForward> trade2 = QuantLib::ext::make_shared<FxForward>();
54 portfolio->add(trade1);
55 BOOST_CHECK_THROW(portfolio->add(trade2), exception);
56}

◆ BOOST_AUTO_TEST_CASE() [3/7]

BOOST_AUTO_TEST_CASE ( testClear  )

Definition at line 58 of file portfolio.cpp.

58 {
59 QuantLib::ext::shared_ptr<Portfolio> portfolio = QuantLib::ext::make_shared<Portfolio>();
60 QuantLib::ext::shared_ptr<FxForward> trade = QuantLib::ext::make_shared<FxForward>();
61 portfolio->add(trade);
62 BOOST_CHECK_EQUAL(portfolio->size(), 1);
63 portfolio->clear();
64 BOOST_CHECK_EQUAL(portfolio->size(), 0);
65}

◆ BOOST_AUTO_TEST_CASE() [4/7]

BOOST_AUTO_TEST_CASE ( testSize  )

Definition at line 67 of file portfolio.cpp.

67 {
68 QuantLib::ext::shared_ptr<Portfolio> portfolio = QuantLib::ext::make_shared<Portfolio>();
69 QuantLib::ext::shared_ptr<FxForward> trade1 = QuantLib::ext::make_shared<FxForward>();
70 QuantLib::ext::shared_ptr<FxForward> trade2 = QuantLib::ext::make_shared<FxForward>();
71 trade1->id() = "1";
72 trade2->id() = "2";
73 BOOST_CHECK_EQUAL(portfolio->size(), 0);
74 portfolio->add(trade1);
75 BOOST_CHECK_EQUAL(portfolio->size(), 1);
76 portfolio->add(trade2);
77 BOOST_CHECK_EQUAL(portfolio->size(), 2);
78}

◆ BOOST_AUTO_TEST_CASE() [5/7]

BOOST_AUTO_TEST_CASE ( testRemove  )

Definition at line 80 of file portfolio.cpp.

80 {
81 QuantLib::ext::shared_ptr<Portfolio> portfolio = QuantLib::ext::make_shared<Portfolio>();
82 QuantLib::ext::shared_ptr<FxForward> trade = QuantLib::ext::make_shared<FxForward>();
83 BOOST_CHECK_EQUAL(portfolio->has(trade->id()), false);
84 portfolio->add(trade);
85 BOOST_CHECK_EQUAL(portfolio->has(trade->id()), true);
86 portfolio->remove(trade->id());
87 BOOST_CHECK_EQUAL(portfolio->has(trade->id()), false);
88}

◆ BOOST_AUTO_TEST_CASE() [6/7]

BOOST_AUTO_TEST_CASE ( testTrades  )

Definition at line 90 of file portfolio.cpp.

90 {
91 QuantLib::ext::shared_ptr<Portfolio> portfolio = QuantLib::ext::make_shared<Portfolio>();
92 QuantLib::ext::shared_ptr<FxForward> trade1 = QuantLib::ext::make_shared<FxForward>();
93 QuantLib::ext::shared_ptr<FxForward> trade2 = QuantLib::ext::make_shared<FxForward>();
94 std::map<std::string, QuantLib::ext::shared_ptr<Trade>> trade_list;
95 trade1->id() = "1";
96 trade2->id() = "2";
97 BOOST_CHECK(portfolio->trades() == trade_list);
98 portfolio->add(trade1);
99 trade_list["1"] = trade1;
100 BOOST_CHECK(portfolio->trades() == trade_list);
101 portfolio->add(trade2);
102 trade_list["2"] = trade2;
103 BOOST_CHECK(portfolio->trades() == trade_list);
104}

◆ BOOST_AUTO_TEST_CASE() [7/7]

BOOST_AUTO_TEST_CASE ( testIds  )

Definition at line 106 of file portfolio.cpp.

106 {
107 QuantLib::ext::shared_ptr<Portfolio> portfolio = QuantLib::ext::make_shared<Portfolio>();
108 QuantLib::ext::shared_ptr<FxForward> trade1 = QuantLib::ext::make_shared<FxForward>();
109 QuantLib::ext::shared_ptr<FxForward> trade2 = QuantLib::ext::make_shared<FxForward>();
110 trade1->id() = "1";
111 trade2->id() = "2";
112 std::set<std::string> trade_ids;
113 BOOST_CHECK(portfolio->ids() == trade_ids);
114 portfolio->add(trade1);
115 trade_ids.insert("1");
116 BOOST_CHECK(portfolio->ids() == trade_ids);
117 portfolio->add(trade2);
118 trade_ids.insert("2");
119 BOOST_CHECK(portfolio->ids() == trade_ids);
120}