public void testGreeksInitialization() { // Testing forward option greeks initialization DayCounter dc = new Actual360(); SavedSettings backup = new SavedSettings(); Date today = Date.Today; Settings.setEvaluationDate(today); SimpleQuote spot = new SimpleQuote(100.0); SimpleQuote qRate = new SimpleQuote(0.04); Handle <YieldTermStructure> qTS = new Handle <YieldTermStructure>(Utilities.flatRate(qRate, dc)); SimpleQuote rRate = new SimpleQuote(0.01); Handle <YieldTermStructure> rTS = new Handle <YieldTermStructure>(Utilities.flatRate(rRate, dc)); SimpleQuote vol = new SimpleQuote(0.11); Handle <BlackVolTermStructure> volTS = new Handle <BlackVolTermStructure>(Utilities.flatVol(vol, dc)); BlackScholesMertonProcess stochProcess = new BlackScholesMertonProcess(new Handle <Quote>(spot), qTS, rTS, volTS); IPricingEngine engine = new ForwardVanillaEngine(stochProcess, process => new TestBinomialEngine(process)); Date exDate = today + new Period(1, TimeUnit.Years); Exercise exercise = new EuropeanExercise(exDate); Date reset = today + new Period(6, TimeUnit.Months); StrikedTypePayoff payoff = new PlainVanillaPayoff(Option.Type.Call, 0.0); ForwardVanillaOption option = new ForwardVanillaOption(0.9, reset, payoff, exercise); option.setPricingEngine(engine); IPricingEngine ctrlengine = new TestBinomialEngine(stochProcess); VanillaOption ctrloption = new VanillaOption(payoff, exercise); ctrloption.setPricingEngine(ctrlengine); double?delta = 0; try { delta = ctrloption.delta(); } catch (Exception) { // if normal option can't calculate delta, // nor should forward try { delta = option.delta(); } catch (Exception) { delta = null; } Utils.QL_REQUIRE(delta == null, () => "Forward delta invalid"); } double?rho = 0; try { rho = ctrloption.rho(); } catch (Exception) { // if normal option can't calculate rho, // nor should forward try { rho = option.rho(); } catch (Exception) { rho = null; } Utils.QL_REQUIRE(rho == null, () => "Forward rho invalid"); } double?divRho = 0; try { divRho = ctrloption.dividendRho(); } catch (Exception) { // if normal option can't calculate divRho, // nor should forward try { divRho = option.dividendRho(); } catch (Exception) { divRho = null; } Utils.QL_REQUIRE(divRho == null, () => "Forward dividendRho invalid"); } double?vega = 0; try { vega = ctrloption.vega(); } catch (Exception) { // if normal option can't calculate vega, // nor should forward try { vega = option.vega(); } catch (Exception) { vega = null; } Utils.QL_REQUIRE(vega == null, () => "Forward vega invalid"); } }