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

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (testAbsoluteStrike)
 
 BOOST_AUTO_TEST_CASE (testDeltaStrike)
 
 BOOST_AUTO_TEST_CASE (testAtmStrikeNoDelta)
 
 BOOST_AUTO_TEST_CASE (testAtmStrikeNoDeltaEquality)
 
 BOOST_AUTO_TEST_CASE (testAtmStrikeWithDelta)
 
 BOOST_AUTO_TEST_CASE (testMoneynessStrike)
 
 BOOST_AUTO_TEST_CASE (testAtmStrikeExceptions)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/7]

BOOST_AUTO_TEST_CASE ( testAbsoluteStrike  )

Definition at line 32 of file strike.cpp.

32 {
33
34 BOOST_TEST_MESSAGE("Testing absolute strike...");
35
36 Real inputStrike = 2.0;
37 Real tolerance = 1e-12;
38
39 // Construct an AbsoluteStrike directly
40 AbsoluteStrike strike(inputStrike);
41 BOOST_CHECK_CLOSE(strike.strike(), inputStrike, tolerance);
42
43 // Write AbsoluteStrike to string
44 string strStrike = strike.toString();
45
46 // Parse AbsoluteStrike from string
47 QuantLib::ext::shared_ptr<BaseStrike> parsedStrike;
48 BOOST_REQUIRE_NO_THROW(parsedStrike = parseBaseStrike(strStrike));
49
50 // Check that we get back an AbsoluteStrike
51 QuantLib::ext::shared_ptr<AbsoluteStrike> castStrike = QuantLib::ext::dynamic_pointer_cast<AbsoluteStrike>(parsedStrike);
52 BOOST_CHECK(castStrike);
53
54 // Check its members
55 BOOST_CHECK_CLOSE(castStrike->strike(), inputStrike, tolerance);
56}
QuantLib::ext::shared_ptr< BaseStrike > parseBaseStrike(const string &strStrike)
Parse a Strike from its string representation, strStrike.
Definition: strike.cpp:262
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [2/7]

BOOST_AUTO_TEST_CASE ( testDeltaStrike  )

Definition at line 58 of file strike.cpp.

58 {
59
60 BOOST_TEST_MESSAGE("Testing delta strike...");
61
62 DeltaVolQuote::DeltaType inputDeltaType = DeltaVolQuote::Spot;
63 Option::Type inputOptionType = Option::Call;
64 Real inputDelta = 0.25;
65 Real tolerance = 1e-12;
66
67 // Construct a DeltaStrike directly
68 DeltaStrike strike(inputDeltaType, inputOptionType, inputDelta);
69 BOOST_CHECK_EQUAL(strike.deltaType(), inputDeltaType);
70 BOOST_CHECK_EQUAL(strike.optionType(), inputOptionType);
71 BOOST_CHECK_CLOSE(strike.delta(), inputDelta, tolerance);
72
73 // Write DeltaStrike to string
74 string strStrike = strike.toString();
75
76 // Parse DeltaStrike from string
77 QuantLib::ext::shared_ptr<BaseStrike> parsedStrike;
78 BOOST_REQUIRE_NO_THROW(parsedStrike = parseBaseStrike(strStrike));
79
80 // Check that we get back a DeltaStrike
81 QuantLib::ext::shared_ptr<DeltaStrike> castStrike = QuantLib::ext::dynamic_pointer_cast<DeltaStrike>(parsedStrike);
82 BOOST_CHECK(castStrike);
83
84 // Check its members
85 BOOST_CHECK_EQUAL(castStrike->deltaType(), inputDeltaType);
86 BOOST_CHECK_EQUAL(castStrike->optionType(), inputOptionType);
87 BOOST_CHECK_CLOSE(castStrike->delta(), inputDelta, tolerance);
88}
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [3/7]

BOOST_AUTO_TEST_CASE ( testAtmStrikeNoDelta  )

Definition at line 90 of file strike.cpp.

90 {
91
92 BOOST_TEST_MESSAGE("Testing ATM strike without delta...");
93
94 DeltaVolQuote::AtmType inputAtmType = DeltaVolQuote::AtmFwd;
95
96 // Construct an AtmStrike directly
97 AtmStrike strike(inputAtmType);
98 BOOST_CHECK_EQUAL(strike.atmType(), inputAtmType);
99 BOOST_CHECK(!strike.deltaType());
100
101 // Write AtmStrike to string
102 string strStrike = strike.toString();
103
104 // Parse AtmStrike from string
105 QuantLib::ext::shared_ptr<BaseStrike> parsedStrike;
106 BOOST_REQUIRE_NO_THROW(parsedStrike = parseBaseStrike(strStrike));
107
108 // Check that we get back an AtmStrike
109 QuantLib::ext::shared_ptr<AtmStrike> castStrike = QuantLib::ext::dynamic_pointer_cast<AtmStrike>(parsedStrike);
110 BOOST_CHECK(castStrike);
111
112 // Check its members
113 BOOST_CHECK_EQUAL(castStrike->atmType(), inputAtmType);
114 BOOST_CHECK(!castStrike->deltaType());
115}
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [4/7]

BOOST_AUTO_TEST_CASE ( testAtmStrikeNoDeltaEquality  )

Definition at line 117 of file strike.cpp.

117 {
118
119 BOOST_TEST_MESSAGE("Testing equality operator for two ATM strikes without delta...");
120 // Checks for failure in operator== if delta type is not given
121
122 DeltaVolQuote::AtmType atmType = DeltaVolQuote::AtmFwd;
123 boost::optional<DeltaVolQuote::DeltaType> atmDeltaType;
124
125 vector<QuantLib::ext::shared_ptr<BaseStrike>> strikes;
126 strikes.push_back(QuantLib::ext::make_shared<AtmStrike>(atmType, atmDeltaType));
127 strikes.push_back(QuantLib::ext::make_shared<AtmStrike>(DeltaVolQuote::AtmFwd));
128 BOOST_CHECK(*strikes[0] == *strikes[1]);
129}
vector< Real > strikes

◆ BOOST_AUTO_TEST_CASE() [5/7]

BOOST_AUTO_TEST_CASE ( testAtmStrikeWithDelta  )

Definition at line 131 of file strike.cpp.

131 {
132
133 BOOST_TEST_MESSAGE("Testing ATM strike with delta...");
134
135 DeltaVolQuote::AtmType inputAtmType = DeltaVolQuote::AtmDeltaNeutral;
136 DeltaVolQuote::DeltaType inputDeltaType = DeltaVolQuote::Fwd;
137
138 // Construct an AtmStrike directly
139 AtmStrike strike(inputAtmType, inputDeltaType);
140 BOOST_CHECK_EQUAL(strike.atmType(), inputAtmType);
141 BOOST_CHECK(strike.deltaType());
142 BOOST_CHECK_EQUAL(*strike.deltaType(), inputDeltaType);
143
144 // Write AtmStrike to string
145 string strStrike = strike.toString();
146
147 // Parse AtmStrike from string
148 QuantLib::ext::shared_ptr<BaseStrike> parsedStrike;
149 BOOST_REQUIRE_NO_THROW(parsedStrike = parseBaseStrike(strStrike));
150
151 // Check that we get back an AtmStrike
152 QuantLib::ext::shared_ptr<AtmStrike> castStrike = QuantLib::ext::dynamic_pointer_cast<AtmStrike>(parsedStrike);
153 BOOST_CHECK(castStrike);
154
155 // Check its members
156 BOOST_CHECK_EQUAL(castStrike->atmType(), inputAtmType);
157 BOOST_CHECK(castStrike->deltaType());
158 BOOST_CHECK_EQUAL(*castStrike->deltaType(), inputDeltaType);
159}
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [6/7]

BOOST_AUTO_TEST_CASE ( testMoneynessStrike  )

Definition at line 161 of file strike.cpp.

161 {
162
163 BOOST_TEST_MESSAGE("Testing moneyness strike ...");
164
165 MoneynessStrike::Type inputMoneynessType = MoneynessStrike::Type::Forward;
166 Real inputMoneyness = 1.10;
167 Real tolerance = 1e-12;
168
169 // Construct an MoneynessStrike directly
170 MoneynessStrike strike(inputMoneynessType, inputMoneyness);
171 BOOST_CHECK_EQUAL(strike.type(), inputMoneynessType);
172 BOOST_CHECK_CLOSE(strike.moneyness(), inputMoneyness, tolerance);
173
174 // Write MoneynessStrike to string
175 string strStrike = strike.toString();
176
177 // Parse MoneynessStrike from string
178 QuantLib::ext::shared_ptr<BaseStrike> parsedStrike;
179 BOOST_REQUIRE_NO_THROW(parsedStrike = parseBaseStrike(strStrike));
180
181 // Check that we get back an MoneynessStrike
182 QuantLib::ext::shared_ptr<MoneynessStrike> castStrike = QuantLib::ext::dynamic_pointer_cast<MoneynessStrike>(parsedStrike);
183 BOOST_CHECK(castStrike);
184
185 // Check its members
186 BOOST_CHECK_EQUAL(castStrike->type(), inputMoneynessType);
187 BOOST_CHECK_CLOSE(castStrike->moneyness(), inputMoneyness, tolerance);
188}
+ Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [7/7]

BOOST_AUTO_TEST_CASE ( testAtmStrikeExceptions  )

Definition at line 190 of file strike.cpp.

190 {
191
192 DeltaVolQuote::AtmType atmType = DeltaVolQuote::AtmNull;
193 BOOST_CHECK_THROW(AtmStrike tmp(atmType), Error);
194
195 atmType = DeltaVolQuote::AtmDeltaNeutral;
196 BOOST_CHECK_THROW(AtmStrike tmp(atmType), Error);
197
198 atmType = DeltaVolQuote::AtmSpot;
199 DeltaVolQuote::DeltaType deltaType = DeltaVolQuote::Spot;
200 BOOST_CHECK_THROW(AtmStrike tmp(atmType, deltaType), Error);
201
202 atmType = DeltaVolQuote::AtmPutCall50;
203 BOOST_CHECK_THROW(AtmStrike tmp(atmType, deltaType), Error);
204}