Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Path-dependent options pricing

C++ Programming with Applications to Finance Spring 2022

The aim of this project is to create a program in C++ that can be used to price path-dependent options of an underlying asset 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 path-dependent options 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 advantage 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 .


Trinomial tree approximation

The  famous  Black-Scholes  model  from  mathematical  nance  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  di↵erential  equation  of the  log-price xt = lnSt  as

dxt = ⌫dt + σdWt .                                                          (1)

where

⌫ = r − σ 2 .


The linearity of this stochastic di↵erential 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 rst two moments of the continuous-time process in  (1) and the trinomial process over the time interval of length t, in other words,

⌫∆t = E(∆x) = qu  ⇥ ∆x + qm  ⇥ 0+ qd  ⇥ (−∆x),

σ 2 ∆t + ⌫2 (∆t)2 = E((∆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 exercise we will use x = σ p2∆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) = S0eix ,

where i = −n, . . . , −1, 0 , 1 , . . . ,n.  The resulting tree is illustrated in the following gure .


S(3 , 3) = S0e3∆x

 

S(3 , 2) = S0e2∆x

 

S(3 , 0) = S0

S(3 , 2) = S0e −2x

S(3 , 3) = S0e −3x

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 .


Generating paths on a trinomial model

For a trinomial tree with N time steps, there are 3N  paths to 2N +1 di↵erent end-nodes .  One can construct a bijection between these paths and a set of arrays of length N consisting of 0’s, 1’s and 2’s, where a 0 corresponds to the underlying asset going down in price, a 1 corresponds to the asset keeping the same price, and a 2 corresponds to the asset going up in price .  For example, if N = 3 then the array {1, 2 , 0} would correspond to an asset remain the same in the first period, moving up in the second, and moving down in the nal period (ultimately obtaining its initial starting price) .  Each path can be assigned a number x 2 [0 , 3N  − 1], corresponding to the end-point of the underlying asset .  To help you visualise this concept, a gure has been provided in 1 .  You are welcome to use an alternative convention for coding paths, as long as it is clear what you are attempting .

    x = 8

x = 6, 7

x = 3, 4, 5

x = 1, 2

x = 0

n = 1              n = 2

Figure  1:  Paths through  a trinomial tree  can  be  mapped with  arrays  of 0’s,  1’s  and  2’s,  and each path can be assigned a unique number linked to an end-node x 2 [0 , 3N − 1]

.

Pricing options on a trinomial model

The payo↵ C of a generic path-dependent option might depend on price of the underlying asset at expiry S(T), strike price K, and a barrier B (see options below for further description of the barrier parameter) .  Path-dependent options for a trinomial model can be priced by calculating the  expectation  of  all  possible  payo↵s  at  expiry  with  respect  to  the  risk-neutral  probability, where discounting is done with respect to the risk-free return, which yields

Price =   T E[C(S(T),K,B)],                                           (2)

In this project, we will price four call options:

  A fixed price Asian option1 , whose variable strike price is defined by the geometric mean of the underlying asset path,

CAsian =  max {S(t) − A(0,T), 0},

t2 [t,T]

(3)

where A(0,T) =  P S(t) is the arithmetic mean .

  A  lookback  option,  whose  variable  strike  price  is  defined  as  the  minimum  value  of the underlying asset over its path,

CLookback  =  max (S(T) − S(t), 0) ,

t2 [0,T]

(4)

Note that the minimum includes t = 0 .

  A  knockout  option,  which  has  a  built-in  mechanism  causing  it  to  expire  worthless  if  a specified  price  level  in  the  underlying  asset  is  reached .   This  price  level  is  defined  as  a barrier B, and the strike price is xed by K ,

8

CKnockout  =  <0

:K

if     maxt2 [0,T]{S(t) B} > 0

otherwise

(5)

  A  classic Parisian  option  (also known as a barrier option), where the derivative expires worthless if the underlying asset exceeds a barrier B for a predefined period of time M . Each time the underlying  asset dips down below the barrier  B the clock is  reset’ .   The derivative expires with strike price K if this condition is never met .

>K

maxS(s)B, S(s+1)B,...,S(t)B{t s +1} < M, if 9t 2 [0,T], such that S(t) ≥ B .

otherwise

(6)

Here,  s is  defined  as  the  moment  in  time  the  asset  exceeds  the  price  barrier  B,  and  t the last element of the path where the underlying asset has continuously been above the barrier price  B .  Each time the path dips below  B, we reset the count  and wait for the underlying asset to rise above B again .

NB: Not a xed  strike Asian option

Task 1: Import data using a custom class (15%)

The attached file StockDataMar2022.csv contains ctional stock data (S0, R and σ) for three car  companies:   Bentley,  Tesla  and  Ford .    Your  rst  task  is  to  create  from  scratch  a  cus- tom  class  called  ReadCSVFile,  which  reads  a   .csv file,  and  outputs  the  content  to  double vector< vector<string> > format, whose rows and columns represent the rows and columns of the  .csv file .  You should create the header and code les for this class from scratch .  The class should contain the following,

  Appropriate private and public member variables,

  A constructor for ReadCSVfile,

  Getter methods  (if necessary) to retrieve the necessary data .

You  should  display  the  contents  of  your  vector  by  using  a  separate  template function DisplayDoubleVector to display the contents of any double vector .

Task 2:  Generate path, prices and probabilities for a trinomial model (20%)

In this task, you must create a subclass for TriModel (provided) called TriPath, which contains three member functions,

 void PathByNumber(int x, int *path)

 void PriceByPath(int *path, double *prices)

 double ProbabilityByPath(int *path)

The  header  le  for  TriPath has  been  included .   You  should  implement  the  constructor, above member functions, and any other member functions you see t .

Task 3: Write a pricer for a trinomial model (20%)

The class PathDependentOptions (included) contains two member functions,

  The virtual abstract function   virtual double Payoff(double *prices, int N),

  The pricer function double PriceByExpectation (TriPath Model)

In this task, you should implement the PriceByExpectation member function in a seperate  .cpp file, using the expectation described in equation  (2) .

Task 4:  Implement payo↵s for exotic options  (20%)

Now we need to implement the fixed price Asian,  lookback,  knockout  and  classic Parisian op- tions,  according  to  their  various  payo↵s .   Each  option  should  be  created  as  a  subclass  in  the header le of PathDependentOptions and implemented in the associated  .cpp file .  Each sub- class should contain appropriate private member variables, constructor and any other methods you see t to include .

Task  5:  Price options for Tesla & Ford  (15%)

In this task,  you program  should  neatly  display the price of options  for both  Tesla  and  Ford over a time period T = 1 and N = 6 time steps, using the ctional data for S0 , R and σ you imported in Task  1 .  The strike, barrier and period-limit variables K ,  B and M for the Tesla and Ford derivatives are as follows for all options:

KT  = 130 ,

BT  = 160 ,

MT  = 2 ,

KF  = 160 ,

BF  = 200 ,

MF  = 2 .

The output to the console should be neat and easy to read for the end-user .

Task 6:  Create end-user documentation  (10%)

Finally, you should create documentation for the ReadCSVFile class and DisplayDoubleVector function ONLY . No other descriptions for the other classes, test data, or using the executable file is necessary.


Hint

Documentation should allow a user to read about your class/function and understand its func- tion, inputs and outputs, without needing to know any of the internal workings of that class/- function .  It is not  a description of algorithms,  nor  a description  about how you programmed the class/function .  The documentation should be created in Latex and included in the top-most directory of your project le .