Ejemplo n.º 1
0
        public static double atmRate(Bond bond, YieldTermStructure discountCurve, Date settlementDate = null, double?cleanPrice = null)
        {
            if (settlementDate == null)
            {
                settlementDate = bond.settlementDate();
            }

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

            double?dirtyPrice      = cleanPrice == null ? null : cleanPrice + bond.accruedAmount(settlementDate);
            double currentNotional = bond.notional(settlementDate);
            double?npv             = dirtyPrice / 100.0 * currentNotional;

            return(CashFlows.atmRate(bond.cashflows(), discountCurve, false, settlementDate, settlementDate, npv));
        }
Ejemplo n.º 2
0
        public CapFloor value()
        {
            VanillaSwap swap = makeVanillaSwap_;

            List <CashFlow> leg = swap.floatingLeg();

            if (firstCapletExcluded_)
            {
                leg.RemoveAt(0);
            }

            // only leaves the last coupon
            if (asOptionlet_ && leg.Count > 1)
            {
                leg.RemoveRange(0, leg.Count - 2); // Sun Studio needs an lvalue
            }

            List <double> strikeVector;

            if (strike_ == null)
            {
                // temporary patch...
                // should be fixed for every CapFloor::Engine
                BlackCapFloorEngine temp = engine_ as BlackCapFloorEngine;
                Utils.QL_REQUIRE(temp != null, () => "cannot calculate ATM without a BlackCapFloorEngine");
                Handle <YieldTermStructure> discountCurve = temp.termStructure();
                strikeVector = new InitializedList <double>(1, CashFlows.atmRate(leg, discountCurve, false, discountCurve.link.referenceDate()));
            }
            else
            {
                strikeVector = new InitializedList <double>(1, strike_.Value);
            }

            CapFloor capFloor = new CapFloor(capFloorType_, leg, strikeVector);

            capFloor.setPricingEngine(engine_);
            return(capFloor);
        }
Ejemplo n.º 3
0
 public virtual double atmRate(YieldTermStructure discountCurve)
 {
     return(CashFlows.atmRate(yoyLeg_, discountCurve,
                              false, discountCurve.referenceDate()));
 }