public double CalculateParRate(IFundingModel model) { var discountCurvePay = model.Curves[DiscountCurvePay]; var discountCurveRec = model.Curves[DiscountCurveRec]; var forecastCurvePay = model.Curves[ForecastCurvePay]; var forecastCurveRec = model.Curves[ForecastCurveRec]; var payCCY = MtmSwapType == MTMSwapType.ReceiveNotionalFixed ? CcyRec : CcyPay; var recCCY = MtmSwapType == MTMSwapType.PayNotionalFixed ? CcyPay : CcyRec; var baseCCY = Pvccy ?? payCCY; var fxPayToBase = model.GetFxRate(model.BuildDate, payCCY, baseCCY); var fxRecToBase = model.GetFxRate(model.BuildDate, recCCY, baseCCY); if (ParSpreadPay != 0.0) { var newSched = FlowSchedulePay.Clone(); var recPV = FlowScheduleRec.PV(discountCurveRec, forecastCurveRec, true, true, true, BasisRec, null); recPV *= fxRecToBase; var targetFunc = new Func <double, double>(spread => { foreach (var s in newSched.Flows.Where(x => x.FlowType == FlowType.FloatRate)) { s.FixedRateOrMargin = spread; } var pv = newSched.PV(discountCurvePay, forecastCurvePay, true, true, true, BasisPay, null); pv *= fxPayToBase; return(pv - recPV); } ); var newSpread = Math.Solvers.Newton1D.MethodSolve(targetFunc, 0, 0.000001); return(newSpread); } else { var newSched = FlowScheduleRec.Clone(); var payPV = FlowSchedulePay.PV(discountCurvePay, forecastCurvePay, true, true, true, BasisPay, null); payPV *= fxPayToBase; var targetFunc = new Func <double, double>(spread => { foreach (var s in newSched.Flows.Where(x => x.FlowType == FlowType.FloatRate)) { s.FixedRateOrMargin = spread; } var pv = newSched.PV(discountCurveRec, forecastCurveRec, true, true, true, BasisRec, null); pv *= fxRecToBase; return(pv - payPV); } ); var newSpread = Math.Solvers.Newton1D.MethodSolve(targetFunc, 0, 0.000001); return(newSpread); } }
public double Pv(IFundingModel model, bool updateState) { var updateDF = updateState || model.CurrentSolveCurve == DiscountCurve; var updatePayEst = updateState || model.CurrentSolveCurve == ForecastCurvePay; var updateRecEst = updateState || model.CurrentSolveCurve == ForecastCurveRec; var discountCurve = model.Curves[DiscountCurve]; var forecastCurvePay = model.Curves[ForecastCurvePay]; var forecastCurveRec = model.Curves[ForecastCurveRec]; var payPV = FlowSchedulePay.PV(discountCurve, forecastCurvePay, updateState, updateDF, updatePayEst, BasisPay, null); var recPV = FlowScheduleRec.PV(discountCurve, forecastCurveRec, updateState, updateDF, updateRecEst, BasisRec, null); return(payPV + recPV); }
public double CalculateParRate(IFundingModel model) { var discountCurve = model.Curves[DiscountCurve]; var forecastCurvePay = model.Curves[ForecastCurvePay]; var forecastCurveRec = model.Curves[ForecastCurveRec]; if (ParSpreadPay != 0.0) { var newSched = FlowSchedulePay.Clone(); var recPV = FlowScheduleRec.PV(discountCurve, forecastCurveRec, true, true, true, BasisRec, null); var targetFunc = new Func <double, double>(spread => { foreach (var s in newSched.Flows.Where(x => x.FlowType == FlowType.FloatRate)) { s.FixedRateOrMargin = spread; } var pv = newSched.PV(discountCurve, forecastCurvePay, true, true, true, BasisPay, null); return(pv - recPV); } ); var newSpread = Math.Solvers.Newton1D.MethodSolve(targetFunc, 0, 0.000001); return(newSpread); } else { var newSched = FlowScheduleRec.Clone(); var payPV = FlowSchedulePay.PV(discountCurve, forecastCurvePay, true, true, true, BasisPay, null); var targetFunc = new Func <double, double>(spread => { foreach (var s in newSched.Flows.Where(x => x.FlowType == FlowType.FloatRate)) { s.FixedRateOrMargin = spread; } var pv = newSched.PV(discountCurve, forecastCurveRec, true, true, true, BasisRec, null); return(pv - payPV); } ); var newSpread = Math.Solvers.Newton1D.MethodSolve(targetFunc, 0, 0.000001); return(newSpread); } }