dayCounter() public abstract method

public abstract dayCounter ( ) : QLNet.DayCounter
return QLNet.DayCounter
Ejemplo n.º 1
0
        private static double aggregateRate(Leg leg, CashFlow cf)
        {
            if (cf == null)
            {
                return(0.0);
            }

            Date       paymentDate      = cf.date();
            bool       firstCouponFound = false;
            double     nominal          = 0.0;
            double     accrualPeriod    = 0.0;
            DayCounter dc     = null;
            double     result = 0.0;

            foreach (CashFlow x in leg.Where(x => x.date() == paymentDate))
            {
                Coupon cp = x as Coupon;
                if (cp != null)
                {
                    if (firstCouponFound)
                    {
                        Utils.QL_REQUIRE(nominal.IsEqual(cp.nominal()) &&
                                         accrualPeriod.IsEqual(cp.accrualPeriod()) &&
                                         dc == cp.dayCounter(), () =>
                                         "cannot aggregate two different coupons on "
                                         + paymentDate);
                    }
                    else
                    {
                        firstCouponFound = true;
                        nominal          = cp.nominal();
                        accrualPeriod    = cp.accrualPeriod();
                        dc = cp.dayCounter();
                    }
                    result += cp.rate();
                }
            }

            Utils.QL_REQUIRE(firstCouponFound, () => "no coupon paid at cashflow date " + paymentDate);
            return(result);
        }
        private static double couponRate(List <CashFlow> leg, CashFlow cf)
        {
            if (cf == null)
            {
                return(0.0);
            }

            Date       paymentDate      = cf.date();
            bool       firstCouponFound = false;
            double     nominal          = 0;
            double     accrualPeriod    = 0;
            DayCounter dc     = null;
            double     result = 0.0;

            foreach (CashFlow x in leg.Where(x => x.date() == paymentDate))
            {
                Coupon cp = x as Coupon;
                if (cp != null)
                {
                    if (firstCouponFound)
                    {
                        if (!(nominal == cp.nominal() && accrualPeriod == cp.accrualPeriod() && dc == cp.dayCounter()))
                        {
                            throw new ApplicationException("cannot aggregate two different coupons on " + paymentDate);
                        }
                    }
                    else
                    {
                        firstCouponFound = true;
                        nominal          = cp.nominal();
                        accrualPeriod    = cp.accrualPeriod();
                        dc = cp.dayCounter();
                    }
                    result += cp.rate();
                }
            }

            if (!firstCouponFound)
            {
                throw new ApplicationException("next cashflow (" + paymentDate + ") is not a coupon");
            }
            return(result);
        }
Ejemplo n.º 3
0
        public double accruedAmount(Date settlement)
        {
            if (settlement == null)
            {
                settlement = settlementDate();
            }

            CashFlow cf = CashFlows.nextCashFlow(cashflows_, false, settlement);

            if (cf == cashflows_.Last())
            {
                return(0.0);
            }

            Date       paymentDate      = cf.date();
            bool       firstCouponFound = false;
            double     nominal          = 0;
            double     accrualPeriod    = 0;
            DayCounter dc     = null;
            double     result = 0.0;

            foreach (CashFlow x in cashflows_.FindAll(x => x.date() == paymentDate && x.GetType().IsSubclassOf(typeof(Coupon))))
            {
                Coupon cp = (Coupon)x;
                if (firstCouponFound)
                {
                    if (!(nominal == cp.nominal() && accrualPeriod == cp.accrualPeriod() && dc == cp.dayCounter()))
                    {
                        throw new ApplicationException("cannot aggregate accrued amount of two different coupons on " + paymentDate);
                    }
                }
                else
                {
                    firstCouponFound = true;
                    nominal          = cp.nominal();
                    accrualPeriod    = cp.accrualPeriod();
                    dc = cp.dayCounter();
                }
                result += cp.accruedAmount(settlement);
            }
            return(result / notional(settlement) * 100.0);
        }