MAT00021M C++ Programming with Applications in Finance
作者:互联网
DEPARTMENT OF MATHEMATICS
C++ Programming with Applications in Finance
MAT00021M
Individual Project Deadline: 23:55 on 18/04/2019
Pricing European Two-Asset Options
and Chooser Options
Contents
Important Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Project Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Submission Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Important Information
This project contributes 30% towards the final mark for the module.
This is an individual programming project.
Background
There is a range of options whose payoff depends on more than one underlying asset; such options
are sometimes referred to as rainbow options. In order to price these multi-asset options,
we must model the price movements of all assets simultaneously.
Consider the case of an option whose payoff is based on the prices of two assets, S 0 and S 1.
The natural two-dimensional extension of the famous Black-Scholes model is
S 0(t) = S 0(0) exp.
Here, W0 and W1 are two independent Brownian motions; r ≥ 0 is the risk-free interest rate; q0
and q1 are the continuous dividend yields paid by S 0 and S 1, respectively; σ0 and σ1 are the
volatilities of S 0 and S 1, respectively; and ρ ∈ [?1, 1] is the correlation between the logarithmic
returns of S 0 and S 1. The current stock prices S 0(0) and S 1(0) are required to be strictly
positive.
Many of the most commonly traded options depend on the spread (S 0 ?S 1), sum (S 0 +S 1),
maximum (max{S 0, S 1}) or minimum (min{S 0, S 1}) of the prices of the two stocks. An example
1 of 10
C++ Programming with Applications in Finance Individual Project
of a two-asset option is the Margrabe option (also known as an exchange option), which allows
its owner to exchange S 1 for S 0 at the expiry date T if it is favourable to do so. In other words,
the terminal payoff from such an option is
h(S 0(T) , S 1(T)) = max{S 0(T) ? S 1(T) , 0} .
Its theoretical time-0 price in the two-dimensional Black-Scholes model is given by the formula
M(S 0, S 1, q0, q1, σ0, σ1, ρ, T) = eq0T
S 0(0) N(d+) eq1T
S 1(0) N(d) , (1)where d± B
log(S 0(0) /S 1(0)) +q1 q0 ± σ
(note that d= d+ σT),
is the cumulative distribution function of the standard normal distribution (note that there is no
dependence on r).
Other examples of options on two underlying assets include: basket options, whose payoff
is based on the total performance (more precisely, the sum) of the prices of the two underlying
assets; correlation options, which are regular options on one of the assets, except that they are
activated only when the other asset moves in or out of a specific range; and dual strike options,
whose payoff involves receiving the best payoff of two standard plain options. The table below
summarises the payoff functions of the various two-asset options just mentioned.
Two-Asset Option h(S 0(T) , S 1(T))
Margrabe max{S 0(T) S 1(T) , 0}
Basket Call (strike K) max{S 0(T) + S 1(T) K, 0}
Basket Put (strike K) max{K S 0(T) S 1(T) , 0}
Correlation Call (strikes K0, K1) max{S 1(T) K1, 0} 11{S 0(T)>K0}
Correlation Put (strikes K0, K1) max{K1 S 1(T) , 0} 11{S 0(T)<K0}
Dual Strike Call (strikes K0, K1) max{S 0(T) K0, S 1(T) K1, 0}
Dual Strike Put (strikes K0, K1) max{K0 S 0(T) , K1 S 1(T) , 0}
Calibration
Before a model can be used to price options, it needs to be calibrated—that is, the values of
the model parameters should be calculated to match observed market data.
In the two-dimensional Black-Scholes model above, quotes for the initial stock prices S 0(0)
and S 1(0), the risk-free interest rate r, and the dividend yields q0 and q1 are typically readily
available; by contrast, the volatilities σ0 and σ1 as well as the correlation coefficient ρ usually
need to be calibrated from the market.
Once σ0 and σ1 have been found, a popular way of calibrating ρ is to look up a quote Mquote
for the price of a traded European Margrabe option with expiry T, and then solve the non-linear
equation
M(S 0, S 1, q0, q1, σ0, σ1, ρ, T) = Mquote (2)
for ρ, where M(S 0, S 1, q0, q1, σ0, σ1, ρ, T) is the formula for the price of a Margrabe option
given in (1). In this way, we obtain an estimate for ρ, called the implied correlation and denoted
by ρimp. Once the model has been calibrated, it can be used to price a variety of options.
2 of 10
C++ Programming with Applications in Finance Individual Project
Tree approximation
While explicit pricing formulae can be derived for some options (such as the Margrabe option),
in general the only viable pricing method for many other options is approximation.
We can approximate the joint evolution of S 0 and S 1 in the continuous-time two-dimensional
Black-Scholes model over a ‘real’ time interval [0, T] with a two-dimensional binomial tree
with N time steps and step size ?t B T/N.
There are (n + 1)
2
different possibilities for the stock price at time step n in the tree model,
each of which is called a node. Each node at time n can be represented uniquely by an index
j = (j0, j1) consisting of two integers, j0 ∈ {0, 1, . . . , n ? 1, n} and j1 ∈ {0, 1, . . . , n ? 1, n}.
We now have four branches instead of two at every node, corresponding to the four possible
combinations of the two assets going up or down. More precisely, every node j = (j0, j1) at
time n has four successors at time step n + 1, with indices (j0, j1), (j0 + 1, j1), (j0, j1 + 1), and
(j0 + 1, j1 + 1). Assume that each of the successors has equal probability 1/4.
In such a tree, the stock prices
(n; j) at every step n ∈ {0, 1, . . . , N 1, N}
of the tree approximate the prices S 0(nt) and S 1(nt) at time nt in the continuous-time
model. Stock prices in the tree are given by the formulae
(n; j) = S 0(0) expn,
for all n and j = (j0, j1), where.
The price of a European option in the two-dimensional binomial model can then be used to
approximate its price in the two-dimensional Black-Scholes model. Denoting by H(n; j0, j1) the
European option price at each time step n and node (j0, j1) of the two-dimensional binomial tree
with expiry date N and payoff h(S 0(N; j0) , S 1(N; j1)), the European option pricing procedure
on a two-dimensional binomial tree is similar to that on a one-dimensional binomial tree, and
follows the CRR backward scheme described below:
At the expiry date N, set
H(N; j0, j1) = h
for all j0, j1 ∈ {0, 1, . . . , N 1, N}.At every time step n ∈ {N 1, N 2, . . . , 1, 0}, assume that H(n + 1; j0, j1) are already
known for all j0, j1 ∈ {0, 1, . . . , n, n + 1}. Then let
H(n; j0, j1) =H(n+1; j0, j1)+H(n+1; j0+1, j1)+H(n+1; j0, j1+1)+H(n+1; j0+1, j1+1)
for all j0, j1 ∈ {0, 1, . . . , n 1, n}.
In particular, the price of the option at time 0 is H(0; 0, 0).
3 of 10
C++ Programming with Applications in Finance Individual Project
Monte Carlo approximation
The number of computations in the multi-dimensional binomial tree model grows exponentially
with the number of underlying assets. Instead, we can employ Monte Carlo simulation,
which is relatively more efficient as the number of underlyings becomes larger (the number of
computations of Monte Carlo simulation grows only linearly with the number of assets).
The price of a path-independent European two-asset option with expiry time T and payoff
function h(S 0(T) , S 1(T)) can be approximated by Monte Carlo simulation, which involves
generating M random sample paths of the stock prices at m + 1 times tk B kT/m for k ∈
{0, 1, . . . , m}. The Monte Carlo method is as follows for each i ∈ {1, . . . , M}:
Generate 2m independent random samples W
1, . . . , W m and Z
1, . . . , Zm from a standard normal
distribution (e.g., using the Box-Muller method).
Generate a random price path for each asset, ,
for all k ∈ {1, . . . , m}.
The price of the option at time 0 is then approximated by.
Chooser options
A chooser option (sometimes referred to as an as-you-like-it option) is a contract with the
feature that, at a specified future time T0 > 0 prior to the expiry date T, the holder has the right
to decide between two options. In other words, the value of the chooser option at the choice
time T0 is the best between the payoffs of the two options underlying the chooser. At the expiry
time T > T0 of the chooser option (as well as of the underlying options), the holder receives
the payoff of the option chosen at T0.
The CRR procedure for pricing a chooser option is an adaptation of the pricing procedures
for European options in a binomial tree. Let C(n; j0, j1) be the price of a chooser option, with
N steps to maturity, and N0 < N steps to choosing time, at each time step n ∈ {0, 1, . . . , N} and
node (j0, j1) of the two-dimensional binomial tree.
At the choosing step N0, set
C(N0; j0, j1) = max{H0(N0; j0, j1) , H1(N0; j0, j1)} ,
for all j0, j1 ∈ {0, 1, . . . , N0 ? 1, N0}. Here, H0(N0; j0, j1) and H1(N0; j0, j1) denote the prices
of the two underlying options, both with N steps to expiry, at time step N0 and node (j0, j1).
Each of these prices is calculated using the CRR pricing procedure for two-asset European
options given above.
4 of 10
C++ Programming with Applications in Finance Individual Project
At every time step n ∈ {N0 ? 1, . . . , 1, 0}, assume that C(n + 1; j0, j1) have already been
determined for all j0, j1 ∈ {0, 1, . . . , n, n + 1}. Then let
C(n+1; j0, j1)+C(n+1; j0+1, j1)+C(n+1; j0, j1+1)+C(n+1; j0+1, j1+1),
Finally, the price of the chooser option at time 0 is C(0; 0, 0).
Non-linear solvers
One of the most basic problems of numerical approximation involves finding a solution of an
equation of the form f(x) = c, for a given real-valued continuous function f of a single real
variable, and a real constant c.
The Regula Falsi method (also called of method of false position), like the bisection method,
generates approximations in such a way that the solution is always bracketed between successive
iterations.
The idea is as follows: First, choose initial approximations a and b such that f(a) ? c and
f(b) c have opposite signs. The approximation p1 is chosen as the x-intercept of the secant
line joining (a, f(a)) and (b, f(b)). To decide which secant line to use (i.e., the one through the
graph of f at a and p1, or at p1 and b) to compute the next approximation p2 and ensure that
the solution remains bracketed between approximations, we study the signs of f(p1) c and
f(b) c. The process is described below, and is always guaranteed to converge to a solution.
Start by specifying a, b such that f(a) c, f(b) c have opposite signs, as well as a required
accuracy ε > 0. Set a1 B a and b1 B b.
Proceed recursively as follows: for each n ∈ N compute
pn B bn (f(bn) c)
bn anf(bn) f(an).
Next, if f(pn) c and f(bn) c have opposite signs, then let
an+1 B pn and bn+1 B bn,
otherwise let
an+1 B an and bn+1 B pn,
The sequence {pn}n∈N converges (as n → +∞) to a solution x ∈ [a, b], and we can ensure an
accuracy of ε if we carry on the procedure as long as |pn bn| ≥ ε.
Project Tasks
The goal of this project is to create an option pricing application by completing the following
tasks based on the information provided above. You should use the given header file
Project.h without change.
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.
Below are some general hints:
5 of 10
C++ Programming with Applications in Finance Individual Project
Please be sure to read the submission instructions at the end of this document before starting
work on the project.
Please read all tasks carefully before starting work on the project. Note that tasks need not
be completed in the order that they are listed here.
Your 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 the source of
such code is acknowledged.
It is a good idea to test your project with a freshly downloaded copy of Project.h just
before submission.
1. Data input and calibration (15%)
Your program should start by asking the user to enter values for the initial stock prices S 0(0)
and S 1(0), the risk-free rate r, the dividend yields q0 and q1, and the volatilities σ0 and σ1.
Next, add to your project a new header file Solver04.h, which should contain the declaration
and definition of the template function
template <typename T>
double solveByRF(const T& Fct , double tgt , double lEnd , double rEnd ,
double acc)
implementing the Regula Falsi method described above for approximating solutions of nonlinear
equations.
Finally, compute the implied correlation ρimp by using the observed market price Mquote of a
Margrabe option, and solving the non-linear equation (2). Your program should ask the user to
enter Mquote, as well as the expiry date T and the number of time steps N; it should then display
the estimated value for ρimp (which should be accurate to at least 5 decimal places) once it has
been calculated.
Hint: Partial credit will be given if you use the bisection solver provided in the lectures, rather than the
Regula Falsi solver. You may be tempted to try the Newton-Raphson solver as well, in which case you
should bear in mind that convergence is not guaranteed.
2. Two-dimensional Black-Scholes model (10%)
The header file Project.h contains the definition of a TwoDimBSModel class representing the
two-dimensional Black-Scholes model described above. Add to your project a new source code
file TwoDimModels.cpp, and implement in it the genSamplePath method.
3. Two-dimensional binomial tree approximation (10%)
The header file Project.h also contains the definition of a TwoDimBinModel class representing
the two-dimensional binomial tree described above. Implement in the accompanying
source code file TwoDimModels.cpp all methods of the TwoDimBinModel class, which are
declared but not defined in the header file Project.h.
6 of 10
C++ Programming with Applications in Finance Individual Project
4. Two-asset option pricing (15%)
Also defined in Project.h is the TwoAssetOption class representing a generic option on two
underlying assets. Add to your project a new source code file named TwoAssetOptions.cpp,
and define in it all member functions of the TwoAssetOption class that are not defined in the
header file Project.h, namely:
the parametrised and copy constructors;
the ‘setter’ methods setT and setN;
priceByMC implementing the Monte Carlo method for pricing options;
priceByTree implementing the pricing procedure on a two-dimensional binomial tree described
above.
Note that some methods of the TwoAssetOption class are actually defined rather than just
declared in Project.h, and these should not be defined again in TwoAssetOptions.cpp.
5. Two-asset option payoffs (20%)
Add to your project a new header file TwoAssetOptions.h, and provide in it the definitions
of the following subclasses of the TwoAssetOption class:
Margrabe, representing a Margrabe option. Among other member functions, this class
should include a priceByBSFormula method (to implement the pricing formula (1) for
Margrabe options). It is worth considering whether this class can be used for the calibration
procedure in Task 1.
BasketCall and BasketPut, representing basket call and put options, respectively.
CorrCall and CorrPut, representing correlation call and put options, respectively.
DualStrikeCall and DualStrikePut, representing dual strike call and put options, respectively.
Each class should contain a parametrised constructor; moreover, the definitions of any member
functions not given in TwoAssetOptions.h should appear in TwoAssetOptions.cpp.
6. Chooser option pricing (10%)
The header file Project.h contains the definition of the Chooser class, encapsulating chooser
options (on two underlying options on two assets). Add to your project a new source code
file Chooser.cpp, where you should define the priceByTree method of Chooser described
above.
7. Numerical study of option prices (20%)
Your program should perform a numerical study of option prices, in two parts. In this task,
your program should use the parameter values entered by the user as part of Task 1.
Your program should produce two files, Margrabe.csv (with Margrabe option prices) and
Chooser.csv (with chooser option prices) using the correct comma separated values (.csv)
format.
7 of 10
C++ Programming with Applications in Finance Individual Project
The file Margrabe.csv should contain a table of Margrabe option prices, together with
appropriate row and column headings. Each row should consist of 5 column entries, as follows:
The first entry should show the number of steps to expiry N ∈ {100, 200, 300, 400, 500};
The second entry should be the price in the two-dimensional binomial tree, calculated with
the CRR method;
The remaining three entries should be the prices calculated with the Monte Carlo method
with M = 100000, M = 300000, and M = 500000 repetitions, respectively.
As for the file Chooser.csv, it should consist of a table of Chooser option prices on three
different pairs of underlying options: basket call and put options (with the same strike price K),
correlation call and put options (both with strike prices K0 = K1 = K), dual strike call and put
options (both with strike prices K0 = K1 = K). You should specify suitable 0 < Kmin < Kmax.
Each row l ∈ {1, . . . , 11} of the table in this file should contain the price at time 0 of each
chooser option with expiry time T = 1, choosing time T0 = 0.5, steps to expiry N = 500, and
K = Kmin +l 110
(Kmax Kmin) ,
in a two-dimensional binomial model with the same parameter values considered above. The
first entry should display the value of K, while the remaining three entries should be the prices
of the chooser option on a basket call and put, on a correlation call and put, and on a dual strike
call and put.
Each .csv file should contain the table of option prices, together with appropriate row
and column headings. Sample files Margrabe.csv and Chooser.csv have been provided to
illustrate the structure of the output (although you may vary the heading text if you wish).
Please include two sample files Margrabe.csv and Chooser.csv in your submission,
placed in the directory where your program will be producing these files. Please do not hardwire
any absolute paths into your program, as there paths may not exist on the marker’s computer.
Please include information in the end-user instructions on how these files can be used. In
addition, you should include reports on test runs of your code on 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 Chooser.csv output (namely,
the prices of the chooser options as functions of K).
Submission Instructions
Please submit your work by uploading it in Moodle by 23:55 on Thursday, 18th April. It
is advisable to allow enough time (at least one hour) to upload your files to avoid possible
congestion in Moodle before the deadline.
You may use and adapt all C++ code provided in Moodle as part of this module, including
the code developed in support of lectures or solutions to exercises. You may use and adapt
any code submitted by yourself (but not by other students) as part of this module, including
your own solutions to the exercises. Any code not written by yourself must be clearly
acknowledged.
8 of 10
C++ Programming with Applications in Finance Individual Project
Please submit your code as a single compressed .zip file with the name
PRJ<your student id>.zip
(e.g., PRJasmr500.zip), including all Code::Blocks project (.cbp) files, 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:
I 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 directions on how to extend the code by adding new payoffs. 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.
I End-user instructions, explaining how to use the compiled .exe program, how to
input data, and how the results are presented, as well as briefly describing the methods
implemented.
The documentation files must be submitted in .pdf format (namely, two separate .pdf
files containing developer documentation and user instructions), and uploaded in Moodle as
a single compressed .zip file separate from the code file with the name
DOC<your student id>.zip
It may prove impossible to examine projectsthat cannot be unzipped and opened, compiled,
and run on computer lab machines in Code::Blocks 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 be 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.
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 marker would have no access to the
file (since the marker has no access to your part of the network drive) and would be unable
to compile the project. All files must be submitted inside the zipped project directory, and
all of the files in the project directory should be connected to the project.
Please note that the header file Project.h must not be edited or changed in any way.
As part of the marking process, 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. It is therefore advisable to check for inadvertent
modifications by replacing Project.h with a freshly downloaded copy before submission.
9 of 10
C++ Programming with Applications in Finance Individual Project
In the unlikely event of technical problems in Moodle, please email your .zip files to
andrea[dot]meirelesrodrigues[at]york[dot]ac[dot]uk before the deadline.
Late submissions without an approved claim of Exceptional Circumstances Affecting Assessment
will incur penalties according to the standard University rules for assessed work.
10 of 10
MAT00021M作业代写、MATHEMATICS留学生作业代做、代写C++课程设计作业、C++编程作业调试
DEPARTMENT OF MATHEMATICS
C++ Programming with Applications in Finance
MAT00021M
Individual Project Deadline: 23:55 on 18/04/2019
Pricing European Two-Asset Options
and Chooser Options
Contents
Important Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Project Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Submission Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Important Information
This project contributes 30% towards the final mark for the module.
This is an individual programming project.
Background
There is a range of options whose payoff depends on more than one underlying asset; such options
are sometimes referred to as rainbow options. In order to price these multi-asset options,
we must model the price movements of all assets simultaneously.
Consider the case of an option whose payoff is based on the prices of two assets, S 0 and S 1.
The natural two-dimensional extension of the famous Black-Scholes model is
S 0(t) = S 0(0) exp.
Here, W0 and W1 are two independent Brownian motions; r ≥ 0 is the risk-free interest rate; q0
and q1 are the continuous dividend yields paid by S 0 and S 1, respectively; σ0 and σ1 are the
volatilities of S 0 and S 1, respectively; and ρ ∈ [?1, 1] is the correlation between the logarithmic
returns of S 0 and S 1. The current stock prices S 0(0) and S 1(0) are required to be strictly
positive.
Many of the most commonly traded options depend on the spread (S 0 ?S 1), sum (S 0 +S 1),
maximum (max{S 0, S 1}) or minimum (min{S 0, S 1}) of the prices of the two stocks. An example
1 of 10
C++ Programming with Applications in Finance Individual Project
of a two-asset option is the Margrabe option (also known as an exchange option), which allows
its owner to exchange S 1 for S 0 at the expiry date T if it is favourable to do so. In other words,
the terminal payoff from such an option is
h(S 0(T) , S 1(T)) = max{S 0(T) ? S 1(T) , 0} .
Its theoretical time-0 price in the two-dimensional Black-Scholes model is given by the formula
M(S 0, S 1, q0, q1, σ0, σ1, ρ, T) = eq0T
S 0(0) N(d+) eq1T
S 1(0) N(d) , (1)where d± B
log(S 0(0) /S 1(0)) +q1 q0 ± σ
(note that d= d+ σT),
is the cumulative distribution function of the standard normal distribution (note that there is no
dependence on r).
Other examples of options on two underlying assets include: basket options, whose payoff
is based on the total performance (more precisely, the sum) of the prices of the two underlying
assets; correlation options, which are regular options on one of the assets, except that they are
activated only when the other asset moves in or out of a specific range; and dual strike options,
whose payoff involves receiving the best payoff of two standard plain options. The table below
summarises the payoff functions of the various two-asset options just mentioned.
Two-Asset Option h(S 0(T) , S 1(T))
Margrabe max{S 0(T) S 1(T) , 0}
Basket Call (strike K) max{S 0(T) + S 1(T) K, 0}
Basket Put (strike K) max{K S 0(T) S 1(T) , 0}
Correlation Call (strikes K0, K1) max{S 1(T) K1, 0} 11{S 0(T)>K0}
Correlation Put (strikes K0, K1) max{K1 S 1(T) , 0} 11{S 0(T)<K0}
Dual Strike Call (strikes K0, K1) max{S 0(T) K0, S 1(T) K1, 0}
Dual Strike Put (strikes K0, K1) max{K0 S 0(T) , K1 S 1(T) , 0}
Calibration
Before a model can be used to price options, it needs to be calibrated—that is, the values of
the model parameters should be calculated to match observed market data.
In the two-dimensional Black-Scholes model above, quotes for the initial stock prices S 0(0)
and S 1(0), the risk-free interest rate r, and the dividend yields q0 and q1 are typically readily
available; by contrast, the volatilities σ0 and σ1 as well as the correlation coefficient ρ usually
need to be calibrated from the market.
Once σ0 and σ1 have been found, a popular way of calibrating ρ is to look up a quote Mquote
for the price of a traded European Margrabe option with expiry T, and then solve the non-linear
equation
M(S 0, S 1, q0, q1, σ0, σ1, ρ, T) = Mquote (2)
for ρ, where M(S 0, S 1, q0, q1, σ0, σ1, ρ, T) is the formula for the price of a Margrabe option
given in (1). In this way, we obtain an estimate for ρ, called the implied correlation and denoted
by ρimp. Once the model has been calibrated, it can be used to price a variety of options.
2 of 10
C++ Programming with Applications in Finance Individual Project
Tree approximation
While explicit pricing formulae can be derived for some options (such as the Margrabe option),
in general the only viable pricing method for many other options is approximation.
We can approximate the joint evolution of S 0 and S 1 in the continuous-time two-dimensional
Black-Scholes model over a ‘real’ time interval [0, T] with a two-dimensional binomial tree
with N time steps and step size ?t B T/N.
There are (n + 1)
2
different possibilities for the stock price at time step n in the tree model,
each of which is called a node. Each node at time n can be represented uniquely by an index
j = (j0, j1) consisting of two integers, j0 ∈ {0, 1, . . . , n ? 1, n} and j1 ∈ {0, 1, . . . , n ? 1, n}.
We now have four branches instead of two at every node, corresponding to the four possible
combinations of the two assets going up or down. More precisely, every node j = (j0, j1) at
time n has four successors at time step n + 1, with indices (j0, j1), (j0 + 1, j1), (j0, j1 + 1), and
(j0 + 1, j1 + 1). Assume that each of the successors has equal probability 1/4.
In such a tree, the stock prices
(n; j) at every step n ∈ {0, 1, . . . , N 1, N}
of the tree approximate the prices S 0(nt) and S 1(nt) at time nt in the continuous-time
model. Stock prices in the tree are given by the formulae
(n; j) = S 0(0) expn,
for all n and j = (j0, j1), where.
The price of a European option in the two-dimensional binomial model can then be used to
approximate its price in the two-dimensional Black-Scholes model. Denoting by H(n; j0, j1) the
European option price at each time step n and node (j0, j1) of the two-dimensional binomial tree
with expiry date N and payoff h(S 0(N; j0) , S 1(N; j1)), the European option pricing procedure
on a two-dimensional binomial tree is similar to that on a one-dimensional binomial tree, and
follows the CRR backward scheme described below:
At the expiry date N, set
H(N; j0, j1) = h
for all j0, j1 ∈ {0, 1, . . . , N 1, N}.At every time step n ∈ {N 1, N 2, . . . , 1, 0}, assume that H(n + 1; j0, j1) are already
known for all j0, j1 ∈ {0, 1, . . . , n, n + 1}. Then let
H(n; j0, j1) =H(n+1; j0, j1)+H(n+1; j0+1, j1)+H(n+1; j0, j1+1)+H(n+1; j0+1, j1+1)
for all j0, j1 ∈ {0, 1, . . . , n 1, n}.
In particular, the price of the option at time 0 is H(0; 0, 0).
3 of 10
C++ Programming with Applications in Finance Individual Project
Monte Carlo approximation
The number of computations in the multi-dimensional binomial tree model grows exponentially
with the number of underlying assets. Instead, we can employ Monte Carlo simulation,
which is relatively more efficient as the number of underlyings becomes larger (the number of
computations of Monte Carlo simulation grows only linearly with the number of assets).
The price of a path-independent European two-asset option with expiry time T and payoff
function h(S 0(T) , S 1(T)) can be approximated by Monte Carlo simulation, which involves
generating M random sample paths of the stock prices at m + 1 times tk B kT/m for k ∈
{0, 1, . . . , m}. The Monte Carlo method is as follows for each i ∈ {1, . . . , M}:
Generate 2m independent random samples W
1, . . . , W m and Z
1, . . . , Zm from a standard normal
distribution (e.g., using the Box-Muller method).
Generate a random price path for each asset, ,
for all k ∈ {1, . . . , m}.
The price of the option at time 0 is then approximated by.
Chooser options
A chooser option (sometimes referred to as an as-you-like-it option) is a contract with the
feature that, at a specified future time T0 > 0 prior to the expiry date T, the holder has the right
to decide between two options. In other words, the value of the chooser option at the choice
time T0 is the best between the payoffs of the two options underlying the chooser. At the expiry
time T > T0 of the chooser option (as well as of the underlying options), the holder receives
the payoff of the option chosen at T0.
The CRR procedure for pricing a chooser option is an adaptation of the pricing procedures
for European options in a binomial tree. Let C(n; j0, j1) be the price of a chooser option, with
N steps to maturity, and N0 < N steps to choosing time, at each time step n ∈ {0, 1, . . . , N} and
node (j0, j1) of the two-dimensional binomial tree.
At the choosing step N0, set
C(N0; j0, j1) = max{H0(N0; j0, j1) , H1(N0; j0, j1)} ,
for all j0, j1 ∈ {0, 1, . . . , N0 ? 1, N0}. Here, H0(N0; j0, j1) and H1(N0; j0, j1) denote the prices
of the two underlying options, both with N steps to expiry, at time step N0 and node (j0, j1).
Each of these prices is calculated using the CRR pricing procedure for two-asset European
options given above.
4 of 10
C++ Programming with Applications in Finance Individual Project
At every time step n ∈ {N0 ? 1, . . . , 1, 0}, assume that C(n + 1; j0, j1) have already been
determined for all j0, j1 ∈ {0, 1, . . . , n, n + 1}. Then let
C(n+1; j0, j1)+C(n+1; j0+1, j1)+C(n+1; j0, j1+1)+C(n+1; j0+1, j1+1),
Finally, the price of the chooser option at time 0 is C(0; 0, 0).
Non-linear solvers
One of the most basic problems of numerical approximation involves finding a solution of an
equation of the form f(x) = c, for a given real-valued continuous function f of a single real
variable, and a real constant c.
The Regula Falsi method (also called of method of false position), like the bisection method,
generates approximations in such a way that the solution is always bracketed between successive
iterations.
The idea is as follows: First, choose initial approximations a and b such that f(a) ? c and
f(b) c have opposite signs. The approximation p1 is chosen as the x-intercept of the secant
line joining (a, f(a)) and (b, f(b)). To decide which secant line to use (i.e., the one through the
graph of f at a and p1, or at p1 and b) to compute the next approximation p2 and ensure that
the solution remains bracketed between approximations, we study the signs of f(p1) c and
f(b) c. The process is described below, and is always guaranteed to converge to a solution.
Start by specifying a, b such that f(a) c, f(b) c have opposite signs, as well as a required
accuracy ε > 0. Set a1 B a and b1 B b.
Proceed recursively as follows: for each n ∈ N compute
pn B bn (f(bn) c)
bn anf(bn) f(an).
Next, if f(pn) c and f(bn) c have opposite signs, then let
an+1 B pn and bn+1 B bn,
otherwise let
an+1 B an and bn+1 B pn,
The sequence {pn}n∈N converges (as n → +∞) to a solution x ∈ [a, b], and we can ensure an
accuracy of ε if we carry on the procedure as long as |pn bn| ≥ ε.
Project Tasks
The goal of this project is to create an option pricing application by completing the following
tasks based on the information provided above. You should use the given header file
Project.h without change.
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.
Below are some general hints:
5 of 10
C++ Programming with Applications in Finance Individual Project
Please be sure to read the submission instructions at the end of this document before starting
work on the project.
Please read all tasks carefully before starting work on the project. Note that tasks need not
be completed in the order that they are listed here.
Your 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 the source of
such code is acknowledged.
It is a good idea to test your project with a freshly downloaded copy of Project.h just
before submission.
1. Data input and calibration (15%)
Your program should start by asking the user to enter values for the initial stock prices S 0(0)
and S 1(0), the risk-free rate r, the dividend yields q0 and q1, and the volatilities σ0 and σ1.
Next, add to your project a new header file Solver04.h, which should contain the declaration
and definition of the template function
template <typename T>
double solveByRF(const T& Fct , double tgt , double lEnd , double rEnd ,
double acc)
implementing the Regula Falsi method described above for approximating solutions of nonlinear
equations.
Finally, compute the implied correlation ρimp by using the observed market price Mquote of a
Margrabe option, and solving the non-linear equation (2). Your program should ask the user to
enter Mquote, as well as the expiry date T and the number of time steps N; it should then display
the estimated value for ρimp (which should be accurate to at least 5 decimal places) once it has
been calculated.
Hint: Partial credit will be given if you use the bisection solver provided in the lectures, rather than the
Regula Falsi solver. You may be tempted to try the Newton-Raphson solver as well, in which case you
should bear in mind that convergence is not guaranteed.
2. Two-dimensional Black-Scholes model (10%)
The header file Project.h contains the definition of a TwoDimBSModel class representing the
two-dimensional Black-Scholes model described above. Add to your project a new source code
file TwoDimModels.cpp, and implement in it the genSamplePath method.
3. Two-dimensional binomial tree approximation (10%)
The header file Project.h also contains the definition of a TwoDimBinModel class representing
the two-dimensional binomial tree described above. Implement in the accompanying
source code file TwoDimModels.cpp all methods of the TwoDimBinModel class, which are
declared but not defined in the header file Project.h.
6 of 10
C++ Programming with Applications in Finance Individual Project
4. Two-asset option pricing (15%)
Also defined in Project.h is the TwoAssetOption class representing a generic option on two
underlying assets. Add to your project a new source code file named TwoAssetOptions.cpp,
and define in it all member functions of the TwoAssetOption class that are not defined in the
header file Project.h, namely:
the parametrised and copy constructors;
the ‘setter’ methods setT and setN;
priceByMC implementing the Monte Carlo method for pricing options;
priceByTree implementing the pricing procedure on a two-dimensional binomial tree described
above.
Note that some methods of the TwoAssetOption class are actually defined rather than just
declared in Project.h, and these should not be defined again in TwoAssetOptions.cpp.
5. Two-asset option payoffs (20%)
Add to your project a new header file TwoAssetOptions.h, and provide in it the definitions
of the following subclasses of the TwoAssetOption class:
Margrabe, representing a Margrabe option. Among other member functions, this class
should include a priceByBSFormula method (to implement the pricing formula (1) for
Margrabe options). It is worth considering whether this class can be used for the calibration
procedure in Task 1.
BasketCall and BasketPut, representing basket call and put options, respectively.
CorrCall and CorrPut, representing correlation call and put options, respectively.
DualStrikeCall and DualStrikePut, representing dual strike call and put options, respectively.
Each class should contain a parametrised constructor; moreover, the definitions of any member
functions not given in TwoAssetOptions.h should appear in TwoAssetOptions.cpp.
6. Chooser option pricing (10%)
The header file Project.h contains the definition of the Chooser class, encapsulating chooser
options (on two underlying options on two assets). Add to your project a new source code
file Chooser.cpp, where you should define the priceByTree method of Chooser described
above.
7. Numerical study of option prices (20%)
Your program should perform a numerical study of option prices, in two parts. In this task,
your program should use the parameter values entered by the user as part of Task 1.
Your program should produce two files, Margrabe.csv (with Margrabe option prices) and
Chooser.csv (with chooser option prices) using the correct comma separated values (.csv)
format.
7 of 10
C++ Programming with Applications in Finance Individual Project
The file Margrabe.csv should contain a table of Margrabe option prices, together with
appropriate row and column headings. Each row should consist of 5 column entries, as follows:
The first entry should show the number of steps to expiry N ∈ {100, 200, 300, 400, 500};
The second entry should be the price in the two-dimensional binomial tree, calculated with
the CRR method;
The remaining three entries should be the prices calculated with the Monte Carlo method
with M = 100000, M = 300000, and M = 500000 repetitions, respectively.
As for the file Chooser.csv, it should consist of a table of Chooser option prices on three
different pairs of underlying options: basket call and put options (with the same strike price K),
correlation call and put options (both with strike prices K0 = K1 = K), dual strike call and put
options (both with strike prices K0 = K1 = K). You should specify suitable 0 < Kmin < Kmax.
Each row l ∈ {1, . . . , 11} of the table in this file should contain the price at time 0 of each
chooser option with expiry time T = 1, choosing time T0 = 0.5, steps to expiry N = 500, and
K = Kmin +l 110
(Kmax Kmin) ,
in a two-dimensional binomial model with the same parameter values considered above. The
first entry should display the value of K, while the remaining three entries should be the prices
of the chooser option on a basket call and put, on a correlation call and put, and on a dual strike
call and put.
Each .csv file should contain the table of option prices, together with appropriate row
and column headings. Sample files Margrabe.csv and Chooser.csv have been provided to
illustrate the structure of the output (although you may vary the heading text if you wish).
Please include two sample files Margrabe.csv and Chooser.csv in your submission,
placed in the directory where your program will be producing these files. Please do not hardwire
any absolute paths into your program, as there paths may not exist on the marker’s computer.
Please include information in the end-user instructions on how these files can be used. In
addition, you should include reports on test runs of your code on 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 Chooser.csv output (namely,
the prices of the chooser options as functions of K).
Submission Instructions
Please submit your work by uploading it in Moodle by 23:55 on Thursday, 18th April. It
is advisable to allow enough time (at least one hour) to upload your files to avoid possible
congestion in Moodle before the deadline.
You may use and adapt all C++ code provided in Moodle as part of this module, including
the code developed in support of lectures or solutions to exercises. You may use and adapt
any code submitted by yourself (but not by other students) as part of this module, including
your own solutions to the exercises. Any code not written by yourself must be clearly
acknowledged.
8 of 10
C++ Programming with Applications in Finance Individual Project
Please submit your code as a single compressed .zip file with the name
PRJ<your student id>.zip
(e.g., PRJasmr500.zip), including all Code::Blocks project (.cbp) files, 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:
I 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 directions on how to extend the code by adding new payoffs. 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.
I End-user instructions, explaining how to use the compiled .exe program, how to
input data, and how the results are presented, as well as briefly describing the methods
implemented.
The documentation files must be submitted in .pdf format (namely, two separate .pdf
files containing developer documentation and user instructions), and uploaded in Moodle as
a single compressed .zip file separate from the code file with the name
DOC<your student id>.zip
It may prove impossible to examine projectsthat cannot be unzipped and opened, compiled,
and run on computer lab machines in Code::Blocks 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 be 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.
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 marker would have no access to the
file (since the marker has no access to your part of the network drive) and would be unable
to compile the project. All files must be submitted inside the zipped project directory, and
all of the files in the project directory should be connected to the project.
Please note that the header file Project.h must not be edited or changed in any way.
As part of the marking process, 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. It is therefore advisable to check for inadvertent
modifications by replacing Project.h with a freshly downloaded copy before submission.
9 of 10
C++ Programming with Applications in Finance Individual Project
In the unlikely event of technical problems in Moodle, please email your .zip files to
andrea[dot]meirelesrodrigues[at]york[dot]ac[dot]uk before the deadline.
Late submissions without an approved claim of Exceptional Circumstances Affecting Assessment
will incur penalties according to the standard University rules for assessed work.
10 of 10
因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:99515681@qq.com
微信:codinghelp
标签:option,Programming,j0,two,j1,Applications,MAT00021M,should,options 来源: https://www.cnblogs.com/pythonhelpyou/p/10623140.html