Skip to content

Instantly share code, notes, and snippets.

@yakneens
Created June 1, 2018 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yakneens/80438ac939e4977110bddc3f1573646f to your computer and use it in GitHub Desktop.
Save yakneens/80438ac939e4977110bddc3f1573646f to your computer and use it in GitHub Desktop.
import QuantLib as ql # version 1.5
#import matplotlib.pyplot as plt
#%matplotlib inline
# option data
maturity_date = ql.Date(1, 6, 2018)
spot_price = 2720
strike_price = 2725
volatility = 0.13 # the historical vols for a year
dividend_rate = 0.0
option_type = ql.Option.Call
risk_free_rate = 0.003
day_count = ql.Actual365Fixed()
calendar = ql.UnitedStates()
calculation_date = ql.Date(1, 6, 2018)
ql.Settings.instance().evaluationDate = calculation_date
ql.Settings.instance().includeReferenceDateEvents = True
# construct the European Option
payoff = ql.PlainVanillaPayoff(option_type, strike_price)
exercise = ql.EuropeanExercise(maturity_date)
european_option = ql.VanillaOption(payoff, exercise)
spot_handle = ql.QuoteHandle(
ql.SimpleQuote(spot_price)
)
flat_ts = ql.YieldTermStructureHandle(
ql.FlatForward(calculation_date, risk_free_rate, day_count)
)
dividend_yield = ql.YieldTermStructureHandle(
ql.FlatForward(calculation_date, dividend_rate, day_count)
)
flat_vol_ts = ql.BlackVolTermStructureHandle(
ql.BlackConstantVol(calculation_date, calendar, volatility, day_count)
)
bsm_process = ql.BlackScholesMertonProcess(spot_handle,
dividend_yield,
flat_ts,
flat_vol_ts)
european_option.setPricingEngine(ql.AnalyticEuropeanEngine(bsm_process))
bs_price = european_option.NPV()
print "The theoretical price is ", bs_price
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment