Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
0
 public PriceError(IPricingEngine engine, SimpleQuote vol, double targetValue) {
     engine_ = engine;
     vol_ = vol;
     targetValue_ = targetValue;
     
     results_ = engine_.getResults() as Instrument.Results;
     if (results_ == null)
         throw new ApplicationException("pricing engine does not supply needed results");
 }
Ejemplo n.º 4
0
        public PriceError(IPricingEngine engine, SimpleQuote vol, double targetValue)
        {
            engine_      = engine;
            vol_         = vol;
            targetValue_ = targetValue;

            results_ = engine_.getResults() as Instrument.Results;
            Utils.QL_REQUIRE(results_ != null, () => "pricing engine does not supply needed results");
        }
        public PriceError(IPricingEngine engine, SimpleQuote vol, double targetValue)
        {
            engine_      = engine;
            vol_         = vol;
            targetValue_ = targetValue;

            results_ = engine_.getResults() as Instrument.Results;
            if (results_ == null)
            {
                throw new ApplicationException("pricing engine does not supply needed results");
            }
        }
Ejemplo n.º 6
0
 /*! When a derived result structure is defined for an instrument,
  * this method should be overridden to read from it.
  * This is mandatory in case a pricing engine is used.  */
 public virtual void fetchResults(IPricingEngineResults r)
 {
     Instrument.Results results = r as Instrument.Results;
     if (results == null)
     {
         throw new ArgumentException("no results returned from pricing engine");
     }
     NPV_               = results.value;
     CASH_              = results.cash;
     errorEstimate_     = results.errorEstimate;
     additionalResults_ = results.additionalResults;
 }
Ejemplo n.º 7
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;
        }
Ejemplo n.º 8
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;
            }