GUIDELINES
Columbia University
MATH GR5260 Spring 2021 Programming for Quant and Computational Finance Ng
Feb 26th 2021 (Fri) 8:15pm – 9:30pm
Copyright By PowCoder代写 加微信 powcoder
This is an open book exam. You may use any notes, reference materials, internet, Jupyter Notebook or any Python IDEs during the exam period. However, you only have limited time to complete the exam, so you must use your time wisely.
All answers must be written legibly.
In the Python code you write, add comments to your code where you think will help grader understand your logic.
If you suspect of any typos or some questions are wrong, please email the instructor during the exam.
The exam will be closed. Anything submitted or emailed after this time will not be accepted as your exam solution.
Solution submission
Exam paper will be uploaded onto Courseworks as ‘Exam 1’ under the Assignment section.
Once you see the exam paper in ‘Exam 1’ section, you may download the exam paper and
work on your solution
You should finish completing the exam and prepare to upload your solution files onto Courseworks, in the same way you uploaded your homework previously. You have 10 mins to prepare the solution files for upload.
a proper timestamp of submission.
If you have technical issues in submitting your
solution (eg. courseworks is crashed), please email your solution directly to Prof Ng and
your TA to get
Submit your python code (and output results) as a Jupyter notebook or HTML or pdf file.
Your solution to the theory questions can be included in your Jupyter notebook or submitted separately as
image files (eg. jpg, png, pdf) which can be viewed by standard tools.
You may name these files whichever way you like.
Make sure that in each of these files, you have your name and UNI on it.
Question 1 2 3 4 Total Points 10 40 25 20 95
During the exam, if you have questions, please email Prof Ng and TA.
Any clarifications or corrections will be posted in the Chat room within the Zoom session.
HONOR CODE AFFIRMATION
I affirm that I will not plagiarize, use unauthorized materials, or give or receive illegitimate help on assignments, papers, or examinations. I will also uphold equity and honesty in the evaluation of my work and the work of others. I do so to sustain a community built around this Code of Honor. (https://www.college.columbia.edu/honorcode#:~:text=)
First name Last name UNI Signature
Please include the above statement, your name and signature in one of your solution files.
QUESTION 1 (10 POINTS)
Joe found a Python module which can be used to evaluate options and wants to make use of this to run a scenario analysis on his option trades. Below are the class definitions in the Python module.
xyzmodel.py:
Write a class method (called scenValues) for the above Option class to compute the present value of the option under different scenarios of spot price and zero rate curve. The inputs shall include: an IrCurve object, a VolCurve object and a 1-D numpy array 𝑥 of spot prices and a 1-D numpy array 𝑠 of zero rate shifts. The class method should return a 2-dimensional numpy array of scenario values where the value in row 𝑖 and column 𝑗 of the 2D array output is the option value when the spot price is the 𝑖𝑡h value in the spot price array 𝑥 and the zero rate curve is shifted by the 𝑗𝑡h value in the rate shift array 𝑠.
You may assume these input parameters without validating them in your class method.
Note: you don’t need to run this piece of code as the Option class is not explicitly provided to you.
QUESTION 2 (40 POINTS)
This question is about applying Monte Carlo simulation to the valuation of a put option on the average of an index.
A put option on an average of an index with strike 𝐾 is a European option contract where on option expiry date if the average of the index falls on or below 𝐾, the option buyer receives the difference between the strike price and the average price; otherwise, the option buyer receives nothing.
Suppose 𝑆0 is the initial index price, 𝑆𝑡 is the index price at time t and 𝑇 is the time (in years) to the option expiry date. Here we consider the average index 𝐴𝑇 to be the average of the index over the last five calendar days prior to the option expiry. That is, the payoff function 𝑝(𝐴𝑇) of the put option is:
𝑝(𝐴𝑇) = max(𝐾 − 𝐴𝑇, 0)
where 𝐴𝑇 = (𝑆𝑡1 + 𝑆𝑡2 + 𝑆𝑡3 + 𝑆𝑡4 + 𝑆𝑡5 )/5 and 𝑡1, … , 𝑡5 refer to the five consecutive days prior to the option
expiry date with 𝑡1 < 𝑡2 < ⋯ < 𝑡5 < 𝑇.
The value of the option contract can be written as follows, where 𝑟 is the zero coupon rate for the time to
option expiry.
Let’s assume that 𝑟 is a constant and is known initially and 𝑆𝑡 follows a Geometric Brownian motion:
𝑑𝑆 =𝑆(𝜇𝑑𝑡+𝜎𝑑𝑊) 𝑡𝑡𝑡
where 𝜇 and 𝜎 are known constants and 𝑊 is a standard Brownian motion. 𝑡
a) Write down an expression for 𝑆𝑡𝑖 (for i=1,2,...,5) in terms of 𝑆0 , 𝜇, 𝜎, 𝑡𝑖 ′𝑠. Clearly define any additional variables or random variables you have used in the expression.
𝑉 = 𝐸[𝑒−𝑟𝑇𝑝(𝐴𝑇)]
b) Write a Python function to return 𝑛 samples of the average price 𝐴𝑇 as a numpy array. Define the function as sim_average_price(S0, mu, vol, times, n) where S0 is the initial index price, mu is 𝜇, vol is 𝜎 and times is a Python list [0, 𝑡1, 𝑡2, ... , 𝑡5]. You may assume these input parameters without validating them within the function.
c) Use part (b) to write a Python function to return the simulated value of the option using the Monte Carlo general method discussed in class.
Consider an option example where 𝑆0 = 430, 𝐾 = 460, 𝑇 = 0.5, 𝜇 = 15%, 𝜎 = 20%, 𝑟 = 0.1%.
d) Use part (c) to compute an estimate 𝑉 for the option using n=10000 simulations.
e) Use antithetical sampling technique to compute an estimate 𝑉 for the option using n=5000 simulations.
part (d) and (e) respectively.
g) We stated in class that: “Let 𝑧 be a standard normal random variable and 𝑓(𝑥) be an increasing or decreasing continuous function of x. Suppose 𝑓(𝑧) has finite mean and variance. Then 𝐸(𝑓(−𝑧)) = 𝐸(𝑓(𝑧)) and 𝑣𝑎𝑟(𝑓(−𝑧)) = 𝑣𝑎𝑟(𝑓(𝑧)).” Prove this statement.
f) Estimate 𝜎1(10000) and 𝜎2(5000) by computing the sample variance of 1000 option value estimates using
̃ Let𝜎 (𝑛)=𝑣𝑎𝑟(𝑉) and𝜎 (𝑛)=𝑣𝑎𝑟(𝑉)
QUESTION 3 (25 POINTS)
This question is an extension of homework 1 about “ ”. In homework 1, the following game was discussed:
Suppose we play two independent games at the same table at the same time. Below are the payoff distributions of betting M dollars in each game.
outcome probability Payoff
𝑝1 𝑞1 =1−𝑝1 𝑏1𝑀 −𝑀
𝑝2 𝑞2 =1−𝑝2 𝑏2𝑀 −𝑀
Suppose your initial wealth is 𝑊 . Your strategy is to place a bet of 𝑥 𝑊 01020
on game A and place a bet of 𝑥 𝑊 game B where 0 ≤ 𝑥1, 𝑥2 ≤ 1 and 0 ≤ 𝑥1 + 𝑥2 ≤ 1. Let W1 be the random variable of the wealth after game A
and B are played once.
a) Writedowntheexpressionfor𝐸(𝑊 −𝑊)intermsof𝑊,𝑏 ,𝑏 ,𝑝 ,𝑞 ,𝑝 ,𝑞 ,𝑥 ,𝑥
1 0 012112212
Suppose game A and game B are indeed identical independent games with the same probability distribution, ie. 𝑝1 = 𝑝2 = 𝑝 , 𝑞1 = 𝑞2 = 𝑞 and 𝑏1 = 𝑏2 = 𝑏 . As these games are identical, we may as well use the same betting ratio on game A and B. That is, 𝑥1 = 𝑥2 = 𝑥.
b) What value of 𝑥 will maximize your expected wealth 𝐸(𝑊 − 𝑊 )? Please explain. 10
7 Similar to homework 1, we will play the 2-game strategy (of placing bet on game A and B) 𝑁 times in a roll. Let
𝑊 be the random variable of the wealth after 𝑁 trials. 𝑁
Here is the summary of the 𝑁 trials.
What is the expression for 𝑊 in terms of 𝑊 , 𝑏, 𝑥, 𝑆(𝑖, 𝑗)′𝑠? 𝑁0
No. of trials where you win in both games
No. of trials where you win in game A and lose in game B
No. of trials where you lose in game A and win in game B
No. of trials where you lose in both games
d) Assume that 𝑏 = 1. Let x be the value of x that maximizes 𝐸(log(𝑊 ) − log(𝑊 )). What is𝑥 ? (Hint: K 𝑁0𝐾
recall properties of a multinomial distribution)
Below is a Python function that computes the final wealth of playing the original game N times.
e) Change the above function to return the final wealth of playing the 2-game strategy N times.
QUESTION 4 (20 POINTS)
Below shows the first few rows of a .csv file which keeps the FX transactions for different customers.
FX_trans.csv:
Here are descriptions for some of the columns.
TradeDate: date on which the FX transaction is traded
ValueDate: value date of the FX transaction (ie. the date on which currency amounts will be exchanged) BuySellDir: If BuySellDir = 1, then currency amount 1 is received and currency amount 2 is paid.
Amt1: currency amount 1 (in Ccy1)
Amt2: currency amount 2 (in Ccy2)
Rate: FX rate at which the transaction is booked
RateQuoteDir: FX rate quote direction. If it equals 1, the FX rate value is # units of Ccy2 per unit of Ccy1. If it equals -1, the FX rate value is # units of Ccy1 per unit of Ccy2.
a) Write a Python program that reads the input file and returns a DataFrame object that represents an aggregated view of the FX positions by customer by currency by value date.
Run your program with the attached file, FX_trans.csv, to display the resulted view. Below is the expected format of the returned view.
b) Write a Python function to read an input file that has the same format as FX_trans.csv and make the following checks. Raise an exception with proper error message (including the row number) when any of these checks fail. Define the function as check_data(filepath) where filepath specifies the path of the input file as a string (eg. ‘fx_trans.csv’).
(i) The values in Rate column are positive.
(ii) Values in RateQuoteDir column are valid.
(iii) Values in Amt1, Amt2 are consistent with the Rate column.
--end of exam-- --Happy spring break--
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com