Пример #1
0
 // Factory - for Leg generators
 public override CashFlow factory(double nominal, Date paymentDate, Date startDate, Date endDate, int fixingDays,
                                  InterestRateIndex index, double gearing, double spread,
                                  Date refPeriodStart, Date refPeriodEnd, DayCounter dayCounter, bool isInArrears)
 {
     return(new IborCoupon(paymentDate, nominal, startDate, endDate, fixingDays,
                           (IborIndex)index, gearing, spread, refPeriodStart, refPeriodEnd, dayCounter, isInArrears));
 }
Пример #2
0
        // constructors
        public FloatingRateCoupon(Date paymentDate,
                                  double nominal,
                                  Date startDate,
                                  Date endDate,
                                  int fixingDays,
                                  InterestRateIndex index,
                                  double gearing        = 1.0,
                                  double spread         = 0.0,
                                  Date refPeriodStart   = null,
                                  Date refPeriodEnd     = null,
                                  DayCounter dayCounter = null,
                                  bool isInArrears      = false)
            : base(paymentDate, nominal, startDate, endDate, refPeriodStart, refPeriodEnd)
        {
            index_       = index;
            dayCounter_  = dayCounter ?? new DayCounter();
            fixingDays_  = fixingDays == default(int) ? index.fixingDays() : fixingDays;
            gearing_     = gearing;
            spread_      = spread;
            isInArrears_ = isInArrears;

            if (gearing_.IsEqual(0))
            {
                throw new ArgumentException("Null gearing not allowed");
            }

            if (dayCounter_.empty())
            {
                dayCounter_ = index_.dayCounter();
            }

            // add as observer
            index_.registerWith(update);
            Settings.Instance.registerWith(update);
        }
Пример #3
0
        public FloatFloatSwap(VanillaSwap.Type type,
                              List <double> nominal1,
                              List <double> nominal2,
                              Schedule schedule1,
                              InterestRateIndex index1,
                              DayCounter dayCount1,
                              Schedule schedule2,
                              InterestRateIndex index2,
                              DayCounter dayCount2,
                              bool intermediateCapitalExchange         = false,
                              bool finalCapitalExchange                = false,
                              List <double> gearing1                   = null,
                              List <double> spread1                    = null,
                              List <double?> cappedRate1               = null,
                              List <double?> flooredRate1              = null,
                              List <double> gearing2                   = null,
                              List <double> spread2                    = null,
                              List <double?> cappedRate2               = null,
                              List <double?> flooredRate2              = null,
                              BusinessDayConvention?paymentConvention1 = null,
                              BusinessDayConvention?paymentConvention2 = null)
            : base(2)
        {
            type_         = type;
            nominal1_     = nominal1;
            nominal2_     = nominal2;
            schedule1_    = schedule1;
            schedule2_    = schedule2;
            index1_       = index1;
            index2_       = index2;
            gearing1_     = gearing1;
            gearing2_     = gearing2;
            spread1_      = spread1;
            spread2_      = spread2;
            cappedRate1_  = cappedRate1;
            flooredRate1_ = flooredRate1;
            cappedRate2_  = cappedRate2;
            flooredRate2_ = flooredRate2;
            dayCount1_    = dayCount1;
            dayCount2_    = dayCount2;
            intermediateCapitalExchange_ = intermediateCapitalExchange;
            finalCapitalExchange_        = finalCapitalExchange;

            init(paymentConvention1, paymentConvention2);
        }
Пример #4
0
        public FloatFloatSwap(VanillaSwap.Type type,
                              double nominal1,
                              double nominal2,
                              Schedule schedule1,
                              InterestRateIndex index1,
                              DayCounter dayCount1,
                              Schedule schedule2,
                              InterestRateIndex index2,
                              DayCounter dayCount2,
                              bool intermediateCapitalExchange = false,
                              bool finalCapitalExchange        = false,
                              double gearing1     = 1.0,
                              double spread1      = 0.0,
                              double?cappedRate1  = null,
                              double?flooredRate1 = null,
                              double gearing2     = 1.0,
                              double spread2      = 0.0,
                              double?cappedRate2  = null,
                              double?flooredRate2 = null,
                              BusinessDayConvention?paymentConvention1 = null,
                              BusinessDayConvention?paymentConvention2 = null)
            : base(2)
        {
            type_         = type;
            nominal1_     = new InitializedList <double> (schedule1.size() - 1, nominal1);
            nominal2_     = new InitializedList <double> (schedule2.size() - 1, nominal2);
            schedule1_    = schedule1;
            schedule2_    = schedule2;
            index1_       = index1;
            index2_       = index2;
            gearing1_     = new InitializedList <double>(schedule1.size() - 1, gearing1);
            gearing2_     = new InitializedList <double>(schedule2.size() - 1, gearing2);
            spread1_      = new InitializedList <double>(schedule1.size() - 1, spread1);
            spread2_      = new InitializedList <double>(schedule2.size() - 1, spread2);
            cappedRate1_  = new InitializedList <double?>(schedule1.size() - 1, cappedRate1);
            flooredRate1_ = new InitializedList <double?>(schedule1.size() - 1, flooredRate1);
            cappedRate2_  = new InitializedList <double?>(schedule2.size() - 1, cappedRate2);
            flooredRate2_ = new InitializedList <double?>(schedule2.size() - 1, flooredRate2);
            dayCount1_    = dayCount1; dayCount2_ = dayCount2;
            intermediateCapitalExchange_ = intermediateCapitalExchange;
            finalCapitalExchange_        = finalCapitalExchange;

            init(paymentConvention1, paymentConvention2);
        }
Пример #5
0
        public override double swapletRate()
        {
            List<Date> fixingDates = coupon_.fixingDates();
             InterestRateIndex index = coupon_.index();

             int cutoffDays = 0; // to be verified
             Date startDate = coupon_.accrualStartDate() - cutoffDays,
              endDate = coupon_.accrualEndDate() - cutoffDays,
              d1 = startDate;

             Utils.QL_REQUIRE(fixingDates.Count > 0, () => "fixing date list empty");
             Utils.QL_REQUIRE(index.valueDate(fixingDates.First()) <= startDate, () => "first fixing date valid after period start");
             Utils.QL_REQUIRE(index.valueDate(fixingDates.Last()) >= endDate, () => "last fixing date valid before period end");

             double avgBMA = 0.0;
             int days = 0;
             for (int i = 0; i < fixingDates.Count - 1; ++i)
             {
            Date valueDate = index.valueDate(fixingDates[i]);
            Date nextValueDate = index.valueDate(fixingDates[i + 1]);

            if (fixingDates[i] >= endDate || valueDate >= endDate)
               break;
            if (fixingDates[i + 1] < startDate || nextValueDate <= startDate)
               continue;

            Date d2 = Date.Min(nextValueDate, endDate);

            avgBMA += index.fixing(fixingDates[i]) * (d2 - d1);

            days += d2 - d1;
            d1 = d2;
             }
             avgBMA /= (endDate - startDate);

             Utils.QL_REQUIRE(days == endDate - startDate, () =>
                          "averaging days " + days + " differ from " + "interest days " + (endDate - startDate));

             return coupon_.gearing() * avgBMA + coupon_.spread();
        }