C++实验程序代做、代写c++程序、代写program编程语言 代做R语言编程|代写Database

- 首页 >> Algorithm 算法作业
Project 2 (50% of the final mark)
Path dependent options pricing
using object-oriented programming
C++ Programming with Applications to Finance Spring 2021
The aim of this project is to create a program in C++ that can be used to study the prices of Path
Dependent on an underlying asset driven by a binomial model in discrete time. Your program
should be accompanied by end-user and developer documentation. The project is aimed at testing
your knowledge from the Term 2 of the course and must be implemented in the object-oriented
programming paradigm. You must use object-oriented approach when creating this project.
A path dependent option is an exotic option that's value depends not only on the price of the
underlying asset but the path that asset took during all or part of the life of the option.
(source: Investopedia)
We assume that the price of the underlying is strictly positive at moment 0 (S0 = S(0) > 0) and at
each moment t in can either move up (1+u) times or down (1+d) times. As always in the binomial
model there is a risk-free security growing by a factor (1+r) during each time step. For more
details on binomial model please see Capinski & Zastawniak (2012) pp. 1-2.
Further we use S(t) for the price of the underlying asset at moment t, K for the strike, T for
maturity and A(0,T) for the average price for the period [0, T].
You should create a project that includes pricing of four types of path dependent options: a
lookback option, a fixed strike Asian call option (with arithmetic average), a Parisian option and
the one that we will refer to as Consecutive Growth option.
A lookback option is a path dependent option where the option owner has the right to buy the
underlying instrument at its lowest price over some preceding period:
( ( ) ( ))
min lookback t T
C S T S t
 
= −
. Pleases notice that the minimum is taken over all
t T 0, .
Fixed strike Asian call payoff is given by
C A T K Asian Call = − max 0, , 0 ( ( ) ) , where A(0,T) stands
for arithmetic mean
( ) ( )
A T S t
T =
=  .
The payoff of a standard Parisian option is dependent on the maximum amount of time the
underlying asset value has spent consecutively above or below a strike price
( ) ( ) ( )
( )   ( )
, 1 ,...,
max 1 , 0,
S s K S s K S t K
t s if t T such that S t K
 +  
 − +    
= 
. Notice that we
consider the maximal number of consecutive moments (not the periods between the moments)
when the price S(t) of the underlying is at or above some strike value K, and the payoff equals the
number of the moments in such streak. If at all moments from 0 to T the price S(t) is below K (i.e.,
S(t)The payoff of the Consecutive Growth option is also defined in terms of the number of days:
( ) ( ) ( )
( )   ( ) ( )
max , 0, 1 1
S s S s S t
Consecutive Growth
t s if t T such that S t S t
 + 
 −   −  + 
= 
. Notice that
we consider the maximal number of consecutive periods (not the moments, but the periods
between them) of growth when the price S(t) of the underlying is non-decreasing. If the price S(t)
always decreases, then the payoff is zero.
General hints and tips
• Read the submission instructions at the end of this document before starting work on the
• 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
This project contributes 50% to the mark for this module. The deadline for submission is
23:59pm on Monday 17 May 2021 (Week 5 Summer Term). 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.
You will do this project in the object-oriented paradigm. There are 10 header files and 2 cpp files
attached to the task. You project must include the following classes:
1) BinModel (h file and cpp files are attached to the task)
2) Pathinfo (h file is attached to the task)
3) AllPaths (h file is attached to the task)
4) PricePathGenerator (h file is attached to the task)
5) Option (h file is attached to the task)
6) EurOption (h file is attached, the class is intentionally left empty as it is not a matter of
interest in this project and you do NOT need to write any implementation in this class)
7) AmOption (h file is attached, the class is intentionally left empty as it is not a matter of
interest in this project, and you do NOT need to write any implementation in this class)
8) PathDependentOption (h file is attached to the task)
9) AsianCallOption
10) ParOption (h file is attached to the task)
11) LookbackOption
12) GrowOption (h file is attached to the task)
Two classes that do not have h files are AsianCallOption and LookbackOption. It means that they
must be created from scratch. If you want you can create additional classes or members in the
existing classes, but you must justify and describe them in the comments and in the
BinModel.h and BinModel.cpp form the class for binomial model (they repeat BinModel02.h and
BinModel02.cpp from the project for the book Capinski & Zastawniak (2012)). This class is
already implemented.
Class Pathinfo contains information about a single path: its number, the path itself represented
as a vector of length N of numbers from {0,1} set (according to the bijection explained below, you
need to create and implement this bijection), the vector of prices along this path and the riskneutral
probability of this path. Please notice that the main goal this class to store the information
about the path and provide an access to this information via getters. Generation of the path (as a
vector of numbers from {0,1}), the prices along the path and the probability of the path are left in
a separate class PricePathGenerator. Finally, class AllPaths contains the vector of objects of
PathInfo and a method GetPathsNumber that returns the number of paths in the vector. Such
design provides greater flexibility as, for example, one may prefer to read the paths, from the file
instead of generating them in the program. Notice that three classes mentioned in this paragraph
are related to the price paths of the underlying assets only and do not require a presence of any
options. If the paths are needed for some reasons other than option pricing, then these classes
can be used there as well. You need to write implementation of all necessary functions in this
classes. You are allowed to add members to these classes, but you must justify and describe them
all in the comments and in the documentation.
There are several classes related to the options. First, there is a general class Option, that has
three children: class EurOption of European options, class AmOption of American options and
class PathDependentOption of path dependent options. Classes EurOption and AmOption are
intentionally left totally empty as they are not a matter of interest in this project, and you do NOT
need to write any implementation in these two classes. Class Option contains the information
about the binary model Model associated with this option and the number of steps to expiry N, it
also has a virtual function GetPrice that will be redefine in the subclasses and will return the price
of the option.
Class PathDependentOption is inherited from Option and should contain information about all
paths, a virtual function GetPayoffByPathInfo that will be redefined in the subclasses and return
a payoff on each path. It also has a sketch of a GetPrice function that prices a path dependent
option (the implementation of this function must be moved to a corresponding cpp file, you may
also want to modify it).
All four path dependent options that you need to price in this project: Lookback, Asian call,
Parisian, and Consecutive Growth options are particular cases of path dependent options. Their
classes then must be inherited from PathDependentOption. Class ParOption stands for Parisian
option, class GrowOption stands Consecutive Growth option. Notice that there is a considerable
difference between these two options as Parisian option has an extra parameter Strike price. You
need to create a class AsianCallOption for Asian call option and a class LookbackOption for
Lookback option from scratch. Perhaps, you will want to create some intermediary classes such
as AsianOption for Asian options. If you decide to create such class, then you must justify and
document it properly. When working on the project, please keep in mind the idea of the
reusability of your code and its possible extensions. These aspects must necessarily be
addressed in the documentation.
Your program should ask the user to enter the value of the parameters S0, U, D, R, Ka (a strike
price for the Asian Call option), Kp (a strike price for the Parisian option) and N (the number of
steps to expiry – the same as T in the description of the model).
Clearly, for the N-period model there are 2N different paths, and one can easily construct a
bijection between these paths and the set of arrays of length N consisting of zeros and ones. For
example, if N = 3 then then an array {0,0,1} may correspond to the underlying asset growing in
the first two periods and then falling in the period 3, i.e. getting S1=S0(1+U), S2=S0(1+U)2 and
S3=S0(1+U)2(1+D), if one codes an upward moving of the asset with 0 and a downward moving
with 1 (or falling in the first two periods and then growing in the period 3 if one codes a
downward moving of the asset with 0 and an upward moving with 1, or perhaps, even the
elements of the array may describe the changes in the underlying asset in the opposite order with
the last elements corresponding to the moves in the first periods – you can use any approach that
suits you, but you need to describe it carefully and be consistent). For this purpose, you should
use the function GenPathByNumber.
After successfully coding the path with number x as an array of zeros and ones you can generate
a vector of prices along this path with GenPricesByPath. The probability of moving along the path
should be calculated with GenProbabilityByPath. The probability of getting a path along which the
price moves up i times and down (N-i) times equals qi(1-q)
, where q is the risk-neutral


For pricing the option, one needs to find the discounted value of the average payoff. The main
difficulty you may face is that the payoff is defined by all values of the underlying asset along the
path, so the payoffs must be computed along each path separately.
Your program should then calculate the prices of Lookback, Asian call, Parisian, and Consecutive
Growth options according to the formulas listed on pages 1 and 2.
Please notice that this project tests your understanding of object-oriented programming. Before
writing a code, you need to think on the design of your project. As mentioned above, reusability
of your code and its possible extensions also affect the mark for the assignment!
Submission instructions
Submit your work by uploading it in Moodle by 23:59pm on Monday 17 May 2021 (Week 5
Summer Term).
Submit the code as a single compressed .zip file, including all Code::Blocks project (.cbp) files (if
you used Code::Blocks), source code and header (.cpp and .h) files, 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).
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 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 sergei.belkov@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 Capinski & 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 investigated.
If things go wrong
Late submissions will incur penalties according to the standard University rules for assessed
It may prove impossible to examine projects that cannot be unzipped and opened due to file
corruption, or projects that cannot be compiled and run due to coding errors. 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 your machine 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
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.
Capinski, M. J. & Zastawniak, T. (2012), Numerical Methods in Finance with C++, Mastering
Mathematical Finance, Cambridge University Press.