辅导案例-FM442

欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top
FM442
London School of Economics
Quantitative Methods for Finance & Risk Analysis MT 2020
Instructions for all assignments
Assignments 3 and 8 are marked (with a weight of 5% each). Submissions are to be made individually by 9am
on the respective submission date. The write-up for submission does not usually cover the full assignment.
Please read and follow the instructions carefully.
You are free to use any software to solve the assignments. Suggested solutions are based on the latest version
of Matlab.
Follow good programming practices, including:
• Use a consistent indentation style.
• Use descriptive variable and function names, with appropriate prefixes.
• Comment all function inputs and outputs and comment other parts of your code where appropriate.
1
FM442
London School of Economics
Quantitative Methods for Finance & Risk Analysis MT 2020
Assignment 1 (week 2): CRSP
This assignment gets you started working with databases and data. Start by going to WRDS
http://wrds.wharton.upenn.edu/ and register for an account. This might take a day or two days so make
sure you do it early enough. The instructions below outline the steps to download stock price and additional
information for a series of stocks.
1. Log into WRDS, go on the “Get Data” tab and find the “CRSP” link. Next, click on the “Stock /
Security Files” link. There you have daily and monthly stock files. We start by downloading monthly
data. Select data range Dec 1989 to Dec 2019. In step 2, choose PERMNO as the format for the
company codes. Upload PERMNO.txt available on MOODLE (this file contains the CRSP codes for
Microsoft MSFT, Exxon XOM, General Electric GE, JPMorgan Chase JPM, Intel INTC and Citigroup C).
2. From step 3 (“Query Variables”), select the following variables from “Identifying Information”: Com-
pany Name, Ticker and Primary Exchange. From the “Time Series Information”, select the following
variables: Price, Closing Bid, Closing Ask, Holding Period Return and Holding Period Return with-
out Dividends. From the “Distribution Information”, select the following variables: Dividend Cash
Amount, Factor to Adjust Price and Cumulative Factor to Adjust Price. From “Market Information”,
select the following variables: Value-Weighted Return (includes distributions), Value-Weighted Re-
turn (excluding dividends), Equal-Weighted Return (includes distributions), Equal-Weighted Return
(excluding dividends) and Return on S&P 500 Composite Index.
3. Use comma-delimited text and default date format (“YYMMDDn8”) for the output and submit request.
Now a new window opens up and eventually you will have a link to a .csv file. Save the file as
Data Monthly.csv in a new folder, e.g. h:FM442. Open the file in Excel and check how the data is
organized. Check the tickers and company names.
4. Note: If you have problems uploading the file then type in the codes manually.
5. Download JPMorgan Chase data using the TICKER JPM instead of the PERMNO. Compare the data
for JPMorgan Chase and discuss the differences.
6. If you have followed the instructions correctly, you should get the same file as FM442 2020 Data Monthly.csv
posted on MOODLE. Make sure you understand how the returns are calculated given the prices, divi-
dends and adjustment factors, i.e. replicate the holding period returns using the other data. You can
find information about the variables on the CRSP page where you downloaded the data.
2
FM442
London School of Economics
Quantitative Methods for Finance & Risk Analysis MT 2020
Assignment 2 (week 3): Basic data handling
Use the same data as last week. This assignment asks you do perform some tasks to handle the data and
make it operational. Moreover, you are asked to perform simple operations and plot some price and return
series. You can do everything in MATLAB (or R) although it is not always straightforward as you will see.
Instead, you can clean the data in Excel and then only do the calculations in MATLAB. However, I would
suggest you spend at least some time thinking about how you would do the things in MATLAB. For now
we are only working with six different stocks and it is possible to do some things manually. If you have a
sample of hundreds of stocks this might become more difficult.
1. The raw data from Data Monthly.csv needs to be cleaned and rearranged. There are various ways to do
this but here we are opting to organise prices, returns, dividends and adjustment factors in separate ma-
trices were the data is arranged in columns. In addition, we need one column with the month and year.
Make sure the order of the individual stocks remains unchanged. The file FM442 A2 monthly sol.m
available on MOODLE is one example how this can be done. If you don’t want to write your own
code, go through the suggested solution and try to understand what happens line by line.
2. Use the holding period returns to create a total return index for the stocks, which shows the theoretical
growth in value of an investment in the stock assuming that dividends are reinvested (normalize the
start value to 1). Calculate the size, mean, variance, and kurtosis of the holding period returns. Plot
the data. Again, try to understand the code.
3. Normalize the unadjusted prices. Adjust the prices using the cumulative adjustment factor and nor-
malize. Pick MSFT and C and plot the total return index, the adjusted price index, the unadjusted prices
and an appropriate benchmark. You need the additional file Figure1.m. Again, try to understand the
code.
4. The holding period returns are normal returns. Create log returns. Calculate the size, mean, vari-
ance, skew, and kurtosis of the normal and log returns. Plot the data. You need the additional file
returnmaker log.m.
5. Download FM442 2020 Data Daily.xls fromMOODLE. This file contains three worksheets. HPR Daily
contains the daily holding period for the six stocks, the S&P 500 Composite Index and the value-
weighted market portfolio (including dividends) from CRSP. Prices Daily contains the prices for the
six stocks and the S&P 500 Composite Index and Data Yahoo contains daily data for the S&P 500,
Citigroup and Microsoft that can be downloaded from http://finance.yahoo.com (with tickers G^SPC,
C and, MSFT, respectively).
6. Construct a daily total return index for the stocks. Normalize the adjusted closing prices from Yahoo
and plot. Compare the time series—are they the same? If there is a discrepancy try to find out where
it comes from (hint: compare the unadjusted prices).
7. Compare the total return index based on daily data with the previous one based on monthly data. Are
they the same at the end of every month?
8. As before, the holding period returns are normal returns. Create log returns. Calculate the size, mean,
variance, skew, and kurtosis of the normal and log returns. Compare your results with the results
from monthly frequency. Create log returns using the adjusted closing prices from Yahoo. Plot the log
returns for MSFT, C and the S&P 500 Index.
3
FM442
London School of Economics
Quantitative Methods for Finance & Risk Analysis MT 2020
Assignment 3 (week 4): Examining returns
Due: Friday, 23 October 2020, 9:00 a.m. Submit your solutions via the FM442 Moodle page.
In this assignment you are asked to further explore properties of stock and market returns and submit a
short write up not exceeding two pages (including tables and figures). You can use FM442 2020 Data Daily.xls
(Data from 31/12/1989–31/12/2019) from the last assignment and the daily total return indices you created.
FM442 A2 daily sol.m on MOODLE reads in FM442 2020 Data Daily.xls, calculates log returns, daily to-
tal return indices and the summary statistics required in the first homework (for MSFT, GE and C). You will
also need Figure2.m to create a plot of the returns.
Here are a few MATLAB functions that might be helpful for this assignment: jbtest, lillietest, kstest,
qqplot, histfit, cov, autocorr. To learn more about the functions look them up in MATLAB help or
type help and then the function name directly in the MATLAB command window.
1. Pick three stocks and the S&P 500 index from last week (either you can use MSFT, GE and C or adapt
the code to pick three random stocks). You will need the holding period returns (both normal and log
returns) and the total return indices you created.
2. Compare the statistical properties of the log holding period return time series, including a test for
normality. Plot the histogram and a QQ diagram of each series. For the QQ plot you can either use
the Matlab command mentioned above or program it out yourself.
Optional: Try to create figures with subplots, i.e. try to get the four plots for the three assets and
the index into one figure.
3. Calculate the covariance matrix for the log return series, using both the returns and returns squared.
4. Plot the ACF (autocorrelation function) for prices, returns, returns squared, and absolute returns.
5. Calculate a moving window volatility and correlation (using 10 and 20 week window) and plot the
result. A moving window value of the variance σ¯2t is created as follows. Suppose N is the window
length and T the data length, then
σ¯2t = V ar(rt−N , . . . , rt), t = N, . . . , T
where V ar indicates the variance.
6. Use the three assets and make up a portfolio by assigning arbitrary portfolio weights. What does it
imply if you keep the weights fixed over time?
7. Calculate the portfolio returns (eventually, you want to have log returns again). Use some easy numer-
ical examples to verify whether you want to use normal or log returns or whether it doesn’t matter.
For the write up please discuss the relevant and interesting differences between MSFT and
GE. Use figures and tables as appropriate.
4
FM442
London School of Economics
Quantitative Methods for Finance & Risk Analysis MT 2020
Assignment 4 (week 5): Volatility models
This assignment gets you started with volatility modelling. Start by skimming through the MATLAB
documentation for “Conditional Variance Models” and explore the functionality. Some of the functions you
may want to explore are: garch, egarch, gjr, estimate, infer, and summarize. These are all functions
available in the latest Matlab version (2020).
If you are working with an older versions then you may find the function help ugarch as part of the
financial toolbox. Additionally, I recommend you look into installing the UCSD GARCH toolbox that can be
downloaded from Kevin Sheppard’s website at https://www.kevinsheppard.com/MFE MATLAB/. The main
function to use is help garchpq and I have included the function and some required files on Moodle.
The second part of the assignment asks you to verify the fat tails of a GARCH(1,1) process (no coding
required for this one).
1. Volatility modelling using MATLAB
• Select one daily log return series (either a single stock or the S&P 500 index).
• Estimate the volatility time series using the EWMA and MA models, making all necessary as-
sumptions.
• Produce GARCH(1,1) volatility forecasts, making all necessary assumptions.
• Diagnose the results from the GARCH estimation.
• Explore the impact of different p and q values in the GARCH model.
• Plot the time series of the volatilities that you estimated using the three volatility models (EWMA,
MA and GARCH(1,1)).
2. Unconditional variance, skewness and kurtosis of a GARCH(1,1) process
• Consider the GARCH(1,1) model:
Rt =

htzt
ht = ω + αR
2
t−1 + βht−1
zt ∼ N (0, 1) ω, α, β > 0, α+ β < 1
• Show that the unconditional variance E(R2t ) = E(ht) is given by ω1−(α+β)
• The skewness and kurtosis of the residuals zt are 0 and 3, respectively:
Et−1z
3
t = 0 and Et−1z
4
t = 3
• Calculate the unconditional skewness of the GARCH(1,1) process. Start by calculating E(R3t ).
Note that E(R3t ) = E(Et−1R
3
t ) and use Rt =

htzt and Et−1ht = ht (as ht can be calculated at
time t− 1).
• The unconditional kurtosis is calculated as follows:
K =
E(R4t )
(E(R2t ))
2 =
E(h2t z
4
t )
(E(ht))
2
• Prove that:
E(R4t ) = 3
ω2 (1 + (α+ β))
(1− (α+ β)) (1− 2α2 − (α+ β)2)
Show that the kurtosis then is:
K =
3
(
1− (α+ β)2)
(1− 2α2 − (α+ β)2)
Note that the conditional kurtosis is:
KC =
Et−1R
4
t
(Et−1R2t )
2 =
h2tEt−1z
4
t
(htEt−1z2t )
2 = Et−1z
4
t = 3
So the kurtosis is
K =
E(R4t )
(E(R2t ))
2 =
3E(h2t )
(E(ht))
2
5
FM442
London School of Economics
Quantitative Methods for Finance & Risk Analysis MT 2020
Assignment 5 (week 6): Volatility models and VaR
In this assignment you will calculate the term structure of volatility using a GARCH model and compare it
to the term structure of implied volatility from option prices. You are also asked simulate and estimate a
DCC(1,1) model and you will calculate VaR using GARCH.
1. Term structure of GARCH volatility.
• Download 10 years of daily S&P 500 values from Yahoo finance. Take the index values and
calculate log returns.
• Estimate a GARCH(1,1) process.
Optional: Estimate a GARCH(p,q) process where you pick p and q such that AIC or BIC are
minimized.
• Forecast the variance using the estimated parameters for horizons up to three years. You need to
work this out analytically before coding it up.
• Check whether your term structure depends on the length of the sample period used, i.e. repeat
the GARCH estimation and the forecast for various sample sizes (e.g. 10 years, 5 years, 2 years,
1 year of data).
• Compare the term structure of volatility with the term structure of implied volatility.
2. DCC model simulation and estimation.
• Take a look at the MATLAB file Contents.m in the UCSD GARCH toolbox if you have installed
it. I have added the relevant files from the toolbox on Moodle. In particular, you want to use
dcc mvgarch.
• Simulate 2,500 data points for a DCC(1,1) process with 2 return time series. Make appropri-
ate assumptions for parameter values. You can use the function dcc univariate simulate on
Moodle.
• Estimate the DCC(1,1) model you just estimated and check whether you can recover the original
parameters.
Optional: Run a Monte Carlo simulation of the simulation/estimation. Keep the parameter
values fixed but simulate multiple data sets and subsequently estimate the parameters. Do this
in a loop and store the estimated parameter values. Calculate mean and standard deviation of
the estimation parameter values. Ideally, you would simulate a few hundred data sets but it will
probably take too long to run so choose the number of simulations based on how long it takes to
do it once.
3. VaR with GARCH
• Pick three stocks from our usual data set, use daily holding period returns, transform to log
returns.
• Calculate VaR for all of them using GARCH, historical simulation, MA and EWMA.
• Vary the sample length for the GARCH estimation and HS and the window length for MA and
EWMA and compare the various results.
6
FM442
London School of Economics
Quantitative Methods for Finance & Risk Analysis MT 2020
Assignment 6 (week 7): Simulations
This assignment will get you started on simulations.
1. Use the randtool command in Matlab to explore the various aspects of random number generation.
2. Generate 10 observations from a standard normal, plot the histogram and distribution, and calculate
the mean and variance. Repeat this 10 times. What do you get?
3. Repeat the above but instead use the following command first before generating the 10 observations:
randn(’state’,100);. What do you get? Why is this helpful?
4. Use a for loop to increase the number of simulations in a few steps up to 1 million and examine how
the plots and sample statistics improve.
5. Generate 1,000 observations from a Student–t with 4 degrees of freedom, plot the histogram and
distribution, and calculate the mean and variance.
6. Price a European call option with simulation and compare the answer to the Black–Scholes solution
from blsprice.
7. A down-and-out call is a call option that is knocked out (becomes worthless) when the price of the
underlying hits a lower barrier during the lifetime of the option. An up-and-out call expires when the
stock price hits an upper barrier. What is the main difference between a plain vanilla call and either of
the knock-out calls from a programming standpoint? How would you proceed to price a barrier option
using MC simulation?
Optional: Write a code to price barrier options via simulation.
7
FM442
London School of Economics
Quantitative Methods for Finance & Risk Analysis MT 2020
Assignment 7 (week 8): Simulations and option implied volatility
Due: Friday, 20 November 2020, 9:00 a.m. Submit your solutions via the FM442 Moodle page.
Follow the instructions below to obtain the data. If you do not manage to get the data from CBOE you can
use the options data posted on Moodle in file FM442 2020 Data Options.xls (note that you will have up to
10 marks deducted for not collecting the options data yourself. For the submission calculate and plot
the implied volatility smile (or smirk) as well as the term structure of implied volatility from
part 1. (see bullet points in bold below). Discuss both plots. From part 2. price a Margrabe
option using simulation and discussion how the price of the option depends on the correlation
coefficient (again, see the relevant bullet point in bold). Submit a printout of the relevant
simulation code as an attachment.
1. Volatility smile and term structure of implied volatility.
• Go to the CBOE website http://www.cboe.com/DelayedQuote/QuoteTableDownload.aspx to
get option prices on one day for a series of options on the S&P 500 index. Type in SPX and
download the .dat file. You can save it as a .txt file and then import to Excel.
• The downloaded data contain weekly options. Remove them from the data. Their symbols start
with SPXW (e.g. SPXW201218P00100000).
• We would like to get prices of options that are fairly liquid. Therefore, avoid options with little
outstanding interest or volume, or with prices below USD 0.25 or above USD 100 (although I
have included some liquid prices in that high range). Take either the closing midquote or the last
transaction.
• Pick a series of put options with maturity 18 December 2020 and a range of strike prices. We will
need this to calculate the implied volatility smile/skew. You can check the range of strikes I used
in the data file.
• Pick the 3350 strike price and get option prices for different maturities (you should find options
up to December 2022).
• To get the implied volatility from the Black-Scholes formula, we need to get the remaining input
parameters, namely the risk free rate and the time to maturity.
– Calculate the maturity using the expiration date given in the data. Use days to expiration
but remember to divide this by 360 to get the relevant number expressed in years.
– Considering the range of options you are looking at, pick a reasonable risk free interest rate.
Justify your choice. You can get risk-free interest rates from the St. Louis Fed website
http://research.stlouisfed.org/fred2/categories/22.
• Given all the inputs, you can calculate the implied volatility in MATLAB using blsimpv().
• For summative assignment: Using the option prices with the same maturity calculate
the implied skew and plot it. Discuss the resulting plot.
• For summative assignment: Using the option prices with the same strike price calcu-
late the term structure of implied volatilities and plot it. The CBOE data contains
an IV estimate along with the prices. Plot the CBOE IVs on the same graph as your
own calculated IVs. Interpret the term structure of implied volatilities based on the
CBOE IV plot and discuss any differences you find between the CBOE calculation
and your own results.
2. Correlated assets and the Margrabe option (option to exchange one asset for another).
• Assume you have two assets, S1 and S2, both currently (time t) trading at USD 100.
• The underlying asset prices are assumed to follow geometric Brownian motions:
dS1 = µ1S1dt+ σ1S1dW1
dS2 = µ2S2dt+ σ2S2dW2
Assume σ1 = 20%, σ2 = 35% and (T−t) = 1year. For risk neutral valuation we have µ1 = µ2 = r.
Assume the risk-free rate is 5% with annual compounding.
• Assume the two assets are correlated with correlation coefficient ρ, i.e. dW1dW2 = ρdt. Simulate
the paths of the two assets using:
ST = St exp
((
r − 1
2
σ2
)
(T − t) + σ

(T − t)ǫ
)
8
FM442
London School of Economics
Quantitative Methods for Finance & Risk Analysis MT 2020
• Plot the distribution of the value of the portfolio under the risk neutral measure for various values
of ρ. How does the 5th percentile change as a function of the correlation coefficient?
• A An exchange option (or Margrabe option) gives its owner the right, but not the obligation, to
exchange Q2 units of asset S2 for Q1 units of asset S1 at expiration. The payoff is:
max(Q1S1 −Q2S2, 0)
• For summative assignment: Price an exchange option using simulation. Use the
assumptions above and Q1 = Q2 = 1. How does the price of the option depend on the
correlation coefficient?
• Optional. There is a closed form solution for the exchange option (see, eg. Espen Gaarder
Haug: The Complete Guide to Option Pricing Formulas, Chapter 5). Implement the formula in
MATLAB and compare your simulated prices with the closed form solution.
To reiterate, for the submission you need to do the following:
1. Collect the option prices as per the instructions.
2. Plot the option-implied volatilities for put options with expiration date 18 December
2020. Plot the option-implied volatilities for put options with a strike 3350. For the
latter please plot your calculated IVs along with the IVs supplied by CBOE. Discuss the
plots and the differences between the CBOE calculations and your results.
3. Price an exchange option using simulation and discuss the importance of the correlation
coefficient. Attach a printout of your code (regardless in what environment you coded
up the solution).
The submission should not exceed two pages (including tables and figures but excluding the
code to be attached.)
9

欢迎咨询51作业君
51作业君

Email:51zuoyejun

@gmail.com

添加客服微信: abby12468