예제 #1
0
            public ZSpreadFinder(Leg leg, YieldTermStructure discountCurve, double npv, DayCounter dc, Compounding comp, Frequency freq,
                                 bool includeSettlementDateFlows, Date settlementDate, Date npvDate)
            {
                leg_     = leg;
                npv_     = npv;
                zSpread_ = new SimpleQuote(0.0);
                curve_   = new ZeroSpreadedTermStructure(new Handle <YieldTermStructure>(discountCurve),
                                                         new Handle <Quote>(zSpread_), comp, freq, dc);
                includeSettlementDateFlows_ = includeSettlementDateFlows;
                settlementDate_             = settlementDate;
                npvDate_ = npvDate;

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

                if (npvDate == null)
                {
                    npvDate_ = settlementDate_;
                }

                // if the discount curve allows extrapolation, let's
                // the spreaded curve do too.
                curve_.enableExtrapolation(discountCurve.allowsExtrapolation());
            }
예제 #2
0
        // NPV of the cash flows.
        //  The NPV is the sum of the cash flows, each discounted
        //  according to the z-spreaded term structure.  The result
        //  is affected by the choice of the z-spread compounding
        //  and the relative frequency and day counter.
        public static double npv(Leg leg, YieldTermStructure discountCurve, double zSpread, DayCounter dc, Compounding comp,
                                 Frequency freq, 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;
            }

            Handle <YieldTermStructure> discountCurveHandle = new Handle <YieldTermStructure>(discountCurve);
            Handle <Quote> zSpreadQuoteHandle = new Handle <Quote>(new SimpleQuote(zSpread));

            ZeroSpreadedTermStructure spreadedCurve = new ZeroSpreadedTermStructure(discountCurveHandle, zSpreadQuoteHandle,
                                                                                    comp, freq, dc);

            spreadedCurve.enableExtrapolation(discountCurveHandle.link.allowsExtrapolation());

            return(npv(leg, spreadedCurve, includeSettlementDateFlows, settlementDate, npvDate));
        }