程序代写代做代考 Please upload a version of this notebook as well as a PDF of the results of executing this notebook (running all cells)

Please upload a version of this notebook as well as a PDF of the results of executing this notebook (running all cells)
Part 1 – Create a single price path.
Define a function ​def price_path(spot, r, sigma, T, num_steps)​ that returns a numpy array of floats the represent a simulated price path of a stock.
The time period for the simulated path is ​T​ years. The array should have length (num_steps + 1)​ with the first value being the spot value. IMPORTANT, the array contains PRICES not stock returns.
We assume the stock follows a geoemtric brownian motion (refer to lecture 3 notes) with annualized return of r and annualized volatility of sigma. The price path should use equal timesteps of ​dt = T / num_steps​. Make sure to adjust drift and vol using dt.
You are encouraged to use functionality from numpy to create the random price path. In particular, you may find numpy.random.normal and numpy.cumsum useful
Part 2 – Create a chart with 100 price paths
Use your favorite plotting library (like matplotlib) to create simple line chart with 100 simulated price paths where:
● spot = 100
● r = 0.05
● sigma = 0.15
● T = 1.0
● num_steps = 252
Part 3 – Create an RKO valuation function that returns the discounted exercise value for a single price path
Next, we’ll calculate the terminal value of the RKO for a ​single​ price path.
Define a function ​def rko_path_value(spot, strike, barrier, r, sigma,
that returns the discounted value of the option at maturity. rko_path_value()​ should call ​price_path()​ and check if the barrier was crossed.
● If the barrier is crossed (or touched), should return 0
● If the barrier is not crossed (or touched), should
max(ST−strike,0)∗e−rT where​ ​ST is the final spot value in the price path.
T, num_steps)​
​rko_path_value()​
​rko_path_value()​

Important: each path should be different. If you see the same path, over and over, that probably means you are ‘seeding’ the random number generator within the price_path()​ function (or not using a random number generator at all).
Note: you may want to calculate dt = 1/T and then create x-values for your chart by doing something like ​steps = numpy.linspace(0, 1.0, num_steps+1)
Part 4 – Create an RKO value estimate function that returns the estimated value of the RKO for a specified number of price paths
Define function
that estimates the value of the RKO.
estimate_rko_value() should call rko_path_value() a total of ​num_sims​ times and then return the average value as its estimate.
Part 5 – Explore RKO value for a range of spots
Assume that we have an RKO with the following characteristics:
● T = 0.5 years
● Strike = 100
● Barrier = 110
● Sigma = 0.30
● Risk-Free Rate (r) = 0.05
Estimate the value of the RKO for Spots ranging from​ 8​ 0through106 at $2.0 increments (you may find ​numpy.linspace()​ or ​numpy.arange()​ to be useful). Use 126 time steps and 100,000 simulations for your estimates.
Create a line chart with x-axis as Spot and y-axis representing RKO value.
Part 6 – Explore RKO value for a range of maturities
Assume that we have an RKO with the following characteristics:
● Spot = 105
● Strike = 100
● Barrier = 110
● Volatility = 0.30
● Risk-Free Rate (r) = 0.05
​def estimate_rko_value(spot, strike, barrier, r,
sigma, T, num_steps, num_sims)​

Estimate the value of the RKO for T ranging from 0.25 to 2 years at 0.25 year increments. Use ​num_steps = math.ceil(T*252.0)​ time steps and 50,000 simulations for your estimates.
Create a line chart with x-axis as T and y-axis representing RKO value.
Part 7 – Create a dataframe with RKO values for different spots and maturities
For the maturities and spots below, estimate the value of an RKO with the following characteristics and simulation parameters:
● Strike = 50
● Barrier = 60
● Sigma = 0.25
● Risk-Free Rate (r) = 0.01
● Num Time Steps = ceil(T * 252)
● Num Sims = 50000
Create a pandas DataFrame with rows being maturities and columns being spots. Make sure to label the columns and rows (index). Print the DataFrame value to the console using print().