Exemple #1
0
 public CommoditySwap(Date startDate,
                      Date maturityDate,
                      string recTicker,
                      string payTicker,
                      string fxTicker,
                      double recNotional,
                      double payNotional,
                      double fxNotional,
                      CurrencyCode recCcy,
                      CurrencyCode payCcy,
                      DayGap settlementGap        = null,
                      Date underlyingMaturityDate = null
                      )
 {
     StartDate              = startDate;
     MaturityDate           = maturityDate;
     RecTicker              = recTicker;
     PayTicker              = payTicker;
     FxTicker               = fxTicker;
     RecNotional            = recNotional;
     PayNotional            = payNotional;
     FxNotional             = fxNotional;
     RecCcy                 = recCcy;
     PayCcy                 = payCcy;
     SettlmentGap           = settlementGap;
     UnderlyingMaturityDate = underlyingMaturityDate;
 }
Exemple #2
0
        public FxSpot(Date startDate,
                      Date maturityDate,
                      double fxRate,
                      ICalendar domCalendar,
                      CurrencyCode domCcy,
                      double notionalInDomCcy,
                      ICalendar fgnCalendar,
                      CurrencyCode fgnCcy,
                      double notionalInFgnCcy,
                      CurrencyCode settlementCcy
                      )
        {
            StartDate = startDate;
            UnderlyingMaturityDate = maturityDate;
            FxRate = fxRate;

            DomCalendar = domCalendar;
            DomCcy      = domCcy;
            Notional    = notionalInDomCcy;

            FgnCalendar      = fgnCalendar;
            FgnCcy           = fgnCcy;
            NotionalInFgnCcy = notionalInFgnCcy;

            SettlementCcy = settlementCcy;
            SettlmentGap  = new DayGap("0BD");

            if (!notionalInDomCcy.AlmostEqual(notionalInFgnCcy / fxRate))
            {
                throw new PricingBaseException("Fx spot's domCcyAmt, fgnCcyAmt, and Fx spot rate does not match!");
            }
        }
Exemple #3
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="startDate">开始日期</param>
 /// <param name="maturityDate">到期日</param>
 /// <param name="exercise">行权方式</param>
 /// <param name="optionType">看涨看跌</param>
 /// <param name="strike">行权价</param>
 /// <param name="underlyingInstrumentType">标的资产类型</param>
 /// <param name="calendar">交易日历</param>
 /// <param name="dayCount">日期规则</param>
 /// <param name="payoffCcy">收益计算币种</param>
 /// <param name="settlementCcy">结算币种</param>
 /// <param name="exerciseDates">行权日</param>
 /// <param name="observationDates">观察日</param>
 /// <param name="notional">名义本金</param>
 /// <param name="settlementGap">结算日规则</param>
 /// <param name="optionPremiumPaymentDate">权利金支付日</param>
 /// <param name="optionPremium">权利金</param>
 /// <param name="isMoneynessOption">是否为相对行权价期权</param>
 /// <param name="initialSpotPrice">标的资产期初价格</param>
 /// <param name="dividends">标的资产分红</param>
 /// <param name="hasNightMarket">标的资产是否有夜盘交易</param>
 /// <param name="commodityFuturesPreciseTimeMode">是否启用精确时间计算模式</param>
 public VanillaOption(Date startDate,
                      Date maturityDate, //underlying maturity,  for option on forward
                      OptionExercise exercise,
                      OptionType optionType,
                      double strike,
                      InstrumentType underlyingInstrumentType,
                      ICalendar calendar,
                      IDayCount dayCount,
                      CurrencyCode payoffCcy,
                      CurrencyCode settlementCcy,
                      Date[] exerciseDates,
                      Date[] observationDates,
                      double notional                      = 1,
                      DayGap settlementGap                 = null,
                      Date optionPremiumPaymentDate        = null,
                      double optionPremium                 = 0.0,
                      bool isMoneynessOption               = false,
                      double initialSpotPrice              = 0.0,
                      Dictionary <Date, double> dividends  = null,
                      bool hasNightMarket                  = false,
                      bool commodityFuturesPreciseTimeMode = false
                      )
     : base(startDate, maturityDate, exercise, optionType, new double[] { strike }, underlyingInstrumentType,
            calendar, dayCount, payoffCcy, settlementCcy, exerciseDates, observationDates, notional, settlementGap,
            optionPremiumPaymentDate, optionPremium,
            isMoneynessOption: isMoneynessOption, initialSpotPrice: initialSpotPrice, dividends: dividends, hasNightMarket: hasNightMarket,
            commodityFuturesPreciseTimeMode: commodityFuturesPreciseTimeMode)
 {
     if (Exercise == OptionExercise.European && exerciseDates.Length != 1)
     {
         throw new PricingLibraryException("Vanilla European option can have only 1 observation date");
     }
 }
Exemple #4
0
        }                                                           //quoted as FgnCcy/DomCcy

        public FxSwap(Date startDate,
                      Date maturityDate,
                      Date spotDate,
                      Date nearStrikeDate,
                      DayGap dayGap,
                      double notional,
                      ICalendar domCalendar,
                      CurrencyCode domCcy,
                      double fgnNotional,
                      ICalendar fgnCalendar,
                      CurrencyCode fgnCcy,
                      double nearStrikeFxRate,
                      double farStrikeFxRate,
                      CurrencyCode settlementCcy
                      )
        {
            StartDate = startDate;
            UnderlyingMaturityDate = maturityDate;
            SpotDate       = spotDate;
            NearStrikeDate = nearStrikeDate;
            SettlmentGap   = dayGap ?? new DayGap("0BD");

            Notional    = notional;
            DomCalendar = domCalendar;
            DomCcy      = domCcy;

            NotionalInFgnCcy = fgnNotional;
            FgnCalendar      = fgnCalendar;
            FgnCcy           = fgnCcy;

            NearStrikeFxRate = nearStrikeFxRate;
            FarStrikeFxRate  = farStrikeFxRate;

            SettlementCcy = settlementCcy;
        }
Exemple #5
0
        public override SwapLeg 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();

            return(new SwapLeg(startDate,
                               maturityDate,
                               TradeInfo.Notional * swapDirection.Sign(),
                               true,
                               TradeInfo.Currency.ToCurrencyCode(),
                               new FixedCoupon(TradeInfo.FixedLegCoupon),
                               calendar,
                               TradeInfo.FixedLegFreq.ToFrequency(),
                               TradeInfo.FixedLegStub.ToStub(),
                               TradeInfo.FixedLegDC.ToDayCountImpl(),
                               TradeInfo.FixedLegBD.ToBda()
                               ));
        }
Exemple #6
0
 public FloatingCoupon(IIndex index,
                       ICalendar calendar,
                       IDayCount dayCount,
                       double couponSpread,
                       ITerm resetTerm,
                       Stub resetStub,
                       BusinessDayConvention bda,
                       DayGap resetToFixingGap        = null,
                       DayGap initialResetToFixingGap = null,
                       double floorRate = -100,
                       double capRate   = 100,
                       FloatingCouponCalcType frnCalc = FloatingCouponCalcType.SimpleFrn,
                       double multiplier = 1.0)
 {
     Index                   = index;
     Calendar                = calendar;
     DayCount                = dayCount;
     CouponSpread            = couponSpread;
     ResetTerm               = resetTerm;
     ResetStub               = resetStub;
     Bda                     = bda;
     ResetToFixingGap        = resetToFixingGap;
     InitialResetToFixingGap = initialResetToFixingGap;
     FloorRate               = floorRate;
     CapRate                 = capRate;
     FrnCalc                 = frnCalc;
     Multiplier              = multiplier;
 }
Exemple #7
0
 public LookbackOption(Date startDate,
                       Date maturityDate,
                       OptionExercise exercise,
                       OptionType optionType,
                       StrikeStyle strikeStyle,
                       double strike,
                       InstrumentType underlyingInstrumentType,
                       ICalendar calendar,
                       IDayCount dayCount,
                       CurrencyCode payoffCcy,
                       CurrencyCode settlementCcy,
                       Date[] exerciseDates,
                       Date[] observationDates,
                       Dictionary <Date, double> fixings,
                       double notional                      = 1,
                       DayGap settlementGap                 = null,
                       Date optionPremiumPaymentDate        = null,
                       double optionPremium                 = 0,
                       bool isMoneynessOption               = false,
                       double initialSpotPrice              = 0.0,
                       Dictionary <Date, double> dividends  = null,
                       bool hasNightMarket                  = false,
                       bool commodityFuturesPreciseTimeMode = false
                       )
     : base(startDate, maturityDate, exercise, optionType, new double[] { strike }, underlyingInstrumentType, calendar, dayCount,
            settlementCcy, payoffCcy, exerciseDates, observationDates, notional, settlementGap,
            optionPremiumPaymentDate, optionPremium,
            isMoneynessOption: isMoneynessOption, initialSpotPrice: initialSpotPrice, dividends: dividends, hasNightMarket: hasNightMarket,
            commodityFuturesPreciseTimeMode: commodityFuturesPreciseTimeMode)
 {
     Fixings     = fixings;
     StrikeStyle = strikeStyle;
 }
Exemple #8
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="startDate">开始日期</param>
 /// <param name="maturityDate">到期日</param>
 /// <param name="exercise">行权方式</param>
 /// <param name="optionType">看涨看跌</param>
 /// <param name="spreadType">价差期权类型</param>
 /// <param name="weights">权重</param>
 /// <param name="strike">行权价</param>
 /// <param name="underlyingInstrumentType">标的资产类型</param>
 /// <param name="calendar">交易日历</param>
 /// <param name="dayCount">日期规则</param>
 /// <param name="payoffCcy">收益计算币种</param>
 /// <param name="settlementCcy">结算币种</param>
 /// <param name="exerciseDates">行权日</param>
 /// <param name="observationDates">观察日</param>
 /// <param name="underlyingTickers">标的代码</param>
 /// <param name="notional">名义本金</param>
 /// <param name="settlementGap">结算日规则</param>
 /// <param name="optionPremiumPaymentDate">权利金支付日</param>
 /// <param name="optionPremium">权利金</param>
 /// <param name="hasNightMarket">标的资产是否有夜盘交易</param>
 /// <param name="commodityFuturesPreciseTimeMode">是否启用精确时间计算模式</param>
 public SpreadOption(Date startDate,
                     Date maturityDate,
                     OptionExercise exercise,
                     OptionType optionType,
                     SpreadType spreadType,
                     double[] weights,
                     double strike,
                     InstrumentType underlyingInstrumentType,
                     ICalendar calendar,
                     IDayCount dayCount,
                     CurrencyCode payoffCcy,
                     CurrencyCode settlementCcy,
                     Date[] exerciseDates,
                     Date[] observationDates,
                     string[] underlyingTickers,
                     double notional                      = 1,
                     DayGap settlementGap                 = null,
                     Date optionPremiumPaymentDate        = null,
                     double optionPremium                 = 0,
                     bool hasNightMarket                  = false,
                     bool commodityFuturesPreciseTimeMode = false)
     : base(startDate: startDate, maturityDate: maturityDate, exercise: exercise, optionType: optionType, strike: new double[] { strike },
            underlyingInstrumentType: underlyingInstrumentType, calendar: calendar, dayCount: dayCount,
            settlementCcy: settlementCcy, payoffCcy: payoffCcy, exerciseDates: exerciseDates, observationDates: observationDates,
            notional: notional, settlementGap: settlementGap, optionPremiumPaymentDate: optionPremiumPaymentDate, optionPremium: optionPremium, underlyingTickers: underlyingTickers,
            hasNightMarket: hasNightMarket, commodityFuturesPreciseTimeMode: commodityFuturesPreciseTimeMode)
 {
     SpreadType = spreadType;
     Weights    = weights;
 }
Exemple #9
0
        /// <summary>
        /// Return fixing curve by historicalIndexRates
        /// </summary>
        /// <param name="settlementDate"></param>
        /// <param name="historicalIndexRates"></param>
        /// <param name="floatingBondInfo"></param>
        /// <returns></returns>
        public static InstrumentCurveDefinition GetFixingCurve(string settlementDate, Dictionary <string, Dictionary <string, double> > historicalIndexRates, FloatingRateBondInfo floatingBondInfo)
        {
            var resetCalendar = CalendarImpl.Get(floatingBondInfo.Calendar);
            var index         = floatingBondInfo.Index;
            var rates         = historicalIndexRates[index];
            var tradeId       = floatingBondInfo.TradeId;

            var indexDate   = new DayGap(floatingBondInfo.ResetToFixingGap).Get(resetCalendar, settlementDate.ToDate());
            var fixingTuple = rates.TryGetValue(indexDate.ToString(), resetCalendar);
            var indexRate   = rates.GetAverageIndex(fixingTuple.Item1, resetCalendar, floatingBondInfo.ResetAverageDays, floatingBondInfo.ResetRateDigits);

            string fixingCurveName      = "FixingCurve_" + tradeId;
            var    fixingRateDefinition = new[]
            {
                new RateMktData("1D", indexRate, index, "None", fixingCurveName),
                new RateMktData("50Y", indexRate, index, "None", fixingCurveName),
            };
            var curveConvention = new CurveConvention("fixingCurveConvention_" + tradeId,
                                                      "CNY",
                                                      "ModifiedFollowing",
                                                      "Chn_ib",
                                                      index == null ? "Act365" : index.ToIndexType().DayCountEnum(),
                                                      "Continuous",
                                                      "ForwardFlat");

            floatingBondInfo.ValuationParamters.FixingCurveName = fixingCurveName;
            AddTrades(new [] { floatingBondInfo });
            return(new InstrumentCurveDefinition(fixingCurveName, curveConvention, fixingRateDefinition, "ForwardCurve"));
        }
Exemple #10
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="startDate">开始日</param>
 /// <param name="maturityDate">到期日</param>
 /// <param name="exercise">行权方式</param>
 /// <param name="optionType">看涨看跌</param>
 /// <param name="rainbowType">彩虹期权类型</param>
 /// <param name="strikes">行权价</param>
 /// <param name="cashAmount">现金金额</param>
 /// <param name="underlyingInstrumentType">标的资产类型</param>
 /// <param name="calendar">交易日历</param>
 /// <param name="dayCount">日期规则</param>
 /// <param name="payoffCcy">收益计算币种</param>
 /// <param name="settlementCcy">结算币种</param>
 /// <param name="exerciseDates">行权日</param>
 /// <param name="observationDates">观察日</param>
 /// <param name="fixings">观察价格序列</param>
 /// <param name="notional">名义本金</param>
 /// <param name="settlementGap">结算日规则</param>
 /// <param name="optionPremiumPaymentDate">权利金支付日</param>
 /// <param name="optionPremium">权利金</param>
 /// <param name="hasNightMarket">标的资产是否有夜盘交易</param>
 /// <param name="commodityFuturesPreciseTimeMode">是否启用精确时间模式</param>
 public RainbowOption(Date startDate,
                      Date maturityDate,
                      OptionExercise exercise,
                      OptionType optionType,
                      RainbowType rainbowType,
                      double[] strikes,
                      double cashAmount,
                      InstrumentType underlyingInstrumentType,
                      ICalendar calendar,
                      IDayCount dayCount,
                      CurrencyCode payoffCcy,
                      CurrencyCode settlementCcy,
                      Date[] exerciseDates,
                      Date[] observationDates,
                      string [] underlyingTickers,
                      double notional                      = 1,
                      DayGap settlementGap                 = null,
                      Date optionPremiumPaymentDate        = null,
                      double optionPremium                 = 0,
                      bool hasNightMarket                  = false,
                      bool commodityFuturesPreciseTimeMode = false)
     : base(startDate: startDate, maturityDate: maturityDate, exercise: exercise, optionType: optionType, strike: strikes,
            underlyingInstrumentType: underlyingInstrumentType, calendar: calendar, dayCount: dayCount,
            settlementCcy: settlementCcy, payoffCcy: payoffCcy, exerciseDates: exerciseDates, observationDates: observationDates,
            notional: notional, settlementGap: settlementGap, optionPremiumPaymentDate: optionPremiumPaymentDate, optionPremium: optionPremium, underlyingTickers: underlyingTickers,
            hasNightMarket: hasNightMarket, commodityFuturesPreciseTimeMode: commodityFuturesPreciseTimeMode)
 {
     RainbowType = rainbowType;
     CashAmount  = cashAmount;
     Strikes     = strikes;
 }
Exemple #11
0
 public ResetStrikeOption(Date startDate,
                          Date maturityDate,
                          OptionExercise exercise,
                          OptionType optionType,
                          ResetStrikeType resetStrikeType,
                          double strike,
                          InstrumentType underlyingInstrumentType,
                          ICalendar calendar,
                          IDayCount dayCount,
                          CurrencyCode payoffCcy,
                          CurrencyCode settlementCcy,
                          Date[] exerciseDates,
                          Date[] observationDates,
                          Date strikefixingDate,
                          double notional               = 1,
                          DayGap settlementGap          = null,
                          Date optionPremiumPaymentDate = null,
                          double optionPremium          = 0)
     : base(startDate: startDate, maturityDate: maturityDate, exercise: exercise, optionType: optionType, strike: new double[] { strike },
            underlyingInstrumentType: underlyingInstrumentType, calendar: calendar, dayCount: dayCount,
            settlementCcy: settlementCcy, payoffCcy: payoffCcy, exerciseDates: exerciseDates, observationDates: observationDates,
            notional: notional, settlementGap: settlementGap, optionPremiumPaymentDate: optionPremiumPaymentDate, optionPremium: optionPremium)
 {
     ResetStrikeType  = resetStrikeType;
     StrikeFixingDate = strikefixingDate;
 }
Exemple #12
0
        protected OptionBase(Date startDate,
                             Date maturityDate,
                             OptionExercise exercise,
                             OptionType optionType,
                             double[] strike,
                             InstrumentType underlyingInstrumentType,
                             ICalendar calendar,
                             IDayCount dayCount,
                             CurrencyCode payoffCcy,
                             CurrencyCode settlementCcy,
                             Date[] exerciseDates,
                             Date[] observationDates,
                             double notional                      = 1.0,
                             DayGap settlementGap                 = null,
                             Date optionPremiumPaymentDate        = null,
                             double optionPremium                 = 0.0,
                             string[] underlyingTickers           = null,
                             bool isMoneynessOption               = false,
                             double initialSpotPrice              = 0.0,
                             Dictionary <Date, double> dividends  = null,
                             bool hasNightMarket                  = false,
                             bool commodityFuturesPreciseTimeMode = false)
        {
            StartDate = startDate;

            Exercise              = exercise;
            OptionType            = optionType;
            Strike                = strike[0];
            Strikes               = strike;
            UnderlyingProductType = underlyingInstrumentType;

            Calendar               = calendar;
            DayCount               = dayCount;
            SettlmentGap           = settlementGap ?? new DayGap("+0BD");
            UnderlyingMaturityDate = SettlmentGap.Get(Calendar, maturityDate);

            ExerciseDates    = exerciseDates;
            ObservationDates = observationDates;

            UnderlyingTickers = underlyingTickers;

            Notional      = notional;
            PayoffCcy     = payoffCcy;
            SettlementCcy = settlementCcy;

            OptionPremiumPaymentDate = optionPremiumPaymentDate;
            OptionPremium            = optionPremium;

            IsMoneynessOption = isMoneynessOption;
            InitialSpotPrice  = initialSpotPrice;
            Dividends         = dividends;

            HasNightMarket = hasNightMarket;
            CommodityFuturesPreciseTimeMode = commodityFuturesPreciseTimeMode;
        }
Exemple #13
0
        public DummyInstrument(
            Date startDate,
            Date maturityDate,
            double rate)
        {
            StartDate = startDate;
            UnderlyingMaturityDate = maturityDate;
            Rate = rate;

            Notional     = 1.0;
            Tenor        = new Term(maturityDate - StartDate, Period.Day).ToString();
            SettlmentGap = new DayGap("+0BD");
        }
Exemple #14
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="startDate">开始日</param>
 /// <param name="maturityDate">到期日</param>
 /// <param name="exercise">行权方式</param>
 /// <param name="optionType">看涨看跌</param>
 /// <param name="strike">行权价</param>
 /// <param name="rebate">敲出补偿收益</param>
 /// <param name="coupon">敲出额外收益</param>
 /// <param name="participationRate">名义本金有效比例</param>
 /// <param name="barrierType">障碍类型</param>
 /// <param name="lowerBarrier">障碍价格下限</param>
 /// <param name="upperBarrier">障碍价格上限</param>
 /// <param name="isDiscreteMonitored">是否离散观察</param>
 /// <param name="underlyingType">标的资产类型</param>
 /// <param name="calendar">交易日历</param>
 /// <param name="dayCount">日期规则</param>
 /// <param name="payoffCcy">收益计算币种</param>
 /// <param name="settlementCcy">结算币种</param>
 /// <param name="exerciseDates">行权日</param>
 /// <param name="observationDates">观察日</param>
 /// <param name="fixings">观察价格序列</param>
 /// <param name="notional">名义本金</param>
 /// <param name="settlementGap">结算日规则</param>
 /// <param name="optionPremiumPaymentDate">权利金支付日</param>
 /// <param name="optionPremium">权利金</param>
 /// <param name="isMoneynessOption">是否为相对行权价期权</param>
 /// <param name="initialSpotPrice">标的资产期初价格</param>
 /// <param name="dividends">标的资产分红</param>
 /// <param name="position">持仓方向</param>
 /// <param name="barrierShift">障碍价格偏移</param>
 /// <param name="barrierStatus">敲入敲出状态</param>
 /// <param name="hasNightMarket">标的资产是否有夜盘交易</param>
 /// <param name="commodityFuturesPreciseTimeMode">是否启用精确时间模式</param>
 public BarrierOption(Date startDate,
                      Date maturityDate,
                      OptionExercise exercise,
                      OptionType optionType,
                      double strike,
                      double rebate,
                      double coupon,
                      double participationRate,
                      BarrierType barrierType,
                      double lowerBarrier,
                      double upperBarrier,
                      bool isDiscreteMonitored,
                      InstrumentType underlyingType,
                      ICalendar calendar,
                      IDayCount dayCount,
                      CurrencyCode payoffCcy,
                      CurrencyCode settlementCcy,
                      Date[] exerciseDates,
                      Date[] observationDates,
                      Dictionary <Date, double> fixings,
                      double notional                      = 1,
                      DayGap settlementGap                 = null,
                      Date optionPremiumPaymentDate        = null,
                      double optionPremium                 = 0,
                      bool isMoneynessOption               = false,
                      double initialSpotPrice              = 0.0,
                      Dictionary <Date, double> dividends  = null,
                      Position position                    = Position.Buy,
                      double barrierShift                  = 0.0,
                      BarrierStatus barrierStatus          = BarrierStatus.Monitoring,
                      bool hasNightMarket                  = false,
                      bool commodityFuturesPreciseTimeMode = false
                      )
     : base(startDate, maturityDate, exercise, optionType, new double[] { strike }, underlyingType, calendar, dayCount,
            payoffCcy, settlementCcy, exerciseDates, observationDates, notional, settlementGap,
            optionPremiumPaymentDate, optionPremium,
            isMoneynessOption: isMoneynessOption, initialSpotPrice: initialSpotPrice, dividends: dividends, hasNightMarket: hasNightMarket,
            commodityFuturesPreciseTimeMode: commodityFuturesPreciseTimeMode)
 {
     Rebate              = rebate;
     Coupon              = coupon;
     ParticipationRate   = participationRate;
     BarrierType         = barrierType;
     Barrier             = lowerBarrier;
     IsDiscreteMonitored = isDiscreteMonitored;
     UpperBarrier        = upperBarrier;
     Fixings             = fixings;
     Position            = position;
     BarrierShift        = barrierShift;
     BarrierStatus       = barrierStatus;
 }
Exemple #15
0
        public void TestDayGap()
        {
            var x = new DayGap("+2BD");

            Assert.AreEqual(x.Offset, 2);
            Assert.AreEqual(x.IsBizDay, true);
            Assert.AreEqual(x.Period, Period.Day);

            var y = new DayGap("+2D");

            Assert.AreEqual(y.Offset, 2);
            Assert.AreEqual(y.IsBizDay, false);
            Assert.AreEqual(y.Period, Period.Day);
        }
Exemple #16
0
        public SwapLeg(Date startDate,
                       Date maturityDate,
                       double notional,
                       bool notionalExchange,
                       CurrencyCode currency,
                       ICoupon coupon,
                       ICalendar calendar,
                       Frequency paymentFreq,
                       Stub paymentStub,
                       IDayCount dayCount,
                       BusinessDayConvention paymentBda,
                       DayGap settlementGap   = null,
                       Date firstPaymenetDate = null,
                       Date terminationDate   = null,
                       double terminateAmount = double.NaN
                       )
        {
            StartDate = startDate;
            UnderlyingMaturityDate = maturityDate;
            Notional          = notional;
            NotionalExchange  = notionalExchange;
            Currency          = currency;
            Coupon            = coupon;
            Calendar          = calendar;
            PaymentFreq       = paymentFreq;
            PaymentStub       = paymentStub;
            DayCount          = dayCount;
            PaymentBda        = paymentBda;
            SettlmentGap      = settlementGap ?? new DayGap("+0BD");
            FirstPaymentDate  = firstPaymenetDate;
            TerminationDate   = terminationDate;
            TerminationAmount = terminateAmount;

            if (FirstPaymentDate != null)
            {
                var temp = new Schedule(FirstPaymentDate, UnderlyingMaturityDate, PaymentFreq.GetTerm(), PaymentStub, Calendar, PaymentBda);
                Accruals = new Schedule(new[] { StartDate }.Union(temp));
            }
            else
            {
                Accruals = new Schedule(StartDate, UnderlyingMaturityDate, PaymentFreq.GetTerm(), PaymentStub, Calendar, PaymentBda);
            }

            if (TerminationDate != null)
            {
                Accruals = new Schedule(Accruals.Where(x => x < TerminationDate));
            }

            PaymentSchedule = new Schedule(Accruals.Skip(1));
        }
Exemple #17
0
 public CdsProtectionLeg(Date startDate,
                         Date maturityDate,
                         DayGap settlementGap,
                         CurrencyCode currency,
                         double notional,
                         double recoveryRate
                         )
 {
     StartDate = startDate;
     UnderlyingMaturityDate = maturityDate;
     SettlmentGap           = settlementGap;
     Currency     = currency;
     Notional     = notional;
     RecoveryRate = recoveryRate;
 }
Exemple #18
0
 public Forward(Date startDate,
                Date maturityDate,
                double notional,
                double strike,
                TUnderlying underlying,
                CurrencyCode currency,
                DayGap settlementGap = null)
 {
     StartDate = startDate;
     UnderlyingMaturityDate = maturityDate;
     Notional     = notional;
     Strike       = strike;
     Underlying   = underlying;
     Currency     = currency;
     SettlmentGap = settlementGap ?? new DayGap("+0BD");
 }
Exemple #19
0
 public FxOption(Date startDate,
                 Date maturityDate,
                 OptionExercise exercise,
                 OptionType optionType,
                 double strikeFxRate,
                 InstrumentType underlyingType,
                 ICalendar domCalendar,
                 CurrencyCode domCcy,
                 ICalendar fgnCalendar,
                 CurrencyCode fgnCcy,
                 IDayCount dayCount,
                 CurrencyCode payoffCcy,
                 CurrencyCode settlementCcy,
                 Date[] exerciseDates,
                 Date[] observationDates,
                 DayGap underlyingFxSpotSettlement,
                 double notionalInFgnCcy       = 1,
                 DayGap settlementGap          = null,
                 Date optionPremiumPaymentDate = null,
                 double optionPremium          = 0,
                 bool hasNightMarket           = false)
     : base(
         startDate: startDate,
         maturityDate: maturityDate,
         exercise: exercise,
         optionType: optionType,
         strike: new double[] { strikeFxRate },
         underlyingTickers: new string[] { "fgnCcy:domCcy" },
         underlyingInstrumentType: underlyingType,
         calendar: domCalendar,
         dayCount: dayCount,
         payoffCcy: payoffCcy,
         settlementCcy: settlementCcy,
         exerciseDates: exerciseDates,
         observationDates: observationDates,
         notional: notionalInFgnCcy,
         settlementGap: settlementGap,
         optionPremiumPaymentDate: optionPremiumPaymentDate,
         optionPremium: optionPremium,
         hasNightMarket: hasNightMarket)
 {
     FgnCalendar = fgnCalendar;
     FgnCcy      = fgnCcy;
     DomCcy      = domCcy;
     UnderlyingFxSpotSettlement = underlyingFxSpotSettlement;
 }
Exemple #20
0
        public static Date GetFxSpotDate(Date startDate,
                                         DayGap settlement,
                                         CurrencyCode fgnCcy,
                                         CurrencyCode domCcy,
                                         ICalendar fgnCalendar,
                                         ICalendar domCalendar)
        {
            //中国外汇交易中心产品指引(外汇市场)V1.8 58页
            var foreignSpotDate  = settlement.Get(fgnCalendar, startDate);
            var domesticSpotDate = settlement.Get(domCalendar, startDate);

            var usdCalendar = CalendarImpl.Get(Calendar.Usd);

            if (fgnCcy == CurrencyCode.USD)
            {
                if (!usdCalendar.IsHoliday(domesticSpotDate))
                {
                    return(domesticSpotDate);
                }
            }

            if (domCcy == CurrencyCode.USD)
            {
                if (!usdCalendar.IsHoliday(foreignSpotDate))
                {
                    return(foreignSpotDate);
                }
            }

            var guessSettlementDate = foreignSpotDate > domesticSpotDate ? foreignSpotDate : domesticSpotDate;

            if (usdCalendar.IsHoliday(guessSettlementDate) || fgnCalendar.IsHoliday(guessSettlementDate) || domCalendar.IsHoliday(guessSettlementDate))
            {
                //find next biz day for foreign currency and domestic currency
                while (fgnCalendar.IsHoliday(guessSettlementDate) || domCalendar.IsHoliday(guessSettlementDate))
                {
                    guessSettlementDate = new Term("1D").Next(guessSettlementDate);
                }
                return(guessSettlementDate);
            }

            return(guessSettlementDate);
        }
 public CommodityForwardCNY(Date startDate,
                            Date maturityDate,
                            double notional,
                            double basis,
                            CurrencyCode payoffCcy,
                            CurrencyCode settlementCcy,
                            DayGap settlementGap        = null,
                            Date underlyingMaturityDate = null
                            )
 {
     StartDate              = startDate;
     MaturityDate           = maturityDate;
     Notional               = notional;
     Basis                  = basis;
     PayoffCcy              = payoffCcy;
     SettlementCcy          = settlementCcy;
     SettlmentGap           = settlementGap;
     UnderlyingMaturityDate = underlyingMaturityDate;
 }
 public DoubleSharkFinOption(Date startDate,
                             Date maturityDate,
                             OptionExercise exercise,
                             OptionType optionType,
                             double strike,
                             InstrumentType underlyingInstrumentType,
                             ICalendar calendar,
                             IDayCount dayCount,
                             CurrencyCode payoffCcy,
                             CurrencyCode settlementCcy,
                             Date[] exerciseDates,
                             Date[] observationDates,
                             double notional               = 1,
                             DayGap settlementGap          = null,
                             Date optionPremiumPaymentDate = null,
                             double optionPremium          = 0)
     : base(startDate, maturityDate, exercise, optionType, new double[] { strike }, underlyingInstrumentType, calendar, dayCount, payoffCcy, settlementCcy, exerciseDates, observationDates, notional, settlementGap, optionPremiumPaymentDate, optionPremium)
 {
 }
Exemple #23
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="startDate">开始日</param>
 /// <param name="maturityDate">到期日</param>
 /// <param name="exercise">行权方式</param>
 /// <param name="optionType">看涨看跌</param>
 /// <param name="strike">行权价</param>
 /// <param name="underlyingProductType">标的资产类型</param>
 /// <param name="binaryOptionPayoffType">二元期权收益类型</param>
 /// <param name="cashOrNothingAmount">现金金额</param>
 /// <param name="calendar">交易日历</param>
 /// <param name="dayCount">日期规则</param>
 /// <param name="payoffCcy">收益计算币种</param>
 /// <param name="settlementCcy">结算币种</param>
 /// <param name="exerciseDates">行权日</param>
 /// <param name="observationDates">观察日</param>
 /// <param name="notional">名义本金</param>
 /// <param name="settlementGap">结算日规则</param>
 /// <param name="optionPremiumPaymentDate">权利金支付日</param>
 /// <param name="optionPremium">权利金</param>
 /// <param name="isMoneynessOption">是否为相对行权价期权</param>
 /// <param name="initialSpotPrice">标的资产期初价格</param>
 /// <param name="dividends">标的资产分红</param>
 /// <param name="binaryRebateType">二元期权补偿方式</param>
 /// <param name="hasNightMarket">标的资产是否有夜盘交易</param>
 /// <param name="commodityFuturesPreciseTimeMode">是否启用精确时间模式</param>
 public BinaryOption(Date startDate,
                     Date maturityDate,
                     OptionExercise exercise,
                     OptionType optionType,
                     double strike,
                     InstrumentType underlyingProductType,
                     BinaryOptionPayoffType binaryOptionPayoffType,
                     double cashOrNothingAmount,
                     ICalendar calendar,
                     IDayCount dayCount,
                     CurrencyCode payoffCcy,
                     CurrencyCode settlementCcy,
                     Date[] exerciseDates,
                     Date[] observationDates,
                     double notional                      = 1,
                     DayGap settlementGap                 = null,
                     Date optionPremiumPaymentDate        = null,
                     double optionPremium                 = 0,
                     bool isMoneynessOption               = false,
                     double initialSpotPrice              = 0.0,
                     Dictionary <Date, double> dividends  = null,
                     BinaryRebateType binaryRebateType    = BinaryRebateType.AtHit,
                     bool hasNightMarket                  = false,
                     bool commodityFuturesPreciseTimeMode = false)
     : base(startDate, maturityDate, exercise, optionType, new double[] { strike }, underlyingProductType, calendar, dayCount,
            payoffCcy, settlementCcy, exerciseDates, observationDates, notional, settlementGap,
            optionPremiumPaymentDate, optionPremium,
            isMoneynessOption: isMoneynessOption, initialSpotPrice: initialSpotPrice, dividends: dividends, hasNightMarket: hasNightMarket,
            commodityFuturesPreciseTimeMode: commodityFuturesPreciseTimeMode)
 {
     if (exercise == OptionExercise.European && ExerciseDates.Length != 1)
     {
         throw new PricingLibraryException("Binary option cannot have more than 1 exercise dates!");
     }
     BinaryOptionPayoffType = binaryOptionPayoffType;
     CashOrNothingAmount    = cashOrNothingAmount;
     BinaryRebateType       = binaryRebateType;
 }
Exemple #24
0
 public RangeAccrual(Date startDate,
                     Date maturityDate,
                     OptionExercise exercise,
                     OptionType optionType,
                     double strike,
                     RangeDefinition[] ranges,
                     InstrumentType underlyingInstrumentType,
                     ICalendar calendar,
                     IDayCount dayCount,
                     CurrencyCode payoffCcy,
                     CurrencyCode settlementCcy,
                     Date[] exerciseDates,
                     Date[] observationDates,
                     Dictionary <Date, double> fixings,
                     double notional               = 1,
                     DayGap settlementGap          = null,
                     Date optionPremiumPaymentDate = null,
                     double optionPremium          = 0)
     : base(startDate, maturityDate, exercise, optionType, new double[] { strike }, underlyingInstrumentType, calendar, dayCount, payoffCcy, settlementCcy, exerciseDates, observationDates, notional, settlementGap, optionPremiumPaymentDate, optionPremium)
 {
     Ranges  = ranges;
     Fixings = fixings;
 }
Exemple #25
0
        public static void GenerateOptionDates(OptionInfoBase TradeInfo,
                                               out Date[] exerciseDates,
                                               out Date[] obsDates,
                                               out DayGap settlement)
        {
            settlement = string.IsNullOrEmpty(TradeInfo.Settlement) ? new DayGap("+0BD") : TradeInfo.Settlement.ToDayGap();

            var startDate = TradeInfo.StartDate.ToDate();
            var calendar  = TradeInfo.Calendar.ToCalendarImpl();

            if (TradeInfo.Exercise.ToOptionExercise() == OptionExercise.American)
            {
                var inputDates = TradeInfo.ExerciseDates.Split(';');
                if (inputDates.Length > 1)
                {
                    exerciseDates = inputDates.Select(d => d.ToDate()).ToArray();
                }
                else
                {
                    exerciseDates = calendar.BizDaysBetweenDatesInclEndDay(startDate, TradeInfo.ExerciseDates.ToDate()).ToArray();
                }
            }
            else
            {
                exerciseDates = new[] { TradeInfo.ExerciseDates.ToDate() };
            }

            if (!string.IsNullOrEmpty(TradeInfo.ObservationDates))
            {
                obsDates = TradeInfo.ObservationDates.Split(QdpConsts.Semilicon).Select(x => x.ToDate()).ToArray();
            }
            else
            {
                var expiryDate = exerciseDates.Last();
                obsDates = calendar.BizDaysBetweenDatesExcluStartDay(startDate, expiryDate).Union(new[] { expiryDate }).ToArray();
            }
        }
Exemple #26
0
 public BondFutures(
     string id,
     Date startDate,
     Date maturityDate,
     Date finalTradeDate,
     ICalendar calendar,
     Bond[] deliverables,
     IDayCount dayCount,
     CurrencyCode currency = CurrencyCode.CNY,
     double notional       = 100.0,
     double nominalCoupon  = 0.03)
 {
     Id        = id;
     StartDate = startDate;
     UnderlyingMaturityDate = maturityDate;
     Calendar       = calendar;
     FinalTradeDate = finalTradeDate;
     NominalCoupon  = nominalCoupon;
     Deliverables   = deliverables;
     DayCount       = dayCount;
     SettlmentGap   = new DayGap("0BD");
     Currency       = currency;
     Notional       = notional;
 }
Exemple #27
0
 public CommodityForward(Date startDate, Date maturityDate, double notional, double strike, IUnderlyingInstrument underlying, CurrencyCode currency, DayGap settlementGap = null)
     : base(startDate, maturityDate, notional, strike, underlying, currency, settlementGap)
 {
     Tenor = Convert.ToInt32(maturityDate - startDate) + "D";
 }
Exemple #28
0
 public CommodityForward(Date startDate, Term tenor, double notional, double strike, IUnderlyingInstrument underlying, CurrencyCode currency, DayGap settlementGap = null)
     : base(startDate, tenor.Next(startDate), notional, strike, underlying, currency, settlementGap)
 {
     Tenor = tenor.ToString();
 }
Exemple #29
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
                       ));
        }
        /// <summary>
        /// 计算一个金融衍生品交易的定价和风险指标
        /// </summary>
        /// <param name="trade">交易</param>
        /// <param name="market">市场数据对象</param>
        /// <param name="request">计算请求类型</param>
        /// <returns>计算结果</returns>
        public override IPricingResult Calculate(TTrade trade, IMarketCondition market, PricingRequest request)
        {
            var result = new PricingResult(market.ValuationDate, request);

            if (result.IsRequested(PricingRequest.Pv))
            {
                result.Pv = CalcPv(trade, market);
            }

            if (result.IsRequested(PricingRequest.Carry))
            {
                result.Carry = CalcCarry(trade, market);
            }

            if (result.IsRequested(PricingRequest.Dv01))
            {
                if (double.IsNaN(result.Pv))
                {
                    result.Pv = CalcPv(trade, market);
                }
                var mktDown = market.FixingCurve.HasValue
                                        ? market.UpdateCondition(
                    new UpdateMktConditionPack <IYieldCurve>(x => x.DiscountCurve, market.DiscountCurve.Value.Shift(1)),
                    new UpdateMktConditionPack <IYieldCurve>(x => x.FixingCurve, market.FixingCurve.Value.Shift(1)))
                                        : market.UpdateCondition(
                    new UpdateMktConditionPack <IYieldCurve>(x => x.DiscountCurve, market.DiscountCurve.Value.Shift(1)));
                result.Dv01 = CalcPv(trade, mktDown) - result.Pv;
            }

            if (result.IsRequested(PricingRequest.Cashflow))
            {
                result.Cashflows = trade.GetCashflows(market, false);
            }

            //Ai and AiEod are mutually exclusive requests
            var isEod = result.IsRequested(PricingRequest.AiEod);

            if (result.IsRequested(PricingRequest.Ai) || result.IsRequested(PricingRequest.AiEod))
            {
                if (result.Cashflows == null || result.Cashflows.Length == 0)
                {
                    result.Cashflows = trade.GetCashflows(market, false);
                }

                result.Ai = trade.GetAccruedInterest(market.ValuationDate, market, isEod);
            }

            if (result.IsRequested(PricingRequest.KeyRateDv01))
            {
                if (double.IsNaN(result.Pv))
                {
                    result.Pv = CalcPv(trade, market);
                }
                var dc = new Dictionary <string, CurveRisk[]>();
                var fc = new Dictionary <string, CurveRisk[]>();

                Parallel.Invoke(
                    () => CalcDiscountDv01(trade, market, result.Pv, ref dc),
                    () => CalcResetDv01(trade, market, result.Pv, ref fc)
                    );


                result.KeyRateDv01 = PricingResultExtension.Aggregate(dc, fc);
            }

            if (result.IsRequested(PricingRequest.FairQuote))
            {
                result.FairQuote = GetFairQuote(trade, market);
            }

            if (result.IsRequested(PricingRequest.MacDuration))
            {
                if (result.Cashflows == null || result.Cashflows.Length == 0)
                {
                    result.Cashflows = trade.GetCashflows(market, false);
                }
                var weightedCf = 0.0;
                var totalCf    = 0.0;
                foreach (var cashflow in result.Cashflows)
                {
                    if (cashflow.PaymentDate > market.ValuationDate)
                    {
                        var t  = market.DiscountCurve.Value.DayCount.CalcDayCountFraction(market.ValuationDate, cashflow.PaymentDate);
                        var df = market.DiscountCurve.Value.GetDf(market.ValuationDate, cashflow.PaymentDate);

                        weightedCf += cashflow.PaymentAmount * df * t;
                        totalCf    += cashflow.PaymentAmount * df;
                    }
                }
                result.MacDuration = weightedCf / totalCf;
            }

            if (result.IsRequested(PricingRequest.Pv01))
            {
                result.Pv01 = CalcPv01(trade, market, result.Pv);
            }

            Date valueDate = result.ValuationDate;

            if (result.IsRequested(PricingRequest.ProductSpecific))
            {
                var yieldCurve = market.DiscountCurve.Value;

                #region

                var psDict = new Dictionary <string, Dictionary <string, RateRecord> >();
                var dayGap = new DayGap("+0BD");
                var T      = (trade is InterestRateSwap) ? (trade as InterestRateSwap).FloatingLeg : trade as SwapLeg;

                //forward rate points
                var tenors           = new[] { "1D", "7D", "3M", "1Y" };
                var fwdStartInTenors = new List <string> {
                    "1D", "1W", "2W", "1M", "2M", "3M", "4M", "5M", "6M", "7M", "8M", "9M", "10M", "11M", "1Y"
                };
                var totalMonths = Convert.ToInt16((yieldCurve.KeyPoints.Last().Item1 - yieldCurve.KeyPoints.First().Item1) / 30.0) + 1;
                for (var i = 15; i <= totalMonths; i += 3)
                {
                    fwdStartInTenors.Add(i + "M");
                }
                foreach (var tenor in tenors)
                {
                    var fwdRates = new Dictionary <string, RateRecord>();
                    var fwdTerm  = new Term(tenor);
                    foreach (var fwdStartInTenor in fwdStartInTenors)
                    {
                        var fwdStartDate = dayGap.Get(T.Calendar, new Term(fwdStartInTenor).Next(valueDate));
                        var fwdEndDate   = dayGap.Get(T.Calendar, fwdTerm.Next(fwdStartDate));
                        if (fwdEndDate < yieldCurve.KeyPoints.Last().Item1)
                        {
                            fwdRates[fwdStartInTenor] = new RateRecord()
                            {
                                Date = fwdStartDate.ToString(),
                                Rate = yieldCurve.GetForwardRate(fwdStartDate, fwdTerm)
                            };
                        }
                    }

                    psDict["forwardrates" + tenor] = fwdRates;
                }

                //spot rate
                var spotRates    = new Dictionary <string, RateRecord>();
                var spotInTenors = fwdStartInTenors;

                foreach (var spotInTenor in spotInTenors)
                {
                    var spotDate = dayGap.Get(T.Calendar, new Term(spotInTenor).Next(valueDate));
                    if (spotDate <= yieldCurve.KeyPoints.Last().Item1)
                    {
                        spotRates[spotInTenor] = new RateRecord
                        {
                            Date = spotDate.ToString(),
                            Rate = yieldCurve.ZeroRate(valueDate, spotDate, Compound.Simple)
                        };
                    }
                }
                psDict["spotRates"] = spotRates;

                //key rates
                var rates          = new Dictionary <string, RateRecord>();
                var ccTenors       = yieldCurve.GetKeyTenors().ToArray();
                var mktInstruments = yieldCurve.MarketInstruments;
                if (mktInstruments != null)
                {
                    if (mktInstruments.Length != ccTenors.Length)
                    {
                        throw new PricingBaseException("Number of calibration instruments mismatches number of calibrated points!");
                    }
                }
                for (var i = 0; i < ccTenors.Count(); ++i)
                {
                    //var spotDate = mktInstruments != null ? mktInstruments[i].Instrument.GetClibrationDate() : dayGap.Get(T.Calendar, new Term(ccTenors[i]).Next(valueDate));
                    var spotDate = dayGap.Get(T.Calendar, new Term(ccTenors[i]).Next(valueDate));
                    rates[ccTenors[i]] = new RateRecord()
                    {
                        ContinuousRate                           = yieldCurve.ZeroRate(valueDate, spotDate),
                        Date                                     = spotDate.ToString(),
                        DiscountFactor                           = yieldCurve.GetDf(valueDate, spotDate),
                        Rate                                     = mktInstruments == null?yieldCurve.GetSpotRate(spotDate) : mktInstruments[i].TargetValue,
                                                     ProductType = mktInstruments == null ? "None" : (mktInstruments[i].Instrument is Deposit) ? "Index" : "Swap",
                                                     ZeroRate    = yieldCurve.ZeroRate(valueDate, spotDate, Compound.Simple),
                                                     Term        = ccTenors[i]
                    };
                }
                psDict["rates"] = rates;

                //discount at cash flow dates
                var dfs   = new Dictionary <string, RateRecord>();
                var dates = result.Cashflows.Select(x => x.PaymentDate);
                foreach (var date in dates)
                {
                    dfs[date.ToString()] = new RateRecord
                    {
                        DiscountFactor = yieldCurve.GetDf(date)
                    };
                }

                psDict["discountfactor"] = dfs;
                //qb rate return
                result.ProductSpecific = psDict;

                #endregion
            }

            return(result);
        }