コード例 #1
0
            public override double yearFraction(Date d1, Date d2, Date d3, Date d4)
            {
                if (d1 == d2)
                {
                    return(0.0);
                }

                if (d2 < d1)
                {
                    return(-yearFraction(d2, d1, d3, d4));
                }

                List <Date> couponDates =
                    getListOfPeriodDatesIncludingQuasiPayments(schedule_);

                double yearFractionSum = 0.0;

                for (int i = 0; i < couponDates.Count - 1; i++)
                {
                    Date startReferencePeriod = couponDates[i];
                    Date endReferencePeriod   = couponDates[i + 1];
                    if (d1 < endReferencePeriod && d2 > startReferencePeriod)
                    {
                        yearFractionSum +=
                            yearFractionWithReferenceDates(this,
                                                           Date.Max(d1, startReferencePeriod),
                                                           Date.Min(d2, endReferencePeriod),
                                                           startReferencePeriod,
                                                           endReferencePeriod);
                    }
                }
                return(yearFractionSum);
            }
コード例 #2
0
        public override Date maxDate()
        {
            Date maxDate = Date.Min(underlyingDividendTS_.currentLink().maxDate(),
                                    riskFreeTS_.currentLink().maxDate());

            maxDate = Date.Min(maxDate, foreignRiskFreeTS_.currentLink().maxDate());
            maxDate = Date.Min(maxDate, underlyingBlackVolTS_.currentLink().maxDate());
            maxDate = Date.Min(maxDate, exchRateBlackVolTS_.currentLink().maxDate());
            return(maxDate);
        }
コード例 #3
0
 public override double accruedAmount(Date d)
 {
     if (d <= accrualStartDate_ || d > paymentDate_)
     {
         return(0);
     }
     else
     {
         return(nominal() * rate() *
                dayCounter().yearFraction(accrualStartDate_, Date.Min(d, accrualEndDate_), refPeriodStart_, refPeriodEnd_));
     }
 }
コード例 #4
0
 public override double accruedAmount(Date d)
 {
     if (d <= accrualStartDate_ || d > paymentDate_)
     {
         return(0);
     }
     else if (tradingExCoupon(d))
     {
         return(-nominal() * (rate_.compoundFactor(d,
                                                   accrualEndDate_,
                                                   refPeriodStart_,
                                                   refPeriodEnd_) - 1.0));
     }
     else
     {
         return(nominal() * (rate_.compoundFactor(accrualStartDate_, Date.Min(d, accrualEndDate_),
                                                  refPeriodStart_, refPeriodEnd_) - 1.0));
     }
 }
コード例 #5
0
ファイル: CashFlows.cs プロジェクト: OpenDerivatives/QLCore
        public static Date startDate(Leg leg)
        {
            Utils.QL_REQUIRE(!leg.empty(), () => "empty leg");
            Date d = Date.maxDate();

            for (int i = 0; i < leg.Count; ++i)
            {
                Coupon c = leg[i] as Coupon;
                if (c != null)
                {
                    d = Date.Min(d, c.accrualStartDate());
                }
                else
                {
                    d = Date.Min(d, leg[i].date());
                }
            }
            return(d);
        }
コード例 #6
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();
        }