Beispiel #1
0
 public MarketInstrument(ICalibrationSupportedInstrument instrument,
                         double targetValue,
                         MktInstrumentCalibMethod calibMethod)
 {
     Instrument  = instrument;
     TargetValue = targetValue;
     CalibMethod = calibMethod;
 }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }