-- Mostly ripped from Python European Example

-- makes life a little simpler

QL=QuantLib

Date=QL.Date

tD=Date(15,QuantLib.May,1998)

sD=Date(17,QuantLib.May,1998)

QL.Settings_instance():setEvaluationDate(tD)

print(QL.Settings_instance():getEvaluationDate())

riskFreeRate = QL.FlatForward(sD, 0.05, QL.Actual365Fixed())

exercise = QL.EuropeanExercise(Date(17,5,1999))

payoff = QL.PlainVanillaPayoff(QL.Option_Call, 8.0)

underlying = QL.SimpleQuote(7.0)

volatility = QL.BlackConstantVol(tD, QL.TARGET(), 0.10, QL.Actual365Fixed())

dividendYield = QL.FlatForward(sD, 0.05, QL.Actual365Fixed())

process = QL.BlackScholesMertonProcess(QL.QuoteHandle(underlying),QL.YieldTermStructureHandle(dividendYield),QL.YieldTermStructureHandle(riskFreeRate),QL.BlackVolTermStructureHandle(volatility))

option = QL.VanillaOption(payoff, exercise)

option:setPricingEngine(QL.AnalyticEuropeanEngine(process))

-- Analytic

print ("Analytic Price",option:NPV())

-- Finite Difference

-- method: finite differences

timeSteps = 801

gridPoints = 800

option:setPricingEngine(QL.FDEuropeanEngine(process,timeSteps,gridPoints))

print("finite diff.",option:NPV())