Пример #1
0
        public ImpliedVolHelper(CapFloor cap,
                                Handle <YieldTermStructure> discountCurve,
                                double targetValue,
                                double displacement,
                                VolatilityType type)
        {
            discountCurve_ = discountCurve;
            targetValue_   = targetValue;

            vol_ = new SimpleQuote(-1.0);
            Handle <Quote> h = new Handle <Quote>(vol_);

            switch (type)
            {
            case VolatilityType.ShiftedLognormal:
                engine_ = (IPricingEngine) new BlackCapFloorEngine(discountCurve_, h, new Actual365Fixed(), displacement);
                break;

            case VolatilityType.Normal:
                engine_ = (IPricingEngine) new BachelierCapFloorEngine(discountCurve_, h, new Actual365Fixed());
                break;

            default:
                Utils.QL_FAIL("unknown VolatilityType (" + type.ToString() + ")");
                break;
            }

            cap.setupArguments(engine_.getArguments());
            results_ = engine_.getResults() as Instrument.Results;
        }
Пример #2
0
        public ImpliedVolHelper(CapFloor cap, Handle <YieldTermStructure> discountCurve,
                                double targetValue)
        {
            discountCurve_ = discountCurve;
            targetValue_   = targetValue;

            vol_ = new SimpleQuote(-1.0);
            Handle <Quote> h = new Handle <Quote>(vol_);

            engine_ = (IPricingEngine) new BlackCapFloorEngine(discountCurve_, h);
            cap.setupArguments(engine_.getArguments());
            results_ = engine_.getResults() as Instrument.Results;
        }
Пример #3
0
            public ObjectiveFunction(OptionletStripper1 optionletStripper1, CapFloor cap, double targetValue)
            {
                cap_         = cap;
                targetValue_ = targetValue;

                OptionletVolatilityStructure adapter = new StrippedOptionletAdapter(optionletStripper1);

                // set an implausible value, so that calculation is forced
                // at first operator()(Volatility x) call
                spreadQuote_ = new SimpleQuote(-1.0);

                OptionletVolatilityStructure spreadedAdapter = new SpreadedOptionletVolatility(
                    new Handle <OptionletVolatilityStructure>(adapter), new Handle <Quote>(spreadQuote_));

                BlackCapFloorEngine engine = new BlackCapFloorEngine(optionletStripper1.iborIndex().forwardingTermStructure(),
                                                                     new Handle <OptionletVolatilityStructure>(spreadedAdapter));

                cap_.setPricingEngine(engine);
            }
Пример #4
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()));
                //strikeVector[0] = 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);
        }