//public List<CashFlow> interestCashflows()
      //{
      //   List<CashFlow> icf = new List<CashFlow>();
      //   foreach (CashFlow cf in cashflows())
      //   {
      //      if (cf is QLNet.FixedRateCoupon)
      //         icf.Add(cf);
      //   }
      //   return icf;
      //}

      public List<CashFlow> expectedCashflows()
      {
         calcBondFactor();

         List<CashFlow> expectedcashflows = new List<CashFlow>();

         List<double> notionals = new InitializedList<double>(schedule_.Count);
         notionals[0] = notionals_[0];
         for (int i = 0; i < schedule_.Count - 1; ++i)
         {
            double currentNotional = notionals[i];
            double smm = SMM(schedule_[i]);
            double prepay = (notionals[i] * bondFactors_[i + 1]) / bondFactors_[i] * smm;
            double actualamort = currentNotional * (1 - bondFactors_[i + 1] / bondFactors_[i]);
            notionals[i + 1] = currentNotional - actualamort - prepay;

            // ADD
            CashFlow c1 = new VoluntaryPrepay(prepay, schedule_[i + 1]);
            CashFlow c2 = new AmortizingPayment(actualamort, schedule_[i + 1]);
            CashFlow c3 = new FixedRateCoupon(currentNotional, schedule_[i + 1], new InterestRate(PassThroughRate_, dCounter_, Compounding.Simple), schedule_[i], schedule_[i + 1]);
            expectedcashflows.Add(c1);
            expectedcashflows.Add(c2);
            expectedcashflows.Add(c3);
            
         }
         notionals[notionals.Count - 1] = 0.0;
         
         return expectedcashflows;
      }
Esempio n. 2
0
        //public List<CashFlow> interestCashflows()
        //{
        //   List<CashFlow> icf = new List<CashFlow>();
        //   foreach (CashFlow cf in cashflows())
        //   {
        //      if (cf is QLNet.FixedRateCoupon)
        //         icf.Add(cf);
        //   }
        //   return icf;
        //}

        public List <CashFlow> expectedCashflows()
        {
            calcBondFactor();

            List <CashFlow> expectedcashflows = new List <CashFlow>();

            List <double> notionals = new InitializedList <double>(schedule_.Count);

            notionals[0] = notionals_[0];
            for (int i = 0; i < schedule_.Count - 1; ++i)
            {
                double currentNotional = notionals[i];
                double smm             = SMM(schedule_[i]);
                double prepay          = (notionals[i] * bondFactors_[i + 1]) / bondFactors_[i] * smm;
                double actualamort     = currentNotional * (1 - bondFactors_[i + 1] / bondFactors_[i]);
                notionals[i + 1] = currentNotional - actualamort - prepay;

                // ADD
                CashFlow c1 = new VoluntaryPrepay(prepay, schedule_[i + 1]);
                CashFlow c2 = new AmortizingPayment(actualamort, schedule_[i + 1]);
                CashFlow c3 = new FixedRateCoupon(currentNotional, schedule_[i + 1], new InterestRate(PassThroughRate_, dCounter_, Compounding.Simple, Frequency.Annual), schedule_[i], schedule_[i + 1]);
                expectedcashflows.Add(c1);
                expectedcashflows.Add(c2);
                expectedcashflows.Add(c3);
            }
            notionals[notionals.Count - 1] = 0.0;

            return(expectedcashflows);
        }
        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();
        }
Esempio n. 4
0
        void addEffectiveInterestRateAmortizing()
        {
            // Amortizing Schedule
            Schedule schedule = new Schedule(_tradeDate, _maturityDate, new Period(_payFrequency),
                                             _calendar, BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                                             DateGeneration.Rule.Backward, false);
            double currentNominal = _marketValue;
            Date   prevDate       = _tradeDate;
            Date   actualDate     = _tradeDate;

            for (int i = 1; i < schedule.Count; ++i)
            {
                actualDate = schedule[i];
                InterestRate    rate = new InterestRate(_yield, _dCounter, Compounding.Simple, Frequency.Annual);
                InterestRate    rate2 = new InterestRate(_couponRate, _dCounter, Compounding.Simple, Frequency.Annual);
                FixedRateCoupon r, r2;
                if (i > 1)
                {
                    r  = new FixedRateCoupon(actualDate, currentNominal, rate, prevDate, actualDate, prevDate, actualDate);
                    r2 = new FixedRateCoupon(actualDate, currentNominal, rate2, prevDate, actualDate, prevDate, actualDate, null, _originalPayment);
                }

                else
                {
                    Calendar nullCalendar = new NullCalendar();
                    Period   p1           = new Period(_payFrequency);
                    Date     testDate     = nullCalendar.advance(actualDate, -1 * p1);

                    r  = new FixedRateCoupon(actualDate, currentNominal, rate, testDate, actualDate, prevDate, actualDate);
                    r2 = new FixedRateCoupon(actualDate, currentNominal, rate2, testDate, actualDate, prevDate, actualDate, null, _originalPayment);
                }

                double amort = Math.Round(Math.Abs(_originalPayment - r.amount()), 2);

                AmortizingPayment p = new AmortizingPayment(amort, actualDate);
                if (_isPremium)
                {
                    currentNominal -= Math.Abs(amort);
                }
                else
                {
                    currentNominal += Math.Abs(amort);
                }


                cashflows_.Add(r2);
                cashflows_.Add(p);
                prevDate = actualDate;
            }

            // Add single redemption for yield calculation
            setSingleRedemption(_faceValue, 100, _maturityDate);
        }
Esempio n. 5
0
File: Bond.cs Progetto: 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();
        }
Esempio n. 6
0
      void addEffectiveInterestRateAmortizing()
      {

         // Amortizing Schedule
         Schedule schedule = new Schedule(_tradeDate, _maturityDate, new Period(_payFrequency),
                                           _calendar, BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                                           DateGeneration.Rule.Backward, false);
         double currentNominal = _marketValue;
         Date prevDate = _tradeDate;
         Date actualDate = _tradeDate;

         for (int i = 1; i < schedule.Count; ++i)
         {

            actualDate = schedule[i];
            InterestRate rate = new InterestRate(_yield, _dCounter, Compounding.Simple, Frequency.Annual);
            InterestRate rate2 = new InterestRate(_couponRate, _dCounter, Compounding.Simple, Frequency.Annual);
            FixedRateCoupon r,r2;
            if (i > 1)
            {
               r = new FixedRateCoupon(currentNominal, actualDate, rate, prevDate, actualDate, prevDate, actualDate);
               r2 = new FixedRateCoupon(currentNominal, actualDate, rate2, prevDate, actualDate, prevDate, actualDate, null,_originalPayment);
            }

            else
            {
               Calendar nullCalendar = new NullCalendar();
               Period p1 = new Period(_payFrequency);
               Date testDate = nullCalendar.advance(actualDate, -1 * p1);

               r = new FixedRateCoupon(currentNominal, actualDate, rate, testDate, actualDate, prevDate, actualDate);
               r2 = new FixedRateCoupon(currentNominal, actualDate, rate2, testDate, actualDate, prevDate, actualDate, null,_originalPayment);
            }

            double amort = Math.Round(Math.Abs(_originalPayment - r.amount()),2);
          
            AmortizingPayment p = new AmortizingPayment(amort, actualDate);
            if (_isPremium)
               currentNominal -= Math.Abs(amort);
            else
               currentNominal += Math.Abs(amort);


            cashflows_.Add(r2);
            cashflows_.Add(p);
            prevDate = actualDate;
         }

         // Add single redemption for yield calculation
         setSingleRedemption(_faceValue, 100, _maturityDate);

      }