/// <summary> /// </summary> /// <param name="date"></param> /// <returns></returns> public double GetForwardRate(Date date) { //TODO: Index should store the business day and daycount conventions of the index. if (date > discountCurve.GetAnchorDate()) { var df1 = discountCurve.GetDF(date); var laterDate = date.AddTenor(index.tenor); var df2 = discountCurve.GetDF(laterDate); var dt = (laterDate - date) / 365.0; var fwdRate = (df1 / df2 - 1) / dt; return(fwdRate); } return(fixingCurve.GetForwardRate(date)); }
/// <summary> /// Curve based valuation of <see cref="FloatLeg"/>. Assumes that correct forecast and discount curves have been provided. /// </summary> /// <param name="leg"></param> /// <param name="forecastCurve"></param> /// <param name="discountCurve"></param> /// <returns></returns> public static double CurvePV(this FloatLeg leg, IFloatingRateSource forecastCurve, IDiscountingSource discountCurve) { var legIndex = forecastCurve.GetFloatingIndex(); var resetDates1 = leg.GetRequiredIndexDates(legIndex); var indexValues1 = new double[resetDates1.Count]; for (var i = 0; i < resetDates1.Count; i++) { indexValues1[i] = forecastCurve.GetForwardRate(resetDates1[i]); } leg.SetIndexValues(legIndex, indexValues1); var cfs1 = leg.GetCFs(); var value1 = cfs1.PV(discountCurve); return(value1); }
public static ResultStore InflationLinkedSwapMeasures(this InflationLinkedSwap inflationLinkedSwap, Date[] cpiDates, double[] cpiRates, IFloatingRateSource forecastCurve) { //Create Inflation Swap var swap = CreateInflationLinkedSwap(inflationLinkedSwap.payFixed, inflationLinkedSwap.startDate, inflationLinkedSwap.nominal, inflationLinkedSwap.tenor, inflationLinkedSwap.fixedRate, inflationLinkedSwap.index, inflationLinkedSwap.spread, inflationLinkedSwap.zaCalendar, inflationLinkedSwap.ccy); //Set value date swap.SetValueDate(inflationLinkedSwap.startDate); //Set index values var indexValues = new double[swap.indexDates.Length]; for (var i = 0; i < swap.indexDates.Length; i++) { indexValues[i] = forecastCurve.GetForwardRate(swap.indexDates[i]); } swap.SetIndexValues(swap.index, indexValues); //Determine swap end date var unAdjEndDate = inflationLinkedSwap.startDate.AddMonths(12 * inflationLinkedSwap.tenor.Years); var endDate = BusinessDayStore.ModifiedFollowing.Adjust(unAdjEndDate, inflationLinkedSwap.zaCalendar); //Calculate value of fixed and floating cashflows var floatingCashFlows = swap.GetCFs(); var floatingLegCashFlows = floatingCashFlows.Last().Amount; var cpiStartDate = LaggedCPI.GetCPI(inflationLinkedSwap.startDate, cpiDates, cpiRates); var cpiEndDate = LaggedCPI.GetCPI(endDate, cpiDates, cpiRates); var fixedCashFlows = inflationLinkedSwap.payFixed * inflationLinkedSwap.nominal * Math.Pow((1 + inflationLinkedSwap.fixedRate / 2), 2 * (endDate - inflationLinkedSwap.startDate) / 365) * cpiEndDate / cpiStartDate; var netCashFlows = floatingLegCashFlows + fixedCashFlows; // Store results var results = new ResultStore(); results.Add(Keys.FloatingLegCashFlows, floatingLegCashFlows); results.Add(Keys.FixedLegCashFlows, fixedCashFlows); results.Add(Keys.NetCashFlows, netCashFlows); return(results); }
public double GetForwardRate(Date date) { double rate = spline.Interpolate(date); return(underlyingCurve.GetForwardRate(date) + rate); }
public double Objective() { return(1e6 * (_curve.GetForwardRate(_startDate) - _simpleRate)); }