I am right now working throught the "cookbook" of Goutham Balaraman & Luigi Ballabio. By the way a very nice introduction into QuantLib-Python and a good starting point :-)
In section four there is the following example that prices a simple option with Black&Scholes:
from QuantLib import * today = Date(7, March, 2014) Settings.instance().evaluationDate = today # The Instrument option = EuropeanOption( PlainVanillaPayoff(Option.Call, 100.0), EuropeanExercise(Date(7, June, 2014))) # The Market u = SimpleQuote(100.0) # set todays value of the underlying r = SimpleQuote(0.01) # set risk-free rate sigma = SimpleQuote(0.20) # set volatility riskFreeCurve = FlatForward(0, TARGET(), QuoteHandle(r), Actual360()) volatility = BlackConstantVol(0, TARGET(), QuoteHandle(sigma), Actual360()) # The Model process = BlackScholesProcess( QuoteHandle(u), YieldTermStructureHandle(riskFreeCurve), BlackVolTermStructureHandle(volatility)) # The Pricing Engine engine = AnalyticEuropeanEngine(process) # The Result option.setPricingEngine(engine) print( "NPV: ", option.NPV() )
The code spits out the NPV of the option.
In university I once learned that the value of an option could be split up into an 'intrinsic' and 'time' part. Is it possible to achive this with QouantLib-Python?
NPV_intrinsic = max([ 0 , u.value() - option.getStrike() ])
The above does not work because 'option.getStrike()' doesn't exist :-(
Thank you very much!