示例#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));
        }
        protected void addRedemptionsToCashflows(List <double> redemptions)
        {
            // First, we gather the notional information from the cashflows
            calculateNotionalsFromCashflows();
            // Then, we create the redemptions based on the notional
            // information and we add them to the cashflows vector after
            // the coupons.
            redemptions_.Clear();
            for (int i = 1; i < notionalSchedule_.Count; ++i)
            {
                double R = i < redemptions.Count ? redemptions[i] :
                           !redemptions.empty()  ? redemptions.Last() :
                           100.0;
                double   amount = (R / 100.0) * (notionals_[i - 1] - notionals_[i]);
                CashFlow redemption;
                if (i < notionalSchedule_.Count - 1)
                {
                    //payment.reset(new AmortizingPayment(amount,notionalSchedule_[i]));
                    redemption = new AmortizingPayment(amount, notionalSchedule_[i]);
                }
                else
                {
                    //payment.reset(new Redemption(amount, notionalSchedule_[i]));
                    redemption = new Redemption(amount, notionalSchedule_[i]);
                }

                //CashFlow redemption = new SimpleCashFlow(amount, notionalSchedule_[i]);
                cashflows_.Add(redemption);
                redemptions_.Add(redemption);
            }
            // stable_sort now moves the redemptions to the right places
            // while ensuring that they follow coupons with the same date.
            cashflows_.Sort();
        }
示例#3
0
文件: Bond.cs 项目: igitur/qlnet
        /*! This method can be called by derived classes in order to
         *  build redemption payments from the existing cash flows.
         *  It must be called after setting up the cashflows_ vector
         *  and will fill the notionalSchedule_, notionals_, and
         *  redemptions_ data members.
         *
         *  If given, the elements of the redemptions vector will
         *  multiply the amount of the redemption cash flow.  The
         *  elements will be taken in base 100, i.e., a redemption
         *  equal to 100 does not modify the amount.
         *
         *  \pre The cashflows_ vector must contain at least one
         *       coupon and must be sorted by date.
         */
        protected void addRedemptionsToCashflows(List <double> redemptions = null)
        {
            if (redemptions == null)
            {
                redemptions = new List <double>();
            }

            // First, we gather the notional information from the cashflows
            calculateNotionalsFromCashflows();
            // Then, we create the redemptions based on the notional
            // information and we add them to the cashflows vector after
            // the coupons.
            redemptions_.Clear();
            for (int i = 1; i < notionalSchedule_.Count; ++i)
            {
                double R = i < redemptions.Count ? redemptions[i] :
                           !redemptions.empty() ? redemptions.Last() :
                           100.0;
                double   amount = (R / 100.0) * (notionals_[i - 1] - notionals_[i]);
                CashFlow payment;
                if (i < notionalSchedule_.Count - 1)
                {
                    payment = new AmortizingPayment(amount, notionalSchedule_[i]);
                }
                else
                {
                    payment = new Redemption(amount, notionalSchedule_[i]);
                }

                cashflows_.Add(payment);
                redemptions_.Add(payment);
            }
            // stable_sort now moves the AmortizingPayment and Redemptions to the right places
            // while ensuring that they follow coupons with the same date.
            cashflows_ = cashflows_.OrderBy(x => x.date()).ToList();
        }
示例#4
0
        /*! This method can be called by derived classes in order to
         *  build a bond with a single redemption payment.  It will
         *  fill the notionalSchedule_, notionals_, and redemptions_
         *  data members.
         */
        protected void setSingleRedemption(double notional, double redemption, Date date)
        {
            CashFlow redemptionCashflow = new Redemption(notional * redemption / 100.0, date);

            setSingleRedemption(notional, redemptionCashflow);
        }
示例#5
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);
      }