19#include <boost/make_shared.hpp>
20#include <boost/test/unit_test.hpp>
29#include <oret/toplevelfixture.hpp>
30#include <ql/math/distributions/normaldistribution.hpp>
31#include <ql/termstructures/volatility/equityfx/blackconstantvol.hpp>
32#include <ql/termstructures/yield/flatforward.hpp>
33#include <ql/time/daycounters/actualactual.hpp>
38using namespace boost::unit_test_framework;
47 asof_ = Date(3, Feb, 2016);
54 std::map<std::string, QuantLib::Handle<QuantLib::Quote>> quotes;
55 quotes[
"EURUSD"] = Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(1.2));
56 fx_ = QuantLib::ext::make_shared<FXTriangulation>(quotes);
63 Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(100));
71 Handle<EquityIndex2>(QuantLib::ext::make_shared<EquityIndex2>(
73 yieldCurve(YieldCurveType::Discount,
"EUR"),
yieldCurve(YieldCurveType::EquityDividend,
"zzzCorp")));
80 Handle<YieldTermStructure> flatRateYts(Real forward) {
81 QuantLib::ext::shared_ptr<YieldTermStructure> yts(
new FlatForward(0, NullCalendar(), forward, ActualActual(ActualActual::ISDA)));
82 return Handle<YieldTermStructure>(yts);
84 Handle<BlackVolTermStructure> flatRateFxv(Volatility forward) {
85 QuantLib::ext::shared_ptr<BlackVolTermStructure> fxv(
new BlackConstantVol(0, NullCalendar(), forward, ActualActual(ActualActual::ISDA)));
86 return Handle<BlackVolTermStructure>(fxv);
91BOOST_FIXTURE_TEST_SUITE(OREDataTestSuite, ore::test::TopLevelFixture)
93BOOST_AUTO_TEST_SUITE(EquityTradesTests)
98 BOOST_TEST_MESSAGE(
"Testing EquityOption Price...");
100 Date today = Settings::instance().evaluationDate();
103 QuantLib::ext::shared_ptr<Market> market = QuantLib::ext::make_shared<TestMarket>();
104 Settings::instance().evaluationDate() = market->asofDate();
105 Date expiry = market->asofDate() + 6 * Months + 1 * Days;
107 o << QuantLib::io::iso_date(expiry);
108 string exp_str = o.str();
111 OptionData callData(
"Long",
"Call",
"European",
true, vector<string>(1, exp_str));
112 OptionData callDataPremium(
"Long",
"Call",
"European",
true, vector<string>(1, exp_str),
"Cash",
"",
114 OptionData putData(
"Short",
"Put",
"European",
true, vector<string>(1, exp_str));
115 OptionData putDataPremium(
"Short",
"Put",
"European",
true, vector<string>(1, exp_str),
"Cash",
"",
125 Real expectedNPV_Put = -2.4648;
126 Real expectedNPV_Put_Premium = -1.513558;
129 QuantLib::ext::shared_ptr<EngineData> engineData = QuantLib::ext::make_shared<EngineData>();
130 engineData->model(
"EquityOption") =
"BlackScholesMerton";
131 engineData->engine(
"EquityOption") =
"AnalyticEuropeanEngine";
132 engineData->model(
"EquityForward") =
"DiscountedCashflows";
133 engineData->engine(
"EquityForward") =
"DiscountingEquityForwardEngine";
134 QuantLib::ext::shared_ptr<EngineFactory> engineFactory = QuantLib::ext::make_shared<EngineFactory>(engineData, market);
136 eqCall.
build(engineFactory);
137 eqCallPremium.
build(engineFactory);
138 eqPut.
build(engineFactory);
139 eqPutPremium.
build(engineFactory);
140 eqFwd.build(engineFactory);
143 Real npv_call_premium = eqCallPremium.
instrument()->NPV();
145 Real npv_put_premium = eqPutPremium.
instrument()->NPV();
146 Real npv_fwd = eqFwd.instrument()->NPV();
148 Real put_call_sum = npv_call + npv_put;
149 Real put_call_premium_sum = npv_call_premium + npv_put_premium;
151 BOOST_CHECK_CLOSE(expectedNPV_Put, npv_put, 0.001);
152 BOOST_CHECK_CLOSE(expectedNPV_Put_Premium, npv_put_premium, 0.001);
153 BOOST_CHECK_CLOSE(npv_fwd, put_call_sum, 0.001);
154 BOOST_CHECK_CLOSE(npv_fwd, put_call_premium_sum, 0.001);
156 Settings::instance().evaluationDate() = today;
162 BOOST_TEST_MESSAGE(
"Testing EquityFutureOption Price...");
164 Date today = Settings::instance().evaluationDate();
167 QuantLib::ext::shared_ptr<Market> market = QuantLib::ext::make_shared<TestMarket>();
168 Settings::instance().evaluationDate() = market->asofDate();
169 Date expiry = market->asofDate() + 6 * Months + 1 * Days;
171 o << QuantLib::io::iso_date(expiry);
172 string exp_str = o.str();
174 QuantLib::ext::shared_ptr<ore::data::Underlying> underlying = QuantLib::ext::make_shared<ore::data::EquityUnderlying>(
"zzzCorp");
176 OptionData callData(
"Long",
"Call",
"European",
true, vector<string>(1, exp_str));
177 OptionData callDataPremium(
"Long",
"Call",
"European",
true, vector<string>(1, exp_str),
"Physical",
"",
179 OptionData putData(
"Short",
"Put",
"European",
true, vector<string>(1, exp_str));
180 OptionData putDataPremium(
"Short",
"Put",
"European",
true, vector<string>(1, exp_str),
"Physical",
"",
183 TradeStrike strike(TradeStrike::Type::Price, 95.0);
185 EquityFutureOption eqFwdCallPremium(env, callDataPremium,
"EUR", 1.0, underlying, strike, expiry);
187 EquityFutureOption eqFwdPutPremium(env, putDataPremium,
"EUR", 1.0, underlying, strike, expiry);
196 QuantLib::ext::shared_ptr<EngineData> engineData = QuantLib::ext::make_shared<EngineData>();
197 engineData->model(
"EquityOption") =
"BlackScholesMerton";
198 engineData->engine(
"EquityOption") =
"AnalyticEuropeanEngine";
199 engineData->model(
"EquityFutureOption") =
"BlackScholes";
200 engineData->engine(
"EquityFutureOption") =
"AnalyticEuropeanForwardEngine";
201 QuantLib::ext::shared_ptr<EngineFactory> engineFactory = QuantLib::ext::make_shared<EngineFactory>(engineData, market);
203 eqFwdCall.
build(engineFactory);
204 eqFwdCallPremium.
build(engineFactory);
205 eqFwdPut.
build(engineFactory);
206 eqFwdPutPremium.
build(engineFactory);
208 eqCall.
build(engineFactory);
209 eqCallPremium.
build(engineFactory);
210 eqPut.
build(engineFactory);
211 eqPutPremium.
build(engineFactory);
214 BOOST_CHECK_CLOSE(eqCallPremium.
instrument()->NPV(), eqFwdCallPremium.
instrument()->NPV(), 0.001);
216 BOOST_CHECK_CLOSE(eqPutPremium.
instrument()->NPV(), eqFwdPutPremium.
instrument()->NPV(), 0.001);
218 Settings::instance().evaluationDate() = today;
223 BOOST_TEST_MESSAGE(
"Testing EquityFutureOption Put-Call parity...");
225 Date today = Settings::instance().evaluationDate();
228 QuantLib::ext::shared_ptr<Market> market = QuantLib::ext::make_shared<TestMarket>();
229 Settings::instance().evaluationDate() = market->asofDate();
230 Date expiry = market->asofDate() + 6 * Months + 1 * Days;
232 o << QuantLib::io::iso_date(expiry);
233 string exp_str = o.str();
235 Date futureExpiry = market->asofDate() + 12 * Months + 1 * Days;
237 o_2 << QuantLib::io::iso_date(futureExpiry);
238 string f_exp_str = o_2.str();
240 QuantLib::ext::shared_ptr<ore::data::Underlying> underlying = QuantLib::ext::make_shared<ore::data::EquityUnderlying>(
"zzzCorp");
243 OptionData callData(
"Long",
"Call",
"European",
true, vector<string>(1, exp_str));
244 OptionData callDataPremium(
"Long",
"Call",
"European",
true, vector<string>(1, exp_str),
"Physical",
"",
246 OptionData putData(
"Long",
"Put",
"European",
true, vector<string>(1, exp_str));
247 OptionData putDataPremium(
"Long",
"Put",
"European",
true, vector<string>(1, exp_str),
"Physical",
"",
250 TradeStrike strike(TradeStrike::Type::Price, 95.0);
251 EquityFutureOption eqCall(env, callData,
"EUR", 1.0, underlying, strike, futureExpiry);
252 EquityFutureOption eqCallPremium(env, callDataPremium,
"EUR", 1.0, underlying, strike, futureExpiry);
254 EquityFutureOption eqPutPremium(env, putDataPremium,
"EUR", 1.0, underlying, strike, futureExpiry);
258 QuantLib::ext::shared_ptr<EngineData> engineData = QuantLib::ext::make_shared<EngineData>();
259 engineData->model(
"EquityFutureOption") =
"BlackScholes";
260 engineData->engine(
"EquityFutureOption") =
"AnalyticEuropeanForwardEngine";
261 engineData->model(
"EquityOption") =
"BlackScholesMerton";
262 engineData->engine(
"EquityOption") =
"AnalyticEuropeanEngine";
263 engineData->model(
"EquityForward") =
"DiscountedCashflows";
264 engineData->engine(
"EquityForward") =
"DiscountingEquityForwardEngine";
265 QuantLib::ext::shared_ptr<EngineFactory> engineFactory = QuantLib::ext::make_shared<EngineFactory>(engineData, market);
267 eqCall.
build(engineFactory);
268 eqCallPremium.
build(engineFactory);
269 eqPut.
build(engineFactory);
270 eqPutPremium.
build(engineFactory);
271 eqFwd.build(engineFactory);
273 Handle<YieldTermStructure> discountCurve =
280 Real npv_call_premium = eqCallPremium.
instrument()->NPV();
282 Real npv_put_premium = eqPutPremium.
instrument()->NPV();
284 Real npv_fwd = spot * dividend->discount(futureExpiry) / forecast->discount(futureExpiry);;
286 Real put_sum = npv_put + ( npv_fwd - strike.
value() ) * discountCurve->discount(expiry);
287 Real put_premium_sum = npv_put_premium + ( npv_fwd - strike.
value() ) * discountCurve->discount(expiry);
289 BOOST_CHECK_CLOSE(npv_call, put_sum, 0.001);
290 BOOST_CHECK_CLOSE(npv_call_premium, put_premium_sum, 0.001);
292 Settings::instance().evaluationDate() = today;
294BOOST_AUTO_TEST_SUITE_END()
296BOOST_AUTO_TEST_SUITE_END()
Builder that returns an engine to price an equity forward.
Engine builder for equity futures options.
Engine builder for equity options.
Serializable object holding generic trade data, reporting dimensions.
Serializable EQ Futures Option.
void build(const QuantLib::ext::shared_ptr< EngineFactory > &) override
Build QuantLib/QuantExt instrument, link pricing engine.
Serializable Equity Option.
void build(const QuantLib::ext::shared_ptr< EngineFactory > &) override
Build QuantLib/QuantExt instrument, link pricing engine.
static const string defaultConfiguration
Default configuration label.
map< pair< string, string >, QuantLib::Handle< QuantExt::EquityIndex2 > > equityCurves_
map< pair< string, string >, Handle< BlackVolTermStructure > > fxVols_
QuantLib::ext::shared_ptr< FXTriangulation > fx_
map< tuple< string, YieldCurveType, string >, Handle< YieldTermStructure > > yieldCurves_
map< pair< string, string >, Handle< Quote > > equitySpots_
Handle< Quote > equitySpot(const string &eqName, const string &configuration=Market::defaultConfiguration) const override
Equity curves.
map< pair< string, string >, Handle< BlackVolTermStructure > > equityVols_
Handle< YieldTermStructure > yieldCurve(const YieldCurveType &type, const string &ccy, const string &configuration=Market::defaultConfiguration) const override
Yield Curves.
Serializable object holding option data.
Serializable object holding premium data.
const QuantLib::ext::shared_ptr< InstrumentWrapper > & instrument() const
QuantLib::Real value() const
A class to hold pricing engine parameters.
Equity Forward data model and serialization.
EQ Futures Option data model and serialization.
Equity Option data model and serialization.
BOOST_AUTO_TEST_CASE(testEquityTradePrices)
Currency parseCurrency(const string &s)
Convert text to QuantLib::Currency.
An implementation of the Market class that stores the required objects in maps.