Exemple #1
0
        protected override void performCalculations()
        {
            List <BTP>             btps   = basket_.btps();
            List <Handle <Quote> > quotes = basket_.cleanPriceQuotes();
            Date bondSettlementDate       = btps[0].settlementDate();

            for (int i = 0; i < basket_.size(); ++i)
            {
                yields_[i] = BondFunctions.yield(btps[i], quotes[i].link.value(),
                                                 new ActualActual(ActualActual.Convention.ISMA),
                                                 Compounding.Compounded, Frequency.Annual,
                                                 bondSettlementDate,
                                                 // accuracy, maxIterations, guess
                                                 1.0e-10, 100, yields_[i]);

                durations_[i] = BondFunctions.duration(btps[i], yields_[i], new ActualActual(ActualActual.Convention.ISMA),
                                                       Compounding.Compounded, Frequency.Annual, Duration.Type.Modified,
                                                       bondSettlementDate);
            }

            duration_ = 0;
            basket_.weights().ForEach((ii, vv) => duration_ += vv * yields()[ii]);


            //duration_ = std::inner_product(basket_->weights().begin(),
            //                              basket_->weights().end(),
            //                              durations_.begin(), 0.0);

            int        settlDays     = 2;
            DayCounter fixedDayCount = swaps_[0].fixedDayCount();

            equivalentSwapIndex_ = nSwaps_ - 1;
            swapRates_[0]        = swaps_[0].fairRate();
            FixedRateBond swapBond = new FixedRateBond(settlDays,
                                                       100.0,   // faceAmount
                                                       swaps_[0].fixedSchedule(),
                                                       new List <double>()
            {
                swapRates_[0].Value
            },
                                                       fixedDayCount,
                                                       BusinessDayConvention.Following, // paymentConvention
                                                       100.0);                          // redemption

            swapBondYields_[0] = BondFunctions.yield(swapBond,
                                                     100.0, // floating leg NPV including end payment
                                                     new ActualActual(ActualActual.Convention.ISMA),
                                                     Compounding.Compounded, Frequency.Annual,
                                                     bondSettlementDate,
                                                     // accuracy, maxIterations, guess
                                                     1.0e-10, 100, swapBondYields_[0].Value);

            swapBondDurations_[0] = BondFunctions.duration(swapBond, swapBondYields_[0].Value,
                                                           new ActualActual(ActualActual.Convention.ISMA),
                                                           Compounding.Compounded, Frequency.Annual,
                                                           Duration.Type.Modified, bondSettlementDate);
            for (int i = 1; i < nSwaps_; ++i)
            {
                swapRates_[i] = swaps_[i].fairRate();
                FixedRateBond swapBond2 = new FixedRateBond(settlDays,
                                                            100.0, // faceAmount
                                                            swaps_[i].fixedSchedule(),
                                                            new List <double>()
                {
                    swapRates_[i].Value
                },
                                                            fixedDayCount,
                                                            BusinessDayConvention.Following, // paymentConvention
                                                            100.0);                          // redemption

                swapBondYields_[i] = BondFunctions.yield(swapBond2, 100.0,                   // floating leg NPV including end payment
                                                         new ActualActual(ActualActual.Convention.ISMA),
                                                         Compounding.Compounded, Frequency.Annual,
                                                         bondSettlementDate,
                                                         // accuracy, maxIterations, guess
                                                         1.0e-10, 100, swapBondYields_[i].Value);

                swapBondDurations_[i] = BondFunctions.duration(swapBond2, swapBondYields_[i].Value,
                                                               new ActualActual(ActualActual.Convention.ISMA),
                                                               Compounding.Compounded, Frequency.Annual,
                                                               Duration.Type.Modified, bondSettlementDate);
                if (swapBondDurations_[i] > duration_)
                {
                    equivalentSwapIndex_ = i - 1;
                    break; // exit the loop
                }
            }

            return;
        }
Exemple #2
0
 public Date nextCashFlowDate(Date settlement = null)
 {
     return(BondFunctions.nextCashFlowDate(this, settlement));
 }
Exemple #3
0
 public Date previousCashFlowDate(Date settlement = null)
 {
     return(BondFunctions.previousCashFlowDate(this, settlement));
 }
Exemple #4
0
 /*! Expected next coupon: depending on (the bond and) the given date
  *  the coupon can be historic, deterministic or expected in a
  *  stochastic sense. When the bond settlement date is used the coupon
  *  is the already-fixed not-yet-paid one.
  *
  *  The current bond settlement is used if no date is given.
  */
 public virtual double nextCouponRate(Date settlement = null)
 {
     return(BondFunctions.nextCouponRate(this, settlement));
 }
Exemple #5
0
        //! Previous coupon already paid at a given date

        /*! Expected previous coupon: depending on (the bond and) the given
         *  date the coupon can be historic, deterministic or expected in a
         *  stochastic sense. When the bond settlement date is used the coupon
         *  is the last paid one.
         *
         *  The current bond settlement is used if no date is given.
         */
        public double previousCouponRate(Date settlement = null)
        {
            return(BondFunctions.previousCouponRate(this, settlement));
        }
Exemple #6
0
 //! clean price given a yield and settlement date
 /*! The default bond settlement is used if no date is given. */
 public double cleanPrice(double yield, DayCounter dc, Compounding comp, Frequency freq, Date settlement = null)
 {
     return(BondFunctions.cleanPrice(this, yield, dc, comp, freq, settlement));
 }
Exemple #7
0
 public bool isTradable(Date d = null)
 {
     return(BondFunctions.isTradable(this, d));
 }
Exemple #8
0
 public Date maturityDate()
 {
     return((maturityDate_ != null) ? maturityDate_ : BondFunctions.maturityDate(this));
 }
Exemple #9
0
 public Date startDate()
 {
     return(BondFunctions.startDate(this));
 }
Exemple #10
0
 public Date maturityDate()
 {
     return(maturityDate_ ?? BondFunctions.maturityDate(this));
 }