154 {
155
156 const Date& accrStartDate = valuationSchedule.dates().back();
157 const Date& accrEndDate = laggedValuationSchedule.dates().back();
158
159 Variances res;
160
161 for (Size i = 0; i < valuationSchedule.size(); i++) {
162 const Date& vd = valuationSchedule.dates()[i];
163 const Date& lvd = laggedValuationSchedule.dates()[i];
164
165
166 if (lvd <= evalDate) {
167 Real price1 =
index1_->fixing(vd);
168 Real laggedPrice1 =
index1_->fixing(lvd);
169 Real variation1 = std::log(laggedPrice1 / price1);
170 res.accruedVariance1 += variation1 * variation1;
171
172 Real price2 =
index2_->fixing(vd);
173 Real laggedPrice2 =
index2_->fixing(lvd);
174 Real variation2 = std::log(laggedPrice2 / price2);
175 res.accruedVariance2 += variation2 * variation2;
176
177 Real basketPrice = price1 + price2;
178 Real laggedBasketPrice = laggedPrice1 + laggedPrice2;
179 Real basketVariation = std::log(laggedBasketPrice / basketPrice);
180 res.accruedBasketVariance += basketVariation * basketVariation;
181 } else {
182
183 Real expectedN = valuationSchedule.dates().size() - 1.0;
184 Real factor = 252 / (expectedN *
arguments_.accrualLag);
185 res.accruedVariance1 *= factor;
186 res.accruedVariance2 *= factor;
187 res.accruedBasketVariance *= factor;
188
189
190 Real t = ActualActual(ActualActual::ISDA).yearFraction(evalDate, accrEndDate);
191 Real F1 =
193 Real F2 =
195
196 Real variance1 =
process1_->blackVolatility()->blackVariance(t, F1);
197 Real variance2 =
process2_->blackVolatility()->blackVariance(t, F2);
198 Real basketVariance =
199 variance1 + variance2 + 2.0 * std::sqrt(variance1) * std::sqrt(variance2) *
correlation_->value();
200
201 res.futureVariance1 = variance1;
202 res.futureVariance2 = variance2;
203 res.futureBasketVariance = basketVariance;
204 break;
205 }
206 }
207
208 Calendar jointCal =
209 JointCalendar(std::vector<Calendar>{valuationSchedule.calendar(), laggedValuationSchedule.calendar(),
211 Real accrTime = std::abs(jointCal.businessDaysBetween(accrStartDate, evalDate, true, true));
212 Real futTime = std::abs(jointCal.businessDaysBetween(evalDate, accrEndDate, true, false));
213 Real totalTime = accrTime + futTime;
214 Real accrFactor = accrTime / totalTime;
215 Real futFactor = futTime / totalTime;
216
217 res.totalVariance1 = (res.accruedVariance1 * accrFactor) + (res.futureVariance1 * futFactor);
218 res.totalVariance2 = (res.accruedVariance2 * accrFactor) + (res.futureVariance2 * futFactor);
219 res.totalBasketVariance = (res.accruedBasketVariance * accrFactor) + (res.futureBasketVariance * futFactor);
220
221 return res;
222}