Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I have one question related to Matlab to solve Newton iteration (financial math). I attached some photos of the question and below I include the
I have one question related to Matlab to solve Newton iteration (financial math).
I attached some photos of the question and below I include the unfinished mathlab code:
1.
function [x, it] = newton_method(f, it_max, x0, tol) %Newton method to find %Input: f: function % it_max: maximum number of iterations % x0: initial guess % tol: user defined tolerance pre_x = x0; for it = 1:it_max [fx, fpx] = ;%task: fill in new_x = ;%task: fill in by the newton formula if( )%task: fill in with a condition to break the loop break; end pre_x = ;%task: fill in with variable (to prepare for the next iteration) end x = ; %task: fill in with a variable. end
2.
%simple script to call function newton_method clear all; format long; %declare function; it_max = 100; x0 = -10; tol = 1e-6; [x, it] = newton_method(@quad_func, it_max, x0, tol); disp(sprintf('First zero: %2.2g',x)); disp(sprintf('Number of iterations taken: %1d',it));
3.
function [fx, fpx] = quad_func(x) %This is the quadratic function (x-0.5).*(x+1) %Input: (x) %Output: [fx, fpx] which are f(x) and f'(x) fx = (x-0.5).*(x+1); fpx = (x+1) + (x-0.5); end4. (8 marks) In this question, consider a bond with the set of cashflows given in Table 1. Here, note that the face value F is already included in the last cashflow. Let y be the yield to maturity, t be the time of the i cashflow C, and PV 95 be the market price of the bond at t 0. Assume continuous compounding. Then by L1.46, y solves Table 1: Bond cashflows Cashflows (Ca Times 2.5 2.0 2.8 3.0 3.5 4.0 3,5 5.0 3.5 6.0 4.0 7.0 4.8 8.0 5.5 9.0 10.0 a. (1 marks) Write out the Newton iteration to compute ynti (see L2.46). Specifically, clearly indicate the functions f(y) and f (y). b. (7 marks) Implement the above Newton iteration in Matlab. Use the stopping criteria ynl 10 a. (1 marks) Write out the Newton eration to compute yn+ see L2.46 Specifically, clearly indicate the functions f(v) and f(y). b. (7 marks) Implement the above Newton iteration in Matlab. Use the stopping criteria lun +1- val 10-6. How do you choose a good value for yo? Fill in Table 2 Table 2: Output N/A
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started