程序代写代做 graph c++ Excel finance go Bond options in the Vasiˇcek interest rate model

Bond options in the Vasiˇcek interest rate model
C++ Programming with Applications to Finance Spring 2020
The Vasiˇcek model for the short (interest) rate rt in continuous time is formulated in terms of the stochastic differential equation
equivalently
−αt θ 􏱄 −αt􏱅 rt = e r0 + α 1 − e
+ σ
􏱉 t −α(t−u)
e dWu for all t > 0,
drt = (θ − αrt)dt + σdWt,
0
where r0 is the current short rate and Wt is a Brownian motion.
The aim of this project is to create a program in C++ that can be used to study the prices of options on zero coupon bonds produced by means of an approximation method based on the Vasiˇcek trinomial tree. Your program should be accompanied by end-user and developer documentation.
This project description is accompanied by two files, namely a C++ header file Project.h and two sample data files, rates.txt and prices.csv. The header file Project.h must be included in your project without change.
General hints and tips
• This project description contains all the properties of the Vasiˇcek model that are needed to complete this project. Further knowledge of the model (which is covered in the module Modelling of Bonds, Term Structure and Interest Rate Derivatives) might make the project more interesting, but is not required, and will not give any advantage when completing the project.
• Read the submission instructions at the end of this document before starting work on the project.
• Read through all the tasks before starting work on the project. Tasks do not have to be completed in the order that they are listed here.
• You are free to recycle any code produced by yourself during the module. You are also free to use any code provided in Moodle during the module, provided that such code is acknowledged.
• Test your project with a freshly downloaded copy of Project.h just before submission.
This project contributes 30% to the mark for this module. The deadline for submission is 1pm on Monday 4 May 2020. The marks for each of the tasks below will be split into 60% for coding style, clarity, accuracy and efficiency of computation, and 40% for documentation (including comments within the code) and ease of use. Credit will be given for partial completion of each task.
1

Task 1: Data input, estimation and calibration (20%)
The Vasiˇcek model has three parameters: θ ∈ (−∞, ∞) is the long term mean parameter, α > 0 is the mean reversion parameter, and σ > 0 is called the volatility.
Your program should ask the user to enter the value of the parameter α, as well as the current value of the short rate, denoted r0.
Your program should then estimate the value of θ, as follows. It should read a time series of observed short rates rˆ1, . . . , rˆn from a file called rates.txt containing a series of past rates, as in the sample rates.txt provided. The estimated value of θ is then calculated as
where
θ = α r ̄ , n
r ̄ = 1 􏱈 rˆ k n
k=1
is the average of the observed short rates. Your program should display the value of θ once it
has been calculated.
Finally, your program should calibrate the value of σ by using the formula for the price of
a zero coupon bond in the continuous-time Vasiˇcek model. A zero coupon bond with maturity date T is a financial contract guaranteeing a payoff of 1 at time T, and its price at time 0 in the continuous-time Vasiˇcek model is
B(0,T) = e−r0A(0,T)+D(0,T), where r0 is the current short rate and
A(0,T)= 1 􏱄1−e−αT􏱅, D(0,T)=􏱆θ −1σ2􏱇(A(0,T)−T)−1σ2(A(0,T))2. α α 2α2 4α
Your program should ask the user to enter a maturity date T and the observed market price Bquote of the zero coupon bond with maturity date T, and then solve the non-linear equation
Bquote =B(0,T)
for σ. When calculating B(0,T), your program should use the values of r0, θ and α that have already been obtained. Your program should display the value of σ once it has been calculated. The value of σ should be accurate to at least 5 decimal places.
Technical note for Task 1
The actual rates.txt file used for testing the program by the marker will contain a different and much longer time series. Include the sample rates.txt file in your submission, placed in the directory where your program will be looking for it, but do not hard wire the absolute path to the file into your program as this path is likely to be different on the marker’s computer. Explain in the end-user instructions how to propare and provide the file rates.txt so that your program can read it.
Task 2: Vasiˇcek model (10%)
The header file Project.h contains a class VasicekModel that encapsulates a few of the essential
properties of the continuous-time Vasiˇcek model. Create a new source file VasicekModel.cpp
containing the implementations of the two member functions of VasicekModel that are incom-
plete. The function VasicekModel::Long_term_average() should return the long term average
rate θ , and the function VasicekModel::Is_well_defined() should return true if α > 0 and α
σ > 0, otherwise it should return false.
2

Task 3: Vasiˇcek trinomial tree (20%)
The header file Project.h also contains a class VasicekTree encapsulating a trinomial tree that can be used to compute approximate prices of financial derivatives, such as options, in the Vasiˇcek model. Create a new source file VasicekTree.cpp containing the implementations of the member functions of VasicekTree that are not already implemented in Project.h, using the information provided below.
The starting point for the tree is the length ∆t > 0 of the small time interval between successive steps. The value of the short rate r(n, k) at each time step n = 0, 1, . . . and node k in the tree is
where
r(n, k) = e−αn∆tr0 + θ 􏱄1 − e−αn∆t􏱅 + k∆r, α

∆r=σ 3∆t
is the vertical space between nodes. Here r0 is the initial short rate and θ, α and σ are the parameters of the Vasiˇcek model.
The key idea behind the trinomial tree approximation is that the Vasiˇcek model is mean- reverting, in other words, whenever the short rate moves away from the long term mean θ/α, it tends to move back closer to it over the long run. This means that it is less important to model the short rate at values far away from the mean, and we incorporate this by limiting the number of nodes in the tree at each time step to a fixed number. Thus the number of nodes in the tree do not grow over time, which leads to very efficient pricing procedures.
Let kmax be the smallest integer that is larger than (or equal to) 0.184α . At early time steps ∆t
n = 0,…,kmax − 1, the tree grows like a standard trinomial tree: it has 2n + 1 nodes at time step n, numbered −n, . . . , n, and every node has three successors. At time step kmax, the tree stops growing. At each time step n = kmax, kmax +1, . . ., the tree has 2kmax +1 nodes, numbered −kmax,…,kmax. At such time steps, every node still has three successors, but the choice of successors are now constrained by the fact that the tree does not grow any more. In all cases, the three successors of each node k, called uk, mk, dk are always chosen so that mk is as close to k as possible, and then uk = mk + 1 and dk = mk − 1.
Here is an illustration of the node structure on a tree with kmax = 3. Each node in the diagram is labelled (n, k), where n denotes the time step and k the node number. The successors of each node are indicated by arrows.
(3, 3)
(4, 3)
(5, 3)
(2, 2)
(4, 2)
(1, 1)
(2, 1)
(3, 2)
(5, 2)
(3, 1)
(4, 1)
(5, 1)
(0, 0)
(1, 0)
(2, 0)
(3, 0)
(4, 0)
(5, 0)
(1, −1)
(2, −1)
(3, −1)
(4, −1)
(5, −1)
(2, −2)
(3, −2)
(4, −2)
(5, −2)
(3, −3)
(4, −3)
(5, −3)
The probability of transitioning from any node k at any time step n = 0, 1, . . . to a node l at time step n + 1 is denoted by pk,l. The successors and transition probabilities are summarised
3

in the following table:
Node k
Successors
Transition probabilities
k = kmax
dk = kmax − 2 mk = kmax − 1 uk = kmax
pk,d = 1 + 1 􏱄α2k2(∆t)2 − αk∆t􏱅 k62
pk,m = −1 − α2k2(∆t)2 + 2αk∆t k3
pk,u = 7 + 1 􏱄α2k2(∆t)2 − 3αk∆t􏱅 k62
k = −kmax + 1, . . . , kmax − 1
dk = k − 1 mk = k
uk = k + 1
pk,d = 1 + 1 􏱄α2k2(∆t)2 + αk∆t􏱅 k62
pk,m = 2 − α2k2(∆t)2 k3
pk,u = 1 + 1 􏱄α2k2(∆t)2 − αk∆t􏱅 k62
k = −kmax
dk = −kmax
mk = −kmax + 1 uk = −kmax + 2
pk,d = 7 + 1 􏱄α2k2(∆t)2 + 3αk∆t􏱅 k62
pk,m = −1 − α2k2(∆t)2 − 2αk∆t k3
pk,u = 1 + 1 􏱄α2k2(∆t)2 + αk∆t􏱅 k62
Note that the successors and the transition probabilities associated with any node k do not depend on the time step n at which the node appears.
Task 4: Derivative pricing in the Vasiˇcek trinomial tree (20%)
The header file Project.h contains a pure virtual class EurOptionVasicekTree encapsulating a European style derivative that offers a payoff at its maturity date N in the Vasiˇcek trinomial tree. It also contains an inherited class ZeroCouponBondVasicekTree, which encapsulates a zero coupon bond with payoff 1 at its maturity date N. Create a new source file EurOptionVasicekTree.cpp containing the implementation of the function EurOptionVasicekTree::Price() using the infor- mation below.
The payoff of a European style derivative with maturity date N can be represented by the numbers H(−kN ), H(−kN + 1), . . . , H(kN ) where kN = min{kmax, N}, and where H(k) is the payoff of the derivative at each node k at time step N. The price P(n,k) at each node k at some earlier time step n < N is then calculated by means of the following procedure: • At time step N, let P(N,k) = H(k) for all k = −kN,...,kN. • At every time step l = N−1,N−2,...,n, assume that kl+1 is known, as well as P(l+1,k) for all k = −kl+1,...,kl+1. Then define kl = min{kmax, l} and P (l, k) = e−r(l,k)∆t (pk,dk P (l + 1, dk ) + pk,mk P (l + 1, mk ) + pk,uk P (l + 1, uk )) for all k = −kl,...,kl. If n = 0, then the number P (0, 0) is referred to as the price of the derivative at time 0. Technical note for Task 3 You can use the ceil() function in the cmath library to determine kmax. The smallest integer larger than a given number x is (int)ceil(x). 4 Task 5: Call options on zero coupon bonds (10%) A European call option on a zero coupon bond with maturity date M is a financial asset with maturity date N < M that gives its holder the right, without obligation, to buy the zero coupon bond at a predetermined strike price K > 0 at time N. Its payoff at time N is therefore
max{B(N,M)−K,0},
where B(N,M) is the price of the zero coupon bond at time N.
Create a subclass CallOption of EurOptionVasicekTree in a new header file CallOption.h to
represent European call options on zero coupon bonds in the Vasiˇcek tree model. The subclass should use the class ZeroCouponBondVasicekTree that is defined in Project.h. This header file may be accompanied by a code file CallOption.cpp if appropriate.
Task 6: Numerical study of call options (20%)
Your program should perform a numerical study of the prices of call options. In this task, your program should use the values of α, r0 and T entered by the user, and the calculated values of θ and σ, all from Task 1. It should ask the user to enter the strike K of a call option on a zero coupon bond with maturity date T.
Your program should produce a file prices.csv using the comma separated values (csv) format. It should contain a table of call option prices, together with appropriate row and column headings. Every row m = 1, 2, . . . , 10 corresponds to the Vasiˇcek tree with
∆t = T , M
where M = 100m, and contains 10 column entries. The first entry is the price at time 0 of a zero coupon bond in the Vasicek tree with maturity date M, and for n = 2,…,10, the nth entry in the row is the price at time 0 of a call option with strike K on a zero coupon bond in the Vasiˇek trinomial tree, where the maturity date of the bond is M, and the maturity date of the option is
N = n − 1 × M = 10(n − 1)m. 10
Technical notes for Task 6
• A sample file prices.csv has been provided to illustrate the structure of the output. Your output should contain numerical results in place of each of the entries marked “price”, and you may vary the heading text if you wish.
• Spreadsheet applications (e.g. Microsoft Excel) can be used to open .csv files and create graphs from the data they contain.
Submission instructions
Submit your work by uploading it in Moodle by 1pm on Monday 4 May 2020.
5

Format
Submit the code as a single compressed .zip file, including all Code::Blocks project (.cbp) files, data files (.csv), source code and header (.cpp and .h) files and the executable (.exe) file produced by compiling and linking the project, all residing in a single parent directory. The .zip file should preserve the subdirectory structure of the parent directory (that is, the subdirectory structure must be automatically recreated when unzipping the file). It must be possible to open all project files and to compile, link and run the project using the version of Code::Blocks running on computer lab machines.
The code should be accompanied by detailed documentation, split into two parts:
1. Code developer documentation containing information to help understand the code. It should contain the following:
• Description of the file structure.
• Description of the available classes and functions.
• Instructions on how to extend the code by adding new options or derivatives. • Test runs, including tables. Graphs are optional but encouraged.
The developer documentation should not include extensive extracts from the code (brief snippets are perfectly fine, if typeset correctly—no screenshots!), and there is no need to describe the mathematical methods in any detail. It is expected that the developer documentation will be less than 10 pages in length.
2. The end user instructions should contain instructions on how to use the compiled .exe program, how to input data and how the results are presented, and a brief description of the methods implemented. The contents of this document should be appropriate for a reader who is not familiar with C++. It is expected that the end user instructions will be less than 5 pages in length.
The documentation files must be submitted in .pdf format (two separate .pdf files containing developer documentation and user instructions) and uploaded in Moodle separately from the code .zip file.
It is advisable to allow enough time (at least one hour) to upload your files to avoid possible congestion in Moodle before the deadline. In the unlikely event of technical problems in Moodle please email your .zip files to alet.roux@york.ac.uk before the deadline.
Code usage permissions and academic integrity
You may use and adapt any code submitted by yourself as part of this module, including your own solutions to the exercises. You may use and adapt all C++ code provided in Moodle as part of this module, including code from Capin ́ski & Zastawniak (2012) and the solutions to exercises. Any code not written by yourself must be acknowledged and referenced both in your source files and developer documentation.
This is an individual project. You may not collaborate with anybody else or use code that has not been provided in Moodle. You may not use code written by other students. Collusion and plagiarism detection software will be used to detect academic misconduct, and suspected offences will be investiaged.
6

If things go wrong
Late submissions will incur penalties according to the standard University rules for assessed work.
It must be possible to open all project files and to compile, link and run the project using the version of Code::Blocks running on computer lab machines. It may prove impossible to examine projects that cannot be unzipped and opened, compiled and run on computer lab machines directly from the directories created by unzipping the submitted .zip files. In such cases a mark of 0 will be recorded. It is therefore essential that all project files and the directory structure are tested thoroughly on computer lab machines before being submitted in Moodle. It is advisable to run all such tests starting from the .zip files about to be submitted, and using a different lab computer to that on which the files have been created.
All files must be submitted inside the zipped project directory, and all the files in the project directory should be connected to the project. A common error is to place some files on a network drive rather than in the submitted directory. Please bear in mind that testing on a lab computer may not catch this error if the machine has access to the network drive. However, the markers would have no access to the file (since they have no access to your part of the network drive) and would be unable to compile the project.
As part of the marking process, the file Project.h will be replaced. If the copy of Project.h used in a project has been modified in such a way that the code does not compile with the original file, then a mark of 0 will be recorded.
References
Capin ́ski, M. J. & Zastawniak, T. (2012), Numerical Methods in Finance with C++, Mastering Mathematical Finance, Cambridge University Press.
7