Exemple #1
0
        //! \name Volatility
        /*! by default, inflation is observed with the lag
            of the term structure.

            Because inflation is highly linked to dates (for
            interpolation, periods, etc) time-based overload of the
            methods are not provided.
        */

        //@{
        //! Returns the volatility for a given maturity date and strike rate.
        double volatility(Date maturityDate, double strike,
                           Period obsLag = null,
                           bool extrapolate = false)
        {
            if (obsLag == null)
                obsLag = new Period(-1, TimeUnit.Days);

            Period useLag = obsLag;
            if (obsLag == new Period(-1, TimeUnit.Days))
            {
                useLag = observationLag();
            }

            if (indexIsInterpolated())
            {
                checkRange(maturityDate - useLag, strike, extrapolate);
                double t = timeFromReference(maturityDate - useLag);
                return volatilityImpl(t, strike);
            }
            else
            {
                KeyValuePair<Date, Date> dd = Utils.inflationPeriod(maturityDate - useLag, frequency());
                checkRange(dd.Key, strike, extrapolate);
                double t = timeFromReference(dd.Key);
                return volatilityImpl(t, strike);
            }
        }
Exemple #2
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 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();

      }
 //! returns the volatility for a given option date and swap tenor
 public double volatility(Date optionDate, Period swapTenor, double strike, bool extrapolate = false)
 {
    checkSwapTenor(swapTenor, extrapolate);
    checkRange(optionDate, extrapolate);
    checkStrike(strike, extrapolate);
    return volatilityImpl(optionDate, swapTenor, strike);
 }
Exemple #5
0
        SwaptionHelper( Date exerciseDate,
            Period length,
            Handle<Quote> volatility,
            IborIndex index,
            Period fixedLegTenor,
            DayCounter fixedLegDayCounter,
            DayCounter floatingLegDayCounter,
            Handle<YieldTermStructure> termStructure,
            CalibrationErrorType errorType = CalibrationErrorType.RelativePriceError,
            double? strike = null,
            double nominal = 1.0)
            : base(volatility, termStructure, errorType)
        {
            exerciseDate_ = exerciseDate;
            endDate_ = null;
            maturity_ = new Period(0,TimeUnit.Days);
            length_ = length;
            fixedLegTenor_ = fixedLegTenor;
            index_ = index;
            fixedLegDayCounter_ = fixedLegDayCounter;
            floatingLegDayCounter_ = floatingLegDayCounter;
            strike_ = strike;
            nominal_ = nominal;

            index_.registerWith( update );
        }
Exemple #6
0
 public YoYInflationCoupon(Date paymentDate, double nominal, Date startDate, Date endDate, int fixingDays, YoYInflationIndex yoyIndex, Period observationLag, DayCounter dayCounter, double gearing, double spread, Date refPeriodStart, Date refPeriodEnd)
     : base(paymentDate, nominal, startDate, endDate, fixingDays, yoyIndex, observationLag, dayCounter, refPeriodStart, refPeriodEnd)
 {
     yoyIndex_ = yoyIndex;
     gearing_ = gearing;
     spread_ = spread;
 }
Exemple #7
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);
             }
        }
 public CallableBondConstantVolatility(Date referenceDate, double volatility, DayCounter dayCounter)
    :base(referenceDate)
 {
    volatility_ = new Handle<Quote>(new SimpleQuote(volatility));
    dayCounter_ = dayCounter;
    maxBondTenor_ = new Period(100,TimeUnit.Years);
 }
Exemple #9
0
 public BlackVanillaOptionPricer(double forwardValue, Date expiryDate, Period swapTenor, SwaptionVolatilityStructure volatilityStructure) {
     forwardValue_ = forwardValue;
     expiryDate_ = expiryDate;
     swapTenor_ = swapTenor;
     volatilityStructure_ = volatilityStructure;
     smile_ = volatilityStructure_.smileSection(expiryDate_, swapTenor_);
 }
 public CallableBondConstantVolatility(int settlementDays, Calendar calendar, double volatility, DayCounter dayCounter)
    :base(settlementDays, calendar)
 {
    volatility_ = new Handle<Quote>(new SimpleQuote(volatility));
    dayCounter_ = dayCounter;
    maxBondTenor_ = new Period(100,TimeUnit.Years);
 }
Exemple #11
0
        public SwapRateHelper(double rate, Period tenor, Calendar calendar,
            Frequency fixedFrequency, BusinessDayConvention fixedConvention, DayCounter fixedDayCount,
            IborIndex iborIndex)
            : this(rate, tenor, calendar, fixedFrequency, fixedConvention, fixedDayCount, iborIndex,
		                      	     new Handle<Quote>(), new Period(0, TimeUnit.Days))
        {
        }
 public CallableBondConstantVolatility(int settlementDays, Calendar calendar, Handle<Quote> volatility,DayCounter dayCounter)
     :base(settlementDays, calendar)
 {
    volatility_ = volatility;
    dayCounter_ = dayCounter;
    maxBondTenor_ = new Period(100,TimeUnit.Years);
    volatility_.registerWith(update);
 }
Exemple #13
0
 public IborIndex(string familyName, Period tenor, int settlementDays, Currency currency,
          Calendar fixingCalendar, BusinessDayConvention convention, bool endOfMonth,
          DayCounter dayCounter)
     : this(familyName, tenor, settlementDays, currency,
            fixingCalendar, convention, endOfMonth,
            dayCounter, new Handle<YieldTermStructure>())
 {
 }
Exemple #14
0
 public Euribor365(Period tenor, Handle<YieldTermStructure> h)
     : base("Euribor365", tenor,
            2, // settlement days
            new EURCurrency(), new TARGET(), Utils.euriborConvention(tenor), Utils.euriborEOM(tenor),
            new Actual365Fixed(), h) {
     if (this.tenor().units() == TimeUnit.Days)
         throw new ApplicationException("for daily tenors (" + this.tenor() + ") dedicated DailyTenor constructor must be used");
 }
 //! returns the volatility for a given option time and swap tenor
 public double volatility(double optionTime, Period swapTenor, double strike, bool extrapolate = false)
 {
    checkSwapTenor(swapTenor, extrapolate);
    checkRange(optionTime, extrapolate);
    checkStrike(strike, extrapolate);
    double length = swapLength(swapTenor);
    return volatilityImpl(optionTime, length, strike);
 }
 public DepositRateHelper(double rate, Period tenor, int fixingDays, Calendar calendar,
     BusinessDayConvention convention, bool endOfMonth, DayCounter dayCounter)
     : base(rate)
 {
     iborIndex_ = new IborIndex("no-fix", tenor, fixingDays, new Currency(), calendar, convention,
                                endOfMonth, dayCounter, termStructureHandle_);
     initializeDates();
 }
Exemple #17
0
 public EURLibor(Period tenor, Handle<YieldTermStructure> h)
     : base("EURLibor", tenor, 2, new EURCurrency(), new JointCalendar(new UnitedKingdom(UnitedKingdom.Market.Exchange), new TARGET(),
         JointCalendar.JointCalendarRule.JoinHolidays),
         Utils.eurliborConvention(tenor), Utils.eurliborEOM(tenor), new Actual360(), h) {
     target_ = new TARGET();
     if (!(this.tenor().units() != TimeUnit.Days))
         throw new ApplicationException("for daily tenors (" + this.tenor() + ") dedicated DailyTenor constructor must be used");
 }
 public CallableBondConstantVolatility(Date referenceDate, Handle<Quote> volatility, DayCounter dayCounter)
    :base(referenceDate)
 {
    volatility_ = volatility;
    dayCounter_ = dayCounter;
    maxBondTenor_ = new Period(100,TimeUnit.Years);
    volatility_.registerWith(update);
 }
Exemple #19
0
 public BlackVanillaOptionPricer(double forwardValue, Date expiryDate, Period swapTenor, SwaptionVolatilityStructure volatilityStructure)
 {
     _forwardValue = forwardValue;
     _expiryDate = expiryDate;
     _swapTenor = swapTenor;
     _volatilityStructure = volatilityStructure;
     _smile = _volatilityStructure.smileSection(_expiryDate, _swapTenor);
 }
Exemple #20
0
 public CPILegBase withExCouponPeriod(Period period, Calendar cal, BusinessDayConvention convention, bool endOfMonth = false)
 {
     exCouponPeriod_ = period;
       exCouponCalendar_ = cal;
       exCouponAdjustment_ = convention;
       exCouponEndOfMonth_ = endOfMonth;
       return this;
 }
Exemple #21
0
 public static AmortizingFixedRateBond makeAmortizingFixedBond( Date startDate, 
                                                               Period bondLength, 
                                                               DayCounter dCounter, 
                                                               Frequency payFrequency, 
                                                               double amount, 
                                                               double rate)
 {
    return makeAmortizingFixedBond(startDate, bondLength, dCounter, payFrequency, amount, rate, new TARGET());
 }
Exemple #22
0
 public MakeSwaption(SwapIndex swapIndex,
     Period optionTenor,
     double strike)
 {
     swapIndex_ = swapIndex;
     delivery_ = Settlement.Type.Physical;
     optionTenor_ = optionTenor;
     optionConvention_ = BusinessDayConvention.ModifiedFollowing;
     strike_ = strike;
 }
Exemple #23
0
 public yoyInflationLeg(Schedule schedule,Calendar cal,
                        YoYInflationIndex index,
                        Period observationLag)
 {
    schedule_ = schedule;
    index_ = index;
    observationLag_ = observationLag;
    paymentAdjustment_ = BusinessDayConvention.ModifiedFollowing;
    paymentCalendar_ = cal;
 }
 //! floating reference date, fixed market data
 public ConstantSwaptionVolatility(int settlementDays,
                             Calendar cal,
                            BusinessDayConvention bdc,
                            double vol,
                            DayCounter dc)
     : base(settlementDays, cal, bdc, dc)
 {
     volatility_ = new Handle<Quote>(new SimpleQuote(vol));
     maxSwapTenor_ = new Period(100, TimeUnit.Years);
 }
Exemple #25
0
 public JpyLiborSwapIsdaFixPm(Period tenor, Handle<YieldTermStructure> h)
    : base("JpyLiborSwapIsdaFixPm", // familyName
           tenor,
           2, // settlementDays
           new JPYCurrency(),
           new TARGET(),
           new Period(6, TimeUnit.Months), // fixedLegTenor
           BusinessDayConvention.ModifiedFollowing, // fixedLegConvention
           new ActualActual(ActualActual.Convention.ISDA), // fixedLegDaycounter
           new JPYLibor(new Period(6, TimeUnit.Months), h)) { }
Exemple #26
0
 public UsdLiborSwapIsdaFixPm(Period tenor, Handle<YieldTermStructure> h)
    : base("UsdLiborSwapIsdaFixPm", // familyName
           tenor,
           2, // settlementDays
           new USDCurrency(),
           new TARGET(),
           new Period(6, TimeUnit.Months), // fixedLegTenor
           BusinessDayConvention.ModifiedFollowing, // fixedLegConvention
           new Thirty360(Thirty360.Thirty360Convention.BondBasis), // fixedLegDaycounter
           new USDLibor(new Period(3, TimeUnit.Months), h)) { }
 //! fixed reference date, floating market data
 public ConstantSwaptionVolatility(Date referenceDate,
                            Calendar cal,
                            BusinessDayConvention bdc,
                            Handle<Quote> vol,
                            DayCounter dc)
     : base(referenceDate, cal, bdc, dc)
 {
     volatility_ = vol;
     maxSwapTenor_ = new Period(100, TimeUnit.Years);
     volatility_.registerWith(update);
 }
Exemple #28
0
        public FRARateHelper(double rate, int monthsToStart, int monthsToEnd, int fixingDays, Calendar calendar,
            BusinessDayConvention convention, bool endOfMonth, DayCounter dayCounter)
            : base(rate)
        {
            periodToStart_ = new Period(monthsToStart, TimeUnit.Months);

            if (!(monthsToEnd > monthsToStart)) throw new ArgumentException("monthsToEnd must be grater than monthsToStart");
            iborIndex_ = new IborIndex("no-fix", new Period(monthsToEnd - monthsToStart, TimeUnit.Months), fixingDays,
                                       new Currency(), calendar, convention, endOfMonth, dayCounter, termStructureHandle_);
            initializeDates();
        }
Exemple #29
0
 public EuriborSwapIsdaFixB(Period tenor,Handle<YieldTermStructure> h)
    : base("EuriborSwapIsdaFixB", // familyName
           tenor,
           2, // settlementDays
           new EURCurrency(),
           new TARGET(),
           new Period(1,TimeUnit.Years), // fixedLegTenor
           BusinessDayConvention.ModifiedFollowing, // fixedLegConvention
           new Thirty360(Thirty360.Thirty360Convention.BondBasis), // fixedLegDaycounter
           tenor > new Period(1,TimeUnit.Years) ?
               new Euribor(new Period(6,TimeUnit.Months), h) :
               new Euribor(new Period(3,TimeUnit.Months), h)) {}
Exemple #30
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="familyName"></param>
        /// <param name="tenor"></param>
        /// <param name="settlementDays"></param>
        /// <param name="currency"></param>
        /// <param name="financialCenterCalendar"></param>
        /// <param name="dayCounter"></param>
        /// <param name="h"></param>
        /// <remarks>
        /// 
        /// http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1412 :
        ///		UnitedKingdom::Exchange is the fixing calendar for
        ///			a) all currencies but EUR
        ///			b) all indexes but o/n and s/n
        /// </remarks>
        public Libor(string familyName, Period tenor, int settlementDays, Currency currency, Calendar financialCenterCalendar, DayCounter dayCounter, Handle<YieldTermStructure> h)
            : base(familyName, tenor, settlementDays, currency, new UnitedKingdom(UnitedKingdom.Market.Exchange), Utils.liborConvention(tenor), Utils.liborEOM(tenor), dayCounter, h)
        {
            financialCenterCalendar_ = financialCenterCalendar;
            jointCalendar_ = new JointCalendar(new UnitedKingdom(UnitedKingdom.Market.Exchange), financialCenterCalendar, JointCalendar.JointCalendarRule.JoinHolidays);

            if (this.tenor().units() == TimeUnit.Days)
                throw new ApplicationException("for daily tenors (" + this.tenor() + ") dedicated DailyTenor constructor must be used");

            if (currency == new EURCurrency())
                throw new ApplicationException("for EUR Libor dedicated EurLibor constructor must be used");
        }
Exemple #31
0
 /*! The resulting interest rate has the required day-counting
  *  rule.
  *  \warning dates are not adjusted for holidays
  */
 public InterestRate forwardRate(Date d, Period p, DayCounter dayCounter, Compounding comp,
                                 Frequency freq = Frequency.Annual, bool extrapolate = false)
 {
     return(forwardRate(d, d + p, dayCounter, comp, freq, extrapolate));
 }
Exemple #32
0
        public CPISwap(Type type,
                       double nominal,
                       bool subtractInflationNominal,
                       // float+spread leg
                       double spread,
                       DayCounter floatDayCount,
                       Schedule floatSchedule,
                       BusinessDayConvention floatPaymentRoll,
                       int fixingDays,
                       IborIndex floatIndex,
                       // fixed x inflation leg
                       double fixedRate,
                       double baseCPI,
                       DayCounter fixedDayCount,
                       Schedule fixedSchedule,
                       BusinessDayConvention fixedPaymentRoll,
                       Period observationLag,
                       ZeroInflationIndex fixedIndex,
                       InterpolationType observationInterpolation = InterpolationType.AsIndex,
                       double?inflationNominal = null)
            : base(2)
        {
            type_    = type;
            nominal_ = nominal;
            subtractInflationNominal_ = subtractInflationNominal;
            spread_                   = spread;
            floatDayCount_            = floatDayCount;
            floatSchedule_            = floatSchedule;
            floatPaymentRoll_         = floatPaymentRoll;
            fixingDays_               = fixingDays;
            floatIndex_               = floatIndex;
            fixedRate_                = fixedRate;
            baseCPI_                  = baseCPI;
            fixedDayCount_            = fixedDayCount;
            fixedSchedule_            = fixedSchedule;
            fixedPaymentRoll_         = fixedPaymentRoll;
            fixedIndex_               = fixedIndex;
            observationLag_           = observationLag;
            observationInterpolation_ = observationInterpolation;

            Utils.QL_REQUIRE(floatSchedule_.Count > 0, () => "empty float schedule");
            Utils.QL_REQUIRE(fixedSchedule_.Count > 0, () => "empty fixed schedule");
            // todo if roll!=unadjusted then need calendars ...

            inflationNominal_ = inflationNominal ?? nominal_;

            List <CashFlow> floatingLeg;

            if (floatSchedule_.Count > 1)
            {
                floatingLeg = new IborLeg(floatSchedule_, floatIndex_)
                              .withFixingDays(fixingDays_)
                              .withPaymentDayCounter(floatDayCount_)
                              .withSpreads(spread_)
                              .withNotionals(nominal_)
                              .withPaymentAdjustment(floatPaymentRoll_);
            }
            else
            {
                floatingLeg = new List <CashFlow>();
            }

            if (floatSchedule_.Count == 1 ||
                !subtractInflationNominal_ ||
                (subtractInflationNominal && Math.Abs(nominal_ - inflationNominal_) > 0.00001)
                )
            {
                Date payNotional;
                if (floatSchedule_.Count == 1)
                {
                    // no coupons
                    payNotional = floatSchedule_[0];
                    payNotional = floatSchedule_.calendar().adjust(payNotional, floatPaymentRoll_);
                }
                else
                {
                    // use the pay date of the last coupon
                    payNotional = floatingLeg.Last().date();
                }

                double   floatAmount = subtractInflationNominal_ ? nominal_ - inflationNominal_ : nominal_;
                CashFlow nf          = new SimpleCashFlow(floatAmount, payNotional);
                floatingLeg.Add(nf);
            }

            // a CPIleg know about zero legs and inclusion of base inflation notional
            List <CashFlow> cpiLeg = new CPILeg(fixedSchedule_, fixedIndex_, baseCPI_, observationLag_)
                                     .withFixedRates(fixedRate_)
                                     .withPaymentDayCounter(fixedDayCount_)
                                     .withObservationInterpolation(observationInterpolation_)
                                     .withSubtractInflationNominal(subtractInflationNominal_)
                                     .withNotionals(inflationNominal_)
                                     .withPaymentAdjustment(fixedPaymentRoll_);

            foreach (CashFlow cashFlow in cpiLeg)
            {
                cashFlow.registerWith(update);
            }

            if (floatingLeg.Count > 0)
            {
                foreach (CashFlow cashFlow in floatingLeg)
                {
                    cashFlow.registerWith(update);
                }
            }

            legs_[0] = cpiLeg;
            legs_[1] = floatingLeg;


            if (type_ == Type.Payer)
            {
                payer_[0] = 1.0;
                payer_[1] = -1.0;
            }
            else
            {
                payer_[0] = -1.0;
                payer_[1] = 1.0;
            }
        }
Exemple #33
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;

            if (notionals_.empty())
            {
                throw new ApplicationException("no notional given");
            }

            if (notionals_.Count > n)
            {
                throw new ApplicationException("too many nominals (" + notionals_.Count +
                                               "), only " + n + " required");
            }
            if (gearings_ != null && gearings_.Count > n)
            {
                throw new ApplicationException("too many gearings (" + gearings_.Count +
                                               "), only " + n + " required");
            }

            if (spreads_ != null && spreads_.Count > n)
            {
                throw new ApplicationException("too many spreads (" + spreads_.Count +
                                               "), only " + n + " required");
            }

            if (caps_ != null && caps_.Count > n)
            {
                throw new ApplicationException("too many caps (" + caps_.Count +
                                               "), only " + n + " required");
            }

            if (floors_ != null && floors_.Count > n)
            {
                throw new ApplicationException("too many floors (" + floors_.Count +
                                               "), only " + n + " required");
            }


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

            Calendar calendar = paymentCalendar_;

            Date refStart, start, refEnd, end;

            //Date lastPaymentDate = calendar.adjust(schedule_.date(n), paymentAdjustment_);

            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) == 0.0)
                {
                    // fixed coupon
                    leg.Add(new FixedRateCoupon(Utils.Get(notionals_, i, 1.0),
                                                paymentDate,
                                                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);
        }
Exemple #34
0
 public NZDLibor(Period tenor, Handle <YieldTermStructure> h)
     : base("NZDLibor", tenor, 2, new NZDCurrency(), new NewZealand(), new Actual360(), h)
 {
 }