Example #1
0
        //! Basis-point value

        /*! Obtained by setting dy = 0.0001 in the 2nd-order Taylor
         *  series expansion.
         */
        public static double basisPointValue(Leg leg, InterestRate yield, bool includeSettlementDateFlows,
                                             Date settlementDate = null, Date npvDate = null)
        {
            if (leg.empty())
            {
                return(0.0);
            }

            if (settlementDate == null)
            {
                settlementDate = Settings.evaluationDate();
            }

            if (npvDate == null)
            {
                npvDate = settlementDate;
            }

            double npv = CashFlows.npv(leg, yield, includeSettlementDateFlows, settlementDate, npvDate);
            double modifiedDuration = CashFlows.duration(leg, yield, Duration.Type.Modified, includeSettlementDateFlows,
                                                         settlementDate, npvDate);
            double convexity = CashFlows.convexity(leg, yield, includeSettlementDateFlows, settlementDate, npvDate);
            double delta     = -modifiedDuration * npv;
            double gamma     = (convexity / 100.0) * npv;

            double shift = 0.0001;

            delta *= shift;
            gamma *= shift * shift;

            return(delta + 0.5 * gamma);
        }
Example #2
0
        public static double convexity(Bond bond, InterestRate yield, Date settlementDate = null)
        {
            if (settlementDate == null)
            {
                settlementDate = bond.settlementDate();
            }

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

            return(CashFlows.convexity(bond.cashflows(), yield, false, settlementDate));
        }
        //! Basis-point value

        /*! Obtained by setting dy = 0.0001 in the 2nd-order Taylor
         *    series expansion.
         */
        public static double basisPointValue(List <CashFlow> leg, InterestRate y, Date settlementDate)
        {
            if (leg.Count == 0)
            {
                return(0.0);
            }


            double shift            = 0.0001;
            double dirtyPrice       = CashFlows.npv(leg, y, settlementDate);
            double modifiedDuration = CashFlows.duration(leg, y, Duration.Type.Modified, settlementDate);
            double convexity        = CashFlows.convexity(leg, y, settlementDate);

            double delta = -modifiedDuration * dirtyPrice;

            double gamma = (convexity / 100.0) * dirtyPrice;

            delta *= shift;
            gamma *= shift * shift;

            return(delta + 0.5 * gamma);
        }