72 {
73
74 for (Size i = 0; i <
arguments_.currency.size(); i++) {
76 Handle<YieldTermStructure> yts =
fetchTS(ccy);
77 QL_REQUIRE(!yts.empty(), "Discounting term structure is "
78 "empty for "
79 << ccy.name());
80 Handle<Quote> fxQuote =
fetchFX(ccy);
81 QL_REQUIRE(!fxQuote.empty(), "FX quote is empty "
82 "for "
83 << ccy.name());
84 }
85
86
88
89
91 results_.errorEstimate = Null<Real>();
92
93
95 results_.inCcyLegNPV.resize(numLegs);
96
97
98
99 std::map<Currency, std::map<Date, Real>, CurrencyComparator> deltaDiscountRaw, deltaForwardRaw, gammaDiscountRaw;
100 std::map<Currency, std::map<std::pair<Date, Date>, Real>, CurrencyComparator> gammaForwardRaw, gammaDscFwdRaw;
101 std::map<Currency, Real, CurrencyComparator> fxLinkedForeignNpv;
102 std::map<Currency, Real, CurrencyComparator> fxSpot, fxSpotDelta;
103 std::set<Currency, CurrencyComparator>
currencies;
104 std::map<Date, Real> empty, fxLinkedDeltaEmpty;
105
106 for (Size i = 0; i < numLegs; ++i) {
107 try {
109
110
111
112
113 Currency ccy2;
114 Real fx2 = 1.0;
115 for (Size j = 0; j < numLegs; ++j) {
119 fxSpot[ccy2] = fx2;
120 }
121 }
122
124 Handle<YieldTermStructure> yts =
fetchTS(ccy);
125 Real npv = 0.0, bps = 0.0, simpleCashFlowNpv = 0.0;
126 Real fxLinkedForeignNpvTmp = 0.0;
127 detail::NpvDeltaGammaCalculator calc(
129 deltaForwardRaw[ccy], empty, gammaDiscountRaw[ccy], gammaForwardRaw[ccy], gammaDscFwdRaw[ccy], empty,
130 fxLinkedForeignNpvTmp,
133 for (Size ii = 0; ii < leg.size(); ++ii) {
134 CashFlow& cf = *leg[ii];
135 if (cf.date() <= yts->referenceDate()) {
136 continue;
137 }
138 cf.accept(calc);
139 }
140 Real fx =
fetchFX(ccy)->value();
141 fxSpotDelta[ccy] += npv;
142 fxSpot[ccy] = fx;
143 results_.inCcyLegNPV[i] = npv + simpleCashFlowNpv;
146
147
148
149 if (!ccy2.empty()) {
150 fxSpotDelta[ccy] -= fxLinkedForeignNpvTmp * fx2 / fx;
151 fxLinkedForeignNpv[ccy2] += fxLinkedForeignNpvTmp;
152 }
153 } catch (std::exception& e) {
154 QL_FAIL("DiscountingCurrencySwapEngineDeltaGamma, leg " << i << ": " << e.what());
155 }
156 }
157
158
159
160 for (auto const& f : fxLinkedForeignNpv) {
161 fxSpotDelta[f.first] += f.second;
162 }
163
164
165
166 results_.additionalResults[
"fxSpot"] = fxSpot;
167 results_.additionalResults[
"deltaFxSpot"] = fxSpotDelta;
168
169
170
172
174 std::map<Currency, std::vector<Real>, CurrencyComparator> deltaDiscount, deltaForward;
175 for (std::map<Currency, std::map<Date, Real>, CurrencyComparator>::const_iterator i = deltaDiscountRaw.begin();
176 i != deltaDiscountRaw.end(); ++i) {
177 Handle<YieldTermStructure> yts =
fetchTS(i->first);
178 deltaDiscount[i->first] =
180 }
181 results_.additionalResults[
"deltaDiscount"] = deltaDiscount;
182
183 for (std::map<Currency, std::map<Date, Real>, CurrencyComparator>::const_iterator i = deltaForwardRaw.begin();
184 i != deltaForwardRaw.end(); ++i) {
185 Handle<YieldTermStructure> yts =
fetchTS(i->first);
186 deltaForward[i->first] =
188 }
189 results_.additionalResults[
"deltaForward"] = deltaForward;
190 }
191
192
193
195 std::map<Currency, Matrix, CurrencyComparator> gamma;
197 Handle<YieldTermStructure> yts =
fetchTS(*i);
198 Matrix tmp =
200 true, yts->referenceDate(), yts->dayCounter(),
linearInZero_);
201 gamma[*i] = tmp;
202 }
203 results_.additionalResults[
"gamma"] = gamma;
204 }
205
206}
const Instrument::results * results_
Handle< Quote > fetchFX(Currency ccy) const
Handle< YieldTermStructure > fetchTS(Currency ccy) const
Matrix rebucketGammas(const std::vector< Time > &gammaTimes, const std::map< Date, Real > &gammaDscRaw, std::map< std::pair< Date, Date >, Real > &gammaForward, std::map< std::pair< Date, Date >, Real > &gammaDscFwd, const bool forceFullMatrix, const Date &referenceDate, const DayCounter &dc, const bool linearInZero)
std::vector< Real > rebucketDeltas(const std::vector< Time > &deltaTimes, const std::map< Date, Real > &deltaRaw, const Date &referenceDate, const DayCounter &dc, const bool linearInZero)
Swap::arguments * arguments_