Question

In: Computer Science

Create a python application that prices both American and European Options using a CRR binomial tree

Create a python application that prices both American and European Options using a CRR binomial tree

Solutions

Expert Solution

I am kindly requesting you to this code should not be compiled in online compilers please download and use python compiler or use anaconda platform to compile . And also download some libraries to compile this , because it will not work if they are not downloaded.

Python Code or Python Application that prices both American and European Options using a CRR binomial tree

import QuantLib as ql

import matplotlib.pyplot as plt

%matplotlib inline

ql.__version__

'1.9.2'

  • Let us consider a European and an American call option for AAPL with a strike price of $130 maturing on 15th Jan, 2020. Let the spot price be $127.62. The volatility of the underlying stock is known to be 20%, and has a dividend yield of 1.63%. Lets value these options as of 7th oct, 2019.

# option data

maturity_date = ql.Date(15, 1, 2020)

spot_price = 127.62

strike_price = 130

volatility = 0.20 # the historical vols or implied vols

dividend_rate = 0.0163

option_type = ql.Option.Call

risk_free_rate = 0.001

day_count = ql.Actual365Fixed()

calendar = ql.UnitedStates()

calculation_date = ql.Date(7, 10, 2019)

ql.Settings.instance().evaluationDate = calculation_date

  • We construct the European and American options here. The main difference here is in the Exercise type. One has to use AmericanExercise instead of EuropeanExercise to pass into the VanillaOption to construct an American option.

payoff = ql.PlainVanillaPayoff(option_type, strike_price)

settlement = calculation_date

am_exercise = ql.AmericanExercise(settlement, maturity_date)

american_option = ql.VanillaOption(payoff, am_exercise)

eu_exercise = ql.EuropeanExercise(maturity_date)

european_option = ql.VanillaOption(payoff, eu_exercise)

#The Black-Scholes-Merton process is constructed here.

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)

  • The value of the American option can be computed using a Binomial Engine using the CRR approach.

steps = 200

binomial_engine = ql.BinomialVanillaEngine(bsm_process, "crr", steps)

american_option.setPricingEngine(binomial_engine)

print (american_option.NPV())

#6.84210328728556

  • For illustration purpose, lets compare the European and American option prices using the binomial tree approach.

def binomial_price(option, bsm_process, steps):

    binomial_engine = ql.BinomialVanillaEngine(bsm_process, "crr", steps)

    option.setPricingEngine(binomial_engine)

    return option.NPV()

steps = range(5, 200, 1)

eu_prices = [binomial_price(european_option, bsm_process, step) for step in steps]

am_prices = [binomial_price(american_option, bsm_process, step) for step in steps]

# theoretican European option price

european_option.setPricingEngine(ql.AnalyticEuropeanEngine(bsm_process))

bs_price = european_option.NPV()

  • In the plot below, the binomial-tree approach is used to value American option for different number of steps. You can see the prices converging with increase in number of steps. The European option price is plotted along with BSM theoretical price for comparison purposes.

plt.plot(steps, eu_prices, label="European Option", lw=2, alpha=0.6)

plt.plot(steps, am_prices, label="American Option", lw=2, alpha=0.6)

plt.plot([5,200],[bs_price, bs_price], "r--", label="BSM Price", lw=2, alpha=0.6)

plt.xlabel("Steps")

plt.ylabel("Price")

plt.ylim(6.7,7)

plt.title("Binomial Tree Price For Varying Steps")

plt.legend()


Related Solutions

American options can be valued using a binomial tree by? Checking whether early exercise is optimal...
American options can be valued using a binomial tree by? Checking whether early exercise is optimal at the final nodes. Increasing the number of time steps on the tree Checking whether early exercise is optimal at the penultimate nodes a the final nodes. Checking whether early exercise is optimal at all nodes where the option is in the money.    The Black-Scholes-Merton model assumes The return from the stock in a short period of time is lognormal The stock price...
American Options Models discuss and compare binomial tree, Trinomial Tree method and least squares simulation method...
American Options Models discuss and compare binomial tree, Trinomial Tree method and least squares simulation method (LSM) towards the goal of identifying when they work best and when they are limited
What are the differences in valuing European put options and American put options when using the...
What are the differences in valuing European put options and American put options when using the Binomial Option Pricing Model?
Suppose that p1, p2, and p3 are the prices of European put options with strike prices...
Suppose that p1, p2, and p3 are the prices of European put options with strike prices K1, K2, and K3, respectively, where K3>K2>K1 and K3-K2=K2-K1. All options have the same maturity. Show that p2 <= 0.5(p1+p3) (Hint: Consider a portfolio that is long one option with strike price K1, long one option with strike price K3, and short two options with strike price K2.)
In the Binomial Option Pricing Model, compare the price of an American Put and a European...
In the Binomial Option Pricing Model, compare the price of an American Put and a European put price using the same 5 step tree with 3 months to maturity and a sigma of 23%. Let the starting futures price be 72, the strike be 75 and let r = 5%.
Describe and compare the eight basic options strategies. American vs European Options like( at-the -money) or...
Describe and compare the eight basic options strategies. American vs European Options like( at-the -money) or ( In-the-money)
1. Explain the following brands of options: American, European, and Bermudan. 2. Options could be classified...
1. Explain the following brands of options: American, European, and Bermudan. 2. Options could be classified as call options and put options; Explain. 3. Differentiate the following scenarios of call option: In-the-money, At-the-money, and Out-of-the-money. 4. Distinguish the following scenarios of put option: In-the-money, At-the-money, and Out-of-the-money
1. Explain the following brands of options: American, European, and Bermudan. 2. Options could be classified...
1. Explain the following brands of options: American, European, and Bermudan. 2. Options could be classified as call options and put options; Explain. 3. Differentiate the following scenarios of call option: In-the-money, At-the-money, and Out-of-the-money. 4. Distinguish the following scenarios of put option: In-the-money, At-the-money, and Out-of-the-money.
Consider a binomial tree problem for an American option. A stock price is currently $50. Over...
Consider a binomial tree problem for an American option. A stock price is currently $50. Over each of the next two 3-month periods it is expected to go up by 7% or down by 6%. The risk-free interest rate is 5% per annum with continuous compounding. What is the value of a 6-month American put option with a strike price of $51?
Python: Trivia Questionaire Create a trivia application using the provided file which contains 15 questions in...
Python: Trivia Questionaire Create a trivia application using the provided file which contains 15 questions in it. Your application should randomly select how many questions will be presented to the user and it must be a number not greater than the number of questions in the file. Every question that is displayed should be randomly selected from the list and should be non-repetitive; in other words, you should not ask the same question twice. Your application should keep track of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT