Pricing Commodity Options with Python

  1. Import the required libraries:
import QuantLib as ql
import math
interest_rate = 0.005
calc_date = ql.Date(23,10,2021)
DCC = ql.ActualActual()
Compounded = ql.Compounded
continuous = ql.Continuous
T = 1.
strike = 50
spot = 48
volatility = 0.45
option_type = ql.Option.Call
yield_curve = ql.FlatForward(calc_date,interest_rate,DCC,Compounded,continuous)
df = yield_curve.discount(T)
opt_payoff = ql.PlainVanillaPayoff(option_type, strike)
std = volatility*math.sqrt(T)
black = ql.BlackCalculator(opt_payoff, spot, std, df)
print("Option Price", black.value())
print("Delta", black.delta(spot))
print("Gamma", black.gamma(spot))
print("Theta", black.theta(spot, T))
print("Vega", black.vega(T))
print("Rho", black.rho(T))

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store