Question is about ecnomics/finance programming in Python

timer Asked: Jan 21st, 2021

Question Description

Need help in ecnomics/finance programming in Python Question ? could you help ? document is attached kindly have a look.

Unformatted Attachment Preview

The yield to maturity, often shortened to simply yield, is the average rate of return, including the loss (or gain) of capital because the bond was purchased above (or below) par. For a bond, this is the r that makes the bond pricing formula equal to the current price. It is easy to find it numerically. One algorithm consists of the following steps: start with an initial guess, and compute the bond price p̂ from that guess. If p̂ is greater than the actual price, the guess is too low. If p̂ is lower than the actual price, the guess is too high. Each pass, we improve our guess by adding or subtracting a certain value (the step size). A good starting value for the step size is 0.02. The key for convergence is to decrease the step size every time we cross over (i.e., if the previous guess was to high, and the new guess is too low, reduce the step size before making the new guess.) Decreasing the step size by half works well. You stop when p̂ is close enough to the price (error is smaller than tolerance). Note that this is different than the example in the tutorial. Do not use a grid for this question. Write a function ytm(price, T, par=1000, c=0.0, n=2, initial ytm=0.1, tolerance=0.001) for computing the yield to maturity of a bond using the algorithm described above. The function takes the following parameters: a) price: the price of the bond. b) T: the maturity of the bond (in years). c) par: the face value of the bond (optional, default value=1000). d) c: the coupon rate of the bond (optional, default value=0.0). e) n: the number of coupon payments per year of the bond (optional, default value=0.2). f) initial ytm: the initial guess (optional, default value=0.1). g) tolerance: the stopping criteria (optional, default value=0.001). The function should call the provided price bond() function. The function should return a float with the yield to maturity of the bond. Note: for the provided tests, the code should execute instantaneously. If it takes time, you are doing something wrong. Example > >> print ( f ’{ ytm ( price = 1019 .32 , T =1 , par = 1000 , c = 0.08 , n =2 , i ni ti al _ ytm =0.1 , tol erance = 0 .0001 ) :0.5 f } ’) Out : 0 .05981 ...
Student has agreed that all tutoring, explanations, and answers provided by the tutor will be used to help in the learning process and in accordance with Studypool's honor code & terms of service.

This question has not been answered.

Create a free account to get help with this and any other question!

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors