Beispiel #1
0
        public override SwapLeg GenerateInstrument()
        {
            var calendar                = TradeInfo.Calendar.ToCalendarImpl();
            var startDate               = TradeInfo.StartDate.ToDate();
            var maturityDate            = !string.IsNullOrEmpty(TradeInfo.Tenor) ?new DayGap("+0BD").Get(calendar, new Term(TradeInfo.Tenor).Next(startDate)) : TradeInfo.MaturityDate.ToDate();
            var swapDirection           = TradeInfo.SwapDirection.ToSwapDirection();
            var floatingLegFrequency    = TradeInfo.FloatingLegFreq.ToFrequency();
            var floatingCouponResetTerm = new Term(TradeInfo.ResetTerm);

            if (floatingCouponResetTerm.Equals(floatingLegFrequency.GetTerm()))
            {
                floatingCouponResetTerm = null;
            }
            var floatingCoupon =
                new FloatingCoupon(
                    new Index(TradeInfo.Index.ToIndexType(), 1, TradeInfo.ResetCompound.ToCouponCompound()),
                    calendar,
                    TradeInfo.FloatingLegDC.ToDayCountImpl(),
                    0.0,
                    floatingCouponResetTerm,
                    TradeInfo.ResetStub.ToStub(),
                    TradeInfo.ResetBD.ToBda(),
                    new DayGap(TradeInfo.ResetToFixingGap));

            return(new SwapLeg(startDate,
                               maturityDate,
                               -TradeInfo.Notional * swapDirection.Sign(),
                               true,
                               TradeInfo.Currency.ToCurrencyCode(),
                               floatingCoupon,
                               calendar,
                               TradeInfo.FloatingLegFreq.ToFrequency(),
                               TradeInfo.FloatingLegStub.ToStub(),
                               TradeInfo.FloatingLegDC.ToDayCountImpl(),
                               TradeInfo.FloatingLegBD.ToBda()
                               ));
        }
Beispiel #2
0
        //leg1 <=> fixedLeg in InterestRateSwap
        //leg2 <=> floatingLeg in InterestRateSwap
        public override InterestRateSwap GenerateInstrument()
        {
            var startDate    = TradeInfo.StartDate.ToDate();
            var maturityDate = TradeInfo.MaturityDate.ToDate();
            var tenor        = new Term(maturityDate - startDate, Period.Day);

            var leg1Frequency       = TradeInfo.Leg1Frequency.ToFrequency();
            var leg1Calendar        = TradeInfo.Leg1Calendar.ToCalendarImpl();
            var leg1CouponResetTerm = new Term(TradeInfo.Leg2ResetTerm);

            if (leg1CouponResetTerm.Equals(leg1Frequency.GetTerm()))
            {
                leg1CouponResetTerm = null;
            }
            var leg1Coupon =
                new FloatingCoupon(
                    new Index(TradeInfo.Leg1Index.ToIndexType(), 1, TradeInfo.Leg1ResetCompound.ToCouponCompound()),
                    leg1Calendar,
                    TradeInfo.Leg1DayCount.ToDayCountImpl(),
                    0.0,
                    leg1CouponResetTerm,
                    TradeInfo.Leg1ResetStub.ToStub(),
                    TradeInfo.Leg1ResetTerm.ToBda(),
                    new DayGap(TradeInfo.Leg1ResetToFixingGap));
            var leg1 = new SwapLeg(startDate,
                                   maturityDate,
                                   1.0,
                                   false,
                                   TradeInfo.Currency.ToCurrencyCode(),
                                   leg1Coupon,
                                   leg1Calendar,
                                   TradeInfo.Leg1Frequency.ToFrequency(),
                                   TradeInfo.Leg1Stub.ToStub(),
                                   TradeInfo.Leg1DayCount.ToDayCountImpl(),
                                   TradeInfo.Leg1BusinessDayConvention.ToBda()
                                   );


            var leg2Calendar        = TradeInfo.Leg2Calendar.ToCalendarImpl();
            var leg2Frequency       = TradeInfo.Leg2Frequency.ToFrequency();
            var leg2CouponResetTerm = new Term(TradeInfo.Leg2ResetTerm);

            if (leg2CouponResetTerm.Equals(leg2Frequency.GetTerm()))
            {
                leg2CouponResetTerm = null;
            }

            var leg2Coupon =
                new FloatingCoupon(
                    new Index(TradeInfo.Leg2Index.ToIndexType(), 1, TradeInfo.Leg2ResetCompound.ToCouponCompound()),
                    leg2Calendar,
                    TradeInfo.Leg2DayCount.ToDayCountImpl(),
                    0.0,
                    leg2CouponResetTerm,
                    TradeInfo.Leg2ResetStub.ToStub(),
                    TradeInfo.Leg2ResetTerm.ToBda(),
                    new DayGap(TradeInfo.Leg2ResetToFixingGap));
            var leg2 = new SwapLeg(startDate,
                                   maturityDate,
                                   1.0,
                                   false,
                                   TradeInfo.Currency.ToCurrencyCode(),
                                   leg2Coupon,
                                   leg2Calendar,
                                   TradeInfo.Leg2Frequency.ToFrequency(),
                                   TradeInfo.Leg2Stub.ToStub(),
                                   TradeInfo.Leg2DayCount.ToDayCountImpl(),
                                   TradeInfo.Leg2BusinessDayConvention.ToBda()
                                   );

            return(new InterestRateSwap(leg1, leg2, TradeInfo.SwapDirection.ToSwapDirection(), tenor.ToString()));
        }
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);
        }
Beispiel #4
0
        public override Bond GenerateInstrument()
        {
            ICoupon coupon   = null;
            var     calendar = string.IsNullOrEmpty(TradeInfo.Calendar) ? CalendarImpl.Get("chn_ib") : TradeInfo.Calendar.ToCalendarImpl();

            if (TradeInfo is FixedRateBondInfo)
            {
                var tempTradeInfo = (FixedRateBondInfo)TradeInfo;
                coupon = new FixedCoupon(tempTradeInfo.FixedCoupon);
            }
            else if (TradeInfo is FloatingRateBondInfo)
            {
                var tempTradeInfo = (FloatingRateBondInfo)TradeInfo;

                var index = new Index(tempTradeInfo.Index.ToIndexType(), tempTradeInfo.ResetAverageDays, tempTradeInfo.ResetCompound.ToCouponCompound(), tempTradeInfo.ResetRateDigits);

                var dayCount = tempTradeInfo.ResetDC.ToDayCountImpl();
                var stub     = tempTradeInfo.ResetStub.ToStub();
                var bda      = tempTradeInfo.ResetBD.ToBda();

                var floatingCouponResetTerm = new Term(tempTradeInfo.ResetTerm);

                var resetFrequency = tempTradeInfo.PaymentFreq.ToFrequency();
                if (floatingCouponResetTerm.Equals(resetFrequency.GetTerm()))
                {
                    floatingCouponResetTerm = null;
                }

                var resetToFixingGap = new DayGap(tempTradeInfo.ResetToFixingGap);
                coupon = new FloatingCoupon(
                    index,
                    calendar,
                    dayCount,
                    tempTradeInfo.Spread,
                    floatingCouponResetTerm,
                    stub,
                    bda,
                    resetToFixingGap,
                    null,
                    double.IsNaN(tempTradeInfo.FloorRate) ? -100 : tempTradeInfo.FloorRate,
                    double.IsNaN(tempTradeInfo.CapRate) ? 100 : tempTradeInfo.CapRate,
                    tempTradeInfo.FloatingCalc.ToFloatingCalcType(),
                    (double.IsNaN(tempTradeInfo.FloatingRateMultiplier) || tempTradeInfo.FloatingRateMultiplier.IsAlmostZero()) ? 1.0 : tempTradeInfo.FloatingRateMultiplier
                    );
            }
            else if (TradeInfo is FixedDateCouonAdjustedBondInfo)
            {
                var tempTradeInfo = (TradeInfo as FixedDateCouonAdjustedBondInfo);
                coupon = new FixedDateAdjustedCoupon(tempTradeInfo.Index.ToIndexType(),
                                                     calendar,
                                                     tempTradeInfo.DayCount.ToDayCountImpl(),
                                                     tempTradeInfo.FixedDateCouponAdjustedStyle.ToFixedDateAdjustedCouponStyle(),
                                                     tempTradeInfo.AdjustMmDd,
                                                     tempTradeInfo.FloatingRateMultiplier,
                                                     tempTradeInfo.Spread
                                                     );
            }

            return(new Bond(
                       TradeInfo.TradeId,
                       TradeInfo.StartDate.ToDate(),
                       TradeInfo.MaturityDate.ToDate(),
                       TradeInfo.Notional,
                       string.IsNullOrEmpty(TradeInfo.Currency) ? CurrencyCode.CNY : TradeInfo.Currency.ToCurrencyCode(),
                       coupon,
                       calendar,
                       TradeInfo.PaymentFreq.ToFrequency(),
                       string.IsNullOrEmpty(TradeInfo.PaymentStub) ? Stub.ShortEnd : TradeInfo.PaymentStub.ToStub(),
                       string.IsNullOrEmpty(TradeInfo.AccrualDC) ? new ActActIsma() : TradeInfo.AccrualDC.ToDayCount().Get(),
                       string.IsNullOrEmpty(TradeInfo.DayCount) ? null : TradeInfo.DayCount.ToDayCount().Get(),
                       TradeInfo.AccrualBD.ToBda(),
                       TradeInfo.PaymentBD.ToBda(),
                       string.IsNullOrEmpty(TradeInfo.Settlement) ? new DayGap("+0D") : new DayGap(TradeInfo.Settlement),
                       string.IsNullOrEmpty(TradeInfo.TradingMarket)
                                        ? TradingMarket.ChinaInterBank
                                        : TradeInfo.TradingMarket.ToTradingMarket(),
                       TradeInfo.StickToEom,
                       (double.IsNaN(TradeInfo.RedemptionRate) || Math.Abs(TradeInfo.RedemptionRate - 0.0) < double.Epsilon)? null : new Redemption(TradeInfo.RedemptionRate, TradeInfo.RedemptionIncludeLastCoupon ? RedemptionType.SeparatePrincipalWithLastCoupon : RedemptionType.SeparatePrincipal),
                       TradeInfo.FirstPaymentDate.ToDate(),
                       TradeInfo.IsZeroCouponBond,
                       TradeInfo.IssuePrice,
                       (double.IsNaN(TradeInfo.IssueRate) || TradeInfo.IssueRate <= 0.0) ? double.NaN : TradeInfo.IssueRate,
                       string.IsNullOrEmpty(TradeInfo.AmortizationType)
                                        ? AmortizationType.None
                                        : TradeInfo.AmortizationType.ToAmortizationType(),
                       TradeInfo.AmoritzationInDate == null
                                        ? null
                                        : TradeInfo.AmoritzationInDate.ToDictionary(x => x.Key.ToDate(), x => x.Value),
                       TradeInfo.AmoritzationInIndex,
                       TradeInfo.RenormAmortization,
                       TradeInfo.CompensationRate,
                       TradeInfo.OptionToCall,
                       TradeInfo.OptionToPut,
                       TradeInfo.OptionToAssPut,
                       TradeInfo.SettlementCoupon.IsAlmostZero() ? double.NaN : TradeInfo.SettlementCoupon,
                       TradeInfo.RoundCleanPrice
                       ));
        }
Beispiel #5
0
        public override InterestRateSwap GenerateInstrument()
        {
            var    calendar  = TradeInfo.Calendar.ToCalendarImpl();
            var    startDate = TradeInfo.StartDate.ToDate();
            Date   maturityDate;
            string tenor;

            if (!string.IsNullOrEmpty(TradeInfo.Tenor))
            {
                maturityDate = new DayGap("+0BD").Get(calendar, new Term(TradeInfo.Tenor).Next(startDate));
                tenor        = TradeInfo.Tenor;
            }
            else
            {
                maturityDate = TradeInfo.MaturityDate.ToDate();
                tenor        = new Term(maturityDate - startDate, Period.Day).ToString();
            }
            var swapDirection = TradeInfo.SwapDirection.ToSwapDirection();
            var fixedLeg      = new SwapLeg(startDate,
                                            maturityDate,
                                            TradeInfo.Notional * swapDirection.Sign(),
                                            false,
                                            TradeInfo.Currency.ToCurrencyCode(),
                                            new FixedCoupon(TradeInfo.FixedLegCoupon),
                                            calendar,
                                            TradeInfo.FixedLegFreq.ToFrequency(),
                                            TradeInfo.FixedLegStub.ToStub(),
                                            TradeInfo.FixedLegDC.ToDayCountImpl(),
                                            TradeInfo.FixedLegBD.ToBda()
                                            );

            var floatingLegFrequency    = TradeInfo.FloatingLegFreq.ToFrequency();
            var floatingCouponResetTerm = new Term(TradeInfo.ResetTerm);

            if (floatingCouponResetTerm.Equals(floatingLegFrequency.GetTerm()))
            {
                floatingCouponResetTerm = null;
            }
            var floatingCoupon =
                new FloatingCoupon(
                    new Index(TradeInfo.Index.ToIndexType(), 1, TradeInfo.ResetCompound.ToCouponCompound()),
                    calendar,
                    TradeInfo.FloatingLegDC.ToDayCountImpl(),
                    0.0,
                    floatingCouponResetTerm,
                    TradeInfo.ResetStub.ToStub(),
                    TradeInfo.ResetBD.ToBda(),
                    new DayGap(TradeInfo.ResetToFixingGap));
            var floatingLeg = new SwapLeg(startDate,
                                          maturityDate,
                                          -TradeInfo.Notional * swapDirection.Sign(),
                                          false,
                                          TradeInfo.Currency.ToCurrencyCode(),
                                          floatingCoupon,
                                          calendar,
                                          TradeInfo.FloatingLegFreq.ToFrequency(),
                                          TradeInfo.FloatingLegStub.ToStub(),
                                          TradeInfo.FloatingLegDC.ToDayCountImpl(),
                                          TradeInfo.FloatingLegBD.ToBda()
                                          );

            return(new InterestRateSwap(fixedLeg, floatingLeg, swapDirection, tenor));
        }