Created
June 1, 2018 19:19
-
-
Save yakneens/80438ac939e4977110bddc3f1573646f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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