Beispiel #1
0
        //swap curve building for both pricing and pnl,   bond curve building only,  not for pnl
        public YieldCurve(
            string name,
            Date referenceDate,
            MarketInstrument[] marketInstruments,
            BusinessDayConvention bda,
            IDayCount dayCount,
            ICalendar calendar,
            CurrencyCode currency,
            Compound compound,
            Interpolation interpolation,
            YieldCurveTrait trait,
            IMarketCondition baseMarket = null,
            Expression <Func <IMarketCondition, object> >[] calibrateMktUpdateCondition = null,
            ISpread spread     = null,
            Date[] knotPoints  = null,
            string[] keyTenors = null,
            InstrumentCurveDefinition rawDefinition = null
            )
        {
            Name          = name;
            ReferenceDate = referenceDate;
            Currency      = currency;
            Bda           = bda;
            DayCount      = dayCount;
            Compound      = compound;
            Calendar      = calendar;
            Interpolation = interpolation;
            Trait         = trait;
            RawDefinition = rawDefinition;
            var tempMarketInstruments     = marketInstruments.OrderBy(x => x.Instrument.UnderlyingMaturityDate).ToArray();
            var uniqueTenorMktInstruments = new List <MarketInstrument> {
                tempMarketInstruments[0]
            };

            for (var i = 1; i < tempMarketInstruments.Length; ++i)
            {
                if (tempMarketInstruments[i].Instrument.GetCalibrationDate() != tempMarketInstruments[i - 1].Instrument.GetCalibrationDate())
                {
                    uniqueTenorMktInstruments.Add(tempMarketInstruments[i]);
                }
            }
            MarketInstruments = uniqueTenorMktInstruments.ToArray();
            InputRateByTenor  = MarketInstruments.ToDictionary(p => p.Instrument.Tenor, p => p.TargetValue);

            BaseMarket = baseMarket;
            Spread     = spread ?? new ZeroSpread(0.0);
            CalibrateMktUpdateCondition = calibrateMktUpdateCondition;

            if (MarketInstruments.Any(x => x.Instrument is Bond))
            {
                var err = double.NaN;
                KeyPoints    = BondCurveCalibrator.Calibrate(Name, ReferenceDate, MarketInstruments.ToArray(), Bda, DayCount, Calendar, Compound, Interpolation, Trait, Currency, knotPoints, out err, baseMarket, CalibrateMktUpdateCondition);
                fittingError = err;
            }
            else
            {
                KeyPoints = YieldCurveCalibrator.Calibrate(name, ReferenceDate, MarketInstruments.ToArray(), Bda, DayCount, Calendar, Compound, Interpolation, Trait, Currency, baseMarket, CalibrateMktUpdateCondition);
            }


            //if (KeyPoints.Select(x => x.Item1).Any(z => z is Date))
            //{
            //	_curve = new Curve<Date>(ReferenceDate, KeyPoints, x => x.ToOADate(), interpolation);
            //}
            _curveXInYears = new Curve <double>(0.0,
                                                KeyPoints.Select(x => Tuple.Create(DayCount.CalcDayCountFraction(ReferenceDate, x.Item1), x.Item2)).ToArray(),
                                                x => x,
                                                Interpolation);
        }