예제 #1
0
        public static CashFlow nextCashFlow(Bond bond, Date refDate = null)
        {
            if (refDate == null)
            {
                refDate = bond.settlementDate();
            }

            return(CashFlows.nextCashFlow(bond.cashflows(), false, refDate));
        }
        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);
        }