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; }
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; }
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"); }
/*! 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; valuationDate_ = results.valuationDate; additionalResults_ = new Dictionary <string, object>(results.additionalResults); }