示例#1
0
文件: BasisSwap.cs 项目: ariesy/QLNet
 // constructor
 public BasisSwap(Type type, double nominal,
     Schedule float1Schedule, IborIndex iborIndex1, double spread1, DayCounter float1DayCount,
     Schedule float2Schedule, IborIndex iborIndex2, double spread2, DayCounter float2DayCount)
     : this(type, nominal, float1Schedule, iborIndex1, spread1, float1DayCount,
                        float2Schedule, iborIndex2, spread2, float2DayCount, null)
 {
 }
示例#2
0
        public void testCashedValues()
        {
            Date startDate = new Date(01, 03, 2007);
             Period period = new Period(360, TimeUnit.Months);
             Calendar calendar = new TARGET();
             Date endDate = calendar.advance(startDate,period,BusinessDayConvention.Unadjusted);

             Schedule schedule = new Schedule( startDate, endDate, new Period(1,TimeUnit.Months), calendar,
                                           BusinessDayConvention.Unadjusted,
                                           BusinessDayConvention.Unadjusted,
                                           DateGeneration.Rule.Backward, false);

             // PSA 100%
             PSACurve psa100 = new PSACurve(startDate);
             double[] listCPR = {0.2000,0.4000,0.6000,0.8000,1.0000,1.2000,1.4000,1.6000,1.8000,2.0000,2.2000,2.4000,2.6000,2.8000,
                             3.0000,3.2000,3.4000,3.6000,3.8000,4.0000,4.2000,4.4000,4.6000,4.8000,5.0000,5.2000,5.4000,5.6000,
                             5.8000,6.0000};

             for (int i = 0; i < schedule.Count; i++)
             {
            if ( i <= 29 )
               Assert.AreEqual(listCPR[i], psa100.getCPR(schedule[i])*100,0.001);
            else
               Assert.AreEqual(6.0000, psa100.getCPR(schedule[i])*100);
             }
        }
示例#3
0
        public FloatingRateBond(int settlementDays, double faceAmount, Schedule schedule, IborIndex index, DayCounter paymentDayCounter,
                                BusinessDayConvention paymentConvention, int fixingDays, List<double> gearings, List<double> spreads,
                                List<double> caps, List<double> floors, bool inArrears, double redemption, Date issueDate)
            : base(settlementDays, schedule.calendar(), issueDate) {
            maturityDate_ = schedule.endDate();
            cashflows_ = new IborLeg(schedule, index)
                            .withPaymentDayCounter(paymentDayCounter)
                            .withFixingDays(fixingDays)
                            .withGearings(gearings)
                            .withSpreads(spreads)
                            .withCaps(caps)
                            .withFloors(floors)
                            .inArrears(inArrears)
                            .withNotionals(faceAmount)
                            .withPaymentAdjustment(paymentConvention);

            addRedemptionsToCashflows(new List<double>() { redemption });

            if (cashflows().Count == 0)
                throw new ApplicationException("bond with no cashflows!");
            if (redemptions_.Count != 1)
                throw new ApplicationException("multiple redemptions created");

            index.registerWith(update);
        }
示例#4
0
        public FloatingRateBond(int settlementDays, double faceAmount, Schedule schedule, IborIndex index, 
            DayCounter paymentDayCounter)
            : this(settlementDays, faceAmount, schedule, index, paymentDayCounter, BusinessDayConvention.Following,
                   0, new List<double>() { 1 }, new List<double>() { 0 }, new List<double>(), new List<double>(),
				   false, 100, null)
        {
        }
示例#5
0
 public CmsLeg(Schedule schedule, SwapIndex swapIndex) {
     schedule_ = schedule;
     index_ = swapIndex;
     paymentAdjustment_ = BusinessDayConvention.Following;
     inArrears_ = false;
     zeroPayments_ = false;
 }
示例#6
0
        public FloatingRateBond(int settlementDays, double faceAmount, Schedule schedule, IborIndex index,
            DayCounter paymentDayCounter, BusinessDayConvention paymentConvention, int fixingDays,
            List<double> gearings, List<double> spreads)
            : this(settlementDays, faceAmount, schedule, index, paymentDayCounter, BusinessDayConvention.Following,
				   fixingDays, gearings, spreads, new List<double>(), new List<double>(), false, 100, null)
        {
        }
示例#7
0
        public FixedRateBond(int settlementDays, double faceAmount, Schedule schedule,
            List<double> coupons, DayCounter accrualDayCounter,
            BusinessDayConvention paymentConvention, double redemption, Date issueDate)
            : this(settlementDays, faceAmount, schedule, coupons, accrualDayCounter,
				   paymentConvention, redemption, issueDate, new Calendar())
        {
        }
示例#8
0
        protected ConvertibleBond( Exercise exercise,
                                 double conversionRatio,
                                 DividendSchedule dividends,
                                 CallabilitySchedule callability,
                                 Handle<Quote> creditSpread,
                                 Date issueDate,
                                 int settlementDays,
                                 Schedule schedule,
                                 double redemption)
            : base(settlementDays, schedule.calendar(), issueDate)
        {
            conversionRatio_ = conversionRatio;
             callability_ = callability;
             dividends_ = dividends;
             creditSpread_ = creditSpread;

             maturityDate_ = schedule.endDate();

             if (!callability.empty())
             {
            Utils.QL_REQUIRE( callability.Last().date() <= maturityDate_, () =>
                              "last callability date ("
                              + callability.Last().date()
                              + ") later than maturity ("
                              + maturityDate_.ToShortDateString() + ")");
            }

             creditSpread.registerWith(update);
        }
      public AmortizingFixedRateBond(
                          int settlementDays,
                          List<double> notionals,
                          Schedule schedule,
                          List<double> coupons,
                          DayCounter accrualDayCounter,
                          BusinessDayConvention paymentConvention = BusinessDayConvention.Following,
                          Date issueDate = null)
         :base(settlementDays, schedule.calendar(), issueDate)
      {
         frequency_ = schedule.tenor().frequency();
         dayCounter_ = accrualDayCounter;
         schedule_ = schedule;

         maturityDate_ = schedule.endDate();

         cashflows_ = new FixedRateLeg(schedule)
             .withCouponRates(coupons, accrualDayCounter)
             .withNotionals(notionals)
             .withPaymentAdjustment(paymentConvention).value();
             

         addRedemptionsToCashflows();

         if ( cashflows().empty())
            throw new ApplicationException("bond with no cashflows!");
      }
示例#10
0
      public AmortizingFixedRateBond(
                          int settlementDays,
                          Calendar calendar,
                          double faceAmount,
                          Date startDate,
                          Period bondTenor,
                          Frequency sinkingFrequency,
                          double coupon,
                          DayCounter accrualDayCounter,
                          BusinessDayConvention paymentConvention = BusinessDayConvention.Following,
                          Date issueDate = null)
         :base(settlementDays, calendar, issueDate)
      {
         frequency_ = sinkingFrequency;
         dayCounter_ = accrualDayCounter;

         Utils.QL_REQUIRE( bondTenor.length() > 0,() =>
                  "bond tenor must be positive. "
                  + bondTenor + " is not allowed." );

         maturityDate_ = startDate + bondTenor;
         maturityDate_ = startDate + bondTenor;
         schedule_ = sinkingSchedule(startDate, bondTenor, sinkingFrequency, calendar);
         cashflows_ = new FixedRateLeg(schedule_)
                        .withCouponRates(coupon, accrualDayCounter)
                        .withNotionals(sinkingNotionals(bondTenor, sinkingFrequency, coupon, faceAmount))        
                        .withPaymentAdjustment(paymentConvention).value();

         addRedemptionsToCashflows();

      }
示例#11
0
文件: T_Loan.cs 项目: akasolace/qlnet
        public void testFairRate()
        {
            Calendar calendar = new TARGET();

             Date settlementDate = new Date(10, Month.Mar, 2010);

             /*********************
             * LOAN TO BE PRICED *
             **********************/

             // constant nominal 1,000,000 Euro
             double nominal = 1000000.0;
             // fixed leg
             Frequency fixedLegFrequency = Frequency.Monthly;
             BusinessDayConvention fixedLegConvention = BusinessDayConvention.Unadjusted;
             BusinessDayConvention principalLegConvention = BusinessDayConvention.ModifiedFollowing;
             DayCounter fixedLegDayCounter = new Thirty360(Thirty360.Thirty360Convention.European);
             double fixedRate = 0.04;

             // Principal leg
             Frequency pricipalLegFrequency = Frequency.Annual;

             int lenghtInMonths = 3;
             Loan.Type loanType = Loan.Type.Payer;

             Date maturity = settlementDate + new Period(lenghtInMonths, TimeUnit.Years);
             Schedule fixedSchedule = new Schedule(settlementDate, maturity, new Period(fixedLegFrequency),
                                  calendar, fixedLegConvention, fixedLegConvention, DateGeneration.Rule.Forward, false);
             Schedule principalSchedule = new Schedule(settlementDate, maturity, new Period(pricipalLegFrequency),
                                  calendar, principalLegConvention, principalLegConvention, DateGeneration.Rule.Forward, false);
             Loan testLoan = new FixedLoan(loanType, nominal, fixedSchedule, fixedRate, fixedLegDayCounter,
                                     principalSchedule, principalLegConvention);
        }
示例#12
0
      //! fixed-rate bond
      /*! \ingroup instruments

          \test calculations are tested by checking results against
                cached values.
      */
 

      //! simple annual compounding coupon rates      
      public FixedRateBond(int settlementDays, double faceAmount, Schedule schedule,List<double> coupons, 
                           DayCounter accrualDayCounter, BusinessDayConvention paymentConvention = BusinessDayConvention.Following,
                           double redemption = 100, Date issueDate = null,Calendar paymentCalendar = null,
			                  Period exCouponPeriod = null,
                           Calendar exCouponCalendar = null,
									BusinessDayConvention exCouponConvention = BusinessDayConvention.Unadjusted,
                           bool exCouponEndOfMonth = false)
         : base(settlementDays, paymentCalendar == null ? schedule.calendar() : paymentCalendar, 
                issueDate) 
      {
         frequency_ = schedule.tenor().frequency();
         dayCounter_ = accrualDayCounter;
         maturityDate_ = schedule.endDate();

         cashflows_ = new FixedRateLeg(schedule)
            .withCouponRates(coupons, accrualDayCounter)
				.withExCouponPeriod(exCouponPeriod,
										  exCouponCalendar,
										  exCouponConvention,
										  exCouponEndOfMonth)
            .withPaymentCalendar(calendar_)
            .withNotionals(faceAmount)
            .withPaymentAdjustment(paymentConvention); 

         addRedemptionsToCashflows(new List<double>() { redemption });

         if (cashflows().Count == 0)
            throw new ApplicationException("bond with no cashflows!");

         if (redemptions_.Count != 1)
            throw new ApplicationException("multiple redemptions created");
      }
        //public FixedRateBondHelper(Quote cleanPrice, int settlementDays, double faceAmount, Schedule schedule,
        //                   List<double> coupons, DayCounter dayCounter,
        //                   BusinessDayConvention paymentConv = Following,
        //                   double redemption = 100.0,
        //                   Date issueDate = null);
        public FixedRateBondHelper(Handle<Quote> cleanPrice, int settlementDays, double faceAmount, Schedule schedule,
                                   List<double> coupons, DayCounter dayCounter, BusinessDayConvention paymentConvention,
                                   double redemption, Date issueDate)
            : base(cleanPrice, new FixedRateBond(settlementDays, faceAmount, schedule,
                                                 coupons, dayCounter, paymentConvention,
                                                 redemption, issueDate)) {

            fixedRateBond_ = bond_ as FixedRateBond;
        }
示例#14
0
        public void testATMRate()
        {
            CommonVars vars = new CommonVars();

            int[] lengths = { 1, 2, 3, 5, 7, 10, 15, 20 };
            double[] strikes = { 0.0, 0.03, 0.04, 0.05, 0.06, 0.07 };
            double[] vols = { 0.01, 0.05, 0.10, 0.15, 0.20 };

            Date startDate = vars.termStructure.link.referenceDate();

            for (int i = 0; i < lengths.Length; i++) {
                List<CashFlow> leg = vars.makeLeg(startDate, lengths[i]);
                Date maturity = vars.calendar.advance(startDate, lengths[i], TimeUnit.Years, vars.convention);
                Schedule schedule = new Schedule(startDate, maturity,
                                                 new Period(vars.frequency), vars.calendar,
                                                 vars.convention, vars.convention,
                                                 DateGeneration.Rule.Forward, false);

                for (int j = 0; j < strikes.Length; j++) {
                    for (int k = 0; k < vols.Length; k++) {

                        CapFloor cap = vars.makeCapFloor(CapFloorType.Cap, leg, strikes[j], vols[k]);
                        CapFloor floor = vars.makeCapFloor(CapFloorType.Floor, leg, strikes[j], vols[k]);
                        double capATMRate = cap.atmRate(vars.termStructure);
                        double floorATMRate = floor.atmRate(vars.termStructure);

                        if (!checkAbsError(floorATMRate, capATMRate, 1.0e-10))
                            Assert.Fail(
                              "Cap ATM Rate and floor ATM Rate should be equal :\n"
                              + "   length:        " + lengths[i] + " years\n"
                              + "   volatility:    " + vols[k] + "\n"
                              + "   strike:        " + strikes[j] + "\n"
                              + "   cap ATM rate:  " + capATMRate + "\n"
                              + "   floor ATM rate:" + floorATMRate + "\n"
                              + "   relative Error:"
                              + Utilities.relativeError(capATMRate, floorATMRate, capATMRate) * 100 + "%");
                        VanillaSwap swap = new VanillaSwap(VanillaSwap.Type.Payer, vars.nominals[0],
                                                           schedule, floorATMRate,
                                                           vars.index.dayCounter(),
                                                           schedule, vars.index, 0.0,
                                                           vars.index.dayCounter());
                        swap.setPricingEngine((IPricingEngine)(
                                               new DiscountingSwapEngine(vars.termStructure)));
                        double swapNPV = swap.NPV();
                        if (!checkAbsError(swapNPV, 0, 1.0e-10))
                            Assert.Fail(
                              "the NPV of a Swap struck at ATM rate "
                              + "should be equal to 0:\n"
                              + "   length:        " + lengths[i] + " years\n"
                              + "   volatility:    " + vols[k] + "\n"
                              + "   ATM rate:      " + floorATMRate + "\n"
                              + "   swap NPV:      " + swapNPV);

                    }
                }
            }
        }
示例#15
0
        private int bmaCutoffDays = 0; // to be verified

        // double gearing = 1.0, double spread = 0.0, 
        // Date refPeriodStart = Date(), Date refPeriodEnd = Date(), DayCounter dayCounter = DayCounter());
        public AverageBMACoupon(double nominal, Date paymentDate, Date startDate, Date endDate, BMAIndex index,
                                double gearing, double spread, Date refPeriodStart, Date refPeriodEnd, DayCounter dayCounter)
            : base(nominal, paymentDate, startDate, endDate, index.fixingDays(), index, gearing, spread,
                         refPeriodStart, refPeriodEnd, dayCounter, false) {
            fixingSchedule_ = index.fixingSchedule(
                                index.fixingCalendar()
                                    .advance(startDate, new Period(-index.fixingDays() + bmaCutoffDays, TimeUnit.Days),
                                                   BusinessDayConvention.Preceding), endDate);
            setPricer(new AverageBMACouponPricer());
        }
示例#16
0
 public yoyInflationLeg(Schedule schedule,Calendar cal,
                        YoYInflationIndex index,
                        Period observationLag)
 {
    schedule_ = schedule;
    index_ = index;
    observationLag_ = observationLag;
    paymentAdjustment_ = BusinessDayConvention.ModifiedFollowing;
    paymentCalendar_ = cal;
 }
示例#17
0
 public DigitalIborLeg(Schedule schedule, IborIndex index)
 {
    schedule_ = schedule;
    index_ = index;
    paymentAdjustment_ = BusinessDayConvention.Following;
    inArrears_ = false;
    longCallOption_ = Position.Type.Long;
    callATM_ = false;
    longPutOption_ = Position.Type.Long;
    putATM_ = false;
 }
示例#18
0
        public Cash value()
        {
            Period principalPeriod = amortising_ == Loan.Amortising.Bullet ?
                                  new Period(Frequency.Once) :
                                  new Period(frequency_);

             Schedule principalSchedule = new Schedule(startDate_, endDate_, principalPeriod,
                                  calendar_, convention_, convention_, rule_, endOfMonth_);

             Cash c = new Cash(type_, nominal_, principalSchedule, convention_);
             return c;
        }
      public BasisSwap(Type type, double nominal,
                         Schedule float1Schedule, IborIndex iborIndex1, double spread1, DayCounter float1DayCount,
                         Schedule float2Schedule, IborIndex iborIndex2, double spread2, DayCounter float2DayCount,
                         BusinessDayConvention? paymentConvention) :
         base(2)
      {
         type_ = type;
         nominal_ = nominal;
         floating1Schedule_ = float1Schedule;
         spread1_ = spread1;
         floating1DayCount_ = float1DayCount;
         iborIndex1_ = iborIndex1;
         floating2Schedule_ = float2Schedule;
         spread2_ = spread2;
         floating2DayCount_ = float2DayCount;
         iborIndex2_ = iborIndex2;

         if (paymentConvention.HasValue)
            paymentConvention_ = paymentConvention.Value;
         else
            paymentConvention_ = floating1Schedule_.businessDayConvention();

         List<CashFlow> floating1Leg = new IborLeg(float1Schedule, iborIndex1)
                                     .withPaymentDayCounter(float1DayCount)
                                     .withSpreads(spread1)
                                     .withNotionals(nominal)
                                     .withPaymentAdjustment(paymentConvention_);

         List<CashFlow> floating2Leg = new IborLeg(float2Schedule, iborIndex2)
                                     .withPaymentDayCounter(float2DayCount)
                                     .withSpreads(spread2)
                                     .withNotionals(nominal)
                                     .withPaymentAdjustment(paymentConvention_);

         foreach (var cf in floating1Leg)
            cf.registerWith(update);
         foreach (var cf in floating2Leg)
            cf.registerWith(update);


         legs_[0] = floating1Leg;
         legs_[1] = floating2Leg;
         if (type_ == Type.Payer)
         {
            payer_[0] = -1;
            payer_[1] = +1;
         }
         else
         {
            payer_[0] = +1;
            payer_[1] = -1;
         }
      }
示例#20
0
文件: CPIBond.cs 项目: minikie/test
        public CPIBond(int settlementDays,
                double faceAmount,
                bool growthOnly,
                double baseCPI,
                Period observationLag,
                ZeroInflationIndex cpiIndex,
                InterpolationType observationInterpolation,
                Schedule schedule,
                List<double> fixedRate,
                DayCounter accrualDayCounter,
                BusinessDayConvention paymentConvention = BusinessDayConvention.ModifiedFollowing,
                Date issueDate = null,
                Calendar paymentCalendar = null,
                Period exCouponPeriod = null,
                Calendar exCouponCalendar = null,
					 BusinessDayConvention exCouponConvention = BusinessDayConvention.Unadjusted,
                bool exCouponEndOfMonth = false)                
            :base(settlementDays, paymentCalendar == null ? schedule.calendar() : paymentCalendar, issueDate)
        {
            frequency_ = schedule.tenor().frequency();
            dayCounter_ = accrualDayCounter;
            growthOnly_ = growthOnly;
            baseCPI_=baseCPI;
            observationLag_ = observationLag;
            cpiIndex_= cpiIndex;
            observationInterpolation_ = observationInterpolation;

            maturityDate_ = schedule.endDate();

            // a CPIleg know about zero legs and inclusion of base inflation notional
            cashflows_ = new CPILeg(schedule, cpiIndex_,
                                    baseCPI_, observationLag_)
             .withSubtractInflationNominal(growthOnly_)
             .withObservationInterpolation(observationInterpolation_)
             .withPaymentDayCounter(accrualDayCounter)
             .withFixedRates(fixedRate)
             .withPaymentCalendar(calendar_)
             .withExCouponPeriod(exCouponPeriod,
                                exCouponCalendar,
                                exCouponConvention,
                                exCouponEndOfMonth)
             .withNotionals(faceAmount)
             .withPaymentAdjustment(paymentConvention);
            

            calculateNotionalsFromCashflows();

            cpiIndex_.registerWith(update);

            foreach ( CashFlow i in cashflows_) 
                i.registerWith(update);
        }
示例#21
0
        // constructor
        public VanillaSwap(Type type, double nominal,
                         Schedule fixedSchedule, double fixedRate, DayCounter fixedDayCount,
                         Schedule floatSchedule, IborIndex iborIndex, double spread, DayCounter floatingDayCount,
                         BusinessDayConvention? paymentConvention = null)
            : base(2)
        {
            type_ = type;
             nominal_ = nominal;
             fixedSchedule_ = fixedSchedule;
             fixedRate_ = fixedRate;
             fixedDayCount_ = fixedDayCount;
             floatingSchedule_ = floatSchedule;
             iborIndex_ = iborIndex;
             spread_ = spread;
             floatingDayCount_ = floatingDayCount;

             if (paymentConvention.HasValue)
            paymentConvention_ = paymentConvention.Value;
             else
            paymentConvention_ = floatingSchedule_.businessDayConvention();

             legs_[0] = new FixedRateLeg(fixedSchedule)
                                     .withCouponRates(fixedRate, fixedDayCount)
                                     .withPaymentAdjustment(paymentConvention_)
                                     .withNotionals(nominal);

             legs_[1] = new IborLeg(floatSchedule, iborIndex)
                                     .withPaymentDayCounter(floatingDayCount)
            //.withFixingDays(iborIndex.fixingDays())
                                     .withSpreads(spread)
                                     .withNotionals(nominal)
                                     .withPaymentAdjustment(paymentConvention_);

             foreach (var cf in legs_[1])
            cf.registerWith(update);

             switch (type_)
             {
            case Type.Payer:
               payer_[0] = -1.0;
               payer_[1] = +1.0;
               break;
            case Type.Receiver:
               payer_[0] = +1.0;
               payer_[1] = -1.0;
               break;
            default:
               throw new ApplicationException("Unknown vanilla-swap type");
             }
        }
示例#22
0
      public OvernightIndexedSwap(Type type,
                                  double nominal,
                                  Schedule schedule,
                                  double fixedRate,
                                  DayCounter fixedDC,
                                  OvernightIndex overnightIndex,
                                  double spread) : 
      base(2)
      {
      
         type_= type;
         nominal_ = nominal;
         paymentFrequency_ = schedule.tenor().frequency();
         fixedRate_ = fixedRate;
         fixedDC_ = fixedDC;
         overnightIndex_ = overnightIndex;
         spread_ = spread;

         if (fixedDC_== null)
            fixedDC_ = overnightIndex_.dayCounter();

         legs_[0] = new FixedRateLeg(schedule)
            .withCouponRates(fixedRate_, fixedDC_)
            .withNotionals(nominal_);

        legs_[1] = new OvernightLeg(schedule, overnightIndex_)
            .withNotionals(nominal_)
            .withSpreads(spread_);

         for (int j = 0; j < 2; ++j)
         {
            for (int i = 0; i < legs_[j].Count; i++)
               legs_[j][i].registerWith(update);
         }

         switch (type_) 
         {
            case Type.Payer:
               payer_[0] = -1.0;
               payer_[1] = +1.0;
               break;
            case Type.Receiver:
               payer_[0] = +1.0;
               payer_[1] = -1.0;
               break;
            default:
               throw new ApplicationException("Unknown overnight-swap type"); 
         
         }
      }
示例#23
0
        public SwaptionHelper(Period maturity,
            Period length,
            Handle<Quote> volatility,
            IborIndex index,
            Period fixedLegTenor,
            DayCounter fixedLegDayCounter,
            DayCounter floatingLegDayCounter,
            Handle<YieldTermStructure> termStructure,
            bool calibrateVolatility /*= false*/)
            : base(volatility,termStructure, calibrateVolatility)
        {
            Calendar calendar = index.fixingCalendar();
            Period indexTenor = index.tenor();
            int fixingDays = index.fixingDays();

            Date exerciseDate   = calendar.advance(termStructure.link.referenceDate(),
                                                maturity,
                                                index.businessDayConvention());
            Date startDate      = calendar.advance(exerciseDate,
                                                fixingDays, TimeUnit.Days,
                                                index.businessDayConvention());
            Date endDate        = calendar.advance(startDate, length,
                                                index.businessDayConvention());

            Schedule fixedSchedule=new Schedule(startDate, endDate, fixedLegTenor, calendar,
                                            index.businessDayConvention(),
                                            index.businessDayConvention(),
                                            DateGeneration.Rule.Forward, false);
            Schedule floatSchedule=new Schedule(startDate, endDate, index.tenor(), calendar,
                                            index.businessDayConvention(),
                                            index.businessDayConvention(),
                                            DateGeneration.Rule.Forward, false);

            IPricingEngine swapEngine=new DiscountingSwapEngine(termStructure);

            VanillaSwap temp=new VanillaSwap(VanillaSwap.Type.Receiver, 1.0,
                                        fixedSchedule, 0.0, fixedLegDayCounter,
                                        floatSchedule, index, 0.0, floatingLegDayCounter);
            temp.setPricingEngine(swapEngine);
            exerciseRate_ = temp.fairRate();
            swap_ = new VanillaSwap(VanillaSwap.Type.Receiver, 1.0,
                            fixedSchedule, exerciseRate_, fixedLegDayCounter,
                            floatSchedule, index, 0.0, floatingLegDayCounter);
            swap_.setPricingEngine(swapEngine);

            Exercise exercise=new EuropeanExercise(exerciseDate);
            swaption_ = new Swaption(swap_, exercise);
            marketValue_ = blackPrice(volatility_.link.value());
        }
示例#24
0
        public FloatingLoan(Type type, double nominal,
            Schedule floatingSchedule, double floatingSpread, DayCounter floatingDayCount,
            Schedule principalSchedule, BusinessDayConvention? paymentConvention, IborIndex index)
            : base(2)
        {
            type_ = type;
            nominal_ = nominal;
            floatingSchedule_ = floatingSchedule;
            floatingSpread_ = floatingSpread;
            floatingDayCount_ = floatingDayCount;
            principalSchedule_ = principalSchedule;
            iborIndex_ = index;

            if (paymentConvention.HasValue)
                paymentConvention_ = paymentConvention.Value;
            else
                paymentConvention_ = floatingSchedule_.businessDayConvention();

            List<CashFlow> principalLeg = new PricipalLeg(principalSchedule, floatingDayCount)
                .withNotionals(nominal)
                .withPaymentAdjustment(paymentConvention_)
                .withSign(type == Type.Loan ? -1 : 1);

            // temporary
            for (int i = 0; i < principalLeg.Count - 1; i++)
            {
                Principal p = (Principal)principalLeg[i];
                notionals_.Add(p.nominal());
            }

            List<CashFlow> floatingLeg = new IborLeg(floatingSchedule, iborIndex_)
                .withPaymentDayCounter(floatingDayCount_)
                .withSpreads(floatingSpread_)
                .withPaymentAdjustment(paymentConvention_)
                .withNotionals(notionals_);

            legs_[0] = floatingLeg;
            legs_[1] = principalLeg;
            if (type_ == Type.Loan)
            {
                payer_[0] = -1;
                payer_[1] = +1;
            }
            else
            {
                payer_[0] = +1;
                payer_[1] = -1;
            }
        }
示例#25
0
      public AmortizingFloatingRateBond(int settlementDays,
                                        List<double> notionals,
                                        Schedule schedule,
                                        IborIndex index,
                                        DayCounter accrualDayCounter,
                                        BusinessDayConvention paymentConvention = BusinessDayConvention.Following,
                                        int fixingDays = 0,
                                        List<double> gearings = null,
                                        List<double> spreads = null,
                                        List<double> caps = null,
                                        List<double> floors = null,
                                        bool inArrears = false,
                                        Date issueDate = null)
         :base(settlementDays, schedule.calendar(), issueDate)
      {
         if ( gearings == null ) 
            gearings = new List<double>() {1, 1.0};

         if (spreads == null)
            spreads = new List<double>() { 1, 0.0 };

         if (caps == null)
            caps = new List<double>() ;

         if (floors == null)
            floors = new List<double>();

         maturityDate_ = schedule.endDate();


         cashflows_ = new IborLeg(schedule, index)
                         .withCaps(caps)
                         .withFloors(floors)
                         .inArrears(inArrears)
                         .withSpreads(spreads)
                         .withGearings(gearings)
                         .withFixingDays(fixingDays)
                         .withPaymentDayCounter(accrualDayCounter)
                         .withPaymentAdjustment(paymentConvention)
                         .withNotionals(notionals).value();

         addRedemptionsToCashflows();

         Utils.QL_REQUIRE( !cashflows().empty(), () => "bond with no cashflows!" );

         index.registerWith(update);

      }
示例#26
0
文件: bmaswap.cs 项目: Yenyenx/qlnet
        public BMASwap(Type type, double nominal,
                // Libor leg
                Schedule liborSchedule, double liborFraction, double liborSpread, IborIndex liborIndex, DayCounter liborDayCount,
                // BMA leg
                Schedule bmaSchedule, BMAIndex bmaIndex, DayCounter bmaDayCount)
            : base(2)
        {
            type_ = type;
            nominal_ = nominal;
            liborFraction_ = liborFraction;
            liborSpread_ = liborSpread;

            BusinessDayConvention convention = liborSchedule.businessDayConvention();

            legs_[0] = new IborLeg(liborSchedule, liborIndex)
                        .withPaymentDayCounter(liborDayCount)
                        .withFixingDays(liborIndex.fixingDays())
                        .withGearings(liborFraction)
                        .withSpreads(liborSpread)
                        .withNotionals(nominal)
                        .withPaymentAdjustment(convention);

            legs_[1] = new AverageBMALeg(bmaSchedule, bmaIndex)
                        .withPaymentDayCounter(bmaDayCount)
                        .withNotionals(nominal)
                        .withPaymentAdjustment(bmaSchedule.businessDayConvention());

            for (int j=0; j<2; ++j) {
                for (int i=0; i<legs_[j].Count; i++)
                    legs_[j][i].registerWith(update);
            }

            switch (type_) {
                case Type.Payer:
                    payer_[0] = +1.0;
                    payer_[1] = -1.0;
                    break;
                case Type.Receiver:
                    payer_[0] = -1.0;
                    payer_[1] = +1.0;
                    break;
                default:
                    throw new ApplicationException("Unknown BMA-swap type");
            }
        }
示例#27
0
         public CmsRateBond(int settlementDays,
                            double faceAmount,
                            Schedule schedule,
                            SwapIndex index,
                            DayCounter paymentDayCounter,
                            BusinessDayConvention paymentConvention = BusinessDayConvention.Following,
                            int fixingDays = 0,
                            List<double> gearings = null,
                            List<double> spreads = null,
                            List<double> caps = null,
                            List<double> floors = null,
                            bool inArrears = false,
                            double redemption = 100.0,
                            Date issueDate = null)
             : base(settlementDays, schedule.calendar(), issueDate) 
         {
             // Optional value check
             if ( gearings == null ) gearings = new List<double>(){1};
             if ( spreads == null ) spreads = new List<double>(){0};
             if (caps == null) caps = new List<double>();
             if (floors == null) floors = new List<double>();

             maturityDate_ = schedule.endDate();
             cashflows_ = new CmsLeg(schedule, index)
                            .withPaymentDayCounter(paymentDayCounter)
                            .withFixingDays(fixingDays)
                            .withGearings(gearings)
                            .withSpreads(spreads)
                            .withCaps(caps)
                            .withFloors(floors)
                            .inArrears(inArrears)
                            .withNotionals(faceAmount)
                            .withPaymentAdjustment(paymentConvention); 
              
             addRedemptionsToCashflows(new List<double>() { redemption });

             if (cashflows().Count == 0)
                throw new ApplicationException("bond with no cashflows!");
             if (redemptions_.Count != 1)
                throw new ApplicationException("multiple redemptions created");

             index.registerWith(update);

        
        }
示例#28
0
文件: FixedLoan.cs 项目: vdt/QLNet
        public FixedLoan(Type type, double nominal, Schedule fixedSchedule, double fixedRate, DayCounter fixedDayCount, Schedule principalSchedule, BusinessDayConvention? paymentConvention)
            : base(2)
        {
            type_ = type;
            nominal_ = nominal;
            fixedSchedule_ = fixedSchedule;
            fixedRate_ = fixedRate;
            fixedDayCount_ = fixedDayCount;
            principalSchedule_ = principalSchedule;

            if (paymentConvention.HasValue)
                paymentConvention_ = paymentConvention.Value;
            else
                paymentConvention_ = fixedSchedule_.businessDayConvention();

            List<CashFlow> principalLeg = new PricipalLeg(principalSchedule, fixedDayCount)
                .withNotionals(nominal)
                .withPaymentAdjustment(paymentConvention_)
                .withSign(type == Type.Loan ? -1 : 1);

            // temporary
            for (int i = 0; i < principalLeg.Count - 1; i++)
            {
                Principal p = (Principal)principalLeg[i];
                notionals_.Add(p.nominal());
            }

            List<CashFlow> fixedLeg = new FixedRateLeg(fixedSchedule)
                .withCouponRates(fixedRate, fixedDayCount)
                .withPaymentAdjustment(paymentConvention_)
                .withNotionals(notionals_);

            legs_[0] = fixedLeg;
            legs_[1] = principalLeg;
            if (type_ == Type.Loan)
            {
                payer_[0] = +1;
                payer_[1] = -1;
            }
            else
            {
                payer_[0] = -1;
                payer_[1] = +1;
            }
        }
示例#29
0
        public static AmortizingFixedRateBond makeAmortizingFixedBond( Date startDate, 
                                                                     Period bondLength, 
                                                                     DayCounter dCounter, 
                                                                     Frequency payFrequency, 
                                                                     double amount, 
                                                                     double rate,
                                                                     Calendar calendar)
        {
            AmortizingFixedRateBond bond;
             Date endDate = calendar.advance(startDate,bondLength);

             Schedule schedule = new Schedule(startDate,endDate,bondLength,calendar,BusinessDayConvention.Unadjusted,
                                          BusinessDayConvention.Unadjusted,DateGeneration.Rule.Backward,false);

             bond = new AmortizingFixedRateBond(0, calendar, amount, startDate, bondLength, payFrequency, rate, dCounter);

             return bond;
        }
      //! simple annual compounding coupon rates      
      public FixedRateBond(int settlementDays, double faceAmount, Schedule schedule,List<double> coupons, 
                           DayCounter accrualDayCounter, BusinessDayConvention paymentConvention,
                           double redemption, Date issueDate,Calendar paymentCalendar)
         : base(settlementDays, paymentCalendar == new Calendar() ? schedule.calendar() : paymentCalendar, 
                issueDate) 
      {
         frequency_ = schedule.tenor().frequency();
         dayCounter_ = accrualDayCounter;
         maturityDate_ = schedule.endDate();

         cashflows_ = new FixedRateLeg(schedule)
            .withCouponRates(coupons, accrualDayCounter)
            .withPaymentCalendar(calendar_)
            .withNotionals(faceAmount)
            .withPaymentAdjustment(paymentConvention);

         addRedemptionsToCashflows(new List<double>() { redemption });

         if (cashflows().Count == 0)
            throw new ApplicationException("bond with no cashflows!");

         if (redemptions_.Count != 1)
            throw new ApplicationException("multiple redemptions created");
      }
示例#31
0
        public override void initialize(FloatingRateCoupon coupon)
        {
            coupon_ = coupon as CmsCoupon;
            Utils.QL_REQUIRE(coupon_ != null, "CMS coupon needed");
            gearing_ = coupon_.gearing();
            spread_  = coupon_.spread();

            fixingDate_  = coupon_.fixingDate();
            paymentDate_ = coupon_.date();
            SwapIndex swapIndex = coupon_.swapIndex();

            rateCurve_ = swapIndex.forwardingTermStructure().link;

            Date today = Settings.evaluationDate();

            if (paymentDate_ > today)
            {
                discount_ = rateCurve_.discount(paymentDate_);
            }
            else
            {
                discount_ = 1.0;
            }

            spreadLegValue_ = spread_ * coupon_.accrualPeriod() * discount_;

            if (fixingDate_ > today)
            {
                swapTenor_ = swapIndex.tenor();
                VanillaSwap swap = swapIndex.underlyingSwap(fixingDate_);

                swapRateValue_ = swap.fairRate();

                double bp = 1.0e-4;
                annuity_ = (swap.floatingLegBPS() / bp);

                int        q        = (int)swapIndex.fixedLegTenor().frequency();
                Schedule   schedule = swap.fixedSchedule();
                DayCounter dc       = swapIndex.dayCounter();
                //DayCounter dc = coupon.dayCounter();
                double startTime            = dc.yearFraction(rateCurve_.referenceDate(), swap.startDate());
                double swapFirstPaymentTime = dc.yearFraction(rateCurve_.referenceDate(), schedule.date(1));
                double paymentTime          = dc.yearFraction(rateCurve_.referenceDate(), paymentDate_);
                double delta = (paymentTime - startTime) / (swapFirstPaymentTime - startTime);

                switch (modelOfYieldCurve_)
                {
                case GFunctionFactory.YieldCurveModel.Standard:
                    gFunction_ = GFunctionFactory.newGFunctionStandard(q, delta, swapTenor_.length());
                    break;

                case GFunctionFactory.YieldCurveModel.ExactYield:
                    gFunction_ = GFunctionFactory.newGFunctionExactYield(coupon_);
                    break;

                case GFunctionFactory.YieldCurveModel.ParallelShifts: {
                    Handle <Quote> nullMeanReversionQuote = new Handle <Quote>(new SimpleQuote(0.0));
                    gFunction_ = GFunctionFactory.newGFunctionWithShifts(coupon_, nullMeanReversionQuote);
                }
                break;

                case GFunctionFactory.YieldCurveModel.NonParallelShifts:
                    gFunction_ = GFunctionFactory.newGFunctionWithShifts(coupon_, meanReversion_);
                    break;

                default:
                    throw new ApplicationException("unknown/illegal gFunction type");
                }
                vanillaOptionPricer_ = new BlackVanillaOptionPricer(swapRateValue_, fixingDate_, swapTenor_, swaptionVolatility().link);
            }
        }
示例#32
0
        public static List <CashFlow> yoyInflationLeg(List <double> notionals_,
                                                      Schedule schedule_,
                                                      BusinessDayConvention paymentAdjustment_,
                                                      YoYInflationIndex index_,
                                                      List <double> gearings_,
                                                      List <double> spreads_,
                                                      DayCounter paymentDayCounter_,
                                                      List <double?> caps_,
                                                      List <double?> floors_,
                                                      Calendar paymentCalendar_,
                                                      List <int> fixingDays_,
                                                      Period observationLag_)
        {
            int n = schedule_.Count - 1;

            Utils.QL_REQUIRE(!notionals_.empty(), () => "no notional given");
            Utils.QL_REQUIRE(notionals_.Count <= n, () => "too many nominals (" + notionals_.Count + "), only " + n + " required");
            if (gearings_ != null)
            {
                Utils.QL_REQUIRE(gearings_.Count <= n, () => "too many gearings (" + gearings_.Count + "), only " + n + " required");
            }
            if (spreads_ != null)
            {
                Utils.QL_REQUIRE(spreads_.Count <= n, () => "too many spreads (" + spreads_.Count + "), only " + n + " required");
            }
            if (caps_ != null)
            {
                Utils.QL_REQUIRE(caps_.Count <= n, () => "too many caps (" + caps_.Count + "), only " + n + " required");
            }
            if (floors_ != null)
            {
                Utils.QL_REQUIRE(floors_.Count <= n, () => "too many floors (" + floors_.Count + "), only " + n + " required");
            }


            List <CashFlow> leg = new List <CashFlow>(n);

            Calendar calendar = paymentCalendar_;

            Date refStart, start, refEnd, end;

            for (int i = 0; i < n; ++i)
            {
                refStart = start = schedule_.date(i);
                refEnd   = end = schedule_.date(i + 1);
                Date paymentDate = calendar.adjust(end, paymentAdjustment_);
                if (i == 0 && !schedule_.isRegular(i + 1))
                {
                    BusinessDayConvention bdc = schedule_.businessDayConvention();
                    refStart = schedule_.calendar().adjust(end - schedule_.tenor(), bdc);
                }
                if (i == n - 1 && !schedule_.isRegular(i + 1))
                {
                    BusinessDayConvention bdc = schedule_.businessDayConvention();
                    refEnd = schedule_.calendar().adjust(start + schedule_.tenor(), bdc);
                }
                if (Utils.Get(gearings_, i, 1.0).IsEqual(0.0))
                {
                    // fixed coupon
                    leg.Add(new FixedRateCoupon(paymentDate, Utils.Get(notionals_, i, 1.0),
                                                Utils.effectiveFixedRate(spreads_, caps_, floors_, i),
                                                paymentDayCounter_,
                                                start, end, refStart, refEnd));
                }
                else
                {
                    // yoy inflation coupon
                    if (Utils.noOption(caps_, floors_, i))
                    {
                        // just swaplet
                        YoYInflationCoupon coup = new YoYInflationCoupon(paymentDate,
                                                                         Utils.Get(notionals_, i, 1.0),
                                                                         start, end,
                                                                         Utils.Get(fixingDays_, i, 0),
                                                                         index_,
                                                                         observationLag_,
                                                                         paymentDayCounter_,
                                                                         Utils.Get(gearings_, i, 1.0),
                                                                         Utils.Get(spreads_, i, 0.0),
                                                                         refStart, refEnd);

                        // in this case you can set a pricer
                        // straight away because it only provides computation - not data
                        YoYInflationCouponPricer pricer = new YoYInflationCouponPricer();
                        coup.setPricer(pricer);
                        leg.Add(coup);
                    }
                    else
                    {
                        // cap/floorlet
                        leg.Add(new CappedFlooredYoYInflationCoupon(
                                    paymentDate,
                                    Utils.Get(notionals_, i, 1.0),
                                    start, end,
                                    Utils.Get(fixingDays_, i, 0),
                                    index_,
                                    observationLag_,
                                    paymentDayCounter_,
                                    Utils.Get(gearings_, i, 1.0),
                                    Utils.Get(spreads_, i, 0.0),
                                    Utils.toNullable(Utils.Get(caps_, i, Double.MinValue)),
                                    Utils.toNullable(Utils.Get(floors_, i, Double.MinValue)),
                                    refStart, refEnd));
                    }
                }
            }

            return(leg);
        }
示例#33
0
        public static List <CashFlow> FloatingLeg <InterestRateIndexType, FloatingCouponType, CappedFlooredCouponType>(
            List <double> nominals,
            Schedule schedule,
            InterestRateIndexType index,
            DayCounter paymentDayCounter,
            BusinessDayConvention paymentAdj,
            List <int> fixingDays,
            List <double> gearings,
            List <double> spreads,
            List <double?> caps,
            List <double?> floors,
            bool isInArrears,
            bool isZero)
            where InterestRateIndexType : InterestRateIndex, new()
            where FloatingCouponType : FloatingRateCoupon, new()
            where CappedFlooredCouponType : CappedFlooredCoupon, new()
        {
            int n = schedule.Count;

            Utils.QL_REQUIRE(!nominals.empty(), () => "no notional given");
            Utils.QL_REQUIRE(nominals.Count <= n, () => "too many nominals (" + nominals.Count + "), only " + n + " required");
            if (gearings != null)
            {
                Utils.QL_REQUIRE(gearings.Count <= n, () => "too many gearings (" + gearings.Count + "), only " + n + " required");
            }
            if (spreads != null)
            {
                Utils.QL_REQUIRE(spreads.Count <= n, () => "too many spreads (" + spreads.Count + "), only " + n + " required");
            }
            if (caps != null)
            {
                Utils.QL_REQUIRE(caps.Count <= n, () => "too many caps (" + caps.Count + "), only " + n + " required");
            }
            if (floors != null)
            {
                Utils.QL_REQUIRE(floors.Count <= n, () => "too many floors (" + floors.Count + "), only " + n + " required");
            }
            Utils.QL_REQUIRE(!isZero || !isInArrears, () => "in-arrears and zero features are not compatible");

            List <CashFlow> leg = new List <CashFlow>();

            // the following is not always correct
            Calendar calendar = schedule.calendar();

            Date lastPaymentDate = calendar.adjust(schedule[n - 1], paymentAdj);

            for (int i = 0; i < n - 1; ++i)
            {
                Date refStart, start, refEnd, end;
                refStart = start = schedule[i];
                refEnd   = end = schedule[i + 1];
                Date paymentDate = isZero ? lastPaymentDate : calendar.adjust(end, paymentAdj);
                if (i == 0 && !schedule.isRegular(i + 1))
                {
                    refStart = calendar.adjust(end - schedule.tenor(), schedule.businessDayConvention());
                }
                if (i == n - 1 && !schedule.isRegular(i + 1))
                {
                    refEnd = calendar.adjust(start + schedule.tenor(), schedule.businessDayConvention());
                }

                if (Utils.Get(gearings, i, 1).IsEqual(0.0))
                {
                    // fixed coupon
                    leg.Add(new FixedRateCoupon(paymentDate, Utils.Get(nominals, i),
                                                Utils.effectiveFixedRate(spreads, caps, floors, i),
                                                paymentDayCounter,
                                                start, end, refStart, refEnd));
                }
                else
                {
                    if (Utils.noOption(caps, floors, i))
                    {
                        leg.Add(FastActivator <FloatingCouponType> .Create().factory(
                                    Utils.Get(nominals, i),
                                    paymentDate, start, end,
                                    Utils.Get(fixingDays, i, index.fixingDays()),
                                    index,
                                    Utils.Get(gearings, i, 1),
                                    Utils.Get(spreads, i),
                                    refStart, refEnd, paymentDayCounter,
                                    isInArrears));
                    }
                    else
                    {
                        leg.Add(FastActivator <CappedFlooredCouponType> .Create().factory(
                                    Utils.Get(nominals, i),
                                    paymentDate, start, end,
                                    Utils.Get(fixingDays, i, index.fixingDays()),
                                    index,
                                    Utils.Get(gearings, i, 1),
                                    Utils.Get(spreads, i),
                                    Utils.toNullable(Utils.Get(caps, i, Double.MinValue)),
                                    Utils.toNullable(Utils.Get(floors, i, Double.MinValue)),
                                    refStart, refEnd, paymentDayCounter,
                                    isInArrears));
                    }
                }
            }
            return(leg);
        }
示例#34
0
        public static List <CashFlow> FloatingDigitalLeg <InterestRateIndexType, FloatingCouponType, DigitalCouponType>(
            List <double> nominals,
            Schedule schedule,
            InterestRateIndexType index,
            DayCounter paymentDayCounter,
            BusinessDayConvention paymentAdj,
            List <int> fixingDays,
            List <double> gearings,
            List <double> spreads,
            bool isInArrears,
            List <double> callStrikes,
            Position.Type callPosition,
            bool isCallATMIncluded,
            List <double> callDigitalPayoffs,
            List <double> putStrikes,
            Position.Type putPosition,
            bool isPutATMIncluded,
            List <double> putDigitalPayoffs,
            DigitalReplication replication)
            where InterestRateIndexType : InterestRateIndex, new()
            where FloatingCouponType : FloatingRateCoupon, new()
            where DigitalCouponType : DigitalCoupon, new()
        {
            int n = schedule.Count;

            Utils.QL_REQUIRE(!nominals.empty(), () => "no notional given");
            Utils.QL_REQUIRE(nominals.Count <= n, () => "too many nominals (" + nominals.Count + "), only " + n + " required");
            if (gearings != null)
            {
                Utils.QL_REQUIRE(gearings.Count <= n, () => "too many gearings (" + gearings.Count + "), only " + n + " required");
            }
            if (spreads != null)
            {
                Utils.QL_REQUIRE(spreads.Count <= n, () => "too many spreads (" + spreads.Count + "), only " + n + " required");
            }
            if (callStrikes != null)
            {
                Utils.QL_REQUIRE(callStrikes.Count <= n, () => "too many nominals (" + callStrikes.Count + "), only " + n + " required");
            }
            if (putStrikes != null)
            {
                Utils.QL_REQUIRE(putStrikes.Count <= n, () => "too many nominals (" + putStrikes.Count + "), only " + n + " required");
            }

            List <CashFlow> leg = new List <CashFlow>();

            // the following is not always correct
            Calendar calendar = schedule.calendar();

            Date refStart, start, refEnd, end;
            Date paymentDate;

            for (int i = 0; i < n; ++i)
            {
                refStart    = start = schedule.date(i);
                refEnd      = end = schedule.date(i + 1);
                paymentDate = calendar.adjust(end, paymentAdj);
                if (i == 0 && !schedule.isRegular(i + 1))
                {
                    BusinessDayConvention bdc = schedule.businessDayConvention();
                    refStart = calendar.adjust(end - schedule.tenor(), bdc);
                }
                if (i == n - 1 && !schedule.isRegular(i + 1))
                {
                    BusinessDayConvention bdc = schedule.businessDayConvention();
                    refEnd = calendar.adjust(start + schedule.tenor(), bdc);
                }
                if (Utils.Get(gearings, i, 1.0).IsEqual(0.0))
                {
                    // fixed coupon
                    leg.Add(new FixedRateCoupon(paymentDate, Utils.Get(nominals, i, 1.0),
                                                Utils.Get(spreads, i, 1.0),
                                                paymentDayCounter,
                                                start, end, refStart, refEnd));
                }
                else
                {
                    // floating digital coupon
                    FloatingCouponType underlying = FastActivator <FloatingCouponType> .Create().factory(
                        Utils.Get(nominals, i, 1.0),
                        paymentDate, start, end,
                        Utils.Get(fixingDays, i, index.fixingDays()),
                        index,
                        Utils.Get(gearings, i, 1.0),
                        Utils.Get(spreads, i, 0.0),
                        refStart, refEnd,
                        paymentDayCounter, isInArrears) as FloatingCouponType;

                    DigitalCouponType digitalCoupon = FastActivator <DigitalCouponType> .Create().factory(
                        underlying,
                        Utils.toNullable(Utils.Get(callStrikes, i, Double.MinValue)),
                        callPosition,
                        isCallATMIncluded,
                        Utils.toNullable(Utils.Get(callDigitalPayoffs, i, Double.MinValue)),
                        Utils.toNullable(Utils.Get(putStrikes, i, Double.MinValue)),
                        putPosition,
                        isPutATMIncluded,
                        Utils.toNullable(Utils.Get(putDigitalPayoffs, i, Double.MinValue)),
                        replication) as DigitalCouponType;

                    leg.Add(digitalCoupon);
                }
            }
            return(leg);
        }