Project 2 (50% of the final mark)

Trinomial model for options pricing

using object-oriented programming

C++ Programming with Applications to Finance Summer 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 trinomial 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)

Fig. 1. Trinomial tree (source http://pubs.sciepub.com/jfe/7/3/1/)

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 or stay at the same level (if you refer to figure 1 then it means m=1). In the trinomial model there is a risk-free security growing by a factor (1+r) during each time step.

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 two types of path dependent options: a Parisian option and a fixed strike Asian call option (with arithmetic average).

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

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)<K) then the payoff is zero. 

Fixed strike Asian call payoff is given by , where A(0,T) stands for arithmetic mean .


General hints and tips

● 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.

        This project contributes 50% to the mark for this module. The deadline for submission is 23:59pm on Friday 20 August 2021. 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.


Task.

You will do this project in the object-oriented paradigm. There are 9 header files and 2 cpp files attached to the task. You project must include the following classes:

1) TriModel (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)

One class that does not have an h file is AsianCallOption. It means that the class 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 documentation.

TriModel.h and TriModel.cpp form the class for trinomial model. Their structure is similar to the structure of the class for binomial model (please refer to BinModel02.h and BinModel02.cpp from the project for the book Capinski & Zastawniak (2012)). However, the logic in the TriModel class is more complex. As at each nodes the pricing process is branching into three possible nodes, the risk-neutral probability consists of three components:

i) the risk-neutral probability pu of the price of the underlying asset moving up,

ii) the risk-neutral probability ps of the price of the underlying asset staying at the same level (a horizontal edge on the tree diagram), or

iii) the risk-neutral probability pd of the price of the underlying asset moving down.

The values pu, ps and pd must satisfy normalizing condition  and a risk-neutral condition There are 2 equations with 3 unknowns. To resolve this issue the user must enter the value of ps (the class member RiskNeutProbDown reducing the number of unknowns to 2 and one can easily find formulas for pu and pd from these equations. These formulas should be used in the functions RiskNeutProbUp and RiskNeutProbDown respectively.

Class Pathinfo contains information about a single path: its number, the path itself represented as a vector of length N of numbers from {-1,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 risk-neutral 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 {-1,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 these 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 trinomial 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).

Both path dependent options that you need to price in this project are 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 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 3N 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 = 4 then an array {-1,0,0,1,1} may correspond to the underlying asset going down, then staying at the same level two times and finally going up two times in periods 4 and 5, i.e. getting S1=S0(1+D), S2=S0(1+D), S3=S0(1+D), S4=(1+D)(1+U) and S5=(1+D)(1+U)2, if one codes an upward moving of the asset with 1, a downward moving with -1 and remaining on the previous level with 0 (or perhaps, one may choose to use the elements of the array to 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 j times equals , where pu, ps and pd are the risk-neutral probabilities introduced earlier.

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 Asian call and Parisian options according to the formulas listed on page 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 Friday 20 August 2021.

Format

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 [email protected] 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 work.

        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.


References

Capinski, M. J. & Zastawniak, T. (2012), Numerical Methods in Finance with C++, Mastering

    Mathematical Finance, Cambridge University Press.