// Methods #region Protected Methods used in constructor // Prepare data to be used in Solve() protected override void PreProcessInputs() { // PreProcessInputs() // 1) fill missing data // -find missing swap; // -create them; // -interpolate value of them according to interpolator // 2) Create PreProcessedData: merge missing data with starting available data // fill missing int MaxSwapTenor = OnlyGivenSwap.Last().Tenor.tenor; // Max tenor of available swap List <BuildingBlock> MissingSwapList = new List <BuildingBlock>(); // List of missing swap // Add Missing Swap to MissingSwapList BuildingBlockFactory f = new BuildingBlockFactory(); // factory to create missing building block for (int i = 1; i < MaxSwapTenor; i++) { Period p = new Period(i, TenorType.Y); // needed period if (!OnlyGivenSwap.Any(bb => bb.Tenor.GetPeriodStringFormat() == p.GetPeriodStringFormat())) { // Check if in OnlyGivenSwap period "p" exists. // if not, it starts creating missing swap. Rate 0.0 just to initialise MissingSwapList.Add(f.CreateBuildingBlock(refDate, 0.0, p.GetPeriodStringFormat(), SwapType.buildingBlockType)); } } // interpolate missing rate using given data: it interpolates directly on markets rate IEnumerable <double> xGivenDays = from c in OnlyGivenSwap select c.endDate.SerialValue; IEnumerable <double> yGivenSwap = from c in OnlyGivenSwap select c.rateValue; // Set up interpolator OneDimInterpFactory iFactory = new OneDimInterpFactory(); IInterpolate iSwap = iFactory.FactoryMethod(MissingRateInterp, xGivenDays.ToArray(), yGivenSwap.ToArray()); // Missing swap with interpolated value IEnumerable <BuildingBlock> MissingSwap = from c in MissingSwapList select f.CreateBuildingBlock(c.refDate, iSwap.Solve(c.endDate.SerialValue), c.Tenor.GetPeriodStringFormat(), c.buildingBlockType); // Complete Filled data ready to be bootstrapped PreProcessedData = from c in BBArray.Union(MissingSwap) orderby c.endDate.SerialValue ascending select c; }
// 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 }