// Prepare data to be used in Solve() protected override void PreProcessInputs() { /* * 1) Check if input data are ok (data validation): from date contained * 2) I choose the Longer Swap (LS) * 3) I get array of dates of payment of LS (pass it to data member) * 4) I get array of year fraction of LS (pass it to data member) */ // From date of each fwd rate from longer swap(LS) List <double> FromDatesSerial = Date.GetSerialValue(OnlyGivenSwap.Last().scheduleLeg2.fromDates).ToList <double>(); // validating underlying tenor: swap should be all vs the same tenor string UnderlyingTenor = ((SwapStyle)OnlyGivenSwap.First()).swapLeg2.UnderlyingRateTenor; foreach (SwapStyle b in OnlyGivenSwap) { // Check if contained if (!FromDatesSerial.Contains(((SwapStyle)b).scheduleLeg2.fromDates.Last().SerialValue)) { throw new ArgumentException("From date not contained"); } } DateDf = new SortedList <double, double>(); // Inizialize DateDF DateDf.Add(refDate.SerialValue, 1.0); // first discount factor // IEnumerable<KeyValuePair<double,double>> var f = from c in BBArray where c.GetType().BaseType == typeof(OnePaymentStyle) where c.endDate != refDate.add_period(UnderlyingTenor) let yf = refDate.YF(c.endDate, c.dayCount) // year fraction let df = Formula.DFsimple(yf, c.rateValue) // calculate discount factor select new KeyValuePair <double, double>(c.endDate.SerialValue, df); foreach (KeyValuePair <double, double> kpv in f) { DateDf.Add(kpv.Key, kpv.Value); } // Getting the fixing fixing = (from c in BBArray where c.GetType().BaseType == typeof(OnePaymentStyle) where c.endDate == refDate.add_period(UnderlyingTenor) select c.rateValue).Single(); // Inizialize some data member SwapStyle LongerSwap = OnlyGivenSwap.Last(); // Swap with longer maturity // Year Fraction of floating leg of longer swap. It is needed to calculate DF yfFloatLegLongerSwap = LongerSwap.scheduleLeg2.GetYFVect(LongerSwap.swapLeg2.DayCount); // floating leg is leg 2 // Dates on which I calculate Df DatesDfLongerSwap = Date.GetSerialValue(LongerSwap.scheduleLeg2.payDates); // number of fwd rate to find N = DatesDfLongerSwap.Length; // fwd rate of longer swap fwdGuessLongerSwap = new double[N]; fwdGuessLongerSwap[0] = fixing; // first is the fixing }