首页 > > 详细

Writing C/C++ Homework ,C/C++ Experiment Help With,Help C/C++ Programming,C/C++ Programming Cour

C++ Programming with Applications to Finance
Programming Project
Deadline: 27 April 2017
This project contributes 30% towards the nal mark for the module.
Background
The two-dimensional Black-Scholes model is
S0(t) = S0(0)e(r 12 20)t+ 0W0(t);
S1(t) = S1(0)e(r 12 21)t+ 1 W0(t)+ 1
p
1 2W1(t);
where W0 and W1 are two independent Brownian motions, r 0 is the interest rate, 0 > 0
and 1 > 0 are the volatilities of S0 and S1 respectively, and 2 [ 1;1] is the correlation
between the logarithmic returns of S0 and S1. The current stock prices S0(0) and S1(0) are
required to be positive.
Calibration
Before the model can be used to price options, it needs to be calibrated, that is, the values
of the parameters should be calculated to match market data. Quotes for S0(0), S1(0) and r
are readily available, but not so for 0, 1 or . A popular way to calibrate 0, 1 and is
to estimate them from historical data. Suppose that stock prices S0;i;S1;i, i = 0;1;:::;m have
been recorded at some xed time intervals of length > 0 measured in years (for example,
= 1=12 for monthly recorded stock prices). The log returns on these prices over each time
interval of length are
rk;i = ln (Sk;i=Sk;i 1)
for k = 0;1 and i = 1;:::;m. The sample variances of these returns are s20 and s21, where
s2k = 1m 1
mX
i=1
r2k;i mm 1r2k
and
rk = 1m
mX
i=1
rk;i:
The sample covariance of these returns is
s01 = 1m 1
mX
i=1
r0;ir1;i mm 1r0r1:
1
The sample variance s2k estimates the variance 2k of the log return on the stock price Sk over
a time interval of length . We can therefore make the estimation
k = skp :
This is called the historical volatility. The historical correlation is then
= s01
0 1
:
Option pricing
Once the model has been calibrated, it can be used to price a variety of options. Many of the
most commonly traded options depend on the spread S0 S1, the minimum minfS0;S1g or
the maximum maxfS0;S1g of the prices of the two stocks. Here are three examples of payo
functions:
Spread call f(S0;S1) = maxfS0 S1 K;0g;
Min call f(S0;S1) = maxfminfS0;S1g K;0g;
Max call f(S0;S1) = maxfmaxfS0;S1g K;0g:
While explicit option pricing formulae can be found for some options, the only viable pricing
method for most options is approximation.
The continuous-time model can be approximated by a two-dimensional tree with step size
h > 0; note that h is usually di erent from the parameter used in calibration. In such a
tree, the stock prices Sh0 (n) and Sh1 (n) at every step n = 0;1;::: of the tree approximate the
prices S0(nh) and S1(nh) at time nh in the continuous-time model. There are (n+ 1)2 di erent
possibilities for the stock price at time step n in the tree model; each possibility is called a node.
Each node at time n can be represented uniquely in the form. (j0;j1) where j0 2f0;:::;ng,
j12f0;:::;ng. Every node (j0;j1) at time step n has four successors at time step n+1, namely
(j0;j1), (j0 + 1;j1), (j0;j1 + 1) and (j0 + 1;j1 + 1). Stock prices in the tree are given by the
formulae
Sh0 (n;j0;j1) = S0(0)e h0n+ h0(2j0 n);
Sh1 (n;j0;j1) = S1(0)e h1n+ h1(2j0 n)+ h2(2j1 n)
for all n and (j0;j1), where
h0 = (r 12 20)h; h0 = 0
p
h;
h1 = (r 12 21)h; h1 = 1
p
h;
h2 = 1
p
(1 2)h:
The risk-neutral probability of any node (j0;j1) at time n is
Qh(n;j0;j1) =
n
j0

(qh0)j0(1 qh0)n j0
n
j1

(qh1)j1(1 qh1)n j1;
where nj0 = n!(n k)!k! and qh0 and qh1 satisfy the system
erhS0(0) = (1 qh0)(1 qh1)Sh0 (1; 0;0) +qh0(1 qh1)Sh0 (1; 1;0)
+ (1 qh0)qh1Sh0 (1; 0;1) +qh0qh1Sh0 (1; 1;1); (1)
erhS1(0) = (1 qh0)(1 qh1)Sh1 (1; 0;0) +qh0(1 qh1)Sh1 (1; 1;0)
+ (1 qh0)qh1Sh1 (1; 0;1) +qh0qh1Sh1 (1; 1;1): (2)
2
The tree is said to be free of arbitrage if 0 Suppose that a European option with payo function f in the continuous-time model o ers
the payo f(S0(T);S1(T)) at time T. Its fair price at time 0 can be approximated by
h(f) = e rhN
NX
j0=0
NX
j1=0
Qh(N;j0;j1)f(Sh0 (N;j0;j1);Sh1 (N;j0;j1)) (3)
in the two-dimensional tree with time step h = TN.
Project tasks
Based on the above information, complete the following tasks. You should use the header le
Project.h, which should be included in your project without change.
The marks for each of the tasks below will be split into 60% for coding style, clarity, accuracy
and e ciency of computation, and 40% for documentation (including comments within the code)
and ease of use. Tasks do not have to be completed in the order that they are listed here. Credit
will be given for part completion of each task.
1. Calibration (20%)
Calibrate the Black-Scholes model by computing the historical volatilities 0 and 1 and the
historical correlation from a given sequence of historical stock prices S0;i, S1;i, i = 0;1;:::;m
recorded at equal time intervals of length . Your program should ask the user to enter a value
for , and display the values of 0, 1 and once they have been calculated.
Your program should read the time series of stock prices S0;i, S1;i i = 0;1;:::;m from a le
called data.csv in which each pair of numbers is listed on a separate line and separated by a
comma, as in the sample data.csv le provided. (The actual data.csv le used for testing
the program by the marker will contain a di erent and much longer time series.) Include a
data.csv le 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 le into your program, as this path is likely
to be di erent on the marker’s computer. Explain in the end-user instructions how to prepare
and provide the data.csv le so that your program can read it.
Hint. Refer to a good C++ manual to learn about reading input les. You may wish to
investigate the standard libraries iostream and fstream.
2. Two-dimensional Black-Scholes model (10%)
Your program should ask the user to enter values for S0(0), S1(0) and r. Implement all member
functions of the class BSModel2 that aren’t de ned in Project.h.
3. Tree approximation (25%)
Build the option pricing tree by implementing all member functions of the class CorrBinModel
that aren’t de ned in Project.h.
Choose an appropriate method for computing qh0 and qh1 accurately to within EPSILON (de-
ned in Project.h). You should provide details of the method used to solve (1){(2) in the
developer documentation.
Hint. Note that Sh0 (1; 0;0) = Sh0 (1; 0;1) and Sh0 (1; 1;0) = Sh0 (1; 1;1), and so (1) can be rear-
ranged to give
qh0 = e
rhS0(0) Sh0 (1; 0;0)
Sh0 (1; 1;0) Sh0 (1; 0;0):
3
4. Option payo (10%)
De ne and implement subclasses of the Payoff class for each of the example payo s given.
These subclasses will be used for both European and American option pricing.
5. Option pricing (15%)
Implement the pricing formula (3) for European options.
The function PriceAmerican in Project.h can be used to price American options. You
should analyse this function, and the documentation should include a full description of the
method used.
6. Numerical study of option prices (20%)
Your program should ask the user to enter a value for the expiry date T, choose an option payo
from the list of example payo s, and enter a minimum strike Kmin and maximum strike Kmax.
Your program should then produce two les, Eprices.csv (with European option prices)
and Aprices.csv (with American option prices) using the correct .csv format. Each le should
contain a table of option prices, together with appropriate row and column headings. Every
entry in the ith row (i = 0;:::;10) should correspond to an option with strike price
Ki = Kmin + i10(Kmax Kmin);
and every entry in the jth column (j = 1;:::;5) should correspond to an option with expiry
date 100j in the tree model with step size hj = T100j. A sample le Eprices.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".
Include two sample les Eprices.csv and Aprices.csv in your submission, placed in the
directory where your program will be producing these les. Do not hard wire any absolute paths
into your program, as these paths may not exist on the marker’s computer. Include information
in the end-user instructions on how these les can be used.
You should include reports on test runs of your code in a separate section of the developer
documentation. This section should include numerical results, comments on the convergence of
option prices, as well as graphs produced from your output.
1 Submission instructions
The code should be accompanied by detailed documentation, split into two parts:
Code developer documentation Presenting the structure of the code, available classes and
functions, main variables and any other information to help understand the code. This
should include information on how to extend the code by adding new payo s. Test runs of
your code, as well as more detailed explanations of the methods used, should be reported
in separate sections of the developer documentation.
End user instructions 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.
You may use and adapt all C++ code provided in Moodle as part of this module, including
the code developed in support of lectures and the solutions to exercises. You may use and adapt
any code submitted by yourself (but not by other students) as part of this module, including
4
your own solutions to the exercises. Any code not written by yourself must be clearly
acknowledged.
Submit your work by uploading it in Moodle by 23:55 on Thursday 27 April 2017. Submit
the code as a single compressed .zip le, including all Code::Blocks project (.cbp) les, data
les (.csv), source code and header (.cpp and .h) les and the executable (.exe) le produced
by compiling and linking the project, all residing in a single parent directory, whose name should
contain your name and student code. The .zip le should preserve the subdirectory structure
of the parent directory (that is, the subdirectory structure must be automatically recreated
when unzipping the le). It must be possible to open all project les and to compile, link and
run the project using the version of Code::Blocks running on computer lab machines.
The documentation les must be submitted in .pdf format (two separate .pdf les contain-
ing developer documentation and user instructions) and uploaded in Moodle as a single .zip
le separate from the code le. The .zip le containing documentation should also bear your
name and student number.
It is advisable to allow enough time (at least one hour) to upload your les to avoid possible
congestion in Moodle before the deadline. In the unlikely event of technical problems in Moodle
please email your .zip les to before the deadline. Late submissions
will incur penalties according to the standard University rules for assessed work.
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 sub-
mitted .zip les. In such cases a mark of 0 will be recorded. It is therefore essential that all
project les 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 les
about to be submitted, and using a di erent lab computer to that on which the les have been
created.
A common error is to place some les 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 le
(since they have no access to your part of the network drive) and would be unable to compile
the project. All les must be submitted inside the zipped project directory, and all the les in
the project directory should be connected to the project.
As part of the marking process, the le Project.h will be replaced. If the copy of Project.h
used in a project has been modi ed in such a way that the code does not compile with the
original le, then a mark of 0 will be recorded. It is therefore advisable to check for inadvertent
modi cation by replacing Project.h with a freshly downloaded copy before submission.
5
 

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!