20#include <boost/test/unit_test.hpp>
22#include <oret/toplevelfixture.hpp>
28BOOST_FIXTURE_TEST_SUITE(OREDataTestSuite, ore::test::TopLevelFixture)
30BOOST_AUTO_TEST_SUITE(StrikeTests)
34 BOOST_TEST_MESSAGE(
"Testing absolute strike...");
36 Real inputStrike = 2.0;
37 Real tolerance = 1e-12;
41 BOOST_CHECK_CLOSE(strike.
strike(), inputStrike, tolerance);
44 string strStrike = strike.
toString();
47 QuantLib::ext::shared_ptr<BaseStrike> parsedStrike;
51 QuantLib::ext::shared_ptr<AbsoluteStrike> castStrike = QuantLib::ext::dynamic_pointer_cast<AbsoluteStrike>(parsedStrike);
52 BOOST_CHECK(castStrike);
55 BOOST_CHECK_CLOSE(castStrike->strike(), inputStrike, tolerance);
60 BOOST_TEST_MESSAGE(
"Testing delta strike...");
62 DeltaVolQuote::DeltaType inputDeltaType = DeltaVolQuote::Spot;
63 Option::Type inputOptionType = Option::Call;
64 Real inputDelta = 0.25;
65 Real tolerance = 1e-12;
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);
74 string strStrike = strike.
toString();
77 QuantLib::ext::shared_ptr<BaseStrike> parsedStrike;
81 QuantLib::ext::shared_ptr<DeltaStrike> castStrike = QuantLib::ext::dynamic_pointer_cast<DeltaStrike>(parsedStrike);
82 BOOST_CHECK(castStrike);
85 BOOST_CHECK_EQUAL(castStrike->deltaType(), inputDeltaType);
86 BOOST_CHECK_EQUAL(castStrike->optionType(), inputOptionType);
87 BOOST_CHECK_CLOSE(castStrike->delta(), inputDelta, tolerance);
92 BOOST_TEST_MESSAGE(
"Testing ATM strike without delta...");
94 DeltaVolQuote::AtmType inputAtmType = DeltaVolQuote::AtmFwd;
98 BOOST_CHECK_EQUAL(strike.
atmType(), inputAtmType);
102 string strStrike = strike.
toString();
105 QuantLib::ext::shared_ptr<BaseStrike> parsedStrike;
109 QuantLib::ext::shared_ptr<AtmStrike> castStrike = QuantLib::ext::dynamic_pointer_cast<AtmStrike>(parsedStrike);
110 BOOST_CHECK(castStrike);
113 BOOST_CHECK_EQUAL(castStrike->atmType(), inputAtmType);
114 BOOST_CHECK(!castStrike->deltaType());
119 BOOST_TEST_MESSAGE(
"Testing equality operator for two ATM strikes without delta...");
122 DeltaVolQuote::AtmType atmType = DeltaVolQuote::AtmFwd;
123 boost::optional<DeltaVolQuote::DeltaType> atmDeltaType;
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));
133 BOOST_TEST_MESSAGE(
"Testing ATM strike with delta...");
135 DeltaVolQuote::AtmType inputAtmType = DeltaVolQuote::AtmDeltaNeutral;
136 DeltaVolQuote::DeltaType inputDeltaType = DeltaVolQuote::Fwd;
139 AtmStrike strike(inputAtmType, inputDeltaType);
140 BOOST_CHECK_EQUAL(strike.
atmType(), inputAtmType);
142 BOOST_CHECK_EQUAL(*strike.
deltaType(), inputDeltaType);
145 string strStrike = strike.
toString();
148 QuantLib::ext::shared_ptr<BaseStrike> parsedStrike;
152 QuantLib::ext::shared_ptr<AtmStrike> castStrike = QuantLib::ext::dynamic_pointer_cast<AtmStrike>(parsedStrike);
153 BOOST_CHECK(castStrike);
156 BOOST_CHECK_EQUAL(castStrike->atmType(), inputAtmType);
157 BOOST_CHECK(castStrike->deltaType());
158 BOOST_CHECK_EQUAL(*castStrike->deltaType(), inputDeltaType);
163 BOOST_TEST_MESSAGE(
"Testing moneyness strike ...");
166 Real inputMoneyness = 1.10;
167 Real tolerance = 1e-12;
171 BOOST_CHECK_EQUAL(strike.
type(), inputMoneynessType);
172 BOOST_CHECK_CLOSE(strike.
moneyness(), inputMoneyness, tolerance);
175 string strStrike = strike.
toString();
178 QuantLib::ext::shared_ptr<BaseStrike> parsedStrike;
182 QuantLib::ext::shared_ptr<MoneynessStrike> castStrike = QuantLib::ext::dynamic_pointer_cast<MoneynessStrike>(parsedStrike);
183 BOOST_CHECK(castStrike);
186 BOOST_CHECK_EQUAL(castStrike->type(), inputMoneynessType);
187 BOOST_CHECK_CLOSE(castStrike->moneyness(), inputMoneyness, tolerance);
192 DeltaVolQuote::AtmType atmType = DeltaVolQuote::AtmNull;
193 BOOST_CHECK_THROW(
AtmStrike tmp(atmType), Error);
195 atmType = DeltaVolQuote::AtmDeltaNeutral;
196 BOOST_CHECK_THROW(
AtmStrike tmp(atmType), Error);
198 atmType = DeltaVolQuote::AtmSpot;
199 DeltaVolQuote::DeltaType deltaType = DeltaVolQuote::Spot;
200 BOOST_CHECK_THROW(
AtmStrike tmp(atmType, deltaType), Error);
202 atmType = DeltaVolQuote::AtmPutCall50;
203 BOOST_CHECK_THROW(
AtmStrike tmp(atmType, deltaType), Error);
206BOOST_AUTO_TEST_SUITE_END()
208BOOST_AUTO_TEST_SUITE_END()
QuantLib::Real strike() const
Return the absolute strike level.
std::string toString() const override
boost::optional< QuantLib::DeltaVolQuote::DeltaType > deltaType() const
Return the delta type.
QuantLib::DeltaVolQuote::AtmType atmType() const
Return the ATM type.
std::string toString() const override
QuantLib::Real delta() const
Return the delta level.
QuantLib::DeltaVolQuote::DeltaType deltaType() const
Return the delta type.
std::string toString() const override
QuantLib::Option::Type optionType() const
Return the option type.
QuantLib::Real moneyness() const
Return the moneyness level.
std::string toString() const override
Type type() const
Return the moneyness type.
Classes for representing a strike using various conventions.
QuantLib::ext::shared_ptr< BaseStrike > parseBaseStrike(const string &strStrike)
Parse a Strike from its string representation, strStrike.
BOOST_AUTO_TEST_CASE(testAbsoluteStrike)