1
$\begingroup$

I am trying to write a Python function that performs some calculations using a list of Quantlib options, and I would like to pass only that list without other information. In particular, the strike of each option is embedded there somewhere, but I am finding it hard to extract. Here is a toy example of an instance (extracted from one of Luigi Ballabio's excellent tutorial notebooks):

from QuantLib import *
maturity_date = Date(15, 1, 2016)
spot_price = 127.62
strike_price = 130
volatility = 0.20 # the historical vols for a year
dividend_rate =  0.0163
option_type = Option.Call

risk_free_rate = 0.001
day_count = Actual365Fixed()
calendar = UnitedStates()

calculation_date = Date(8, 5, 2015)
Settings.instance().evaluationDate = calculation_date

payoff = PlainVanillaPayoff(option_type, strike_price)
exercise = EuropeanExercise(maturity_date)
european_option = VanillaOption(payoff, exercise)

Now I would like to use something like european_option.strike. That doesn't work, of course. Can someone offer a simple solution? (TIA.)

$\endgroup$
3
$\begingroup$

You can retrieve the strike from the PlainVanillaPayoff object which is payoff in your example.

payoff.strike() returns 130.0 for me.

$\endgroup$
3
  • $\begingroup$ Thanks, but option.payoff.strike() does not work. I want to submit option as an argument to a function, and extract the strike from option inside the function. I do not want to submit additional arguments (like payoff). $\endgroup$ – Drew May 16 '20 at 23:55
  • $\begingroup$ There is no option.payoff.strike(). Your variable is named payoff. You named it as such. You could rename it to option and then option.strike() would work. Sorry if I am misunderstanding your problem. Good luck. $\endgroup$ – amdopt May 17 '20 at 0:37
  • $\begingroup$ Sorry: I should have said european_option.payoff.strike() does not work. I would like my function to derive the strike from european_option. $\endgroup$ – Drew May 17 '20 at 0:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.