예제 #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_(Swaption swaption,
                                 Handle <YieldTermStructure> discountCurve,
                                 double targetValue,
                                 double?displacement = 0.0,
                                 VolatilityType type = VolatilityType.ShiftedLognormal)
        {
            discountCurve_ = discountCurve;
            targetValue_   = targetValue;
            // set an implausible value, so that calculation is forced
            // at first ImpliedVolHelper::operator()(Volatility x) call
            vol_ = new SimpleQuote(-1.0);
            Handle <Quote> h = new Handle <Quote>(vol_);

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

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

            default:
                Utils.QL_FAIL("unknown VolatilityType (" + type.ToString() + ")");
                break;
            }
            swaption.setupArguments(engine_.getArguments());
            results_ = engine_.getResults() as Instrument.Results;
        }