public VanillaSwap value()
{
Date startDate;
if (effectiveDate_ != null)
{
startDate = effectiveDate_;
}
else
{
int fixingDays = iborIndex_.fixingDays();
Date referenceDate = Settings.evaluationDate();
Date spotDate = floatCalendar_.advance(referenceDate, new Period(fixingDays, TimeUnit.Days));
startDate = spotDate + forwardStart_;
}
Date endDate;
if (terminationDate_ != null)
{
endDate = terminationDate_;
}
else
{
endDate = startDate + swapTenor_;
}
Schedule fixedSchedule = new Schedule(startDate, endDate,
fixedTenor_, fixedCalendar_,
fixedConvention_, fixedTerminationDateConvention_,
fixedRule_, fixedEndOfMonth_,
fixedFirstDate_, fixedNextToLastDate_);
Schedule floatSchedule = new Schedule(startDate, endDate,
floatTenor_, floatCalendar_,
floatConvention_, floatTerminationDateConvention_,
floatRule_, floatEndOfMonth_,
floatFirstDate_, floatNextToLastDate_);
double?usedFixedRate = fixedRate_;
if (fixedRate_ == null) // calculate a fair fixed rate if no fixed rate is provided
{
if (iborIndex_.forwardingTermStructure().empty())
{
throw new ArgumentException("no forecasting term structure set to " + iborIndex_.name());
}
VanillaSwap temp = new VanillaSwap(type_, nominal_, fixedSchedule, 0.0, fixedDayCount_,
floatSchedule, iborIndex_, floatSpread_, floatDayCount_);
temp.setPricingEngine(new DiscountingSwapEngine(iborIndex_.forwardingTermStructure()));
usedFixedRate = temp.fairRate();
}
VanillaSwap swap = new VanillaSwap(type_, nominal_, fixedSchedule, usedFixedRate.Value, fixedDayCount_,
floatSchedule, iborIndex_, floatSpread_, floatDayCount_);
swap.setPricingEngine(engine_);
return(swap);
}