CS 335 - Winter 2023: Assignment 1

欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top

CS 335 - Winter 2023: Assignment 1

 Due: Friday, Jan 27, 2023, 23:59pm

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

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

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

1. (6 marks) No-arbitrage option pricing.

Suppose the current price of a stock is $18. Consider a two state tree model defined such that after 3 months, the stock price may increase to $19 with a 40% probability or decrease to $16 with a 60% probability. Consider a European call option, based on this stock, with strike price K=$17 and expiry time T = 3 months. Assume the risk-free interest rate is 9%.

(a) (3 marks) Construct a risk-free portfolio and use it to determine the present no-arbitrage value (fair value) of the option (i.e., at time t = 0).

(b) (3 marks) Suppose such an option is priced on the market at V ∗ = 2.0 (i.e., higher than the no-arbitrage price). Describe the details for a strategy that will result in a guaranteed profit (in present value, i.e., at t = 0) and determine the value of that profit (per option), somewhat similar to what we did in class. (As usual in this course, we will assume short- selling is allowed and the no-arbitrage principle holds.)

2. (10 marks) Coding: Convergence of a walk on a discrete lattice.

Consider a random walk on an N step lattice on t ∈ [0, T ] with the parameters

Xn+1 → Xn + σ√∆t ; with probability p

Xn+1 → Xn −σ ∆t ; with probability 1−p 1? α√ ?

p = 21+σ ∆t ∆ t = NT ,

which converges to the solution of the SDE

dX = α dt + σ dZ ,

as ∆t → 0. The exact solution to this SDE is such that the exact density (probability distribu-

tion) of X (T ) is a normal density with mean Xinit + αT and standard deviation σ the initial value of X is Xinit.

T , assuming

Verify this experimentally via numerical simulation of many lattice walks, by preparing a Jupyter/Python notebook to carry out the following. Perform a lattice walk simulation, us- ing the parameters given in Table 1. Starting at X0 = Xinit, the value of X is then moved up with probability p or down with probability (1 − p). A uniformly distributed random number

1

 

on [0, 1] should be generated and used to determine the actual move taken. At the next lattice node (i.e., time step), this process is repeated, until we obtain the final position of X after N steps, XN, at t = T. This is a single simulation outcome; we perform many such simulations to produce many (possibly) different outcomes. Because each step moves up or down a fixed amount, the set of all possible outcomes for this discrete lattice walk is

j?√?

XN =Xinit+ (2j−N)σ ∆t j=0,...,N.

As indicated in Table 1, you should perform the above process first for 1000 simulations, then separately for 10,000 simulations, and finally for 100,000 simulations. In each case, print out the number of simulations and the corresponding mean and standard deviation of the computed values of XN from the simulations in that set. Also, print out the anticipated exact mean and standard deviation for comparison.

Next, for each set of simulations, we would like to generate a histogram of the observed probability density versus X(T) as described below.

Care must be taken in scaling this histogram to get the correct probability density. Let p(x) be the probability density, and let bin[a,b] be the bin on an interval [a, b] of the x axis. Then

Zb a

p((a + b)/2) ≃

p(x) dx ≃ ≃

p((a + b)/2)(b − a)

Number of occurrences in bin[a,b]

Total number of occurrences

1 Number of occurrences in bin[a,b]

 so that

  (b − a) Total number of occurrences

Use N +1 bins, with the bin boundaries falling half-way between the lattice nodes at timestep N. Use matplotlib’s bar function to display your probability density plot constructed as described above. (Alternatively, if you prefer, Matplotlib’s hist or Numpy’s histogram functionality can automate some of this process, if you give it appropriately chosen values for the range, bin width, and density parameters.) Be sure to include appropriate labeling on your plots (axis labels, title, legend if necessary).

Then, for comparison, over top of each of your histograms, generate a standard (line) plot of

the true normal distribution with mean Xinit + αT and standard deviation σ

range (in a different color). The Scipy function stats.norm.pdf can be used to evaluate a true normal distribution function. Thus each of your three plots will look something roughly along the lines of Figure 1 (albeit generated with different data).

Your code must be vectorized for efficiency, i.e., prefer vector operations instead of scalar oper- ations. As a very simple example of vectorization, if I have a Numpy vector V and I want to add 1 to every entry of the vector, I can simply write the vector operation V = V + 1, instead of using a slower for loop over index i and separately computing V [i] = V [i] + 1 for each entry. Similarly, many Numpy functions work on vectors rather than single numbers.

Specifically, your code for the lattice walk should only explicitly loop over the timesteps, not over the individual simulations - for each time step, the updates for all the simulations (within a set) should be computed together using vector operations. Also, you should not store the entire

2

T , over the same

 

 Figure 1: A histogram of an approximate probability density function, with a normal distribution plotted on top.

 T

σ

α

Xinit

Number of simulations Number of timesteps (N)

1.75 0.3 0.4 17 1000, 10000, 100000 300

 Table 1: Data to be used in your simulations of discrete walks on a lattice.

lattice at once, but rather only one or two columns of it, to save on memory. The example lattice walk code in the course notes is likely to be very helpful, since it illustrates both vectorization and lattice walk implementation! (Course notes, page 17).

In addition to the NumPy functions mentioned previously above, you may also find the mean, std, and random.uniform functions useful.

In a markdown cell in your Jupyter notebook, describe what you observe about your results (plots and statistics) as the number of simulations increases from 1000 to 100,000.

3. (6 marks) Coding: Brownian motion and Ito calculus. Let

∆Zi φ(ti ) Z(t0=0)

Z(ti) ti

= φ(ti) ∆t

∼ N(0,1)

= 0

i−1

= X∆Zj j=0

= i∆t

3

 

and

N−1 I(T,∆t) = X(∆Zi)2

i=0 ∆ t = NT .

Write a Jupyter/Python notebook to evaluate I(T,∆t). For T = 2, for fixed ∆t, compute the value of I(T,∆t). Use 70000 paths, and compute the mean and variance of the result, for N = 100, 200, 400, 800, 1600, 3200, 6400 timesteps. Vectorize your code so that there is only one explicit for loop over the timesteps, for a given value of N.

Write code to generate a simple text-based table of mean and variance of I(T, ∆t) for the different values of ∆t. (No fancy formatting is required! You can just use Python’s print function to generate each row, with appropriate arguments.)

Plot a graph of var(I(T,∆t)) versus ∆t, with appropriate labels. In a markdown cell of your Jupyter notebook, explain mathematically what you observe.

4. (7 marks) Ito calculus.

(a) (3 marks) Let X(t) and Y (t) be two stochastic processes, such that

dX = μX(X(t),t)dt+σX(X(t),t)dZX dY = μY (Y(t),t)dt+σY (Y(t),t)dZY

with dZX (t), dZY (t) being the increments for two distinct Wiener processes, ZX (t) and ZY (t). Let X(ti) = Xi and Y (ti) = Yi. Show that

(Xi+1 − Xi)(Yi+1 − Yi) = Xi+1Yi+1 − XiYi − Xi(Yi+1 − Yi) − Yi(Xi+1 − Xi) .

Then, using the definition of the Ito integral which is the limit of a discrete sum, show that

Zt tZt Zt

X(s)dY (s) = [XY ]0 − Y (s)dX(s) − dX(s)dY (s).

000

(b) (2 marks) Let Z(t) be a stochastic process satisfying dZ = φ dt, and assume Z(0) = 0. Using the result in part (a), show that (assuming Ito calculus)

Zt 12t

Z(s)dZ(s) = 2Z(t)−2. 0

(c) (2 marks) We saw that in Ito calculus, an Ito integral is defined in terms of the limit of a so-called “Ito’s sum”. For the integral R t Z(s)dZ(s), where Z represents the same stochastic

0

process as in (b), the corresponding Ito’s sum is PN−1 Z(tj)(Z(tj+1) − Z(tj)). Determine

the expected value of this sum.

5. (6 marks) Ito calculus and Ito’s Lemma.

Suppose dZ is the increment of a Wiener process and

dX = μ(X(t), t)dt + σ(X(t), t)dZ.

4

j=0

 

(a) (3 marks) If

F (X, t) = −X3 sin(t) + 2Xet,

what is dF (X, t) (interpreted in the sense of Ito calculus)?

(b) (3 marks) Using dX as defined above, and expanding, simplify

ZT

(dX )2

0

as much as possible. The integral is to be interpreted in the Ito calculus sense. (Note that σ(X(t), t) is a function of t, not a constant, so you will not be able to fully solve the integral.)

5

 

 

51作业君

Email:51zuoyejun

@gmail.com

添加客服微信: abby12468