Esempio n. 1
0
        private double calculateYield()
        {
            // We create a bond cashflow from issue to maturity just
            // to calculate effective rate ( the rate that discount _marketValue )
            Schedule schedule = new Schedule(_issueDate, _maturityDate, new Period(_payFrequency),
                                             _calendar, BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                                             DateGeneration.Rule.Backward, false);


            List <CashFlow> cashflows = new FixedRateLeg(schedule)
                                        .withCouponRates(_couponRate, _dCounter)
                                        .withPaymentCalendar(_calendar)
                                        .withNotionals(_faceValue)
                                        .withPaymentAdjustment(BusinessDayConvention.Unadjusted);

            // Add single redemption for yield calculation
            Redemption r = new Redemption(_faceValue, _maturityDate);

            cashflows.Add(r);

            // Calculate Amortizing Yield ( Effective Rate )
            Date testDate = CashFlows.previousCashFlowDate(cashflows, false, _tradeDate);

            return(CashFlows.yield(cashflows, _marketValue, _dCounter, Compounding.Simple, _payFrequency,
                                   false, testDate));
        }
Esempio n. 2
0
        public static Date previousCashFlowDate(Bond bond, Date refDate = null)
        {
            if (refDate == null)
            {
                refDate = bond.settlementDate();
            }

            return(CashFlows.previousCashFlowDate(bond.cashflows(), false, refDate));
        }