在这项任务中,您将使用C编程语言编写代码,该语言使用CRR二项式对固定年度基础资产的普通欧洲/美国期权进行估值的方法股息收益率。您将使用两种不同的算法来实现二项式方法给出相同的结果,使您能够验证是否正确地实现了它们。此外,您
将验证您的计算解决方案是否接近欧洲选项的分析解决方案如果时间间隔足够小,则由Black-Scholes形式主义给出。您可以在解决方案中使用任何标准库数据结构/函数。但是,不要使用任何不属于标准的第三方库。您的代码应该格式清晰并附有详细评论。在如何实现代码方面,您有一定的灵活性并且经过测试,但是您的解决方案应该包含在
文档,以便对其进行测试。非常重要的是,您的最终提交文件仅包含指定的文件,并且无需修改即可编译这些文件。如果你的代码不能在visualstudio或onlineGDB中编译,您可以使用的标记数量非常有限分数请测试它在以上至少一种情况下是否有效。您将获得的模板文件,让你开始
1. IntrodcutioNiNIntrodcution
IB9JH0 Programming Assignment 1In this assignment you will write code in the C programming language which uses the CRR binomialmethod to value vanilla European/American options for an underlying asset with a fixed annualdividend yield. You will implement the binomial method using two different algorithms which shouldgive the same result, allowing you to verify you have implemented them correctly. In addition, youwill verify that your calculated solution approaches the analytical solutions for European optionsgiven by Black-Scholes formalism if the time intervals are sufficiently small.You may use any standard library data structures/functions in your solution. However, do not useany third-party libraries which are not part of the standard. Your code should be clearly formattedand annotated with detailed comments. You have some flexibility in how the code is implementedand tested, but your solution should contain the file structure and functions specified in thisdocument so that it can be tested. It is very important that your final submission only contains thefiles specified, and these files can be compiled without needing modification. If your code can’t becompiled in either visual studio or onlineGDB, you are very limited in the number of marks you canscore. Please test it works in at least one of the above. You will be provided with templates of thefiles to get you started. Please read the document carefully to make sure your submission is inthecorrect format.Submit the followingfiles:OptionPricingFunctions.h OptionPricingFunctions.c Testing. Analysis.c
2. Black Scholes
Black Scholes (European options):For European options, you should find that using larger trees/more timesteps causes the binomialalgorithm to approach the analytical solution for the value of the option in the risk-free frameworkimposed by the Black-Scholes model. The analytical solutions for calls and puts are omitted here asthey are widely known and easy to find. The Black Scholes solution requires one to calculate thenormal cumulative distribution function (). In C this can be done by using the erfc() libraryfunction with the following transform:Forward Recursion method (European options):This method starts from timestep zero and accumulates the option value from the next timestepusing the recurrence relation:is the option value, r is the risk-free interest rate, ▽ is the time increment between eachtimestep, p is the risk-neutral probability of an upwards jump, i is the timestep/tree depth of thecurrent node, and j is height of the current node. This can be visualised in the figure below for a treeof depth 2:
The recurrence relation can be implemented by utilising recursion in C. Note that you will need tokeep track of i and j in your recursive function calls. The recursion terminates at the base of thebinomial tree where i is equal to the depth of the tree (i = 2 in the above figure). For a tree of depthn, the values at the base of the tree are the values of the option at the expiry time, and can becomputed as follows:(2)= max(02 , 0) for call options(3)= max( 02, 0) for put optionsWhere 0 is the asset price at time zero (i = 0) and k is the strike price.Forward Recursion method (American options):The difference in the calculation for American options in comparison to European options is thatthey can be exercised by the contract buyer before the expiry time. This means that the exercisevalue
needs to be calculated at each node:The rest of the algorithm is identical to the version for European options.Backward Induction method:The backward induction method starts from the last timestep and computes the option value at allthe base nodes using equation 2 (calls) or 3 (puts). Next, it uses the recurrence relation fromequation 1 (European options) or equation 6 (American options) to compute the value of all thenodes at the previous timestep. This process is repeated until time zero. You will use a nested loopwith two layers. For a tree of depth n, the outer loop is over timesteps from i = n – 1 down to i = 0.The inner loop is from node height j = 0 to j = i. You need to use an array to store the values at eachtimestep. A single one-dimensional array of size n + 1 is sufficient to price an option with a tree ofdepth n. This is because the values calculated at timestep i will replace the valuescalculated attimestep i + 1. That is, for all j-values at timestep i,will replace +1in the array.
3. Task
Task 1. Implementing the Algorithms:The assignment requires you to complete the functions listed below so they work as described. Youare free to add any additional functions you require in OptionPricingFunctions.c. Do NOT modify thefunction signatures or names. The input variables must stay the same. Moreover, do NOT modifythe header file OptionPricingFunctions.h.
void price_vanilla_option_european_bs(double S0, double r, double volatility,double strike_price, double dividend_yield, double expiration_time, double*call_price, double* put_price)
double price_vanilla_option_european_recursion(unsigned int i, unsigned int j,unsigned int depth, double delta_t, double S0, double r,double volatility, double strike_price, double dividend_yield, doubleexpiration_time, option_fxn exercise_profit_calculator)
double price_vanilla_option_american_recursion(unsigned int i, unsigned int j,unsigned int depth, double delta_t, double S0, double r,double volatility, double strike_price, double dividend_yield, doubleexpiration_time, option_fxn exercise_profit_calculator)
double price_vanilla_option_european_induction(unsigned int depth, double delta_t, double S0, double r,double volatility, double strike_price, double dividend_yield,double expiration_time, option_fxn exercise_profit_calculator)
double price_vanilla_option_american_induction(unsigned int depth, double delta_t, double S0, double r,double volatility, double strike_price, double dividend_yield,double expiration_time, option_fxn exercise_profit_calculator)The functions should be implemented as follows: price_vanilla_option_european_bs – calculate call and put prices for European options usingthe Black-Scholes analytical solution. The outputs are stored in the call_price and put_pricevariables
price_vanilla_option_european_recursion – price a European option using the forward-recursion method.
price_vanilla_option_american_recursion – price an American option using the forward-recursion method.
price_vanilla_option_european_induction - price a European option using the backward-induction method.
price_vanilla_option_american_induction - price an American option using the backward-induction method.Task 2. Testing:
Using only the functions exposed in the header fileOptionPricingFunctions.h (and any otherstandard C library code), demonstrate that the algorithms from task 1 are correctly implemented bywriting a function which tests the outputs under a range of input values (refer to general advicesection for help with this). The tests should print an alert to the console if an error is found. Save allyour testing code in Testing.c and annotate the tests with comments which explain what the codedoes.Task 3. Analysis:
Using only the functions exposed in the header file OptionPricingFunctions.h (and any otherstandard C library code), write code to investigate the following questions: What is the (time) performance difference between the two algorithms (recursion andinduction) What binomial tree depth is required to be reasonably certain the option values areaccurate to within 5 significant figures? How can I estimate the accuracy of an American option without an analytical solution?Save all your analysis code in Analysis.c and annotate the file with comments to explain what thecode does.
4.General Advice:
When testing/debugging, start with a tree depth of 2 so that you can verify the values inyour code by hand and identify where things are going wrong. Then try with bigger trees. Start by getting European call options correct for both the forward recursion method andthe backward induction method. Then it is relatively straightforward to extend this to putoptions, and finally American call/put options. A key thing to remember with testing is that you have two different methods (recursion andinduction) to calculate the exact same thing. Given the same inputs, the outputs should beidentical within machine precision. If the two different sources agree exactly for a few cases,it verifies that you likely implemented the algorithms correctly. The analytical solution isuseful for checking accuracy with respect to the true solution, but less useful for checkingthat the code implementation is correct. Do not take it for granted that your code will work in all four cases, even if it appears to workin one case. The only way to know for sure that things work is to test them. It is important to start working on the assignment early, so you have time to ask questionsthrough the forum or the support classes if you get stuck or need things clarified. You areencouraged to communicate with others, but do not share actual coded solutions and copyfrom each other (it is usually easy to tell if you did so do not risk it).
WX:codehelp
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。