// 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; }
// sort BB in ascending order and create BBs. return array of BB public BuildingBlock[] GetArrayOfBB() { SortMaturity(); // sort IBuildingBlockFactory factory = new BuildingBlockFactory(); // my factory int N = List.Count; // Number of elements BuildingBlock[] outPut = new BuildingBlock[N]; // initialise outPut array // create each Building Block for (int i = 0; i < N; i++) { outPut[i] = factory.CreateBuildingBlock(refDate, Item(i).V, Item(i).M.GetPeriodStringFormat(), Item(i).T); } // outPut return(outPut); }