// Basis-point sensitivity of the cash flows.
        // The result is the change in NPV due to a uniform 1-basis-point change in the rate paid by the cash flows. The change for each coupon is discounted according to the given term structure.
        public static double bps(List <CashFlow> cashflows, YieldTermStructure discountCurve,
                                 Date settlementDate = null, Date npvDate = null, int exDividendDays = 0)
        {
            if (cashflows.Count == 0)
            {
                return(0.0);
            }

            if (settlementDate == null)
            {
                settlementDate = discountCurve.referenceDate();
            }

            BPSCalculator calc = new BPSCalculator(discountCurve, npvDate);

            for (int i = 0; i < cashflows.Count; i++)
            {
                if (!cashflows[i].hasOccurred(settlementDate + exDividendDays))
                {
                    cashflows[i].accept(calc);
                }
            }

            return(basisPoint_ * calc.result());
        }
Ejemplo n.º 2
0
        // Basis-point sensitivity of the cash flows.
        // The result is the change in NPV due to a uniform 1-basis-point change in the rate paid by the cash flows. The change for each coupon is discounted according to the given term structure.
        public static double bps(Leg leg, YieldTermStructure discountCurve, 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;
            }

            BPSCalculator calc = new BPSCalculator(discountCurve);

            for (int i = 0; i < leg.Count; ++i)
            {
                if (!leg[i].hasOccurred(settlementDate, includeSettlementDateFlows) &&
                    !leg[i].tradingExCoupon(settlementDate))
                {
                    leg[i].accept(calc);
                }
            }
            return(Const.BASIS_POINT * calc.bps() / discountCurve.discount(npvDate));
        }
Ejemplo n.º 3
0
        // At-the-money rate of the cash flows.
        // The result is the fixed rate for which a fixed rate cash flow  vector, equivalent to the input vector, has the required NPV according to the given term structure. If the required NPV is
        //  not given, the input cash flow vector's NPV is used instead.
        public static double atmRate(Leg leg, YieldTermStructure discountCurve, bool includeSettlementDateFlows,
                                     Date settlementDate = null, Date npvDate = null, double?targetNpv = null)
        {
            if (settlementDate == null)
            {
                settlementDate = Settings.evaluationDate();
            }

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

            double        npv  = 0.0;
            BPSCalculator calc = new BPSCalculator(discountCurve);

            for (int i = 0; i < leg.Count; ++i)
            {
                CashFlow cf = leg[i];
                if (!cf.hasOccurred(settlementDate, includeSettlementDateFlows) &&
                    !cf.tradingExCoupon(settlementDate))
                {
                    npv += cf.amount() * discountCurve.discount(cf.date());
                    cf.accept(calc);
                }
            }

            if (targetNpv == null)
            {
                targetNpv = npv - calc.nonSensNPV();
            }
            else
            {
                targetNpv *= discountCurve.discount(npvDate);
                targetNpv -= calc.nonSensNPV();
            }

            if (targetNpv.IsEqual(0.0))
            {
                return(0.0);
            }

            double bps = calc.bps();

            Utils.QL_REQUIRE(bps.IsNotEqual(0.0), () => "null bps: impossible atm rate");

            return(targetNpv.Value / bps);
        }
Ejemplo n.º 4
0
      // At-the-money rate of the cash flows.
      // The result is the fixed rate for which a fixed rate cash flow  vector, equivalent to the input vector, has the required NPV according to the given term structure. If the required NPV is
      //  not given, the input cash flow vector's NPV is used instead.
      public static double atmRate(Leg leg,YieldTermStructure discountCurve, bool includeSettlementDateFlows,
                                   Date settlementDate = null, Date npvDate = null,double? targetNpv = null) 
      {

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

         if (npvDate == null)
            npvDate = settlementDate;

         double npv = 0.0;
         BPSCalculator calc = new BPSCalculator(discountCurve);
         for (int i=0; i<leg.Count; ++i) 
         {
            CashFlow cf = leg[i];
				if (!cf.hasOccurred(settlementDate, includeSettlementDateFlows) &&
					 !cf.tradingExCoupon(settlementDate)) 
            {
               npv += cf.amount() * discountCurve.discount(cf.date());
               cf.accept(calc);
            }
         }

         if (targetNpv==null)
            targetNpv = npv - calc.nonSensNPV();
         else 
         {
            targetNpv *= discountCurve.discount(npvDate);
            targetNpv -= calc.nonSensNPV();
         }

         if (targetNpv==0.0)
            return 0.0;

         double bps = calc.bps();
         Utils.QL_REQUIRE( bps != 0.0, () => "null bps: impossible atm rate" );

         return targetNpv.Value/bps;
    }
Ejemplo n.º 5
0
      //! NPV and BPS of the cash flows.
      // The NPV and BPS of the cash flows calculated together for performance reason
      public static void npvbps(Leg leg,YieldTermStructure discountCurve, bool includeSettlementDateFlows,
                                Date settlementDate, Date npvDate, out double npv,out double bps) 
      {
         npv = 0.0;
         if (leg.empty())
         {
            bps = 0.0;
            return;
         }

         BPSCalculator calc = new BPSCalculator(discountCurve);
         for (int i=0; i<leg.Count; ++i) 
         {
            CashFlow cf = leg[i];
				if (!cf.hasOccurred(settlementDate, includeSettlementDateFlows) &&
					 !cf.tradingExCoupon(settlementDate)) 
            {
               npv += cf.amount() * discountCurve.discount(cf.date());
               cf.accept(calc);
            }
         }
         double d = discountCurve.discount(npvDate);
         npv /= d;
         bps = basisPoint_ * calc.bps() / d;
      }
Ejemplo n.º 6
0
      // Basis-point sensitivity of the cash flows.
      // The result is the change in NPV due to a uniform 1-basis-point change in the rate paid by the cash flows. The change for each coupon is discounted according to the given term structure.
      public static double bps(Leg leg, YieldTermStructure discountCurve, 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;

         BPSCalculator calc = new BPSCalculator(discountCurve);
         for (int i = 0; i < leg.Count; ++i)
         {
				if (!leg[i].hasOccurred(settlementDate, includeSettlementDateFlows) &&
					 !leg[i].tradingExCoupon(settlementDate))
               leg[i].accept(calc);
         }
         return basisPoint_ * calc.bps() / discountCurve.discount(npvDate);
      }
      // Basis-point sensitivity of the cash flows.
      // The result is the change in NPV due to a uniform 1-basis-point change in the rate paid by the cash flows. The change for each coupon is discounted according to the given term structure.
      public static double bps(List<CashFlow> cashflows, YieldTermStructure discountCurve,
                               Date settlementDate = null, Date npvDate = null, int exDividendDays = 0 ) 
      {
         if (cashflows.Count == 0)
            return 0.0;

         if (settlementDate == null)
            settlementDate = discountCurve.referenceDate();

         BPSCalculator calc = new BPSCalculator(discountCurve, npvDate);
         for (int i = 0; i < cashflows.Count; i++)
            if (!cashflows[i].hasOccurred(settlementDate + exDividendDays))
               cashflows[i].accept(calc);

         return basisPoint_ * calc.result();
      }