public override void addTimesTo(List <double> times) { calculate(); Swaption.Arguments args = new Swaption.Arguments(); swaption_.setupArguments(args); List <double> swaptionTimes = new DiscretizedSwaption(args, termStructure_.link.referenceDate(), termStructure_.link.dayCounter()).mandatoryTimes(); for (int i = 0; i < swaptionTimes.Count; i++) { times.Insert(times.Count, swaptionTimes[i]); } }
public override void calculate() { Utils.QL_REQUIRE(arguments_.settlementMethod != Settlement.Method.ParYieldCurve, () => "cash-settled (ParYieldCurve) swaptions not priced with tree engine"); Utils.QL_REQUIRE(model_ != null, () => "no model specified"); Date referenceDate; DayCounter dayCounter; ITermStructureConsistentModel tsmodel = (ITermStructureConsistentModel)base.model_.link; try { if (tsmodel != null) { referenceDate = tsmodel.termStructure().link.referenceDate(); dayCounter = tsmodel.termStructure().link.dayCounter(); } else { referenceDate = termStructure_.link.referenceDate(); dayCounter = termStructure_.link.dayCounter(); } } catch { referenceDate = termStructure_.link.referenceDate(); dayCounter = termStructure_.link.dayCounter(); } DiscretizedSwaption swaption = new DiscretizedSwaption(arguments_, referenceDate, dayCounter); Lattice lattice; if (lattice_ != null) { lattice = lattice_; } else { List <double> times = swaption.mandatoryTimes(); TimeGrid timeGrid = new TimeGrid(times, times.Count, timeSteps_); lattice = model_.link.tree(timeGrid); } List <double> stoppingTimes = new InitializedList <double>(arguments_.exercise.dates().Count); for (int i = 0; i < stoppingTimes.Count; ++i) { stoppingTimes[i] = dayCounter.yearFraction(referenceDate, arguments_.exercise.date(i)); } swaption.initialize(lattice, stoppingTimes.Last()); double nextExercise; List <double> listExercise = new List <double>(); listExercise.AddRange(stoppingTimes.FindAll(x => x >= 0)); nextExercise = listExercise[0]; swaption.rollback(nextExercise); results_.value = swaption.presentValue(); }