protected void PrePorcessData(RateSet rateSetMC, ISingleRateCurve DiscountingCurve) { this.refDate = rateSetMC.refDate; this.DCurve = DiscountingCurve; // my curve used in discounting FWDInterpolator = new Interpolation(); // Interpolator used in fwd this.mktRateSet = rateSetMC; // pass market rate set // Create Building block IEnumerable <BuildingBlock> BB = mktRateSet.GetArrayOfBB(); // Sort ascending end date BBArray = from c in BB orderby c.endDate.SerialValue ascending select c; // Only Given Swap from BBArray OnlyGivenSwap = (from c in BBArray where c.GetType().BaseType == typeof(SwapStyle) select(SwapStyle) c).ToArray(); // validating underlying tenor: swap should be all vs the same tenor string UnderlyingTenor = ((SwapStyle)OnlyGivenSwap.First()).swapLeg2.UnderlyingRateTenor; // 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(); // From date of each fwd rate from longer swap(LS) // FromDatesSerial = Date.GetSerialValue(OnlyGivenSwap.Last().scheduleLeg2.fromDates); List <double> SerialDate = (from c in OnlyGivenSwap select c.scheduleLeg2.fromDates.Last().SerialValue).ToList <double>(); // adding reference date at beginning (this is important since I use the fixing) SerialDate.Insert(0, refDate.SerialValue); FromDatesSerial = SerialDate.ToArray(); // some data validation: swap should be all of same building block // the type of building block BuildingBlockType BBT = OnlyGivenSwap[0].buildingBlockType; // Are all them the same? bool IsSameSwapType = OnlyGivenSwap.All(s => s.buildingBlockType == BBT); if (IsSameSwapType) // if true { // it is swap type used as inputs (i.e. EurSwapVs6m, EurSwapVs3m, ...) SwapType = (SwapStyle) new BuildingBlockFactory().CreateEmptyBuildingBlock(BBT); } else { throw new ArgumentException("error in building blocktype"); // if not throw an exception } }
// return array of curves, initialised after shifting mktRateSet elements public ISingleRateCurve[] ShiftedCurveArray(double shift) { // i-curve is built using its setup (interpolator,..), but shifting i-element of mktRateSet // up of 'shift' quantity RateSet[] rsArr = mktRateSet.ShiftedRateSetArray(shift); // array of shifted RateSet (my scenario) int n = rsArr.Length; // number of elements ISingleRateCurve[] curves = new ISingleRateCurve[n]; // array of curves for (int i = 0; i < n; i++) { // iterate to build all curve needed curves[i] = CreateInstance(rsArr[i]); // build the correct curve } return(curves); }
public IMultiRateCurve CreateInstance(RateSet newRateSet, ISingleRateCurve newDiscountingCurve) { return(new MultiCurveBuilder <Interpolation>(newRateSet, newDiscountingCurve)); }
// Constructor public MultiCurveBuilder3(RateSet rateSetMC, ISingleRateCurve DiscountingCurve) { PrePorcessData(rateSetMC, DiscountingCurve); Solve(); }