Creation of this worksheet was supported by IT Academy program of Information Technology Foundation for Education (HITSA)

Exercises of Lab 14

The aim of the lab is to check how well European options can be replicated by trading.

If the Black-Scholes market model holds, then by arguments used in the lecture we know that every European and American option can be replicated by a self-financing trading strategy that uses the sum of money equal to the option price as starting capital and holds at each time moment $\frac{\partial v}{\partial s}(S(t),t)$ shares of the stock. We assume that short selling (holding negative number of stocks) is possible and that stocks are infinitely divisible, so that any fraction of a stock can be held in a portfolio.

We shall simulate the trading by using the historical data of Cisco stock prices (dividend adjusted daily closing prices) for one year.

Exercise 1

Import the adjusted closing price data for Cisco stock for period 11.05.2020-10.05.2021 (these are the first date and last date of the date INCUDED in sample) and use the first half of the date to estimate the $\sigma$ and $\mu$ parameters of BS model with constant parameters.

Solution You can import the data like it was done in Lab 4, here an alternative possibility is described using pandas_datareader library.

In [ ]:
import numpy as np

#For an alternative way: import libraries we need
from datetime import date
from pandas_datareader import data
 
# define start and end dates of the period we want using date() function
# arguments are year,month, day
start = 
end = 

#use data.DataReader() function to get the stock price data
# First argument is the symbol name of the  series we want, 
#second is the source ("yahoo" for Yahoo! Finance), 
#third is the start date, fourth is the end date
#Symbol name for Cisco is "CSCO"
csco=data.DataReader()
csco #view tha data

If we use DataReader, the result is pandas DataFrame, which is an analog to dataframes in R. It is easy to plot a series in a dataframe:

In [ ]:
%matplotlib inline
csco["Adj Close"].plot(grid = True)

We are used to work with arrays, so let us get the column "Adj Close" and make it to numpy array.

In [ ]:
prices=np.array(csco["Adj Close"])
prices
Check your data! The first price should be 41.945267, the last one 53.15999985

Now estimate the parameters $\mu$ and $\sigma$ by using the first half of data

In [ ]:
#estimate parameters
Check your results! Use the prices with indexes 0,1,..., 126 for estimating the parameters Results sould be mu = -0.20616561452297258 , sigma= 0.3056996648928615

Exercise 2

Find from internet a formula for the derivative of BS put option with respect to stock price (so called delta) and implement it as a function Put_delta in the file BSformulas.py (see Lab 2). Import the module and check your functions by the commands given below. Make sure you functions are working correctly!

Solution

In [ ]:
import sys
sys.path.append("location_of_your_BSformulas file")
import BSformulas as bs
In [ ]:
bs.Put(S=100,E=95,r=0.01,D=0.02,sigma=0.5,T=0.6)
Check your result! The price should be 12.748179273611761
In [ ]:
bs.Put_delta(S=100,E=95,r=0.01,D=0.02,sigma=0.5,T=0.6)
Check your result! The derivative should be -0.3735443675076304

Exercise 3

Simulate trading with replicating portfolio for the second half of the year (starting from the last day which was used for estimating the parameters). Assume that the risk free interest rate is $0.02$, the dividend rate $D$ is 0 and that the exercise price is equal to the stock price at the time of selling the option. Compare the final value of the portfolio to the payoff of the option at the exercise date.

Solution

In [ ]:
#Define the index corresponding to the last day which was used 
#in the first part. This is also index of day for selling the option
start=??? 
T=1/2
E=S[start] #current stock price is also the exercise price
r=
D=
#initial value of portfoli0 is the option price
option_price=???
option price

Compute time to expiration for each day in the trading period and recompute dt by assuming that the trade simulation period is exactly 1/2 years

In [ ]:
T_values=np.linspace(??)
dt=
dt
Check your computations! the time interval dt should be 0.003968253968253968 the length of T_values vector should be 126

For each day before the expiration date we can compute the value of portfolio for the next day according to the equation of self-financing portfolios (where differentials are replaced with differences). The starting value of the portfolio is equal to the option price.

So you should define a vector X such that X[0]=option_price At the starting day compute eta=bs.Put_delta(S=S[start],E=E, T=T_values[0],r=r,sigma=sigma) and then we get the value for the portfolio for the next day: X[1]=X[0]+(X[0]-eta*S[start])*r*dt+D*eta*dt+eta*(S[start+1]-S[start]). Then we repeat it for next day (all indexes are increased by one, we get X[2] and so on until we have computed the X value also for the last day of tranding.

In [ ]:
V_portfolio=np.zeros(n-start)
V_portfolio[0]=X
for t in np.arange(start,n-1):
    #compute current time to exercise time
    T_current=T_values[t-start] 
    #compute eta (number of shares) for the current time
    eta=bs.Put_delta(S[t],E,T_current,r,sigma,D)
    #compute value of portfolio for time t+1
    X=X+(X-eta*S[t])*r*dt+D*eta*S[t]*dt+eta*(S[t+1]-S[t])
    V_portfolio[t-start+1]=X
    #print(X)
V_portfolio
Check your results! The vector of portfolio values shold start with 2.98501556, 2.69708143 and end with 0.31296444, 0.31298948

Compare the final value of the portfolio with option payoff:

In [ ]:
 
Check your result! the difference of portfolio value and option payoff is 0.3129894770482097

Exercise 4

Modify the procedure for American put options. Then a numerical method should be used for pricing the option and finding it's derivative. Replication works reasonably well if the value of our portfolio at each time moment never becomes much less than the pay-off value at that time moment and when there exists a time when the value of the portfolio and the value of the pay-off function of the stock price at that time moment are practically equal.

In [ ]: