public double ModelValue(IMarketCondition market, MktInstrumentCalibMethod calibMethod = MktInstrumentCalibMethod.Default) { var fixedPayRate = FixedLeg.GetPaymentRates(market); var fixedRate = ((FixedCoupon)FixedLeg.Coupon).FixedRate; var discountCurve = market.DiscountCurve.Value; var fixedLegAccumulatedDf = fixedPayRate .Where(x => x.Item1 > market.ValuationDate) .Sum(x => (x.Item2 / fixedRate * discountCurve.GetDf(x.Item1))); if (calibMethod == MktInstrumentCalibMethod.Default || calibMethod == MktInstrumentCalibMethod.IrsFloatingPvConst1) { // fair rate return((1.0 * discountCurve.GetDf(StartDate) - 1.0 * discountCurve.GetDf(fixedPayRate.Last().Item1)) / fixedLegAccumulatedDf); } else if (calibMethod == MktInstrumentCalibMethod.IrsFloatingPvReal) { var floatingPayRate = FloatingLeg.GetPaymentRates(market); var floatingPv = floatingPayRate .Where(x => x.Item1 > market.ValuationDate) .Sum(x => x.Item2 * market.DiscountCurve.Value.GetDf(x.Item1)); return(floatingPv / fixedLegAccumulatedDf); } throw new PricingLibraryException("Calibration method " + calibMethod + " is not recognized"); }
public MarketInstrument(ICalibrationSupportedInstrument instrument, double targetValue, MktInstrumentCalibMethod calibMethod) { Instrument = instrument; TargetValue = targetValue; CalibMethod = calibMethod; }
public double ModelValue(IMarketCondition market, MktInstrumentCalibMethod calibMethod = MktInstrumentCalibMethod.Default) { var discountCurve = market.DiscountCurve.Value; var dividendCurve = market.DividendCurves.Value.Values.First(); return(market.SpotPrices.Value.Values.First() * dividendCurve.GetDf(market.ValuationDate, UnderlyingMaturityDate) / discountCurve.GetDf(market.ValuationDate, UnderlyingMaturityDate)); }
public static ICalibrationSupportedInstrument CreateDepositInstrument( Date curveDate, RateMktData rateMktData, out MktInstrumentCalibMethod calibMethod) { ICalibrationSupportedInstrument deposit = null; if (rateMktData.TradeInfo != null) { var depositInfo = (DepositInfo)rateMktData.TradeInfo; deposit = new Deposit(depositInfo.StartDate.ToDate(), depositInfo.MaturityDate.ToDate(), depositInfo.Coupon, depositInfo.DayCount.ToDayCount().Get(), depositInfo.Calendar.ToCalendarImpl(), depositInfo.BusinessDayConvention.ToBda(), depositInfo.Currency.ToCurrencyCode() ); } else { var indexType = rateMktData.IndexType.ToIndexType(); var depositInfo = MktInstrumentDepositRule.MktDepositRule[indexType].DepositInfo; var calendar = depositInfo.Calendar.ToCalendarImpl(); var startDate = curveDate; var isTernor = rateMktData.IsTerm(); var tenor = isTernor ? rateMktData.Tenor : null; var maturityDate = isTernor ? new Term(tenor).Next(startDate) : new Date(DateTime.Parse(rateMktData.Tenor)); deposit = new Deposit(startDate, maturityDate, rateMktData.Rate, depositInfo.DayCount.ToDayCount().Get(), calendar, depositInfo.BusinessDayConvention.ToBda(), depositInfo.Currency.ToCurrencyCode(), 1.0, tenor ); } calibMethod = MktInstrumentCalibMethod.Default; return(deposit); }
public double ModelValue(IMarketCondition market, MktInstrumentCalibMethod calibMethod = MktInstrumentCalibMethod.Default) { return(market.DiscountCurve.Value.GetSpotRate(UnderlyingMaturityDate)); }
protected ICalibrationSupportedInstrument CreateIrsInstrument(RateMktData rateMktData, out MktInstrumentCalibMethod calibMethod) { MktIrsJson irsJson = null; ICalibrationSupportedInstrument irs = null; if (rateMktData.TradeInfo != null) { var irsInfo = (InterestRateSwapInfo)rateMktData.TradeInfo; var vf = new InterestRateSwapVf(irsInfo); irs = vf.GenerateInstrument(); irsJson = MktInstrumentIrsRule.MktIrsRule[irsInfo.Index.ToIndexType()]; } else { irsJson = MktInstrumentIrsRule.MktIrsRule[rateMktData.IndexType.ToIndexType()]; var irsInfo = irsJson.InterestRateSwapInfo; var calendar = irsInfo.Calendar.ToCalendarImpl(); var startDate = calendar.NextBizDay(Market.ReferenceDate); var isTernor = rateMktData.IsTerm(); var tenor = isTernor ? rateMktData.Tenor : null; var maturityDate = isTernor ? new Term(tenor).Next(startDate) : new Date(DateTime.Parse(rateMktData.Tenor)); var fixedLeg = new SwapLeg(startDate, maturityDate, -1.0, false, irsInfo.Currency.ToCurrencyCode(), new FixedCoupon(rateMktData.Rate), calendar, irsInfo.FixedLegFreq.ToFrequency(), irsInfo.FixedLegStub.ToStub(), irsInfo.FixedLegDC.ToDayCountImpl(), irsInfo.FixedLegBD.ToBda() ); var floatingLegFrequency = irsInfo.FloatingLegFreq.ToFrequency(); var floatingCouponResetTerm = new Term(irsInfo.ResetTerm); if (floatingCouponResetTerm.Equals(floatingLegFrequency.GetTerm())) { floatingCouponResetTerm = null; } var floatingCoupon = new FloatingCoupon( new Index(rateMktData.IndexType.ToIndexType(), 1, irsInfo.ResetCompound.ToCouponCompound()), calendar, irsInfo.FloatingLegDC.ToDayCountImpl(), 0.0, floatingCouponResetTerm, irsInfo.ResetStub.ToStub(), irsInfo.ResetBD.ToBda(), new DayGap(irsInfo.ResetToFixingGap)); var floatingLeg = new SwapLeg(startDate, maturityDate, 1.0, false, irsInfo.Currency.ToCurrencyCode(), floatingCoupon, calendar, irsInfo.FloatingLegFreq.ToFrequency(), irsInfo.FloatingLegStub.ToStub(), irsInfo.FloatingLegDC.ToDayCountImpl(), irsInfo.FloatingLegBD.ToBda() ); irs = new InterestRateSwap(fixedLeg, floatingLeg, SwapDirection.Payer, tenor); } calibMethod = irsJson.CalibrationMethod.ToCalibMethod(); return(irs); }
public double ModelValue(IMarketCondition market, MktInstrumentCalibMethod calibMethod = MktInstrumentCalibMethod.Default) { return((1.0 / market.DiscountCurve.Value.GetDf(market.ValuationDate, UnderlyingMaturityDate) - 1.0) / DayCount.CalcDayCountFraction(market.ValuationDate, UnderlyingMaturityDate)); }
public double ModelValue(IMarketCondition market, MktInstrumentCalibMethod calibMethod = MktInstrumentCalibMethod.Default) { var engine = new BondEngine(); return(engine.CalcPv(this, market)); }
public double ModelValue(IMarketCondition market, MktInstrumentCalibMethod calibMethod = MktInstrumentCalibMethod.Default) { var engine = new CdsEngine(PremiumLegIntegrationIntervals); return(engine.ParSpread(this, market)); }