Пример #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));
        }
        // converts the yield volatility into a forward price volatility
        private double forwardPriceVolatility()
        {
            Date            bondMaturity = arguments_.redemptionDate;
            Date            exerciseDate = arguments_.callabilityDates[0];
            List <CashFlow> fixedLeg     = arguments_.cashflows;

            // value of bond cash flows at option maturity
            double fwdNpv = CashFlows.npv(fixedLeg, discountCurve_, false, exerciseDate);

            DayCounter dayCounter = arguments_.paymentDayCounter;
            Frequency  frequency  = arguments_.frequency;

            // adjust if zero coupon bond (see also bond.cpp)
            if (frequency == Frequency.NoFrequency || frequency == Frequency.Once)
            {
                frequency = Frequency.Annual;
            }

            double fwdYtm = CashFlows.yield(fixedLeg,
                                            fwdNpv,
                                            dayCounter,
                                            Compounding.Compounded,
                                            frequency,
                                            false,
                                            exerciseDate);

            InterestRate fwdRate = new InterestRate(fwdYtm, dayCounter, Compounding.Compounded, frequency);

            double fwdDur = CashFlows.duration(fixedLeg,
                                               fwdRate,
                                               Duration.Type.Modified, false,
                                               exerciseDate);

            double cashStrike = arguments_.callabilityPrices[0];

            dayCounter = volatility_.link.dayCounter();
            Date   referenceDate = volatility_.link.referenceDate();
            double exerciseTime  = dayCounter.yearFraction(referenceDate,
                                                           exerciseDate);
            double maturityTime = dayCounter.yearFraction(referenceDate,
                                                          bondMaturity);
            double yieldVol = volatility_.link.volatility(exerciseTime,
                                                          maturityTime - exerciseTime,
                                                          cashStrike);
            double fwdPriceVol = yieldVol * fwdDur * fwdYtm;

            return(fwdPriceVol);
        }
Пример #3
0
        public static double yield(Bond bond, double cleanPrice, DayCounter dayCounter, Compounding compounding, Frequency frequency,
                                   Date settlementDate = null, double accuracy = 1.0e-10, int maxIterations = 100, double guess = 0.05)
        {
            if (settlementDate == null)
            {
                settlementDate = bond.settlementDate();
            }

            Utils.QL_REQUIRE(BondFunctions.isTradable(bond, settlementDate), () =>
                             "non tradable at " + settlementDate +
                             " (maturity being " + bond.maturityDate() + ")",
                             QLNetExceptionEnum.NotTradableException);

            double dirtyPrice = cleanPrice + bond.accruedAmount(settlementDate);

            dirtyPrice /= 100.0 / bond.notional(settlementDate);

            return(CashFlows.yield(bond.cashflows(), dirtyPrice,
                                   dayCounter, compounding, frequency,
                                   false, settlementDate, settlementDate,
                                   accuracy, maxIterations, guess));
        }