C++ Programming with Applications to Finance Summer 2022 Resit
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
Trinomial Single- & Multi-stock option pricing
C++ Programming with Applications to Finance Summer 2022 Resit
The aim of this project is to create a program in C++ that can be used to price a variety of non-path dependent options for single-stock and multi-stock assets which are driven by a trinomial model discrete in time. The project is aimed at testing your knowledge from Term 2 of the course and must implement an object-orientated methodology.
General hints and tips
❼ This project description contains all the properties of pricing single- and multi-stock op-
tions on a trinomial model that is needed to complete this project. Further knowledge might make the project more interesting, but is not required, and will not give any ad- vantage 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.
This project contributes 50% of your final module mark. The deadline for submission is 11:59pm, 8th August, 2022. Credit will be given for partial completion of each task. Across the whole project, marks will be attributed to the readability and efficiency of your code, which will be awarded based on keeping a consistent coding style, sensible parameter names and indentations. Comments are encouraged (but need not be excessive).
Trinomial tree approximation
The famous Black-Scholes model from mathematical finance for a non-dividend paying stock can be formulated as
dSt = rStdt + σStWt ,
where r is the continuously compounded risk-free interest rate, σ > 0 is the volatility of the stock and W is a Brownian motion under the equivalent martingale measure. The Itˆo lemma of stochastic calculus allows us to derive the stochastic differential equation of the log-price xt = ln St as
dxt = νdt + σdWt . (1)
where
ν = r - σ 2 .
The linearity of this stochastic differential equation means that it is often more convenient to model x directly rather than the stock price S itself.
Explicit formulae have been derived for many types of options (including put and call op- tions); however approximation methods are needed to price many other options. One such method is the trinomial model. Let’s consider a trinomial model of the stock price in which, over a small time interval of length ∆t > 0, the log-price x can go up by ∆x > 0, stay the same, or go down by ∆x, with probabilities qu , qm and qd respectively. This is illustrated as follows.
x + ∆x |
| ∆t |
The features of the continuous-time process can now be captured by the parameters ∆x, ∆t, qu , qm and qd . Formula for the transition probabilities qu , qm and qd can be derived by matching the first two moments of the continuous-time process in (1) and the trinomial process over the time interval of length ∆t, in other words,
ν∆t = 与(∆x) = qu × ∆x + qm × 0 + qd × (-∆x),
σ 2 ∆t + ν2 (∆t)2 = 与((∆x)2 ) = qu × (∆x)2 + qm × 02 + qd × (-∆x)2 .
Solving this system for qu and qd, and requiring that the transition probabilities add up to 1, gives
qu = ; + 、 ,
qd = ; - 、 ,
qm = 1 - qu - qd .
There is some freedom in the choice of ∆x and ∆t; in this project we will use ∆x = σ ^2∆t.
This is a good choice for ∆x because it links the size of stock price movements with the length of the time interval over which such movements take place.
The trinomial process described above can be extended to form a trinomial tree. Starting from a given initial stock price S0 > 0, each time step n represents “real time” t = n∆t, and
the stock price at node i is
S(n, i) = S0ei∆北 ,
where i = -n, . . . , -1, 0, 1, . . . , n. The resulting tree is illustrated in the following figure.
S_3 , 3( 3 Soe3Aá
|
S_3 , 2( 3 Soe2Aá |
S_3 , −2( 3 Soe −2Aá |
The trinomial tree with N steps can be used to approximate the stock price movement over a “real” time interval [0, T] by setting ∆t = , and the price of an option in the trinomial model can be used to approximate its price in the Black-Scholes model.
Pricing single and multistock options on a trinomial model
The payoff H of an option price on M assets in general will depend on the price of the underlying assets at expiry, Sm(T) and their strike prices km for m e [1, M]. Options for a single stock can be priced by calculating the expected price of the asset at expiry time N , discounted with respected to the risk-free return and the total number of steps, which yields,
Price = ; 、N E ┌H ╱ Sm(N), km、! ,
Here, the expectation is taken over all possible nodes at expiry, i.e.,
N
E ┌H ╱ Sm(T), km、! = pm╱N, i、H ╱ Sm(N, i)), km、,
i=−N
where p(N, i) is the probability of the node i occuring at expiry time-step N .
In this project, we will consider four call/put options: a European option, and three options whose payoff is a variant on a European call/put option. Each option is defined as follows:
❼ A single stock vanilla (European), option whose payoff is determined by the difference
between a fixed-strike k and stock at expiry time T,
CEuro = max ╱S(T) - k, 0、,
PEuro = max ╱k - S(T), 0、,
❼ A single stock extendable option, where the holder can choose to extend the option by time te, where the length of the extension is given by ne > 0 time steps. The payoff H(N, i) at node i at expiry is given by,
H ╱ Sm(N, i), km(i)、= max ;h ╱Sm(N, i), km、, E [(h ╱Sm(N + ne), km、] 、,
where h can either be CEuro or Peuro .
❼ A single stock Bermudan option, where the holder can choose to exercise the option early at some time tb, corresponding to time step nb < N . The payoff at H(N, i) can be calculated similarly to the extendable option, but where the expectation is evaluated at nb, such that,
H ╱ Sm(nb, i), km(i)、= max ;h ╱Sm(nb, i), km、, E [(h ╱Sm(N), km、] 、,
where h can either be CEuro or Peuro .
❼ A multi stock Basket option, where the pricing is taken as a weighted average of M stocks with weighting wm, each defined with the same expiry time T and time steps N , such that,
Price = ; 、N M E [h ╱Sm(N), km、] ,
where h can either be CEuro or Peuro .
Task 1: Modify TriModel.h (5%)
The project starter files include TriModel .h and TriModel .cpp, a class which contains an implementation of a stock price evolving under a trinomial distribution with initial stock S0 , votaility σ and risk-free interest rate r . The class is a complete description of the stock price evolution, but should be lightly modified to be made fit for purpose. In this task, you should add functionality by directly modifying the header file and adding the ability to retrieve the number of time steps N , the expiry time T and adding a second constructor which additionally sets dt and dx when initialising a instance of TriModel.
Task 2: Implement TrinomialPayoff class (20%)
The starter files include a header file TrinomialPayoff .h. TrinomialPayoff is an abstract class for calculating the expectation of a payoff at a given node. For a model of N time steps, there are 2N + 1 nodes at expiry, where each node can be characterised by the number of up, same and down steps taken to arrive at that node. The probability of arriving at a node with nu up, nm same, and nd down steps, is given by,
p(nu, nm, nd) =
qu(n)u qm(nm)q
Your task is to declare and implement the following methods in the TrinomialPayoff header and code files,
❼ double TerminalProbability(int nu, int nm, int nd), the probability of a node with nu , nm and nd steps,
❼ double TerminalExpectation(int nu, int nm, int nd), an element of the expectation taken
over all nodes at expiry which is given by the payoff multiplied by the probability,
❼ double BranchExpectation(int N), the expected payoff taken over all 2N + 1 nodes which
should utilise TerminalExpectation,
❼ a pure virtual Payoff function.
You should think carefully about which variables and methods should be private, and which should be public.
Task 3: Implement Payoffs (10%)
The call and put fixed-strike payoffs are subclasses of TrinomialPayoff. Your task is to create two subclasses which implement these payoffs, with sensible private and public members, and a class constructor.
Task 4: Implement single stock and multi stock options(20%)
The project starter files include the header file Options .h, which contains two abstract classes: OneStockOption and MultiStockOption which both contain a pure virtual function getPrice. By declaring appropriate subclasses of these two abstract classes in the header and a correspond- ing code file, your task is to implement the definitions of the European, Extendable, Bermuda and Basket options as defined above, where each class has an appropriate constructor, private variables and any public members you see fit.
Task 5: Output (15%)
In main .cpp, you should implement the above methods to price European, Extendable and Bermuda call and put options with the parameters; S0 = 120, σ = 0.03, r = 0.15, N = 10, T = 5, and ne = 4, nb = 5. For the Basket option, you should use the following parameters:
Stock |
S0 |
σ |
r |
K |
w |
Bentley |
100 |
0.03 |
0.01 |
110 |
0.4 |
Ford |
115 |
0.04 |
0.01 |
130 |
0.22 |
Ferrari |
95 |
0.02 |
0.01 |
100 |
0.38 |
The output to the console should be neat, readable, and require no user-input. You will be marked on your coding neatness and for adhering to coding conventions.
Task 6: Documentation (15%)
You should write documentation for the TrinomialPayoff and Options classes, detailing each class and subclass, as well as the usage of all private and public member variables, detailing the inputs and outputs of member function.
Task 7: Discussion of OOP principles by code extensions (15%)
In this final task, you are required to discuss the four principles of object-orientated program- ming, Abstraction, Encapsulation, Inheritance, and Polymorphism in your program by answering the following questions,
1. In Task 1, you were asked to modify the TriModel .h file to make it fit for purpose. How could you have achieved the same functionality of setting dx, dt and retrieving N and T without modifying the header file directly?
2. In Task 3, you were asked to implement the call and put payoffs, discuss the following:
❼ How would you modify the code to allow for a dynamic strike price, such as a geo-
metric average?
❼ If you did not have access to the source code, how instead would you extend the code
to achieve the same functionality?
3. In Task 4, you were asked to implement a Basket option, a weighted average for a European call/put over multiple stocks. How could you have written this code to utilise the option pricing for any single stock option, such as the Extendable and Bermuda option?
The questions should reference the way you have written your code, and how it might be improved and extended. The discussion should be included in your project file as aseparate file from your documentation and be limited to 500 words.
Submission instructions
You should aim to submit your work by 8th August, 2022.
Format
Submit your code as a single compressed .zip file, including all Code::Blocks project ( .cbp) files (you MUST use Code::Blocks in this project), data files ( .csv), source code and header ( .cpp and .h) files and the executable (e.g. .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).
The documentation files must be submitted in .pdf format and uploaded to Moodle in the top directory of the .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 matthew .sparkes@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 investiaged.
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.
2022-08-08
Trinomial Single- & Multi-stock option pricing