private DatesAndRates InitializeCurve(Date calibrationDate, InitialValueCollector initialValueCollector,
                                              ObjectiveFunction objective, DiscountingSourceDescription curveToStrip,
                                              IEnumerable <FloatRateIndex> indicesToBaseOffCurve)
        {
            if (curveToStrip == null)
            {
                return(null);
            }
            var curveNames = new List <string> {
                curveToStrip.Name
            };
            var indices = indicesToBaseOffCurve.ToList();

            curveNames.AddRange(
                indices.Select(ind => new FloatingRateSourceDescription(ind).Name));
            var initial = initialValueCollector.GetValues(curveNames);
            var curve   = new DatesAndRates(curveToStrip.Currency, calibrationDate,
                                            initial.dates, initial.values);

            foreach (var index in indices)
            {
                var name = new FloatingRateSourceDescription(index).Name;
                _floatingRateSources[name] = new ForecastCurveFromDiscount(curve, index, null);
            }

            objective.AddCurve(curve, initial.values);
            return(curve);
        }
        public bool TryCalibrate(Date calibrationDate, IMarketDataContainer marketDataContainer)
        {
            _calibrationDate = calibrationDate;
            var initialValues = new InitialValueCollector(_calibrationDate, _instruments);

            var objective = new ObjectiveFunction();

            _curve = InitializeCurve(calibrationDate, initialValues, objective, _curveToStrip,
                                     _indicesToBaseOffDiscountCurve);
            _secondCurve = InitializeCurve(calibrationDate, initialValues, objective, _secondCurveToStrip,
                                           _indicesToBaseOffSecondCurve);
            objective.SetBenchmarkObjectives(_instruments, marketDataContainer);

            var result = _rootFinder.FindRoot(objective, objective.InitialValues);

            return(true);
        }