Uploaded by AAComps

Week 7 Lab

advertisement
Week 7 Lab: Quick Introduction to Python / Introduction to Numpy
Using Jupyter Notebooks
To use Jupyter notebooks in the labs, first you must create a folder with the exact title
Jupyter in your Documents folder. Download the zip files from the Blackboard site into
this folder, and then extract.
Task 1
Upload the Quick Introduction to Python notebook and work through the notebook.
Task 2
Upload the Introduction to Numpy notebook and work through the notebook.
Question 1
Use the following transformation to simulate 251 daily returns for a stock which has
initial price 𝑃0 = 100:
𝑃𝑡+1
= 1 + 𝜇 + 𝑍𝜎,
𝑃𝑡
where μ = 0.01%, σ = 1%, and Z is a draw from a standard normal N(0,1) distribution.
For example, suppose we draw z = 0.5. Then we obtain
𝑃𝑡+1
= 1 + 𝜇 + 𝑍𝜎 = 1 + 0.0001 + 0.005 = 1.0051
𝑃𝑡
(i)
Use slicing and np.mean to calculate the average of the last 21 returns
(ii)
Use a For loop to calculate a linearly-decaying moving average of the last 21
days’ returns.
Hint: linear decay means apply a weight of 21 to the most recent return, 20 to
yesterday’s return, 19 to the return 2 days’ ago, and so on.
Question 2 a
Use the following transformation to simulate 503 daily returns for a stock which has initial price
𝑃0 = 200:
𝑃𝑡+1
= 1 + 𝜇 + 𝑍𝜎,
𝑃𝑡
where μ = 0.02%, σ = 2%, and Z is a draw from a standard normal N(0,1) distribution.
Question 2 b
Use your array of returns to simulate 𝑃1, 𝑃2, … , 𝑃503
Plot your price chart using matplotlib.
Download