public void SetUp() { _productService = new ProductDemoService(); _promotionProvider = new PromotionProvider(); _pricingEngine = new PricingEngine(_promotionProvider); _shoppingBasket = new ShoppingBasket(_pricingEngine); }
public void CreateOffers(DateTime arrival, DateTime departure, IPricingEngine pricing) { for (var date = arrival; date < departure; date = date.AddDays(1)) { MakePriceOffer(date, pricing); } }
public override double blackPrice(double sigma) { calculate(); SimpleQuote sq = new SimpleQuote(sigma); Handle <Quote> vol = new Handle <Quote>(sq); IPricingEngine engine = null; switch (volatilityType_) { case VolatilityType.ShiftedLognormal: engine = new BlackSwaptionEngine(termStructure_, vol, new Actual365Fixed(), shift_); break; case VolatilityType.Normal: engine = new BachelierSwaptionEngine(termStructure_, vol, new Actual365Fixed()); break; default: Utils.QL_FAIL("can not construct engine: " + volatilityType_); break; } swaption_.setPricingEngine(engine); double value = swaption_.NPV(); swaption_.setPricingEngine(engine_); return(value); }
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; }
// ! \warning see VanillaOption for notes on implied-volatility // calculation. // public double impliedVolatility(double targetValue, GeneralizedBlackScholesProcess process, double accuracy = 1.0e-4, int maxEvaluations = 100, double minVol = 1.0e-7, double maxVol = 4.0) { Utils.QL_REQUIRE(!isExpired(), () => "option expired"); SimpleQuote volQuote = new SimpleQuote(); GeneralizedBlackScholesProcess newProcess = ImpliedVolatilityHelper.clone(process, volQuote); // engines are built-in for the time being IPricingEngine engine = null; switch (exercise_.type()) { case Exercise.Type.European: engine = new AnalyticBarrierEngine(newProcess); break; case Exercise.Type.American: case Exercise.Type.Bermudan: Utils.QL_FAIL("Engine not available for non-European barrier option"); break; default: Utils.QL_FAIL("unknown exercise type"); break; } return(ImpliedVolatilityHelper.calculate(this, engine, volQuote, targetValue, accuracy, maxEvaluations, minVol, maxVol)); }
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 static void ClassInit(TestContext context) { _trade = new FakeTradeData(); _pricing = new FakePricingData(); _engine = new TWRPricingEngine(_pricing); _extracter = new TradeDataExtracter(_trade, _engine); }
public ObjectiveFunction(double target, SimpleQuote quote, IPricingEngine engine, CreditDefaultSwap.Results results) { target_ = target; quote_ = quote; engine_ = engine; results_ = results; }
public MakeCreditDefaultSwap withEngine(Handle <DefaultProbabilityTermStructure> probabilityTermStructure, Handle <YieldTermStructure> discountingTermStructure) { discountingTermStructure_ = discountingTermStructure; probabilityTermStructure_ = probabilityTermStructure; engine_ = new MidPointCdsEngine(probabilityTermStructure, recoveryRate_, discountingTermStructure); return(this); }
public Shop(IPricingEngine pricingEngine, IStockCheckEngine stockCheckEngine, IPaymentEngine paymentEngine) { this.pricingEngine = pricingEngine; this.stockCheckEngine = stockCheckEngine; this.paymentEngine = paymentEngine; }
//! sets the pricing engine to be used. /*! calling this method will have no effects in case the performCalculation method was overridden in a derived class. */ public void setPricingEngine(IPricingEngine e) { if (engine_ != null) engine_.unregisterWith(update); engine_ = e; if (engine_ != null) engine_.registerWith(update); update(); // trigger (lazy) recalculation and notify observers }
public CartItemServiceTest() { _productRepository = A.Fake <IProductRepository>(); _pricingEngine = new Infrastrucure.PricingEngine.PricingEngine(); _cartItemService = new CartItemService(_pricingEngine, _productRepository); A.CallTo(() => _productRepository.GetProductPriceById(A <int> ._)).Returns(10); A.CallTo(() => _productRepository.GetProductPriceByCategoryAndType(A <Category> ._, A <int> ._)).Returns(20); }
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"); }
public double Parallel_NPV(DateTime pricingDate, MarkitSurface marketData, IPricingEngine engine) { _instrument.setPricingEngine(engine); double npv = _instrument.NPV(); Console.WriteLine("NPV {0}", npv.ToString("P", System.Globalization.CultureInfo.InvariantCulture)); _NPV[pricingDate] = npv; return(npv); }
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"); } }
public void setPricingEngine(IPricingEngine engine) { if (pricingEngine != null) pricingEngine.unregisterWith(update); pricingEngine = engine; if (pricingEngine != null) pricingEngine.registerWith(update); update(); // trigger (lazy) recalculation and notify observers }
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 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; }
public double NPV(DateTime pricingDate, MarkitSurface marketData) { IPricingEngine engine = helper().Engine(pricingDate, marketData); _instrument.setPricingEngine(engine); double npv = _instrument.NPV(); Console.WriteLine(" >> NPV : {0}", npv); //Console.WriteLine(" >> NPV : {0}", npv.ToString("P", System.Globalization.CultureInfo.InvariantCulture)); _NPV[pricingDate] = npv; return(npv); }
// Methods public double NPV(DateTime pricingDate, IPricingEngine engine) { // Set the pricing date _pricingDate = pricingDate; Settings.setEvaluationDate(pricingDate); // Set the pricing engine _option.setPricingEngine(engine); _price_points = _option.NPV(); _price_relative = _price_points / _spotAtStrike; return(_price_relative); }
public decimal GetTotalPrice(IPricingEngine pe) { decimal totalPrice = 0; foreach (var item in this.itemsDict) { string sku = item.Key; int totalQuantity = item.Value; totalPrice += pe.GetItemTotalPrice(sku, totalQuantity); } return(totalPrice); }
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); }
// ************************************************************ // ****** METHODS -- OVERRIDDEN METHODS // ************************************************************ #region QLNet methods /// <summary> /// Attaches the Monte Carlo pricing engine to the autocall instrument. /// </summary> new public void setPricingEngine(IPricingEngine e) { if (engine_ != null) { engine_.unregisterWith(update); } engine_ = e; if (engine_ != null) { engine_.registerWith(update); } update(); }
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; }
public decimal GetTotalPrice(IPricingEngine pe) { decimal totalPrice = 0; foreach (var item in this.itemsDict) { string sku = item.Key; int totalQuantity = item.Value; totalPrice += pe.GetItemTotalPrice(sku, totalQuantity); } return totalPrice; }
//! sets the pricing engine to be used. /*! calling this method will have no effects in case the performCalculation method * was overridden in a derived class. */ public void setPricingEngine(IPricingEngine e) { if (engine_ != null) { engine_.unregisterWith(update); } engine_ = e; if (engine_ != null) { engine_.registerWith(update); } update(); // trigger (lazy) recalculation and notify observers }
private void MakePriceOffer(DateTime date, IPricingEngine pricing) { if (HasValidPriceOffer(date)) { return; } pricing .GetAccommodationPrice(date) .IfSome(price => { var expires = DateTime.UtcNow + PriceValidityDuration; Emit(new PriceOffered(date, price, expires)); }); }
private void testFdDegenerate <Engine>(Date today, Exercise exercise) where Engine : IFDEngine, new () { DayCounter dc = new Actual360(); SimpleQuote spot = new SimpleQuote(54.625); Handle <YieldTermStructure> rTS = new Handle <YieldTermStructure>(Utilities.flatRate(0.052706, dc)); Handle <YieldTermStructure> qTS = new Handle <YieldTermStructure>(Utilities.flatRate(0.0, dc)); Handle <BlackVolTermStructure> volTS = new Handle <BlackVolTermStructure>(Utilities.flatVol(0.282922, dc)); BlackScholesMertonProcess process = new BlackScholesMertonProcess(new Handle <Quote>(spot), qTS, rTS, volTS); int timeSteps = 300; int gridPoints = 300; IPricingEngine engine = FastActivator <Engine> .Create().factory(process, timeSteps, gridPoints); StrikedTypePayoff payoff = new PlainVanillaPayoff(Option.Type.Call, 55.0); double tolerance = 3.0e-3; List <double> dividends = new List <double>(); List <Date> dividendDates = new List <Date>(); DividendVanillaOption option1 = new DividendVanillaOption(payoff, exercise, dividendDates, dividends); option1.setPricingEngine(engine); // FLOATING_POINT_EXCEPTION double refValue = option1.NPV(); for (int i = 0; i <= 6; i++) { dividends.Add(0.0); dividendDates.Add(today + i); DividendVanillaOption option = new DividendVanillaOption(payoff, exercise, dividendDates, dividends); option.setPricingEngine(engine); double value = option.NPV(); if (Math.Abs(refValue - value) > tolerance) { QAssert.Fail("NPV changed by null dividend :\n" + " previous value: " + value + "\n" + " current value: " + refValue + "\n" + " change: " + (value - refValue)); } } }
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); }
public void TestSetup() { myPricingSource1.SetupGet(m => m.SupportedInstruments).Returns(new List <string>() { "a", "b", "c", "d" }); myPricingSource1.Setup(m => m.GetPrice("a")).Returns(10.25); myPricingSource1.Setup(m => m.GetPrice("b")).Returns(15.25); myPricingSource1.Setup(m => m.GetPrice("c")).Returns(80.25); myPricingSource1.Setup(m => m.GetPrice("d")).Returns(45.25); myReceivedInstrumentPrices = null; myUpdateInterval = 10; //Updates every 10ms myTestee = new PricingEngine(myPricingSource1.Object, myUpdateInterval); myTestee.InstrumentPricesChanged += OnInstrumentPricesChanged; }
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); }
public MakeOIS(Period swapTenor, OvernightIndex overnightIndex, double?fixedRate, Period fwdStart) { swapTenor_ = swapTenor; overnightIndex_ = overnightIndex; fixedRate_ = fixedRate; forwardStart_ = fwdStart; fixingDays_ = 2; paymentFrequency_ = Frequency.Annual; rule_ = DateGeneration.Rule.Backward; endOfMonth_ = (new Period(1, TimeUnit.Months) <= swapTenor && swapTenor <= new Period(2, TimeUnit.Years) ? true : false); type_ = OvernightIndexedSwap.Type.Payer; nominal_ = 1.0; overnightSpread_ = 0.0; fixedDayCount_ = overnightIndex.dayCounter(); engine_ = new DiscountingSwapEngine(overnightIndex_.forwardingTermStructure()); }
public MakeOIS(Period swapTenor, OvernightIndex overnightIndex, double? fixedRate, Period fwdStart) { swapTenor_=swapTenor; overnightIndex_ = overnightIndex; fixedRate_= fixedRate; forwardStart_= fwdStart; fixingDays_ = 2; paymentFrequency_ = Frequency.Annual; rule_ = DateGeneration.Rule.Backward; endOfMonth_ = (new Period(1,TimeUnit.Months)<=swapTenor && swapTenor<=new Period(2,TimeUnit.Years) ? true : false); type_ = OvernightIndexedSwap.Type.Payer; nominal_ = 1.0; overnightSpread_ = 0.0; fixedDayCount_ = overnightIndex.dayCounter(); engine_ = new DiscountingSwapEngine(overnightIndex_.forwardingTermStructure()); }
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()); }
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()); }
public MakeVanillaSwap(Period swapTenor, IborIndex index, double? fixedRate, Period forwardStart) { swapTenor_ = swapTenor; iborIndex_ = index; fixedRate_ = fixedRate; forwardStart_ = forwardStart; effectiveDate_ = null; fixedCalendar_ = floatCalendar_ = index.fixingCalendar(); type_ = VanillaSwap.Type.Payer; nominal_ = 1.0; fixedTenor_ = new Period(1, TimeUnit.Years); floatTenor_ = index.tenor(); fixedConvention_ = fixedTerminationDateConvention_ = BusinessDayConvention.ModifiedFollowing; floatConvention_ = floatTerminationDateConvention_ = index.businessDayConvention(); fixedRule_ = floatRule_ = DateGeneration.Rule.Backward; fixedEndOfMonth_ = floatEndOfMonth_ = false; fixedFirstDate_ = fixedNextToLastDate_ = floatFirstDate_ = floatNextToLastDate_ = null; floatSpread_ = 0.0; fixedDayCount_ = new Thirty360(Thirty360.Thirty360Convention.BondBasis); floatDayCount_ = index.dayCounter(); engine_ = new DiscountingSwapEngine(index.forwardingTermStructure()); }
public MakeBasisSwap(Period swapTenor, IborIndex index1, IborIndex index2, Period forwardStart) { swapTenor_ = swapTenor; iborIndex1_ = index1; iborIndex2_ = index2; forwardStart_ = forwardStart; effectiveDate_ = null; float1Calendar_ = float2Calendar_ = index1.fixingCalendar(); type_ = BasisSwap.Type.Payer; nominal_ = 1.0; float1Tenor_ = index1.tenor(); float2Tenor_ = index2.tenor(); float1Convention_ = float1TerminationDateConvention_ = index1.businessDayConvention(); float2Convention_ = float2TerminationDateConvention_ = index2.businessDayConvention(); float1Rule_ = float2Rule_ = DateGeneration.Rule.Backward; float1EndOfMonth_ = float2EndOfMonth_ = false; float1FirstDate_ = float1NextToLastDate_ = float2FirstDate_ = float2NextToLastDate_ = null; float1Spread_ = float2Spread_ = 0.0; float1DayCount_ = index1.dayCounter(); float2DayCount_ = index2.dayCounter(); engine_ = new DiscountingBasisSwapEngine(index1.forwardingTermStructure(), index2.forwardingTermStructure()); }
public MakeVanillaSwap withDiscountingTermStructure(Handle<YieldTermStructure> discountingTermStructure) { engine_ = new DiscountingSwapEngine(discountingTermStructure); return this; }
public Checkout(IPricingEngine pricingEngine) { basket = new Basket(); this.pricingEngine = pricingEngine; }
public MakeOIS withDiscountingTermStructure(Handle<YieldTermStructure> discountingTermStructure) { engine_ = (IPricingEngine) new DiscountingSwapEngine(discountingTermStructure); return this; }
public MakeSwaption withPricingEngine(IPricingEngine engine) { engine_ = engine; return this; }
public void setPricingEngine(IPricingEngine engine) { engine_ = engine; }
public MakeBasisSwap withDiscountingTermStructure(Handle<YieldTermStructure> discountingTermStructure1, Handle<YieldTermStructure> discountingTermStructure2) { engine_ = new DiscountingBasisSwapEngine(discountingTermStructure1, discountingTermStructure2); return this; }