讲解:path-dependent、C++、C++、Black-Scholes modelDatabase|Haskel

Pricing path-dependent call optionsC++ Programming with Applications to Finance Spring 2018The famous Black-Scholes model from mathematical finance for a non-dividend paying stockcan be formulated asdSt = rStdt + σStWt,where r is the continuously compounded risk-free interest rate, σ > 0 is the volatility of thestock and W is a Brownian motion under the equivalent martingale measure. The Black-Scholesmodel depends on two parameters, namely r and σ. The interest rate r is readily available;however the volatility σ cannot be observed directly, and needs to be estimated from marketdata.Vanilla call option pricingExplicit formula have been derived for many types of options. For example, the price at time0 of a vanilla European call option with strike price K and expiry time T is given by theBlack-Scholes formulaC(S0, K, T, σ, r) = S0Φ(d+) ? Ke?rT Φ(d?), (1)whereis the distribution function of the standard normal distribution.Trinomial tree approximationThe It o lemma of stochastic calculus allows us to derive the stochastic differential equation ofthe log-price xt = ln St asdxt = νdt + σdWtThe linearity of this stochastic differential equation means that it is often more convenient tomodel x directly rather than the stock price S itself.Explicit formulae have been derived for many types of options (including put and call options);however approximation methods are needed to price many other options. One suchmethod 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.The features of the continuous-time process can now be captured by the parameters ?x, ?t, qu,qm and qd. Formulae for the transition probabilities qu, qm and qd can be derived by matchingthe first two moments of the continuous-time process in (2) and the trinomial process over thetime interval of length t, in other words,νt = E(?x) = qu × x + qm × 0 + qdSolving this system for qu and qd, and requiring that the transition probabilities add up to 1,givesThis is a good choice for ?x because it links the size of stock price movements with the lengthof the time interval over which such movements take place.The trinomial process described above can be extended to form a trinomial tree. Startingfrom a given initial stock price S0 > 0, each time step n represents “real time” t = n?t, andthe stock price at node i isS(n, i) = S0eix, (3)where i = n, . . . , 1, 0, 1, . . . , n. The resulting tree is illustrated in the following figure.S(0, 0) = S0 S(1, 0) = S0 S(2, 0) = S0 S(3, 0) = S02The trinomial tree with N steps can be used to approximate the stock price movement overa “real” time interval [0, T] by setting t = and the price of an option in the trinomialmodel can be used to approximate its price in the Black-Scholes model.Trinomial method for path-independent options in the trinomial treeIf the payoff of a European option with expiry time T can be expressed as a function h thatdepends on ST only, then it is called path-independent because it doesn’t depend on the pathfollowed by the stock price up to time T (it depends only on the final position at time T). Forexample, a vanilla European call option is path-independent and its payoff function ish(ST ) = max{ST K, 0}.The option price of any path-independent European option with payoff h can be approximatedby the trinomial method using an N-step trinomial tree with t = as follows: At time step N, letH(N, i) = h(S(N, i)) for all i = N, N + 1 . . . , N. At every time step n = N 1, N 2, . . . , 0, assume that H(n + 1, i) is known for alli = n 1,n, . . . , n + 1. Then defineH(n, i) = e[quH(n + 1, i + 1) + qmH(n + 1, i) + qdH(n + 1, i 1)] ,where qu, qm and qd are the risk-neutral probabilities given above.The price of the option is then H(0, 0).Monte Carlo method for path-dependent and path-independent options in thetrinomial treeThe payoff of a path-dependent European option with expiry time T depends not only on thefinal stoock price ST , but also on how the stock price fluctuates during the lifetime of theoption. The payoff of a path-dependent option with expiry time T in the Black-Scholes modelcan usually be approximated by a function g(S(0), S(1), . . . , S(N)) that can be used in an Nsteptrinomial tree with t =, where the sequence S(0), S(1), . . . , S(N) represents a stockprice path over time steps 0, 1, . . . , N in the tree. The following table gives the payoff functionsof two path-dependent call options.Option Black-Scholes payoff g(S(0), S(1), . . . , S(N))Floating strike lookback call optionmax �ST min0≤t≤TFixed strike lookback call option max �max0≤t≤TSt K, 0max maxn=0,...,NS(n) K, 0The price of a path-dependent option with payoff function g can be approximated by MonteCarlo simulation, which involves generating M random sample paths of the trinomial tree. TheMonte Carlo method is as follows for each k = 1, . . . , M: Generate N independent random variables v(n = 1, . . . , N) such that1 with probability qu,0 with probability qm,1 with probability qd,where qu, qm and qd are the risk-neutral probabilities given above.3 Generate a random stock price path (Sk(0), Sk(1), . . . , Sk(N)) by setting Sk(0) = S0 andSk(n) = Sfor all n = 1, . . . , N,where the formula for S(·, ·) is given by (3).The price of the path-dependent option is then approximated by(0), . . . , Sk(N)). (4)The Monte Carlo method also works for a path-independent option with payoff function h;we just writein (4) above.Project tasksThe aim in this project is to create an option pricing application by completing the followingtasks based on the information provided above. You should use the header file Project.h,which must be included in your project without change.The marks for each of the tasks below will be split into 60% for coding style, clarity, accuracyand 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.General hints: Read the submission instructions at the end of this document before starting work on theproject. Read through all tasks before starting work on the project. Tasks do not have to becompleted in the order that they are listed here. It might be helpful to look at Chapter 5 of Capi′nski & Zastawniak (2012), which coversMonte Carlo pricing of path-dependent options in the Black-Scholes model. However, thetechnical details are different in this project. You are free to recycle any code produced by yourself during the module. You are alsofree to use any code provided in Moodle during the module, provided that such code isacknowledged. Test your project with a freshly downloaded copy of Project.h just before submission.1. Data input and calibration (20%)Your program should ask the user to enter values for S0 and r. It should then compute σ byusing the observed market price Cquote of a call option with strike price K and expiry time Tand solving the non-linear equationC(S0, K, T, σ, r) = Cquote4for σ, where the function C(·) is the formula for a call price given in (1). Your program shouldask the user to enter Cquote, K and T, and display the value of σ once it has been calculated.The value of σ should be accurate to at least 5 decimal places.Hint: There is no closed formula for the function N(·) in (1). However, it can be approximatedaccurately in a number of different ways. One such method is described in Section 4.7 ofCapi′nski & Zastawniak (2012).2. Trinomial tree (10%)The header file Project.h contains a class TriModel representing the trinomial tree describedabove. Create a new source code file TriModel01.cpp which should contain the definitions ofall the member functions of the class TriModel that aren’t already defined in Project.h.3. Monte Carlo pricing (20%)The header file Project.h also contains a class PathDepOption representing path-dependentoptions. Create a new source file PathDepOption.cpp and provide the definition of the MonteCarlo pricipath-dependent作业代写、代做C++编程作业、代写C++作业、代做Black-Scholes model作业ng function PathDepOption::PriceByTrinomialMC() in it.Hints: Learn about the rand() and srand() functions from a good C++ manual. Definingn with the desired distribution. Take note when debugging that the number of repetitions in Monte Carlo pricing can bevery large, which means that the sum in (4) may exceed the range of the double variabletype.4. Path-dependent European call options (10%)Create two subclasses LookbackFloatingCall and LookbackFixedCall of PathDepOption ina new header file PathDepCall.h to represent floating and fixed strike lookback call options.The definitions of any member functions not defined in PathDepCall.h should appear in a newcode file PathDepCall.cpp.5. Vanilla call option (20%)Create a class VanillaCall to represent a vanilla European call option with expiry time T andstrike K. The class should offer the following functionality: Can be priced with the Black-Scholes formula. Can be priced with the trinomial method for path-independent options in a trinomial treewith step size Can be priced with the Monte Carlo method for path-independent options in a trinomialtree with step size ?t =5The class declaration should appear in VanillaCall.h. Any member functions not definedthere should appear in VanillaCall.cpp.The class VanillaCall should be designed in accordance with the principles of object orienteddesign. In particular, it must be possible to add further path-independent options (suchas vanilla put options) with similar functionality without modifying the code in VanillaCall.hor VanillaCall.cpp.Hints:? The payoff to be used with the Monte Carlo procedure isg(S(0), S(1), . . . , S(N)) = max{S(N) ? K, 0}.It is worth considering whether this class can be used for the calibration procedure inTask 1. It would be helpful to reuse existing code (for example, the code developed for MonteCarlo pricing in Task 3). It is therefore worth considering whether VanillaCall shouldbe a subclass of some base class (or perhaps more than one base class). There are anumber of different options for this. Consult a good C++ manual if you encounter anytechnical difficulties. It is possible for a C++ class to have two or more member functions with the same name,as long as the parameters are different in each case. This is called function overloading.Consult a good C++ manual on this if needed.6. Numerical study of call option prices (20%)Your program should perform a numerical study of call option prices, in two parts. In this task,your program should use the values of K and T entered by the user as part of Task 1.Your program should produce a file VanillaCall.csv using the comma separated values(csv) format. It should contain a table of vanilla call option prices, together with appropriaterow and column headings. Each row n = 1, 2, . . . , 10 consists of 11 column entries, as follows: The first entry should be the option price in the trinomial tree with N = 100n, calculatedwith the trinomial method. The mth entry, where m = 2, . . . , 11, should be the option price in the trinomial tree withN = 100n, calculated with the Monte Carlo method for path-independent options withM = 10000(m 1) repetitions.Your program should also produce a comma separated values file PathDependentCall.csv.Each row n = 1, 2, . . . , 10 of the table in this file should contain the prices of a floating and fixedstrike lookback option, both computed by using the Monte Carlo method with M = 100000repetitions in a trinomial model with N = 100n steps. You should add row and column headingsas appropriate.Sample files VanillaCall.csv and PathDependentCall.csv have been provided to illustratethe structure of the output. Your output should contain numerical results in place of eachof the entries marked “price”, and you may vary the heading text if you wish.Hint: Spreadsheet applications (e.g. Microsoft Excel) can open .csv files.6Submission instructionsSubmit your work by uploading it in Moodle by 3pm on Wednesday 25 April 2018.FormatSubmit the code as a single compressed .zip file, including all Code::Blocks project (.cbp)files, data files (.csv), 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, thesubdirectory structure must be automatically recreated when unzipping the file). It must bepossible to open all project files and to compile, link and run the project using theversion of Code::Blocks running on computer lab machines.The code should be accompanied by detailed documentation, split into two parts:Code developer documentation Presenting the structure of the code, available classes andfunctions, main variables and any other information to help understand the code. Thisshould include information on how to extend the code by adding new options. Test runsof your code should be reported, including tables and graphs. More detailed explanationsof the methods used should also be reported in a separate section of the developerdocumentation.End user instructions How to use the compiled .exe program, how to input data and howthe results are presented, and a brief description of the methods implemented.The documentation files must be submitted in .pdf format (two separate .pdf files containingdeveloper documentation and user instructions) and uploaded in Moodle as a single .zip fileseparate from the code file.It is advisable to allow enough time (at least one hour) to upload your files to avoid possiblecongestion in Moodle before the deadline. In the unlikely event of technical problems in Moodleplease email your .zip files to [email protected] before the deadline.Code usage permissions and academic integrityYou may use and adapt any code submitted by yourself as part of this module, including yourown solutions to the exercises. You may use and adapt all C++ code provided in Moodle aspart of this module, including code from Capi′nski & Zastawniak (2012) and the solutions toexercises. Any code not written by yourself must be acknowledged and referenced both in yoursource files and developer documentation.This is an individual project. You may not collaborate with anybody else or use codethat 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, andsuspected offences will be reported to University authorities.If things go wrongLate submissions will incur penalties according to the standard University rules for assessedwork.It must be possible to open all project files and to compile, link and run theproject using the version of Code::Blocks running on computer lab machines. Itmay prove impossible to examine projects that cannot be unzipped and opened, compiled and7run on computer lab machines 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 allproject files and the directory structure are tested thoroughly on computer lab machines beforebeing submitted in Moodle. It is advisable to run all such tests starting from the .zip filesabout to be submitted, and using a different lab computer to that on which the files have beencreated.All files must be submitted inside the zipped project directory, and all the filesin the project directory should be connected to the project. A common error is toplace some files on a network drive rather than in the submitted directory. Please bear in mindthat testing on a lab computer may not catch this error if the machine has access to the networkdrive. However, the markers would have no access to the file (since they have no access to yourpart of the network drive) and would be unable to compile the project.As part of the marking process, the file Project.h will be replaced. If the copy ofProject.h used in a project has been modified in such a way that the code does notcompile with the original file, then a mark of 0 will be recorded.ReferencesCapi′nski, M. J. & Zastawniak, T. (2012), Numerical Methods in Finance with C++, MasteringMathematical Finance, Cambridge University Press.转自:http://ass.3daixie.com/2019013047524191.html

你可能感兴趣的:(讲解:path-dependent、C++、C++、Black-Scholes modelDatabase|Haskel)