Exemple #1
0
        //! old constructor for non amortizing bonds.

        /*! \warning The last passed cash flow must be the bond
         *           redemption. No other cash flow can have a date
         *           later than the redemption date.
         */
        public Bond(int settlementDays, Calendar calendar, double faceAmount, Date maturityDate, Date issueDate = null,
                    List <CashFlow> cashflows = null)
        {
            settlementDays_ = settlementDays;
            calendar_       = calendar;
            if (cashflows == null)
            {
                cashflows_ = new List <CashFlow>();
            }
            else
            {
                cashflows_ = cashflows;
            }
            maturityDate_ = maturityDate;
            issueDate_    = issueDate;

            if (cashflows_.Count != 0)
            {
                cashflows_.Sort(0, cashflows_.Count - 1, null);

                if (maturityDate_ == null)
                {
                    maturityDate_ = CashFlows.maturityDate(cashflows_);
                }

                if (issueDate_ != null)
                {
                    Utils.QL_REQUIRE(issueDate_ < cashflows_[0].date(), () =>
                                     "issue date (" + issueDate_ +
                                     ") must be earlier than first payment date (" +
                                     cashflows_[0].date() + ")");
                }

                notionalSchedule_.Add(new Date());
                notionals_.Add(faceAmount);

                notionalSchedule_.Add(maturityDate_);
                notionals_.Add(0.0);

                redemptions_.Add(cashflows.Last());
            }

            Settings.Instance.registerWith(update);
        }
Exemple #2
0
 public Date maturityDate()
 {
     return(CashFlows.maturityDate(floatingLeg_));
 }
Exemple #3
0
 public Date maturityDate()
 {
     Utils.QL_REQUIRE(!legs_.empty(), () => "no legs given");
     return(legs_.Max(leg => CashFlows.maturityDate(leg)));
 }
        // Instrument interface
        public override void calculate()
        {
            Utils.QL_REQUIRE(!discountCurve_.empty(), () => "discounting term structure handle is empty");

            results_.value         = results_.cash = 0;
            results_.errorEstimate = null;

            Date refDate = discountCurve_.link.referenceDate();

            Date settlementDate = settlementDate_;

            if (settlementDate_ == null)
            {
                settlementDate = refDate;
            }
            else
            {
                Utils.QL_REQUIRE(settlementDate >= refDate, () =>
                                 "settlement date (" + settlementDate + ") before " +
                                 "discount curve reference date (" + refDate + ")");
            }

            results_.valuationDate = npvDate_;
            if (npvDate_ == null)
            {
                results_.valuationDate = refDate;
            }
            else
            {
                Utils.QL_REQUIRE(npvDate_ >= refDate, () =>
                                 "npv date (" + npvDate_ + ") before " +
                                 "discount curve reference date (" + refDate + ")");
            }

            results_.npvDateDiscount = discountCurve_.link.discount(results_.valuationDate);

            int n = arguments_.legs.Count;

            results_.legNPV         = new InitializedList <double?>(n);
            results_.legBPS         = new InitializedList <double?>(n);
            results_.startDiscounts = new InitializedList <double?>(n);
            results_.endDiscounts   = new InitializedList <double?>(n);

            bool includeRefDateFlows =
                includeSettlementDateFlows_.HasValue ?
                includeSettlementDateFlows_.Value :
                Settings.Instance.includeReferenceDateEvents;

            for (int i = 0; i < n; ++i)
            {
                try
                {
                    YieldTermStructure discount_ref = discountCurve_.currentLink();
                    double             npv = 0, bps = 0;
                    CashFlows.npvbps(arguments_.legs[i],
                                     discount_ref,
                                     includeRefDateFlows,
                                     settlementDate,
                                     results_.valuationDate,
                                     out npv,
                                     out bps);
                    results_.legNPV[i] = npv * arguments_.payer[i];
                    results_.legBPS[i] = bps * arguments_.payer[i];

                    if (!arguments_.legs[i].empty())
                    {
                        Date d1 = CashFlows.startDate(arguments_.legs[i]);
                        if (d1 >= refDate)
                        {
                            results_.startDiscounts[i] = discountCurve_.link.discount(d1);
                        }
                        else
                        {
                            results_.startDiscounts[i] = null;
                        }

                        Date d2 = CashFlows.maturityDate(arguments_.legs[i]);
                        if (d2 >= refDate)
                        {
                            results_.endDiscounts[i] = discountCurve_.link.discount(d2);
                        }
                        else
                        {
                            results_.endDiscounts[i] = null;
                        }
                    }
                    else
                    {
                        results_.startDiscounts[i] = null;
                        results_.endDiscounts[i]   = null;
                    }
                }
                catch (Exception e)
                {
                    Utils.QL_FAIL((i + 1) + " leg: " + e.Message);
                }
                results_.value += results_.legNPV[i];
            }
        }
Exemple #5
0
 public Date maturityDate()
 {
     return(CashFlows.maturityDate(yoyLeg_));
 }
Exemple #6
0
 public static Date maturityDate(Bond bond)
 {
     return(CashFlows.maturityDate(bond.cashflows()));
 }