示例#1
0
 public MakeOIS withPaymentFrequency(Frequency f)
 {
     paymentFrequency_ = f;
     if (paymentFrequency_ == Frequency.Once)
     {
         rule_ = DateGeneration.Rule.Zero;
     }
     return(this);
 }
 public DateGeneration.Rule rule()
 {
     DateGeneration.Rule ret = (DateGeneration.Rule)NQuantLibcPINVOKE.Schedule_rule(swigCPtr);
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
     return(ret);
 }
示例#3
0
文件: MakeOIS.cs 项目: zhangz/QLNet
 public MakeOIS withRule(DateGeneration.Rule r)
 {
     rule_ = r;
     if (r == DateGeneration.Rule.Zero)
     {
         paymentFrequency_ = Frequency.Once;
     }
     return(this);
 }
        public MakeVanillaSwap withFloatingLegRule(DateGeneration.Rule r)
        {
            MakeVanillaSwap ret = new MakeVanillaSwap(NQuantLibcPINVOKE.MakeVanillaSwap_withFloatingLegRule(swigCPtr, (int)r), false);

            if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
            {
                throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
示例#5
0
        public MakeSchedule withRule(DateGeneration.Rule arg0)
        {
            MakeSchedule ret = new MakeSchedule(NQuantLibcPINVOKE.MakeSchedule_withRule(swigCPtr, (int)arg0), false);

            if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
            {
                throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
示例#6
0
 public Schedule(List <Date> dates__, Calendar calendar__, BusinessDayConvention convention__)
 {
     fullInterface_             = false;
     tenor_                     = new Period();
     calendar_                  = calendar__;
     convention_                = convention__;
     terminationDateConvention_ = convention__;
     rule_          = DateGeneration.Rule.Forward;
     endOfMonth_    = false;
     adjustedDates_ = dates__;
 }
示例#7
0
        public MakeCreditDefaultSwap(Period cdsTenor, double cdsSpread)
        {
            cdsTenor_     = cdsTenor;
            cdsSpread_    = cdsSpread;
            recoveryRate_ = 0.4;

            cdsCalendar_ = new NullCalendar();
            nominal_     = 100.0;
            side_        = Protection.Side.Buyer;

            cdsConvention_ = BusinessDayConvention.ModifiedFollowing;
            cdsRule_       = DateGeneration.Rule.Backward;
            cdsDayCount_   = new  Actual365Fixed();
        }
      public Schedule(List<Date> dates, Calendar calendar = null, BusinessDayConvention convention = BusinessDayConvention.Unadjusted)
      {
         if (calendar == null)
            calendar_ = new NullCalendar();
         else
            calendar_ = calendar;

         fullInterface_ = false;
         tenor_ = new Period();
         convention_ = convention;
         terminationDateConvention_ = convention;
         rule_ = DateGeneration.Rule.Forward;
         endOfMonth_ = false;
         dates_ = dates;
      }
示例#9
0
        public MakeCash(Date startDate, Date endDate, double nominal)
        {
            startDate_ = startDate;
            endDate_   = endDate;
            nominal_   = nominal;

            frequency_  = Frequency.Once;
            type_       = Loan.Type.Loan;
            amortising_ = Loan.Amortising.Bullet;
            calendar_   = new TARGET();
            convention_ = BusinessDayConvention.ModifiedFollowing;
            dayCounter_ = new Actual365Fixed();
            rule_       = DateGeneration.Rule.Forward;
            endOfMonth_ = false;
        }
        //public ObservableCollection<DateTime> dates(int addingDays = 0)
        public void genDates(int addingDays = 0)
        {
            this.dates_.Clear();

            //Period tenor = new Period(this.tenor_);

            QLNet.Calendar calendar = new SouthKorea();

            Period tenor = new Period(this.frequencyEnum_);
            BusinessDayConvention bdc = this.businessDayConvEnum_;

            DateGeneration.Rule dateGen = this.dateGenEnum_;

            try
            {
                Schedule schedule = new Schedule(new Date(initialDate_),
                                                 new Date(endDate_),
                                                 tenor,
                                                 calendar,
                                                 bdc,
                                                 bdc,
                                                 dateGen,
                                                 false);

                List <Date> ql_d = schedule.dates();

                for (int i = 0; i < ql_d.Count; i++)
                {
                    this.dates_.Add(ql_d[i]);
                }
            }
            catch (Exception)
            {
                OutputLogViewModel.addResult("schedule gen error");
            }


            //test

            //for (int i = 0; i < 6; i++)
            //{
            //    this.dates_.Add(new DateTime());
            //}

            //this.dates_ = d;

            //return d;
        }
示例#11
0
        public MakeCommercialPaper(Date startDate, Date endDate, double fixedRate, Frequency frequency)
        {
            startDate_ = startDate;
            endDate_   = endDate;
            fixedRate_ = fixedRate;
            frequency_ = frequency;

            type_       = Loan.Type.Loan;
            amortising_ = Loan.Amortising.Bullet;
            nominal_    = 1.0;
            calendar_   = new TARGET();
            convention_ = BusinessDayConvention.ModifiedFollowing;
            dayCounter_ = new Actual365Fixed();
            rule_       = DateGeneration.Rule.Forward;
            endOfMonth_ = false;
        }
示例#12
0
文件: MakeOIS.cs 项目: Yenyenx/qlnet
 public MakeOIS(Period swapTenor, OvernightIndex overnightIndex,
              double? fixedRate, Period fwdStart)
 {
     swapTenor_=swapTenor;
      overnightIndex_ = overnightIndex;
      fixedRate_= fixedRate;
      forwardStart_= fwdStart;
      fixingDays_ = 2;
      paymentFrequency_ = Frequency.Annual;
      rule_ = DateGeneration.Rule.Backward;
      endOfMonth_ = (new Period(1,TimeUnit.Months)<=swapTenor && swapTenor<=new Period(2,TimeUnit.Years) ? true : false);
      type_ = OvernightIndexedSwap.Type.Payer;
      nominal_ = 1.0;
      overnightSpread_ = 0.0;
      fixedDayCount_ = overnightIndex.dayCounter();
      engine_ = new DiscountingSwapEngine(overnightIndex_.forwardingTermStructure());
 }
示例#13
0
文件: MakeLoans.cs 项目: vdt/QLNet
        public MakeCash(Date startDate, Date endDate, double nominal)
        {
            startDate_ = startDate;
             endDate_ = endDate;
             nominal_ = nominal;

             frequency_  = Frequency.Once;
             type_ = Loan.Type.Loan;
             amortising_ = Loan.Amortising.Bullet;
             calendar_ = new TARGET();
             convention_ = BusinessDayConvention.ModifiedFollowing;
             dayCounter_ = new Actual365Fixed();
             rule_ = DateGeneration.Rule.Forward;
             endOfMonth_ = false;

             //engine_ = new DiscountingSwapEngine(index.termStructure());
        }
示例#14
0
文件: MakeOIS.cs 项目: igitur/qlnet
 public MakeOIS(Period swapTenor, OvernightIndex overnightIndex, double?fixedRate = null, Period fwdStart = null)
 {
     swapTenor_        = swapTenor;
     overnightIndex_   = overnightIndex;
     fixedRate_        = fixedRate;
     forwardStart_     = fwdStart ?? new Period(0, TimeUnit.Days);
     settlementDays_   = 2;
     calendar_         = overnightIndex.fixingCalendar();
     paymentFrequency_ = Frequency.Annual;
     rule_             = DateGeneration.Rule.Backward;
     // any value here for endOfMonth_ would not be actually used
     isDefaultEOM_    = true;
     type_            = OvernightIndexedSwap.Type.Payer;
     nominal_         = 1.0;
     overnightSpread_ = 0.0;
     fixedDayCount_   = overnightIndex.dayCounter();
 }
 public MakeOIS(Period swapTenor, OvernightIndex overnightIndex,
                double?fixedRate, Period fwdStart)
 {
     swapTenor_        = swapTenor;
     overnightIndex_   = overnightIndex;
     fixedRate_        = fixedRate;
     forwardStart_     = fwdStart;
     fixingDays_       = 2;
     paymentFrequency_ = Frequency.Annual;
     rule_             = DateGeneration.Rule.Backward;
     endOfMonth_       = (new Period(1, TimeUnit.Months) <= swapTenor && swapTenor <= new Period(2, TimeUnit.Years) ? true : false);
     type_             = OvernightIndexedSwap.Type.Payer;
     nominal_          = 1.0;
     overnightSpread_  = 0.0;
     fixedDayCount_    = overnightIndex.dayCounter();
     engine_           = new DiscountingSwapEngine(overnightIndex_.forwardingTermStructure());
 }
示例#16
0
        public MakeFloatingLoan(Date startDate, Date endDate, double spread, Frequency frequency)
        {
            startDate_ = startDate;
            endDate_   = endDate;
            spread_    = spread;
            frequency_ = frequency;

            type_       = Loan.Type.Loan;
            amortising_ = Loan.Amortising.Bullet;
            nominal_    = 1.0;
            calendar_   = new TARGET();
            convention_ = BusinessDayConvention.ModifiedFollowing;
            dayCounter_ = new Actual365Fixed();
            rule_       = DateGeneration.Rule.Forward;
            endOfMonth_ = false;
            index_      = new IborIndex();
        }
示例#17
0
        public MakeFixedLoan(Date startDate, Date endDate, double fixedRate, Frequency frequency)
        {
            startDate_ = startDate;
            endDate_   = endDate;
            fixedRate_ = fixedRate;
            frequency_ = frequency;

            type_       = Loan.Type.Loan;
            amortising_ = Loan.Amortising.Bullet;
            nominal_    = 1.0;
            calendar_   = new TARGET();
            convention_ = BusinessDayConvention.ModifiedFollowing;
            dayCounter_ = new Actual365Fixed();
            rule_       = DateGeneration.Rule.Forward;
            endOfMonth_ = false;

            //engine_ = new DiscountingSwapEngine(index.termStructure());
        }
示例#18
0
 public MakeOIS(Period swapTenor, OvernightIndex overnightIndex, double?fixedRate = null, Period fwdStart = null)
 {
     swapTenor_        = swapTenor;
     overnightIndex_   = overnightIndex;
     fixedRate_        = fixedRate;
     forwardStart_     = fwdStart ?? new Period(0, TimeUnit.Days);
     settlementDays_   = 2;
     calendar_         = overnightIndex.fixingCalendar();
     paymentFrequency_ = Frequency.Annual;
     rule_             = DateGeneration.Rule.Backward;
     // any value here for endOfMonth_ would not be actually used
     isDefaultEOM_ = true;
     //endOfMonth_ = (new Period(1,TimeUnit.Months)<=swapTenor && swapTenor<=new Period(2,TimeUnit.Years) ? true : false);
     type_            = OvernightIndexedSwap.Type.Payer;
     nominal_         = 1.0;
     overnightSpread_ = 0.0;
     fixedDayCount_   = overnightIndex.dayCounter();
     //engine_ = new DiscountingSwapEngine(overnightIndex_.forwardingTermStructure());
 }
示例#19
0
        public Schedule(List <Date> dates, Calendar calendar = null, BusinessDayConvention convention = BusinessDayConvention.Unadjusted)
        {
            if (calendar == null)
            {
                calendar_ = new NullCalendar();
            }
            else
            {
                calendar_ = calendar;
            }

            fullInterface_             = false;
            tenor_                     = new Period();
            convention_                = convention;
            terminationDateConvention_ = convention;
            rule_       = DateGeneration.Rule.Forward;
            endOfMonth_ = false;
            dates_      = dates;
        }
示例#20
0
        public MakeVanillaSwap(Period swapTenor, IborIndex index, double?fixedRate = null, Period forwardStart = null)
        {
            swapTenor_      = swapTenor;
            iborIndex_      = index;
            fixedRate_      = fixedRate;
            forwardStart_   = forwardStart ?? new Period(0, TimeUnit.Days);
            settlementDays_ = iborIndex_.fixingDays();
            fixedCalendar_  = floatCalendar_ = index.fixingCalendar();

            type_            = VanillaSwap.Type.Payer;
            nominal_         = 1.0;
            floatTenor_      = index.tenor();
            fixedConvention_ = fixedTerminationDateConvention_ = BusinessDayConvention.ModifiedFollowing;
            floatConvention_ = floatTerminationDateConvention_ = index.businessDayConvention();
            fixedRule_       = floatRule_ = DateGeneration.Rule.Backward;
            fixedEndOfMonth_ = floatEndOfMonth_ = false;
            fixedFirstDate_  = fixedNextToLastDate_ = floatFirstDate_ = floatNextToLastDate_ = null;
            floatSpread_     = 0.0;
            floatDayCount_   = index.dayCounter();
        }
示例#21
0
文件: Schedule.cs 项目: mikaboz/QLNet
        Date previousTwentieth(Date d, DateGeneration.Rule rule)
        {
            Date result = new Date(20, d.month(), d.year());

            if (result > d)
            {
                result -= new Period(1, TimeUnit.Months);
            }
            if (rule == DateGeneration.Rule.TwentiethIMM ||
                rule == DateGeneration.Rule.OldCDS ||
                rule == DateGeneration.Rule.CDS)
            {
                int m = result.month();
                if (m % 3 != 0)
                { // not a main IMM nmonth
                    int skip = m % 3;
                    result -= new Period(skip, TimeUnit.Months);
                }
            }
            return(result);
        }
 public SpreadCdsHelper(double runningSpread,
                        Period tenor,
                        int settlementDays,                      // ISDA: 1
                        Calendar calendar,
                        Frequency frequency,                     // ISDA: Quarterly
                        BusinessDayConvention paymentConvention, //ISDA:Following
                        DateGeneration.Rule rule,                // ISDA: CDS
                        DayCounter dayCounter,                   // ISDA: Actual/360
                        double recoveryRate,
                        Handle <YieldTermStructure> discountCurve,
                        bool settlesAccrual                  = true,
                        bool paysAtDefaultTime               = true,
                        Date startDate                       = null,
                        DayCounter lastPeriodDayCounter      = null, // ISDA: Actual/360(inc)
                        bool rebatesAccrual                  = true, // ISDA: true
                        CreditDefaultSwap.PricingModel model = CreditDefaultSwap.PricingModel.Midpoint)
     : base(runningSpread, tenor, settlementDays, calendar,
            frequency, paymentConvention, rule, dayCounter,
            recoveryRate, discountCurve, settlesAccrual, paysAtDefaultTime,
            startDate, lastPeriodDayCounter, rebatesAccrual, model)
 {
 }
        public CdsHelper(double quote,
                         Period tenor,
                         int settlementDays,
                         Calendar calendar,
                         Frequency frequency,
                         BusinessDayConvention paymentConvention,
                         DateGeneration.Rule rule,
                         DayCounter dayCounter,
                         double recoveryRate,
                         Handle <YieldTermStructure> discountCurve,
                         bool settlesAccrual                  = true,
                         bool paysAtDefaultTime               = true,
                         Date startDate                       = null,
                         DayCounter lastPeriodDayCounter      = null,
                         bool rebatesAccrual                  = true,
                         CreditDefaultSwap.PricingModel model = CreditDefaultSwap.PricingModel.Midpoint)
            : base(quote)
        {
            tenor_             = tenor;
            settlementDays_    = settlementDays;
            calendar_          = calendar;
            frequency_         = frequency;
            paymentConvention_ = paymentConvention;
            rule_              = rule;
            dayCounter_        = dayCounter;
            recoveryRate_      = recoveryRate;
            discountCurve_     = discountCurve;
            settlesAccrual_    = settlesAccrual;
            paysAtDefaultTime_ = paysAtDefaultTime;
            lastPeriodDC_      = lastPeriodDayCounter;
            rebatesAccrual_    = rebatesAccrual;
            model_             = model;
            startDate_         = startDate;
            schedule_          = new Schedule();

            initializeDates();
            discountCurve_.registerWith(update);
        }
示例#24
0
        public void testSingleInstrumentBootstrap()
        {
            //Testing single-instrument curve bootstrap...

            Calendar calendar = new TARGET();

            Date today = Settings.Instance.evaluationDate();

            int settlementDays = 0;

            double quote = 0.005;
            Period tenor = new Period(2, TimeUnit.Years);

            Frequency             frequency  = Frequency.Quarterly;
            BusinessDayConvention convention = BusinessDayConvention.Following;

            DateGeneration.Rule rule       = DateGeneration.Rule.TwentiethIMM;
            DayCounter          dayCounter = new Thirty360();
            double recoveryRate            = 0.4;

            RelinkableHandle <YieldTermStructure> discountCurve = new RelinkableHandle <YieldTermStructure>();

            discountCurve.linkTo(new FlatForward(today, 0.06, new Actual360()));

            List <CdsHelper> helpers = new List <CdsHelper>();

            helpers.Add(
                new SpreadCdsHelper(quote, tenor,
                                    settlementDays, calendar,
                                    frequency, convention, rule,
                                    dayCounter, recoveryRate,
                                    discountCurve));

            PiecewiseDefaultCurve <HazardRate, BackwardFlat> defaultCurve = new PiecewiseDefaultCurve <HazardRate, BackwardFlat>(today, helpers,
                                                                                                                                 dayCounter);

            defaultCurve.recalculate();
        }
示例#25
0
        public MakeVanillaSwap(Period swapTenor, IborIndex index, double? fixedRate, Period forwardStart) {
            swapTenor_ = swapTenor;
            iborIndex_ = index;
            fixedRate_ = fixedRate;
            forwardStart_ = forwardStart;
            effectiveDate_ = null;
            fixedCalendar_ = floatCalendar_ = index.fixingCalendar();
            
            type_ = VanillaSwap.Type.Payer;
            nominal_ = 1.0;
            fixedTenor_ = new Period(1, TimeUnit.Years);
            floatTenor_ = index.tenor();
            fixedConvention_ = fixedTerminationDateConvention_ = BusinessDayConvention.ModifiedFollowing;
            floatConvention_ = floatTerminationDateConvention_ = index.businessDayConvention();
            fixedRule_ = floatRule_ = DateGeneration.Rule.Backward;
            fixedEndOfMonth_ = floatEndOfMonth_ = false;
            fixedFirstDate_ = fixedNextToLastDate_ = floatFirstDate_ = floatNextToLastDate_ = null;
            floatSpread_ = 0.0;
            fixedDayCount_ = new Thirty360(Thirty360.Thirty360Convention.BondBasis);
            floatDayCount_ = index.dayCounter();

            engine_ = new DiscountingSwapEngine(index.forwardingTermStructure());
        }
示例#26
0
        public MakeBasisSwap(Period swapTenor, IborIndex index1, IborIndex index2, Period forwardStart)
        {
            swapTenor_ = swapTenor;
             iborIndex1_ = index1;
             iborIndex2_ = index2;
             forwardStart_ = forwardStart;
             effectiveDate_ = null;
             float1Calendar_ = float2Calendar_ = index1.fixingCalendar();

             type_ = BasisSwap.Type.Payer;
             nominal_ = 1.0;
             float1Tenor_ = index1.tenor();
             float2Tenor_ = index2.tenor();
             float1Convention_ = float1TerminationDateConvention_ = index1.businessDayConvention();
             float2Convention_ = float2TerminationDateConvention_ = index2.businessDayConvention();
             float1Rule_ = float2Rule_ = DateGeneration.Rule.Backward;
             float1EndOfMonth_ = float2EndOfMonth_ = false;
             float1FirstDate_ = float1NextToLastDate_ = float2FirstDate_ = float2NextToLastDate_ = null;
             float1Spread_ = float2Spread_ = 0.0;
             float1DayCount_ = index1.dayCounter();
             float2DayCount_ = index2.dayCounter();

             engine_ = new DiscountingBasisSwapEngine(index1.forwardingTermStructure(), index2.forwardingTermStructure());
        }
示例#27
0
        public MakeVanillaSwap(Period swapTenor, IborIndex index, double?fixedRate, Period forwardStart)
        {
            swapTenor_     = swapTenor;
            iborIndex_     = index;
            fixedRate_     = fixedRate;
            forwardStart_  = forwardStart;
            effectiveDate_ = null;
            fixedCalendar_ = floatCalendar_ = index.fixingCalendar();

            type_            = VanillaSwap.Type.Payer;
            nominal_         = 1.0;
            fixedTenor_      = new Period(1, TimeUnit.Years);
            floatTenor_      = index.tenor();
            fixedConvention_ = fixedTerminationDateConvention_ = BusinessDayConvention.ModifiedFollowing;
            floatConvention_ = floatTerminationDateConvention_ = index.businessDayConvention();
            fixedRule_       = floatRule_ = DateGeneration.Rule.Backward;
            fixedEndOfMonth_ = floatEndOfMonth_ = false;
            fixedFirstDate_  = fixedNextToLastDate_ = floatFirstDate_ = floatNextToLastDate_ = null;
            floatSpread_     = 0.0;
            fixedDayCount_   = new Thirty360(Thirty360.Thirty360Convention.BondBasis);
            floatDayCount_   = index.dayCounter();

            engine_ = new DiscountingSwapEngine(index.forwardingTermStructure());
        }
示例#28
0
        public MakeBasisSwap(Period swapTenor, IborIndex index1, IborIndex index2, Period forwardStart)
        {
            swapTenor_      = swapTenor;
            iborIndex1_     = index1;
            iborIndex2_     = index2;
            forwardStart_   = forwardStart;
            effectiveDate_  = null;
            float1Calendar_ = float2Calendar_ = index1.fixingCalendar();

            type_             = BasisSwap.Type.Payer;
            nominal_          = 1.0;
            float1Tenor_      = index1.tenor();
            float2Tenor_      = index2.tenor();
            float1Convention_ = float1TerminationDateConvention_ = index1.businessDayConvention();
            float2Convention_ = float2TerminationDateConvention_ = index2.businessDayConvention();
            float1Rule_       = float2Rule_ = DateGeneration.Rule.Backward;
            float1EndOfMonth_ = float2EndOfMonth_ = false;
            float1FirstDate_  = float1NextToLastDate_ = float2FirstDate_ = float2NextToLastDate_ = null;
            float1Spread_     = float2Spread_ = 0.0;
            float1DayCount_   = index1.dayCounter();
            float2DayCount_   = index2.dayCounter();

            engine_ = new DiscountingBasisSwapEngine(index1.forwardingTermStructure(), index2.forwardingTermStructure());
        }
示例#29
0
 public MakeVanillaSwap withFixedLegRule(DateGeneration.Rule r)
 {
     fixedRule_ = r;
     return(this);
 }
示例#30
0
 public MakeVanillaSwap withFloatingLegRule(DateGeneration.Rule r)
 {
     floatRule_ = r;
     return(this);
 }
示例#31
0
 public MakeFixedLoan withRule(DateGeneration.Rule r)
 {
     rule_ = r;
     return(this);
 }
示例#32
0
        /*! simple annual compounding coupon rates
         *  with internal schedule calculation */
        public FixedRateBond(int settlementDays,
                             Calendar calendar,
                             double faceAmount,
                             Date startDate,
                             Date maturityDate,
                             Period tenor,
                             List <double> coupons,
                             DayCounter accrualDayCounter,
                             BusinessDayConvention accrualConvention = BusinessDayConvention.Following,
                             BusinessDayConvention paymentConvention = BusinessDayConvention.Following,
                             double redemption         = 100,
                             Date issueDate            = null,
                             Date stubDate             = null,
                             DateGeneration.Rule rule  = DateGeneration.Rule.Backward,
                             bool endOfMonth           = false,
                             Calendar paymentCalendar  = null,
                             Period exCouponPeriod     = null,
                             Calendar exCouponCalendar = null,
                             BusinessDayConvention exCouponConvention = BusinessDayConvention.Unadjusted,
                             bool exCouponEndOfMonth = false)
            : base(settlementDays, paymentCalendar ?? calendar,
                   issueDate)
        {
            frequency_    = tenor.frequency();
            dayCounter_   = accrualDayCounter;
            maturityDate_ = maturityDate;

            Date firstDate = null, nextToLastDate = null;

            switch (rule)
            {
            case DateGeneration.Rule.Backward:
                firstDate      = null;
                nextToLastDate = stubDate;
                break;

            case DateGeneration.Rule.Forward:
                firstDate      = stubDate;
                nextToLastDate = null;
                break;

            case DateGeneration.Rule.Zero:
            case DateGeneration.Rule.ThirdWednesday:
            case DateGeneration.Rule.Twentieth:
            case DateGeneration.Rule.TwentiethIMM:
                Utils.QL_FAIL("stub date (" + stubDate + ") not allowed with " + rule + " DateGeneration::Rule");
                break;

            default:
                Utils.QL_FAIL("unknown DateGeneration::Rule (" + rule + ")");
                break;
            }


            Schedule schedule = new Schedule(startDate, maturityDate_, tenor,
                                             calendar, accrualConvention, accrualConvention,
                                             rule, endOfMonth,
                                             firstDate, nextToLastDate);


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

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


            Utils.QL_REQUIRE(cashflows().Count != 0, () => "bond with no cashflows!");
            Utils.QL_REQUIRE(redemptions_.Count == 1, () => "multiple redemptions created");
        }
示例#33
0
文件: Schedule.cs 项目: Yenyenx/qlnet
 public MakeSchedule()
 {
     rule_ = DateGeneration.Rule.Backward; endOfMonth_ = false;
 }
示例#34
0
 public MakeCash withRule(DateGeneration.Rule r)
 {
     rule_ = r;
     return(this);
 }
示例#35
0
文件: MakeLoans.cs 项目: vdt/QLNet
 public MakeCommercialPaper withRule(DateGeneration.Rule r)
 {
     rule_ = r;
      return this;
 }
示例#36
0
文件: MakeLoans.cs 项目: vdt/QLNet
 public MakeFloatingLoan withRule(DateGeneration.Rule r)
 {
     rule_ = r;
      return this;
 }
示例#37
0
 public MakeOIS withPaymentFrequency(Frequency f)
 {
    paymentFrequency_ = f;
    if (paymentFrequency_== Frequency.Once)
       rule_ = DateGeneration.Rule.Zero;
    return this;
 }
示例#38
0
 public MakeVanillaSwap withRule(DateGeneration.Rule r)
 {
     fixedRule_ = r;
     floatRule_ = r;
     return this;
 }
示例#39
0
 public MakeOIS withRule(DateGeneration.Rule r) 
 {
    rule_ = r;
    if (r==DateGeneration.Rule.Zero)
       paymentFrequency_ = Frequency.Once;
    return this;
 }
示例#40
0
 public MakeBasisSwap withFloating1LegRule(DateGeneration.Rule r)
 {
     float1Rule_ = r;
      return this;
 }
示例#41
0
 public MakeBasisSwap withRule(DateGeneration.Rule r)
 {
     float1Rule_ = r;
      float2Rule_ = r;
      return this;
 }
示例#42
0
文件: Schedule.cs 项目: Yenyenx/qlnet
 public MakeSchedule forwards()
 {
     rule_ = DateGeneration.Rule.Forward;
        return this;
 }
示例#43
0
文件: Schedule.cs 项目: Yenyenx/qlnet
 public MakeSchedule backwards()
 {
     rule_ = DateGeneration.Rule.Backward;
        return this;
 }
示例#44
0
文件: MakeLoans.cs 项目: vdt/QLNet
 public MakeCash withRule(DateGeneration.Rule r)
 {
     rule_ = r;
      return this;
 }
        /*! simple annual compounding coupon rates
         *  with internal schedule calculation */
        public FixedRateBond(int settlementDays,
                             Calendar calendar,
                             double faceAmount,
                             Date startDate,
                             Date maturityDate,
                             Period tenor,
                             List <double> coupons,
                             DayCounter accrualDayCounter,
                             BusinessDayConvention accrualConvention,
                             BusinessDayConvention paymentConvention,
                             double redemption,
                             Date issueDate,
                             Date stubDate,
                             DateGeneration.Rule rule,
                             bool endOfMonth,
                             Calendar paymentCalendar)
            : base(settlementDays, paymentCalendar == new Calendar() ? calendar : paymentCalendar,
                   issueDate)
        {
            frequency_    = tenor.frequency();
            dayCounter_   = accrualDayCounter;
            maturityDate_ = maturityDate;

            Date firstDate, nextToLastDate;

            switch (rule)
            {
            case DateGeneration.Rule.Backward:
                firstDate      = null;
                nextToLastDate = stubDate;
                break;

            case DateGeneration.Rule.Forward:
                firstDate      = stubDate;
                nextToLastDate = null;
                break;

            case DateGeneration.Rule.Zero:
            case DateGeneration.Rule.ThirdWednesday:
            case DateGeneration.Rule.Twentieth:
            case DateGeneration.Rule.TwentiethIMM:
                throw new ApplicationException("stub date (" + stubDate + ") not allowed with " + rule + " DateGeneration::Rule");

            default:
                throw new ApplicationException("unknown DateGeneration::Rule (" + rule + ")");
            }


            Schedule schedule = new Schedule(startDate, maturityDate_, tenor,
                                             calendar, accrualConvention, accrualConvention,
                                             rule, endOfMonth,
                                             firstDate, nextToLastDate);


            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");
            }
        }
示例#46
0
文件: MakeLoans.cs 项目: vdt/QLNet
        public MakeFloatingLoan(Date startDate, Date endDate, double spread, Frequency frequency)
        {
            startDate_ = startDate;
             endDate_ = endDate;
             spread_ = spread;
             frequency_ = frequency;

             type_ = Loan.Type.Loan;
             amortising_ = Loan.Amortising.Bullet;
             nominal_ = 1.0;
             calendar_ = new TARGET();
             convention_ = BusinessDayConvention.ModifiedFollowing;
             dayCounter_ = new Actual365Fixed();
             rule_ = DateGeneration.Rule.Forward;
             endOfMonth_ = false;
             index_ = new IborIndex();

             //engine_ = new DiscountingSwapEngine(index.termStructure());
        }
示例#47
0
        public Schedule(Date effectiveDate__, Date terminationDate__, Period tenor__, Calendar calendar__,
            BusinessDayConvention convention__, BusinessDayConvention terminationDateConvention__,
            DateGeneration.Rule rule__, bool endOfMonth__,
            Date firstDate__, Date nextToLastDate__)
        {
            // first save the properties
            fullInterface_ = true;
            tenor_ = tenor__;
            calendar_ = calendar__;
            convention_ = convention__;
            terminationDateConvention_ = terminationDateConvention__;
            rule_ = rule__;
            endOfMonth_ = endOfMonth__;
            firstDate_ = firstDate__;
            nextToLastDate_ = nextToLastDate__;

            // sanity checks
            if (effectiveDate__ == null) throw new ArgumentException("Null effective date");
            if (terminationDate__ == null) throw new ArgumentException("Null termination  date");
            if (effectiveDate__ >= terminationDate__) throw new ArgumentException("Effective date (" + effectiveDate__ +
                       ") is later than or equal to termination date (" + terminationDate__ + ")");

            if (tenor_.length() == 0)
                rule_ = DateGeneration.Rule.Zero;
            else if (tenor_.length() < 0)
                throw new ArgumentException("Non positive tenor (" + tenor_ + ") is not allowed");

            if (firstDate_ != null) {
                switch (rule_) {
                    case DateGeneration.Rule.Backward:
                    case DateGeneration.Rule.Forward:
                        if (!(firstDate_ > effectiveDate__ && firstDate_ < terminationDate__))
                            throw new ArgumentException("First date (" + firstDate_ + ") is out of range [effective date (" + effectiveDate__
                                                        + "), termination date (" + terminationDate__ + ")]");
                        // we should ensure that the above condition is still verified after adjustment
                        break;
                    case DateGeneration.Rule.ThirdWednesday:
                        if (!IMM.isIMMdate(firstDate_, false))
                            throw new ArgumentException("first date (" + firstDate_ + ") is not an IMM date");
                        break;
                    case DateGeneration.Rule.Zero:
                    case DateGeneration.Rule.Twentieth:
                    case DateGeneration.Rule.TwentiethIMM:
                    case DateGeneration.Rule.OldCDS:
                    case DateGeneration.Rule.CDS:
                        throw new ArgumentException("First date is incompatible with " + rule_ + " date generation rule");
                    default:
                        throw new ArgumentException("Unknown DateGeneration rule: " + rule_);
                }
            }

            if (nextToLastDate_ != null) {
                switch (rule_) {
                    case DateGeneration.Rule.Backward:
                    case DateGeneration.Rule.Forward:
                        if (!(nextToLastDate_ > effectiveDate__ && nextToLastDate_ < terminationDate__))
                            throw new ArgumentException("Next to last date (" + nextToLastDate_ + ") out of range [effective date (" + effectiveDate__
                               + "), termination date (" + terminationDate__ + ")]");
                        // we should ensure that the above condition is still verified after adjustment
                        break;
                    case DateGeneration.Rule.ThirdWednesday:
                        if (!IMM.isIMMdate(firstDate_, false))
                            throw new ArgumentException("first date (" + firstDate_ + ") is not an IMM date");
                        break;
                    case DateGeneration.Rule.Zero:
                    case DateGeneration.Rule.Twentieth:
                    case DateGeneration.Rule.TwentiethIMM:
                    case DateGeneration.Rule.OldCDS:
                    case DateGeneration.Rule.CDS:
                        throw new ArgumentException("next to last is incompatible with " + rule_ + " date generation rule");
                    default:
                        throw new ArgumentException("Unknown DateGeneration rule: " + rule_);
                }
            }

            // calendar needed for endOfMonth adjustment
            Calendar nullCalendar = new NullCalendar();
            int periods = 1;
            Date seed = new Date(), exitDate;
            switch (rule_) {
                case DateGeneration.Rule.Zero:
                    tenor_ = new Period(0, TimeUnit.Years);
                    originalDates_.Add(effectiveDate__);
                    originalDates_.Add(terminationDate__);
                    isRegular_.Add(true);
                    break;

                case DateGeneration.Rule.Backward:
                    originalDates_.Add(terminationDate__);
                    seed = terminationDate__;
                    if (nextToLastDate_ != null) {
                        originalDates_.Insert(0, nextToLastDate_);
                        Date temp = nullCalendar.advance(seed, -periods * tenor_, convention_, endOfMonth_);
                        isRegular_.Insert(0, temp == nextToLastDate_);
                        seed = nextToLastDate_;
                    }
                    exitDate = effectiveDate__;
                    if (firstDate_ != null)
                        exitDate = firstDate_;
                    while (true) {
                        Date temp = nullCalendar.advance(seed, -periods * tenor_, convention_, endOfMonth_);
                        if (temp < exitDate) {
                            if (firstDate_ != null && (calendar_.adjust(originalDates_.First(), convention_) !=
                                 calendar_.adjust(firstDate_, convention_))) {
                                originalDates_.Insert(0, firstDate_);
                                isRegular_.Insert(0, false);
                            }
                            break;
                        } else {
                            originalDates_.Insert(0, temp);
                            isRegular_.Insert(0, true);
                            ++periods;
                        }
                    }
                    if (endOfMonth_ && calendar_.isEndOfMonth(seed))
                        convention_ = BusinessDayConvention.Preceding;
                    if (calendar_.adjust(originalDates_[0], convention_) != calendar_.adjust(effectiveDate__, convention_)) {
                        originalDates_.Insert(0, effectiveDate__);
                        isRegular_.Insert(0, false);
                    }
                    break;

                case DateGeneration.Rule.Twentieth:
                case DateGeneration.Rule.TwentiethIMM:
                case DateGeneration.Rule.ThirdWednesday:
                case DateGeneration.Rule.OldCDS:
                case DateGeneration.Rule.CDS:
                    if (endOfMonth_)
                        throw new ArgumentException("endOfMonth convention is incompatible with " + rule_ + " date generation rule");
                    goto case DateGeneration.Rule.Forward;			// fall through

                case DateGeneration.Rule.Forward:
                    if (rule_ == DateGeneration.Rule.CDS) {
                       originalDates_.Add(previousTwentieth(effectiveDate__,DateGeneration.Rule.CDS));
                    } else {
                       originalDates_.Add(effectiveDate__);
                    }

                    seed = effectiveDate__;
                    if (firstDate_ != null) {
                        originalDates_.Add(firstDate_);
                        Date temp = nullCalendar.advance(seed, periods * tenor_, convention_, endOfMonth_);
                        isRegular_.Add(temp == firstDate_);
                        seed = firstDate_;
                    } else if (rule_ == DateGeneration.Rule.Twentieth ||
                               rule_ == DateGeneration.Rule.TwentiethIMM ||
                               rule_ == DateGeneration.Rule.OldCDS ||
                               rule_ == DateGeneration.Rule.CDS)
                    {
                        Date next20th = nextTwentieth(effectiveDate__, rule_);
                        if (rule_ == DateGeneration.Rule.OldCDS) {
                           // distance rule inforced in natural days
                           long stubDays = 30;
                           if (next20th - effectiveDate__ < stubDays) {
                              // +1 will skip this one and get the next
                              next20th = nextTwentieth(next20th + 1, rule_);
                           }
                        }
                        if (next20th != effectiveDate__) {
                            originalDates_.Add(next20th);
                            isRegular_.Add(false);
                            seed = next20th;
                        }
                    }

                    exitDate = terminationDate__;
                    if (nextToLastDate_ != null)
                        exitDate = nextToLastDate_;
                    while (true) {
                        Date temp = nullCalendar.advance(seed, periods * tenor_, convention_, endOfMonth_);
                        if (temp > exitDate) {
                            if (nextToLastDate_ != null &&
                                (calendar_.adjust(originalDates_.Last(), convention_) !=
                                 calendar_.adjust(nextToLastDate_, convention_))) {
                                originalDates_.Add(nextToLastDate_);
                                isRegular_.Add(false);
                            }
                            break;
                        } else {
                            originalDates_.Add(temp);
                            isRegular_.Add(true);
                            ++periods;
                        }
                    }
                    if (endOfMonth_ && calendar_.isEndOfMonth(seed))
                        convention_ = BusinessDayConvention.Preceding;

                    if (calendar_.adjust(originalDates_.Last(), terminationDateConvention_) != calendar_.adjust(terminationDate__, terminationDateConvention_)) {
                        if (rule_ == DateGeneration.Rule.Twentieth ||
                            rule_ == DateGeneration.Rule.TwentiethIMM ||
                            rule_ == DateGeneration.Rule.OldCDS ||
                            rule_ == DateGeneration.Rule.CDS ) {
                            originalDates_.Add(nextTwentieth(terminationDate__, rule_));
                            isRegular_.Add(true);
                        } else {
                            originalDates_.Add(terminationDate__);
                            isRegular_.Add(false);
                        }
                    }
                    break;

                default:
                    throw new ArgumentException("Unknown DateGeneration rule: " + rule_);
            }

            // adjustments to holidays, etc.
            if (rule_ == DateGeneration.Rule.ThirdWednesday)
                for (int i = 1; i < originalDates_.Count; ++i)
                    originalDates_[i] = Date.nthWeekday(3, DayOfWeek.Wednesday, originalDates_[i].Month, originalDates_[i].Year);

            if (endOfMonth && calendar_.isEndOfMonth(seed))
            {
               // adjust to end of month
               if (convention_ == BusinessDayConvention.Unadjusted)
               {
                  for (int i = 0; i < originalDates_.Count; ++i)
                     originalDates_[i] = Date.endOfMonth(originalDates_[i]);
               }
               else
               {
                  for (int i = 0; i < originalDates_.Count; ++i)
                     originalDates_[i] = calendar_.endOfMonth(originalDates_[i]);
               }
               if (terminationDateConvention_ == BusinessDayConvention.Unadjusted)
                  originalDates_[originalDates_.Count - 1] = Date.endOfMonth(originalDates_.Last());
               else
                  originalDates_[originalDates_.Count - 1] = calendar_.endOfMonth(originalDates_.Last());
            }
            else
            {
               // first date not adjusted for CDS schedules
               if (rule_ != DateGeneration.Rule.OldCDS)
                  originalDates_[0] = calendar_.adjust(originalDates_[0], convention_);
               for (int i = 1; i < originalDates_.Count; ++i)
                  originalDates_[i] = calendar_.adjust(originalDates_[i], convention_);

               foreach (Date d in originalDates_)
                  adjustedDates_.Add(d);

               // termination date is NOT adjusted as per ISDA specifications, unless otherwise specified in the
               // confirmation of the deal or unless we're creating a CDS schedule
               if (terminationDateConvention_ != BusinessDayConvention.Unadjusted
                   || rule_ == DateGeneration.Rule.Twentieth
                   || rule_ == DateGeneration.Rule.TwentiethIMM
                   || rule_ == DateGeneration.Rule.OldCDS
                   || rule_ == DateGeneration.Rule.CDS)
                  adjustedDates_[adjustedDates_.Count - 1] = calendar_.adjust(originalDates_.Last(), terminationDateConvention_);
            }
        }
示例#48
0
 public MakeCommercialPaper withRule(DateGeneration.Rule r)
 {
     rule_ = r;
     return(this);
 }
示例#49
0
文件: Schedule.cs 项目: Yenyenx/qlnet
        public Schedule( Date effectiveDate, Date terminationDate, Period tenor, Calendar calendar,
                       BusinessDayConvention convention, BusinessDayConvention terminationDateConvention,
                       DateGeneration.Rule rule, bool endOfMonth, Date firstDate = null, Date nextToLastDate = null)
        {
            // first save the properties
             fullInterface_ = true;
             tenor_ = tenor;
            if ( calendar == null )
                calendar_ = new NullCalendar();
            else
                calendar_ = calendar;
             convention_ = convention;
             terminationDateConvention_ = terminationDateConvention;
             rule_ = rule;
             endOfMonth_ = endOfMonth;

             if ( firstDate == effectiveDate )
            firstDate_ = null;
             else
            firstDate_ = firstDate;

              if ( nextToLastDate == terminationDate )
            nextToLastDate_ = null;
             else
            nextToLastDate_ = nextToLastDate;

             // sanity checks
              Utils.QL_REQUIRE( terminationDate != null, () => "null termination date" );

             // in many cases (e.g. non-expired bonds) the effective date is not
             // really necessary. In these cases a decent placeholder is enough
             if ( effectiveDate == null && firstDate == null && rule== DateGeneration.Rule.Backward)
             {
            Date evalDate = Settings.evaluationDate();
            Utils.QL_REQUIRE( evalDate < terminationDate, () => "null effective date" );
            int y;
            if (nextToLastDate != null)
            {
                y = (nextToLastDate - evalDate)/366 + 1;
                effectiveDate = nextToLastDate - new Period(y,TimeUnit.Years);
            }
            else
            {
                y = (terminationDate - evalDate)/366 + 1;
                effectiveDate = terminationDate - new Period(y,TimeUnit.Years);
            }
             }
             else
            Utils.QL_REQUIRE( effectiveDate != null, () => "null effective date" );

             if (tenor_.length() == 0)
            rule_ = DateGeneration.Rule.Zero;
             else
            Utils.QL_REQUIRE( tenor.length() > 0, () => "non positive tenor (" + tenor + ") not allowed" );

             if (firstDate_ != null)
             {
            switch (rule_)
            {
               case DateGeneration.Rule.Backward:
               case DateGeneration.Rule.Forward:
                  Utils.QL_REQUIRE(firstDate_ > effectiveDate &&
                                   firstDate_ < terminationDate, () =>
                                   "first date (" + firstDate_ + ") out of effective-termination date range [" +
                                   effectiveDate + ", " + terminationDate + ")");
                  // we should ensure that the above condition is still verified after adjustment
                  break;
               case DateGeneration.Rule.ThirdWednesday:
                  Utils.QL_REQUIRE( IMM.isIMMdate( firstDate_, false ), () => "first date (" + firstDate_ + ") is not an IMM date" );
                  break;
               case DateGeneration.Rule.Zero:
               case DateGeneration.Rule.Twentieth:
               case DateGeneration.Rule.TwentiethIMM:
               case DateGeneration.Rule.OldCDS:
               case DateGeneration.Rule.CDS:
                  Utils.QL_FAIL("first date incompatible with " + rule_ + " date generation rule");
                  break;
               default:
                  Utils.QL_FAIL("unknown rule (" + rule_ + ")");
                  break;
            }
             }

             if (nextToLastDate_ != null)
             {
            switch (rule_)
            {
               case DateGeneration.Rule.Backward:
               case DateGeneration.Rule.Forward:
                  Utils.QL_REQUIRE( nextToLastDate_ > effectiveDate && nextToLastDate_ < terminationDate, () =>
                                   "next to last date (" + nextToLastDate_ + ") out of effective-termination date range (" +
                                   effectiveDate + ", " + terminationDate + "]");
                  // we should ensure that the above condition is still verified after adjustment
                  break;
               case DateGeneration.Rule.ThirdWednesday:
                  Utils.QL_REQUIRE( IMM.isIMMdate( nextToLastDate_, false ), () => "next-to-last date (" + nextToLastDate_ +
                                    ") is not an IMM date");
                  break;
               case DateGeneration.Rule.Zero:
               case DateGeneration.Rule.Twentieth:
               case DateGeneration.Rule.TwentiethIMM:
               case DateGeneration.Rule.OldCDS:
               case DateGeneration.Rule.CDS:
                  Utils.QL_FAIL("next to last date incompatible with " + rule_ + " date generation rule");
                  break;
               default:
                  Utils.QL_FAIL("unknown rule (" + rule_ + ")");
                  break;
            }
             }

             // calendar needed for endOfMonth adjustment
             Calendar nullCalendar = new NullCalendar();
             int periods = 1;
             Date seed = new Date() , exitDate;
             switch (rule_)
             {
            case DateGeneration.Rule.Zero:
               tenor_ = new Period(0, TimeUnit.Years);
               dates_.Add(effectiveDate);
               dates_.Add(terminationDate);
               isRegular_.Add(true);
               break;

            case DateGeneration.Rule.Backward:
               dates_.Add(terminationDate);

               seed = terminationDate;
               if (nextToLastDate_ != null)
               {
                  dates_.Insert(0, nextToLastDate_);
                  Date temp = nullCalendar.advance(seed, -periods * tenor_, convention_, endOfMonth_);
                  if (temp != nextToLastDate_)
                     isRegular_.Insert(0, false);
                  else
                     isRegular_.Insert(0, true);
                  seed = nextToLastDate_;
               }
               exitDate = effectiveDate;
               if (firstDate_ != null)
                  exitDate = firstDate_;

               while (true)
               {
                  Date temp = nullCalendar.advance(seed, -periods * tenor_, convention_, endOfMonth_);
                  if (temp < exitDate)
                  {
                     if (firstDate_ != null && (calendar_.adjust(dates_.First(), convention_) !=
                          calendar_.adjust(firstDate_, convention_)))
                     {
                        dates_.Insert(0, firstDate_);
                        isRegular_.Insert(0, false);
                     }
                     break;
                  }
                  else
                  {
                     // skip dates that would result in duplicates
                     // after adjustment
                     if (calendar_.adjust(dates_.First(), convention_) != calendar_.adjust(temp, convention_))
                     {
                        dates_.Insert(0, temp);
                        isRegular_.Insert(0, true);
                     }
                     ++periods;
                  }
               }

               if (calendar_.adjust(dates_.First(), convention) != calendar_.adjust(effectiveDate, convention))
               {
                  dates_.Insert(0, effectiveDate);
                  isRegular_.Insert(0, false);
               }

               break;

            case DateGeneration.Rule.Twentieth:
            case DateGeneration.Rule.TwentiethIMM:
            case DateGeneration.Rule.ThirdWednesday:
            case DateGeneration.Rule.OldCDS:
            case DateGeneration.Rule.CDS:
               Utils.QL_REQUIRE( !endOfMonth, () => "endOfMonth convention incompatible with " + rule_ + " date generation rule" );
               goto case DateGeneration.Rule.Forward;			// fall through

            case DateGeneration.Rule.Forward:
               if (rule_ == DateGeneration.Rule.CDS)
               {
                  dates_.Add(previousTwentieth(effectiveDate, DateGeneration.Rule.CDS));
               }
               else
               {
                  dates_.Add(effectiveDate);
               }

               seed = dates_.Last();
               if (firstDate_ != null)
               {
                  dates_.Add(firstDate_);
                  Date temp = nullCalendar.advance(seed, periods * tenor_, convention_, endOfMonth_);
                  if (temp != firstDate_)
                     isRegular_.Add(false);
                  else
                     isRegular_.Add(true);
                  seed = firstDate_;
               }
               else if (rule_ == DateGeneration.Rule.Twentieth ||
                        rule_ == DateGeneration.Rule.TwentiethIMM ||
                        rule_ == DateGeneration.Rule.OldCDS ||
                        rule_ == DateGeneration.Rule.CDS)
               {
                  Date next20th = nextTwentieth(effectiveDate, rule_);
                  if (rule_ == DateGeneration.Rule.OldCDS)
                  {
                     // distance rule inforced in natural days
                     long stubDays = 30;
                     if (next20th - effectiveDate < stubDays)
                     {
                        // +1 will skip this one and get the next
                        next20th = nextTwentieth(next20th + 1, rule_);
                     }
                  }
                  if (next20th != effectiveDate)
                  {
                     dates_.Add(next20th);
                     isRegular_.Add(false);
                     seed = next20th;
                  }
               }

               exitDate = terminationDate;
               if (nextToLastDate_ != null)
                  exitDate = nextToLastDate_;
               while (true)
               {
                  Date temp = nullCalendar.advance(seed, periods * tenor_, convention_, endOfMonth_);
                  if (temp > exitDate)
                  {
                     if (nextToLastDate_ != null &&
                         (calendar_.adjust(dates_.Last(), convention_) !=  calendar_.adjust(nextToLastDate_, convention_)))
                     {
                        dates_.Add(nextToLastDate_);
                        isRegular_.Add(false);
                     }
                     break;
                  }
                  else
                  {
                     // skip dates that would result in duplicates
                     // after adjustment
                     if (calendar_.adjust(dates_.Last(), convention_) != calendar_.adjust(temp, convention_))
                     {
                        dates_.Add(temp);
                        isRegular_.Add(true);
                     }
                     ++periods;
                  }
               }

               if (calendar_.adjust(dates_.Last(), terminationDateConvention_) !=
                   calendar_.adjust(terminationDate, terminationDateConvention_))
               {
                  if (rule_ == DateGeneration.Rule.Twentieth ||
                      rule_ == DateGeneration.Rule.TwentiethIMM ||
                      rule_ == DateGeneration.Rule.OldCDS ||
                      rule_ == DateGeneration.Rule.CDS)
                  {
                     dates_.Add(nextTwentieth(terminationDate, rule_));
                     isRegular_.Add(true);
                  }
                  else
                  {
                     dates_.Add(terminationDate);
                     isRegular_.Add(false);
                  }
               }
               break;

            default:
               Utils.QL_FAIL("unknown rule (" + rule_ + ")");
               break;
             }

             // adjustments
             if (rule_ == DateGeneration.Rule.ThirdWednesday)
            for (int i = 1; i < dates_.Count-1; ++i)
               dates_[i] = Date.nthWeekday(3, DayOfWeek.Wednesday, dates_[i].Month, dates_[i].Year);

             if (endOfMonth && calendar_.isEndOfMonth(seed))
             {
            // adjust to end of month
            if (convention_ == BusinessDayConvention.Unadjusted)
            {
               for (int i = 0; i < dates_.Count-1; ++i)
                  dates_[i] = Date.endOfMonth(dates_[i]);
            }
            else
            {
               for (int i = 0; i < dates_.Count-1; ++i)
                  dates_[i] = calendar_.endOfMonth(dates_[i]);
            }
            if (terminationDateConvention_ != BusinessDayConvention.Unadjusted)
               dates_[dates_.Count - 1] = calendar_.endOfMonth(dates_.Last());
             }
             else
             {
            // first date not adjusted for CDS schedules
            if (rule_ != DateGeneration.Rule.OldCDS)
               dates_[0] = calendar_.adjust(dates_[0], convention_);
            for (int i = 1; i < dates_.Count-1; ++i)
               dates_[i] = calendar_.adjust(dates_[i], convention_);

            // termination date is NOT adjusted as per ISDA specifications, unless otherwise specified in the
            // confirmation of the deal or unless we're creating a CDS schedule
            if (terminationDateConvention_ != BusinessDayConvention.Unadjusted
                || rule_ == DateGeneration.Rule.Twentieth
                || rule_ == DateGeneration.Rule.TwentiethIMM
                || rule_ == DateGeneration.Rule.OldCDS
                || rule_ == DateGeneration.Rule.CDS)
               dates_[dates_.Count - 1] = calendar_.adjust(dates_.Last(), terminationDateConvention_);
             }

             // final safety check to remove duplicated last dates, if any
             // it can happen if EOM is applied to two near dates
             if (dates_.Count >= 2 &&  dates_[dates_.Count - 2] >= dates_.Last())
             {
            isRegular_[dates_.Count() - 2] = (dates_[dates_.Count() - 2] == dates_.Last());
            dates_[dates_.Count() - 2] = dates_.Last();

            dates_.RemoveAt(dates_.Count - 1);
            isRegular_.RemoveAt(isRegular_.Count - 1);
             }
        }
示例#50
0
文件: Schedule.cs 项目: Yenyenx/qlnet
 public MakeSchedule withRule(DateGeneration.Rule r)
 {
     rule_ = r;
        return this;
 }
示例#51
0
 public Schedule(List<Date> dates__, Calendar calendar__, BusinessDayConvention convention__)
 {
     fullInterface_ = false;
     tenor_ = new Period();
     calendar_ = calendar__;
     convention_ = convention__;
     terminationDateConvention_ = convention__;
     rule_ = DateGeneration.Rule.Forward;
     endOfMonth_ = false;
     adjustedDates_ = dates__;
 }