88 {
89
90 BOOST_TEST_MESSAGE("Testing FX Asian option trade building with constant vol term structure");
91
92
93
94
95 std::vector<DiscreteAsianTestData> asians = {
96 {Option::Put, 90.0, 87.0, 0.06, 0.025, 0.0, 11.0 / 12.0, 2, 0.13, 1.3942835683},
97 {Option::Put, 90.0, 87.0, 0.06, 0.025, 0.0, 11.0 / 12.0, 4, 0.13, 1.5852442983},
98 {Option::Put, 90.0, 87.0, 0.06, 0.025, 0.0, 11.0 / 12.0, 8, 0.13, 1.66970673},
99 {Option::Put, 90.0, 87.0, 0.06, 0.025, 0.0, 11.0 / 12.0, 12, 0.13, 1.6980019214},
100 {Option::Put, 90.0, 87.0, 0.06, 0.025, 0.0, 11.0 / 12.0, 26, 0.13, 1.7255070456},
101 {Option::Put, 90.0, 87.0, 0.06, 0.025, 0.0, 11.0 / 12.0, 52, 0.13, 1.7401553533},
102 {Option::Put, 90.0, 87.0, 0.06, 0.025, 0.0, 11.0 / 12.0, 100, 0.13, 1.7478303712},
103 {Option::Put, 90.0, 87.0, 0.06, 0.025, 1.0 / 12.0, 11.0 / 12.0, 2, 0.13, 1.8496053697},
104 {Option::Put, 90.0, 87.0, 0.06, 0.025, 1.0 / 12.0, 11.0 / 12.0, 4, 0.13, 2.0111495205},
105 {Option::Put, 90.0, 87.0, 0.06, 0.025, 1.0 / 12.0, 11.0 / 12.0, 8, 0.13, 2.0852138818},
106 {Option::Put, 90.0, 87.0, 0.06, 0.025, 1.0 / 12.0, 11.0 / 12.0, 12, 0.13, 2.1105094397},
107 {Option::Put, 90.0, 87.0, 0.06, 0.025, 1.0 / 12.0, 11.0 / 12.0, 26, 0.13, 2.1346526695},
108 {Option::Put, 90.0, 87.0, 0.06, 0.025, 1.0 / 12.0, 11.0 / 12.0, 52, 0.13, 2.147489651},
109 {Option::Put, 90.0, 87.0, 0.06, 0.025, 1.0 / 12.0, 11.0 / 12.0, 100, 0.13, 2.154728109},
110 {Option::Put, 90.0, 87.0, 0.06, 0.025, 3.0 / 12.0, 11.0 / 12.0, 2, 0.13, 2.63315092584},
111 {Option::Put, 90.0, 87.0, 0.06, 0.025, 3.0 / 12.0, 11.0 / 12.0, 4, 0.13, 2.76723962361},
112 {Option::Put, 90.0, 87.0, 0.06, 0.025, 3.0 / 12.0, 11.0 / 12.0, 8, 0.13, 2.83124836881},
113 {Option::Put, 90.0, 87.0, 0.06, 0.025, 3.0 / 12.0, 11.0 / 12.0, 12, 0.13, 2.84290301412},
114 {Option::Put, 90.0, 87.0, 0.06, 0.025, 3.0 / 12.0, 11.0 / 12.0, 26, 0.13, 2.88179560417},
115 {Option::Put, 90.0, 87.0, 0.06, 0.025, 3.0 / 12.0, 11.0 / 12.0, 52, 0.13, 2.88447044543},
116 {Option::Put, 90.0, 87.0, 0.06, 0.025, 3.0 / 12.0, 11.0 / 12.0, 100, 0.13, 2.89985329603}};
117
118 Date asof = Date(01, Feb, 2021);
120 QuantLib::ext::shared_ptr<EngineFactory> engineFactory;
121 QuantLib::ext::shared_ptr<Market> market;
122
123 for (const auto& a : asians) {
124 Time deltaT = a.length / (a.fixings - 1);
125 Date expiry;
126 vector<Date> fixingDates(a.fixings);
127 vector<std::string> strFixingDates(a.fixings);
128 for (Size i = 0; i < a.fixings; ++i) {
129 fixingDates[i] = (asof + static_cast<Integer>((a.firstFixing + i * deltaT) * 360 + 0.5));
130 strFixingDates[i] =
to_string(fixingDates[i]);
131 }
132 expiry = fixingDates[a.fixings - 1];
133
134 ScheduleDates scheduleDates(
"NullCalendar",
"",
"", strFixingDates);
136
137 market = QuantLib::ext::make_shared<TestMarket>(a.spot, expiry, a.domesticRate, a.foreignRate, a.volatility);
138 QuantLib::ext::shared_ptr<EngineData> engineData = QuantLib::ext::make_shared<EngineData>();
139 std::string productName = "FxAsianOptionArithmeticPrice";
140 engineData->model(productName) = "GarmanKohlhagen";
141 engineData->engine(productName) = "MCDiscreteArithmeticAPEngine";
142 engineData->engineParameters(productName) = {{"ProcessType", "Discrete"}, {"BrownianBridge", "True"},
143 {"AntitheticVariate", "False"}, {"ControlVariate", "True"},
144 {"RequiredSamples", "2047"}, {"Seed", "0"}};
145 engineFactory = QuantLib::ext::make_shared<EngineFactory>(engineData, market);
146
147
148 Settings::instance().evaluationDate() = market->asofDate();
149
150
152 OptionData optionData(
"Long",
to_string(a.type),
"European",
true, {to_string(expiry)},
"Cash",
"",
153 premiumData,
154 vector<Real>(), vector<Real>(), "", "", "", vector<string>(), vector<string>(), "", "",
155 "", "Asian", "Arithmetic", boost::none, boost::none, boost::none);
156
157 QuantLib::ext::shared_ptr<FxAsianOption> asianOption = QuantLib::ext::make_shared<FxAsianOption>(
158 env,
"FxAsianOption", 1.0,
TradeStrike(a.strike,
"USD"), optionData, scheduleData,
159 QuantLib::ext::make_shared<FXUnderlying>("FX", "ECB-JPY-USD", 1.0), Date(), "USD");
160 BOOST_CHECK_NO_THROW(asianOption->build(engineFactory));
161
162
163 QuantLib::ext::shared_ptr<Instrument> qlInstrument = asianOption->instrument()->qlInstrument();
164
165 QuantLib::ext::shared_ptr<DiscreteAveragingAsianOption> discreteAsian =
166 QuantLib::ext::dynamic_pointer_cast<DiscreteAveragingAsianOption>(qlInstrument);
167
168 BOOST_CHECK(discreteAsian);
169 BOOST_CHECK_EQUAL(discreteAsian->exercise()->type(), Exercise::Type::European);
170 BOOST_CHECK_EQUAL(discreteAsian->exercise()->dates().size(), 1);
171 BOOST_CHECK_EQUAL(discreteAsian->exercise()->dates()[0], expiry);
172
173 QuantLib::ext::shared_ptr<TypePayoff> payoff = QuantLib::ext::dynamic_pointer_cast<TypePayoff>(discreteAsian->payoff());
174 BOOST_CHECK(payoff);
175 BOOST_CHECK_EQUAL(payoff->optionType(), a.type);
176
177 Real expectedPrice = a.expectedNPV;
178
179
180 BOOST_CHECK_SMALL(asianOption->instrument()->NPV() - expectedPrice, 2e-2);
181 }
182 }
Serializable object holding generic trade data, reporting dimensions.
Serializable object holding option data.
Serializable object holding premium data.
Serializable schedule data.
Serializable object holding schedule Dates data.
std::string to_string(const LocationInfo &l)