Homework 1
FE621 Computational Finance
due 23:55, Sunday February 16, 2020
For all the problems in this assignment you need to design and use a computer program, output results and present the results in nicely formatted tables and figures. The computer program may be written in any program- ming language you want. Please write comments to all the parts of your code. They are a requirement and they will be graded.
You need to submit a PDF containing the report. Please use a word processor such as Microsoft Word, LATEX, or whatever Apple uses to cre- ate your report. You will be judged by the quality of the writing and the interpretation of the results.
Part 1.
1.
(20 points) Data gathering component
Write a function (program) to connect to sources and download data from one of the following sources:
(a) GOOGLE finance http://www.google.com/finance (b) Yahoo Finance http://finance.yahoo.com
(c) Bloomberg
Notes. For extra credit you can turn in code to download data from the other two sources. Please note that the program needs to down- load both option data and equity data. For this problem (and only for this problem) you may use any built in function or toolbox that will facilitate your work. The data will have to be clean (no duplicated val- ues, only one exchange, every column labeled properly, in other words, consolidated).
1
Note on Bloomberg data. For the Bloomberg source, access to one of Bloomberg terminals in the lab is required. If you use Bloomberg data, you may use the API to download data in Excel automatically and organize the data. However, this should be accomplished with an automatic script. If you use R to interface with the Bloomberg data, a useful package for that is Rblpapi, but there are other packages. For the online students, who do not have access to Bloomberg terminals, you may read about the package quantmod in R to download yahoo and google data automatically.
Bonus (5 points) Create a program that is capable of downloading multiple assets, combine them with the associated time column, and save the data into a csv or excel file.
2. With the function created in problem 1, download data on both options and equity for the following symbols:
• AMZN • SPY
• VIX
for two consecutive days (does not matter when, but no later than February 14th) during the trading day (9:30am to 4:00pm). Please record the asset values (both AMZN and SPY) at the time when down- loading is done. Please do the same with the VIX. For the options please download the next maturities data. Please note that the tradi- tional options are maturing third Friday on the month but there are a lot more options available to download. To be specific you should download at least all the option chains until the ones maturing two to three months from the date you are downloading.
We shall refer to the data sets gathered in the two consecutive days as DATA1 (for the first day) and DATA2 (for the second day) respectively throughout this assignment and the following ones.
3. Writeaparagraphdescribingthesymbolsyouaredownloadingdatafor. Explain what is the SPY and its purpose. (Hint: look up the definition of an ETF). Explain what is VIX and its purpose. Understand the options symbols. Understand when each option expires. Write this information and turn it in.
2
4. The following items will also need to be recorded:
•
Part 2.
• •
The underlying equity or ETF price at the exact moment when the rest of the data is downloaded.
The short-term interest rate which may be obtained here: http://www.federalreserve.gov/releases/H15/Current/. There are a lot of rates posted on the site – they are all yearly, they are in percents and need to be converted to numbers. There is no theo- retical recommendation on which to use, I used to use 3-months Treasury bills which are not available anymore. Since then I have been using the “Federal funds (effective)” rate but you can go ahead and try others. You should remember to be consistent in your choice. Also, make sure that the interest rate that you use is for the same day when the data you use for the implied volatility was gathered and note that the data is typically quoted in per- cents (you will need numbers). The same site has a link to past (historical) interest rates.
Time to Maturity.
(50 points) Analysis of the data.
5. Using your choice of computer programming language implement the Black-Scholes formulas as a function of current stock price S0, volatility σ, time to expiration T − t (in years), strike price K and short-term interest rate r (annual). Please note that no toolbox function is allowed but you may use the normal CDF calculation.
6. Implement the Bisection method to find the root of arbitrary functions. Apply this method to calculate the implied volatility on the first day you downloaded (DATA1). For this purpose use as the option value the average of bid and ask price if they both exist (and if their correspond- ing volume is nonzero). Also use a tolerance level of 10−6. Report the implied volatility at the money (for the option with strike price closest to the traded stock price). You need to do it for both the stock and the ETF data you have (you do not need to do this for VIX). Then average all the implied volatilities for the options between in-the-money and out-of-the-money.
3
Note. There is no clearly defined boundary between options at-the- money and out-of-the-money or in-the-money options. If we define moneyness as the ratio between S0 the stock price today and K the strike price of the option some people use values of moneyness between 0.95 and 1.05 to define the options at the money. Yet, other authors use between 0.9 and 1.1. Use these guidelines if you wish to determine which options’ implied volatilities should be averaged.
7. Implement the Newton method/Secant method or Muller method to find the root of arbitrary functions. You will need to discover the for- mula for the option’s derivative with respect to the volatility σ. Apply these methods to the same options as in the previous problem. Com- pare the time it takes to get the root with the same level of accuracy.
8. Present a table reporting the implied volatility values obtained for every maturity, option type and stock. Also compile the average volatilities as described in the previous point. Comment on the observed difference in values obtained for AMZN and SPY. Compare with the current value of the VIX. Comment on what happens when the maturity increases. Comment on what happen when the options become in the money respectively out of the money.
9. For each option in your table calculate the price of the different type (Call/Put) using the Put-Call parity (please see Section 4 from [2]). Compare the resulting values with the BID/ASK values for the corre- sponding option if they exist.
10. Consider the implied volatility values obtained in the previous parts. Create a 2 dimensional plot of implied volatilities versus strike K for the closest to maturity options. What do you observe? Plot all implied volatilities for the three different maturities on the same plot, where you use a different color for each maturity. In total there should be 3 sets of points plotted with different color. (BONUS) Create a 3D plot of the same implied vols as a function of both maturity and strike, i.e.: σ(τi,Kj) where i = 1,2,3, and j = 1,2,…,20.
11. (Greeks) Calculate the derivatives of the call option price with respect to S (Delta), and σ (Vega) and the second derivative with respect to S (Gamma). First use the Black Scholes formula then approximate these
4
12.
Part 3.
derivatives using an approximation of the partial derivatives. Compare the numbers obtained by the two methods. Output a table containing all derivatives thus calculated.
Next we will use the second dataset DATA2. For each strike price in the data use the Stock price for the same day, the implied volatility you calculated from DATA1 and the current short-term interest rate (corresponding to the day on which DATA2 was gathered). Use the Black-Scholes formula, to calculate the option price.
(20 points) Numerical Integration of real-valued functions. Consider the real–valued function
sin(x), for x ̸= 0, f(x) = x
1,
Note that we can actually calculate this integral as: ∞
−∞
1. Implement the trapezoidal and the Simpson’s quadrature rules to nu-
merically approximate the indefinite integral above. The algorithms are
presented in [3], please see Chapter 5. Hint: you can approximate the
indefinite integral by considering a large interval [−a, +a] (for example
a = 106). Consider equidistant nodes {xn}Nn=0, i.e., xn = −a+n2a, n = N
0,1,…,N, where N is a large integer.
2. Computethetruncationerrorforthenumericalalgorithmsimplemented in1foraparticulara∈RandN ∈N. Thatis,createafunctionof a and N that will output IN − π, where IN,a is the numerical approx- imation of the integral. Study the changes in the approximation as N and a increase as well as the difference between the two quadrature approximations. Please write your observations.
3. In a typical scenario we do not know the true value of the integral. Thus, to ensure the convergence of the numerical algorithms we pick a small tolerance value ε and we check at every iteration k = 1, 2, . . . if the following condition holds:
|Ik − Ik−1| < ε, 5
for x = 0.
f (x)dx = π.
Part 4.
1.
2.
where Ik is the value of the integral at step k. When the condition holds, the algorithm stops. Evaluate the number of steps until the algorithms from a) reach convergence for ε = 10−4. What do you observe?
(10 points) Consider the following functions: f1(x, y) = xy
f2(x, y) = ex+y
Analytically solve the following integral for both f1 and f2
13
fi(x, y)dydx
00
Calculate the numerical integral of the f1 and f2 by applying the trape- zoidal rule for double integral as discussed in [3], Page 118-119. Please choose four different pairs of values for (∆x, ∆y). Use these values to approximate the double integral for both f1 and f2. Calculate the er- ror of the approximation for each choice of values. Comment on the results.
Hint 1 First, discretize the x domain into n+1 points ∆x apart, where x0 = 0 and xn+1 = 1, and the y domain into m+1 points ∆y apart, where y0 = 0 and ym+1 = 3. The composite trapezoidal rule approxi- mates the integral as
[f(xi,yj)+f(xi,yj+1)+f(xi+1,yj) xi +xi+1 yj +yj+1
13 n m∆x∆y f(x,y)dydx ≈
0 0 i=0 j=0 16 xi +xi+1
+f(xi+1,yj+1)+2 f( 2 ,yj)+f( 2 ,yj+1)+f(xi, 2 )
yj +yj+1 xi +xi+1 yj +yj+1 +f(xj+1, 2 ) +4f( 2 , 2
)]
Hint 2. Please note the numbers chosen for (∆x, ∆y) should be specific to each student in the class.
6
References
[1] Clewlow, Les and Strickland, Chris. Implementing Derivative Models (Wiley Series in Financial Engineering), John Wiley & Sons 1996.
[2] Lecture1-ReviewBlackScholesmodel.pdf, 2017.
[3] Rouah, F. D. The Heston Model and Its Extensions in Matlab and C,
2013, John Wiley & Sons.
[4] Mikhailov, Sergei and No ̈gel, Ulrich. “Heston’s stochastic volatility model: Implementation, calibration and some extensions” Wilmott Jour- nal, 2004.
7