Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Functions
commodityforward.cpp File Reference
#include "toplevelfixture.hpp"
#include <boost/test/unit_test.hpp>
#include <ql/currencies/america.hpp>
#include <ql/settings.hpp>
#include <ql/time/calendars/nullcalendar.hpp>
#include <qle/instruments/commodityforward.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testConstructor)
 
 BOOST_AUTO_TEST_CASE (testIsExpired)
 
 BOOST_AUTO_TEST_CASE (testIsExpiredCashSettledMaturityEqualsPayment)
 
 BOOST_AUTO_TEST_CASE (testIsExpiredCashSettledPaymentGtMaturity)
 
 BOOST_AUTO_TEST_CASE (testNegativeQuantityThrows)
 
 BOOST_AUTO_TEST_CASE (testNegativeStrikeThrows)
 
 BOOST_AUTO_TEST_CASE (testPaymentDateLtMaturityCashSettledThrows)
 
 BOOST_AUTO_TEST_CASE (testNonNullPaymentDatePhysicallySettledThrows)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/8]

BOOST_AUTO_TEST_CASE ( testConstructor  )

Definition at line 56 of file commodityforward.cpp.

56 {
57
58 BOOST_TEST_MESSAGE("Testing commodity forward constructor");
59
60 CommonData td;
61
62 CommodityForward forward(td.index, td.currency, td.position, td.quantity, td.maturity, td.strike);
63
64 BOOST_CHECK_EQUAL(forward.index()->name(), td.index->name());
65 BOOST_CHECK_EQUAL(forward.currency(), td.currency);
66 BOOST_CHECK_EQUAL(forward.position(), td.position);
67 BOOST_CHECK_EQUAL(forward.quantity(), td.quantity);
68 BOOST_CHECK_EQUAL(forward.maturityDate(), td.maturity);
69 BOOST_CHECK_EQUAL(forward.strike(), td.strike);
70}
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [2/8]

BOOST_AUTO_TEST_CASE ( testIsExpired  )

Definition at line 72 of file commodityforward.cpp.

72 {
73
74 BOOST_TEST_MESSAGE("Testing commodity forward expiry logic");
75
76 CommonData td;
77
78 CommodityForward forward(td.index, td.currency, td.position, td.quantity, td.maturity, td.strike);
79
80 Settings::instance().evaluationDate() = td.maturity - 1 * Days;
81 Settings::instance().includeReferenceDateEvents() = true;
82 BOOST_CHECK_EQUAL(forward.isExpired(), false);
83
84 Settings::instance().evaluationDate() = td.maturity;
85 BOOST_CHECK_EQUAL(forward.isExpired(), false);
86
87 Settings::instance().includeReferenceDateEvents() = false;
88 BOOST_CHECK_EQUAL(forward.isExpired(), true);
89}
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [3/8]

BOOST_AUTO_TEST_CASE ( testIsExpiredCashSettledMaturityEqualsPayment  )

Definition at line 91 of file commodityforward.cpp.

91 {
92
93 BOOST_TEST_MESSAGE("Testing commodity forward expiry logic for cash-settled forward" <<
94 " with payment equal to maturity");
95
96 CommonData td;
97
98 CommodityForward forward(td.index, td.currency, td.position, td.quantity, td.maturity, td.strike, false);
99
100 Settings::instance().evaluationDate() = td.maturity - 1 * Days;
101 Settings::instance().includeReferenceDateEvents() = true;
102 BOOST_CHECK_EQUAL(forward.isExpired(), false);
103
104 Settings::instance().evaluationDate() = td.maturity;
105 BOOST_CHECK_EQUAL(forward.isExpired(), false);
106
107 Settings::instance().includeReferenceDateEvents() = false;
108 BOOST_CHECK_EQUAL(forward.isExpired(), true);
109}
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [4/8]

BOOST_AUTO_TEST_CASE ( testIsExpiredCashSettledPaymentGtMaturity  )

Definition at line 111 of file commodityforward.cpp.

111 {
112
113 BOOST_TEST_MESSAGE("Testing commodity forward expiry logic for cash-settled forward" <<
114 " with payment date strictly greater than maturity date.");
115
116 CommonData td;
117
118 Date payment(21, Feb, 2019);
119 CommodityForward forward(td.index, td.currency, td.position, td.quantity, td.maturity, td.strike,
120 false, payment);
121
122 // Check not expired right up to payment date when includeReferenceDateEvents is true.
123 Settings::instance().includeReferenceDateEvents() = true;
124 Date tmpDate = td.maturity - 1 * Days;
125 while (tmpDate <= payment) {
126 Settings::instance().evaluationDate() = tmpDate;
127 BOOST_CHECK_EQUAL(forward.isExpired(), false);
128 tmpDate++;
129 }
130
131 // Is expired if we set includeReferenceDateEvents to false.
132 Settings::instance().includeReferenceDateEvents() = false;
133 BOOST_CHECK_EQUAL(forward.isExpired(), true);
134
135 // Is expired always when valuation date is greater than payment.
136 Settings::instance().evaluationDate() = payment + 1 * Days;
137 BOOST_CHECK_EQUAL(forward.isExpired(), true);
138 Settings::instance().includeReferenceDateEvents() = true;
139 BOOST_CHECK_EQUAL(forward.isExpired(), true);
140
141}
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [5/8]

BOOST_AUTO_TEST_CASE ( testNegativeQuantityThrows  )

Definition at line 143 of file commodityforward.cpp.

143 {
144
145 BOOST_TEST_MESSAGE("Test that using a negative quantity in the constructor causes an exception");
146
147 CommonData td;
148
149 BOOST_CHECK_THROW(CommodityForward(td.index, td.currency, td.position, -10.0, td.maturity, td.strike),
150 QuantLib::Error);
151}

◆ BOOST_AUTO_TEST_CASE() [6/8]

BOOST_AUTO_TEST_CASE ( testNegativeStrikeThrows  )

Definition at line 153 of file commodityforward.cpp.

153 {
154
155 BOOST_TEST_MESSAGE("Test that using a negative strike in the constructor causes an exception");
156
157 CommonData td;
158
159 BOOST_CHECK_THROW(CommodityForward(td.index, td.currency, td.position, td.quantity, td.maturity, -50.0),
160 QuantLib::Error);
161}

◆ BOOST_AUTO_TEST_CASE() [7/8]

BOOST_AUTO_TEST_CASE ( testPaymentDateLtMaturityCashSettledThrows  )

Definition at line 163 of file commodityforward.cpp.

163 {
164
165 BOOST_TEST_MESSAGE("Test that using a payment date less than maturity for cash settled causes an exception");
166
167 CommonData td;
168
169 BOOST_CHECK_THROW(CommodityForward(td.index, td.currency, td.position, td.quantity, td.maturity, -50.0,
170 false, td.maturity - 1 * Days), QuantLib::Error);
171}

◆ BOOST_AUTO_TEST_CASE() [8/8]

BOOST_AUTO_TEST_CASE ( testNonNullPaymentDatePhysicallySettledThrows  )

Definition at line 173 of file commodityforward.cpp.

173 {
174
175 BOOST_TEST_MESSAGE("Test that using a payment date for physically settled causes an exception");
176
177 CommonData td;
178
179 BOOST_CHECK_THROW(CommodityForward(td.index, td.currency, td.position, td.quantity, td.maturity, -50.0,
180 true, td.maturity + 2 * Days), QuantLib::Error);
181}