# CS代写｜CS 335 – Winter 2023: Assignment 4

## 这是一篇来自美国的关于解决下面几个问题的CS代写，需要提交解决方案的所有组件（书面/分析工作、代码/脚本/笔记本、图形、绘图等）。在每个问题的部分中以PDF形式进行众包标记。您还必须单独提交一个单独的zip文件，其中包含任何和所有的DropBox文件（也就是说，zip中的文件应该是.ipynb类型）

Submit all components of your solutions (written/analytical work, code/scripts/notebooks, fifigures, plots, etc.) to CrowdMark in PDF form in the section for each question.

You must also separately submit a single zip fifile containing any and all code/notebooks/scripts you write to the DropBox on LEARN in runnable format (that is, the fifiles in the zip should be of type .ipynb).

For full marks, you must show your work and adequately explain your logic!

1. (10 marks) Monte Carlo option pricing.

As we derived in class, for the purposes of pricing options, we can pretend that the asset price S evolves in the risk-neutral world as

dS = rSdt + σ(S, t)SdZ,

where r is the risk free rate, σ(S, t) is the volatility (as a function of S and t), and dZ is the increment of a Weiner process.

Let the expiry time of an option be T, and let

N =T /t ,

Si = S(it),

where ∆t is the time step size. Then, given an initial price S0, M difffferent simulations of the path of the asset should be generated using the simple time-stepping rule

Si+1 = Si + Si(rt + σφi t)(1)

where φi N(0, 1) at each step. If the value of SN = S(T) generated by the mth simulation is denoted by (SN )m, then an approximate value (i.e., Monte Carlo estimate) of the option price is given by

V (S0, 0) = e rT P M m=1 Payoffff((SN )m)/M ! .

For the volatility function, we will use σ(S, t) = γ/S where γ = 20 is a constant.

Since the basic time stepping method of Equation (1) could potentially produce negative values,for this question we will simply set the asset price to  = 108 whenever timestepping produces

Si+1 0.

Prepare a Jupyter notebook that implements this method in Python/NumPy. Use the data for computing European puts given in Table 1. For a fifixed ∆t, write code to plot the computed option value versus number of simulations M, for each of

M = 1000, 2000, 4000, 8000, 16000, 32000, 64000, 96000, 128000, 192000, 256000.

Generate such a plot for the following values of ∆t = 10/250, 2.5/250, 1/250. (We often assume 250 days in a fifinancial year). Title each of your 3 plots with the corresponding timestep size.

Comment on the behavior you observe from these plots.

Additionally, for the smallest ∆t value, write code to generate a simple text table where each row contains M, the estimated option value, and the lower and upper bound values of the 95% confifidence interval, for that value of M.

Be sure to vectorize the inner loop of your code. That is, for a given choice of ∆t and M, there should only be one explicit loop (i.e., over the time steps) so that all of the M simulations are computed simultaneously with vector operations, rather than one entry at a time.

Risk free rate r    0.08

Time to expiry T    1.0 years

Strike Price K   \$101

Initial asset price S0   \$100

γ    20

    108

Table 1: Parameters for Q1.

1. (10 marks) Delta hedging: single stochastic paths.

As we have seen in lecture, discrete delta hedging consists of a portfolio Π(t) with components:

• A short option position V (S(t), t).
• Long α(t) shares at price S(t).
• An amount in a risk-free bank account B(t).

Initially, we have

Π(0) = V (S(0), 0) + α(0) S(0) + B(0) = 0

α(0) =∂V /∂S (S(0), 0)

B(0) = V (S(0), 0) α(0) S(0).

The hedge is rebalanced at discrete times ti . Defifining

αi =∂V /∂S (Si , ti)

Vi = V (Si , ti),

then we have to update the hedge by purchasing αi αi1 shares at t = ti , so that updating our share position requires

S(ti) (αi αi1)

in cash, which we borrow from the bank. At the instant after the rebalancing time ti , the value of the portfolio is

Πi = Vi + αiSi + Bi .

Develop Python/NumPy code in a Jupyter notebook for simulating a stochastic path of a delta hedge. At the end of each discrete hedging interval, update your portfolio, using the current asset price, and the corresponding values of option and delta (using blsprice, blsdelta). (Note that you do not need to rebalance at the fifinal time, t = T.)

Compute the relative hedging error at expiry time t = T, i.e.

Relative Hedge Error =e rT Π(T)/|V (0)|.

Your code should be able to produce plots showing: the stock price Si , the value in the risk free account (Bi), the stock holding (αi Si), and the total portfolio value Πi at each point along this single stochastic path. The plots should be loosely similar to Figure 8.1.3 in the course notes. (Of course, your actual values will be difffferent, due to the randomness inherent in the algorithm). Use the PyPlot function legend to identify the difffferent curves.

Using the code above, generate four difffferent plots, using 10, 100, 1000, 10000 timesteps / intervals in [0, T].

Generate an additional plot of number of rebalances vs. the corresponding absolute value of the relative hedge error. That is, it should have rebalance counts on the x-axis and error on the y-axis.

To evolve the stock price S for this question, we will assume GBM and use the following exact  update rule for GBM:

S(ti+1) = S(ti) exp h (µ σ 2 /2)(ti+1 ti) + σφp ti+1 ti i , (2)

where φ N(0, 1).

Use the data in Table 2. There is no need to vectorize this code. Comment on what you observe.

E-mail: vipdue@outlook.com  微信号:vipnxx