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.
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.
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:
%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.
prices=np.array(csco["Adj Close"])
prices
Now estimate the parameters $\mu$ and $\sigma$ by using the first half of data
#estimate parameters
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
import sys
sys.path.append("location_of_your_BSformulas file")
import BSformulas as bs
bs.Put(S=100,E=95,r=0.01,D=0.02,sigma=0.5,T=0.6)
bs.Put_delta(S=100,E=95,r=0.01,D=0.02,sigma=0.5,T=0.6)
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
#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
T_values=np.linspace(??)
dt=
dt
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.
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
Compare the final value of the portfolio with option payoff:
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.