Exemple #1
0
        public static double calculate(Instrument instrument, IPricingEngine engine, SimpleQuote volQuote, double targetValue, double accuracy, int maxEvaluations, double minVol, double maxVol)
        {
            instrument.setupArguments(engine.getArguments());
            engine.getArguments().validate();

            PriceError f = new PriceError(engine, volQuote, targetValue);
            Brent solver = new Brent();
            solver.setMaxEvaluations(maxEvaluations);
            double guess = (minVol + maxVol) / 2.0;
            double result = solver.solve(f, accuracy, guess, minVol, maxVol);
            return result;
        }
        public static double calculate(Instrument instrument, IPricingEngine engine, SimpleQuote volQuote, double targetValue, double accuracy, int maxEvaluations, double minVol, double maxVol)
        {
            instrument.setupArguments(engine.getArguments());
            engine.getArguments().validate();

            PriceError f      = new PriceError(engine, volQuote, targetValue);
            Brent      solver = new Brent();

            solver.setMaxEvaluations(maxEvaluations);
            double guess  = (minVol + maxVol) / 2.0;
            double result = solver.solve(f, accuracy, guess, minVol, maxVol);

            return(result);
        }
Exemple #3
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;
        }
Exemple #4
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;
        }
Exemple #5
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;
        }
Exemple #6
0
            public SwaptionImpliedVolatilityHelper(Swaption swaption, Handle <YieldTermStructure> discountCurve, double targetValue)
            {
                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_);

                engine_ = new BlackSwaptionEngine(discountCurve_, h);
                swaption.setupArguments(engine_.getArguments());
                results_ = engine_.getResults() as Results;
            }
Exemple #7
0
        protected override double?controlVariateValue()
        {
            IPricingEngine controlPE = this.controlPricingEngine();

            Utils.QL_REQUIRE(controlPE != null, () => "engine does not provide control variation pricing engine");

            DiscreteAveragingAsianOption.Arguments controlArguments =
                (DiscreteAveragingAsianOption.Arguments)controlPE.getArguments();
            controlArguments = arguments_;
            controlPE.calculate();

            DiscreteAveragingAsianOption.Results controlResults =
                (DiscreteAveragingAsianOption.Results)(controlPE.getResults());

            return(controlResults.value);
        }
        protected override double?controlVariateValue()
        {
            IPricingEngine controlPE = controlPricingEngine();

            Utils.QL_REQUIRE(controlPE != null, () => "engine does not provide control variation pricing engine");

            VanillaOption.Arguments controlArguments = controlPE.getArguments() as VanillaOption.Arguments;
            controlArguments          = arguments_;
            controlArguments.exercise = new EuropeanExercise(arguments_.exercise.lastDate());

            controlPE.calculate();

            VanillaOption.Results controlResults = controlPE.getResults() as VanillaOption.Results;

            return(controlResults.value);
        }
Exemple #9
0
        protected override double controlVariateValue()
        {
            IPricingEngine controlPE = controlPricingEngine();

            if (controlPE == null)
            {
                throw new Exception("engine does not provide control variation pricing engine");
            }

            VanillaOption.Arguments controlArguments = controlPE.getArguments() as VanillaOption.Arguments;
            controlArguments          = arguments_;
            controlArguments.exercise = new EuropeanExercise(arguments_.exercise.lastDate());

            controlPE.calculate();

            VanillaOption.Results controlResults = controlPE.getResults() as VanillaOption.Results;

            return(controlResults.value.GetValueOrDefault());
        }
Exemple #10
0
        protected override double controlVariateValue()
        {
            IPricingEngine controlPE = this.controlPricingEngine();

            if (controlPE == null)
            {
                throw new ApplicationException("engine does not provide " +
                                               "control variation pricing engine");
            }

            DiscreteAveragingAsianOption.Arguments controlArguments =
                (DiscreteAveragingAsianOption.Arguments)controlPE.getArguments();
            controlArguments = arguments_;
            controlPE.calculate();

            DiscreteAveragingAsianOption.Results controlResults =
                (DiscreteAveragingAsianOption.Results)(controlPE.getResults());

            return(controlResults.value.GetValueOrDefault());
        }