97 {
98
99 BOOST_TEST_MESSAGE("Testing Equity Coupon");
100
101
102 Settings::instance().evaluationDate() = Date(5, Jan, 2016);
103 Date today = Settings::instance().evaluationDate();
104
105 Date cfDate1(4, Dec, 2015);
106 Date cfDate2(5, Apr, 2016);
107 Date fixingDate1(31, Dec, 2015);
108 Date fixingDate2(1, Apr, 2016);
109
110 Real nominal = 1000000;
111 string eqName = "SP5";
112 QuantLib::ext::shared_ptr<SimpleQuote> sq = QuantLib::ext::make_shared<SimpleQuote>(2100);
113 Handle<Quote> spot(sq);
114 DayCounter dc = ActualActual(ActualActual::ISDA);
115 Calendar cal = TARGET();
116 Currency ccy = USDCurrency();
117 Natural fixingLag = 2;
118 Real divFactor = 1.0;
119 Handle<YieldTermStructure> dividend(
120 QuantLib::ext::shared_ptr<YieldTermStructure>(new FlatForward(0, cal, 0.01, dc)));
121 Handle<YieldTermStructure> equityforecast(
122 QuantLib::ext::shared_ptr<YieldTermStructure>(new FlatForward(0, cal, 0.02, dc)));
123
124 QuantLib::ext::shared_ptr<EquityIndex2> eqIndex =
125 QuantLib::ext::make_shared<EquityIndex2>(eqName, cal, ccy, spot, equityforecast, dividend);
126
127 eqIndex->addFixing(cfDate1, 2000);
128 eqIndex->addFixing(fixingDate1, 1980);
129
130
131 EquityCoupon eq1(cfDate2, nominal, today, cfDate2, 0, eqIndex, dc, EquityReturnType::Price);
132
133 EquityCoupon eq2(cfDate2, nominal, today, cfDate2, 0, eqIndex, dc, EquityReturnType::Total, divFactor);
134
135 EquityCoupon eq3(cfDate2, nominal, cfDate1, cfDate2, 0, eqIndex, dc, EquityReturnType::Price);
136
137 EquityCoupon eq4(cfDate2, nominal, today, cfDate2, fixingLag, eqIndex, dc, EquityReturnType::Total);
138
139
140 Handle<YieldTermStructure> domYTS(QuantLib::ext::shared_ptr<YieldTermStructure>(new FlatForward(0, cal, 0.01, dc)));
141 Handle<YieldTermStructure> forYTS(QuantLib::ext::shared_ptr<YieldTermStructure>(new FlatForward(0, cal, 0.02, dc)));
142 Handle<Quote> fxSpot(QuantLib::ext::make_shared<SimpleQuote>(1.1));
143 QuantLib::ext::shared_ptr<FxIndex> fxIndex =
144 QuantLib::ext::make_shared<FxIndex>("FX::EURUSD", 2, EURCurrency(), USDCurrency(), TARGET(), fxSpot, domYTS, forYTS);
145
146 fxIndex->addFixing(cfDate1, 1.09);
147
148
149 EquityCoupon eq5(cfDate2, nominal, today, cfDate2, 0, eqIndex, dc, EquityReturnType::Total, 1.0,
false,
150 Null<Real>(), Null<Real>(), Date(), Date(), Date(), Date(), Date(), fxIndex);
151
157 eq1.setPricer(pricer1);
158 eq2.setPricer(pricer2);
159 eq3.setPricer(pricer3);
160 eq4.setPricer(pricer4);
161 eq5.setPricer(pricer5);
162
163
164 Time dt = dc.yearFraction(today, cfDate2);
165 Real forward = spot->value() * std::exp((0.02 - 0.01) * dt);
166 Real expectedAmount = nominal * (forward - spot->value()) / spot->value();
167 BOOST_TEST_MESSAGE("Check Price Return is correct.");
168 BOOST_CHECK_CLOSE(eq1.amount(), expectedAmount, 1e-10);
169
170
171 forward = spot->value() * std::exp((0.02 - 0.01) * dt);
172 Real div = spot->value() * std::exp((0.02) * dt) - forward;
173 expectedAmount = nominal * (forward + divFactor * div - spot->value()) / spot->value();
174 BOOST_TEST_MESSAGE("Check Total Return is correct");
175 BOOST_CHECK_CLOSE(eq2.amount(), expectedAmount, 1e-10);
176
177
178 forward = spot->value() * std::exp((0.02 - 0.01) * dt);
179 expectedAmount = nominal * (forward - eqIndex->fixing(cfDate1)) / eqIndex->fixing(cfDate1);
180 BOOST_TEST_MESSAGE("Check Historical starting Price Return is correct.");
181 BOOST_CHECK_CLOSE(eq3.amount(), expectedAmount, 1e-10);
182
183
184 dt = dc.yearFraction(today, fixingDate2);
185 forward = spot->value() * std::exp(0.02 * dt);
186 expectedAmount = nominal * (forward - eqIndex->fixing(fixingDate1)) / eqIndex->fixing(fixingDate1);
187 BOOST_TEST_MESSAGE("Check Total Return fixing lag handling is correct.");
188 BOOST_CHECK_CLOSE(eq4.amount(), expectedAmount, 1e-10);
189
190
191 dt = dc.yearFraction(today, cfDate2);
192 forward = spot->value() * std::exp((0.02 - 0.01) * dt);
193 div = spot->value() * std::exp((0.02) * dt) - forward;
194 expectedAmount =
195 nominal * ((forward + div) * fxIndex->fixing(cfDate2) - spot->value() * 1.1) / (spot->value() * 1.1);
196 BOOST_TEST_MESSAGE("Check Total Return with underlying in different ccy handling is correct.");
197 BOOST_CHECK_CLOSE(eq5.amount(), expectedAmount, 1e-10);
198}
Pricer for equity coupons.