Exemple #1
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 = bps = 0.0;
            if (leg.empty())
            {
                bps = 0.0;
                return;
            }

            for (int i = 0; i < leg.Count; ++i)
            {
                CashFlow cf = leg[i];
                if (!cf.hasOccurred(settlementDate, includeSettlementDateFlows) &&
                    !cf.tradingExCoupon(settlementDate))
                {
                    Coupon cp = leg[i] as Coupon;
                    double df = discountCurve.discount(cf.date());
                    npv += cf.amount() * df;
                    if (cp != null)
                    {
                        bps += cp.nominal() * cp.accrualPeriod() * df;
                    }
                }
            }
            double d = discountCurve.discount(npvDate);

            npv /= d;
            bps  = Const.BASIS_POINT * bps / d;
        }
Exemple #2
0
        //! NPV of the cash flows. The NPV is the sum of the cash flows, each discounted according to the given term structure.
        public static double npv(Leg leg, YieldTermStructure discountCurve, bool includeSettlementDateFlows,
                                 Date settlementDate = null, Date npvDate = null)
        {
            if (leg.empty())
            {
                return(0.0);
            }

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

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

            double totalNPV = 0.0;

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

            return(totalNPV / discountCurve.discount(npvDate));
        }
Exemple #3
0
        //! NPV of a single cash flows
        public static double npv(CashFlow cashflow, YieldTermStructure discountCurve,
                                 Date settlementDate = null, Date npvDate = null, int exDividendDays = 0)
        {
            double NPV = 0.0;

            if (cashflow == null)
            {
                return(0.0);
            }

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

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

            if (!cashflow.hasOccurred(settlementDate + exDividendDays))
            {
                NPV = cashflow.amount() * discountCurve.discount(cashflow.date());
            }


            return(NPV / discountCurve.discount(npvDate));
        }
Exemple #4
0
            public void visit(Coupon c)
            {
                double bps = c.nominal() *
                             c.accrualPeriod() *
                             discountCurve_.discount(c.date());

                bps_ += bps;
            }
        public LongstaffSchwartzPathPricer(TimeGrid times, IEarlyExercisePathPricer <PathType, double> pathPricer,
                                           YieldTermStructure termStructure)
        {
            calibrationPhase_ = true;
            pathPricer_       = pathPricer;
            coeff_            = new InitializedList <Vector>(times.size() - 1);
            dF_ = new InitializedList <double>(times.size() - 1);
            v_  = pathPricer_.basisSystem();

            for (int i = 0; i < times.size() - 1; ++i)
            {
                dF_[i] = termStructure.discount(times[i + 1])
                         / termStructure.discount(times[i]);
            }
        }
Exemple #6
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.Instance.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);
        }
Exemple #7
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.Instance.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));
        }
 //////////////////////////////////////////////////////////////////////////////////////
 // methods
 public double price(YieldTermStructure yts)
 {
     return(amount() * yts.discount(date()));
 }