Risk Management Project案例 | Jupyter notebook案例 |pa
当前位置:以往案例 > >Risk Management Project案例 | Jupyter notebook案例 |pa
2020-08-20

Final Individual Project
Prof. Ricardo A. Collado BIA-670

Risk Management: Methods and Practice
Fall 2018



Instructions
The homework should be typed as a Jupyter notebook interspersing explanations in Markdown text with Python Code . Your solution file must be named in the following way:

last name-first name-Final.ipynb .

Risk Management Project案例Risk Management Project案例
For example, the professor’s homework would be named collado ricardo-Final.ipynb . Each problem and its subparts must be answered explicitly and clearly identified. No credit will be given for answers that are not explicitly stated (use numbers to make your answers easy to identify and read). Make use of Jupyter Notebook’s typesetting Markdown facilities to add text cells in which you could add math formulae, symbols, and good formatting. See the tab named “Jupyter” in the “Modules” section for tutorials on how to install and use Jupyter and Markdown for typesetting. The single solution file must be handled trough the homework link in the class Canvas page.

Evaluation
Answers will be evaluated for correctness and style. State complete answers showing your analysis. No partial points will be given for incorrect answers that do not show development and analysis.

Collaborations
Feel free to brainstorm and discuss the problems with your peers but the work in your homework has to be done individually. Copying another student work or colluding to prepare the home- work will carry a grade of F.

Total Value: 200 pts
Deadline: Wednesday, December 19, 2018


Main Problem

The tasks in this part refer to the parametric portfolio model discussed in Lectures 8.1 and 9.2 (see Lecture-8 1.pdf and Lecture-9 1.pdf included in Materials folder). Folder StockPrices contains daily closing prices of 15 different stocks for years 2012 and 2013. Each stock price history appears in a CSV file named by its corresponding ticker code and numbered in the order that you should use it in your programs. For example, the daily closing prices of Coca-Cola Company appears in the file 12-KO.csv. Refer to Lecture-8 1.pdf to get the technical details on how to perform the following tasks. File useful links.txt contains a list of useful links that explain many of the necessary techniques used in the homework. Some of the most useful Python Packages to perform this homework are: Pandas, Numpy,

Scipy, Statsmodles, and ScikitLearn.



Task 1
(25 points) Do the following:



Transform each stock prices time series to daily returns by using the daily returnsformula


R = Pt − Pt−1 ,

Pt−1



where Rt and Pt are the return and price, respectively, at day t.

Findthe best normal fit to each of the stock daily return time series and use the Kolmogorov- Smirnov goodness of fit test to report how good is the “best fit”.
Foreach stock draw a frequency graph overlaid by your best normal approximation to illustrate your
Definein your code vectors W = (W1, . . . , W15) of invested wealth, w = (w1, . . . , w15) of investment weights where wi := Wi/W . Define also x = W w = (W w1, . . . , W w15), remember that W = W w = x.
Hint: Use Scipy or Statsmodels to do the fitting and goodness of fit test. The text file useful links.txt included in the final project materials package has many links to examples on how to do this (including drawing the graphs).

Supposethat we have a total wealth W = $1,500, Let p0 be the initial investment position where all our wealth is invested evenly across the 15 assets. Then for p0 we have that Wi =
$100,000, for every asset i ∈ {1, 2, . . . , 15}.

Calculatefrom the returns data the returns covariance matrix Σ.


Task 2
(50 points) Given weights w, total wealth W , normal models, and covariance matrix (as obtained in Task 1), do the following:

Writea Python function that calculates the mean and variance of the portfolio rate of  Test the function on the even position p0.


Write a Python function that obtains the portfolio rate of returns diversified VaR at 95% confidence level (see definition of VaR and quantile). Here we use an α such that on the standard normal distribution the probability of observing a loss worse than −α is95%.
Test the function on the even position p0.

Writea Python function that calculates the individual VaR at 95% confidence level for a given asset. Test the function on the even position p0.
Write a Python function that calculates the undiversified VaR at 95% confidence level for a given asset. Test the function on the even positionp0.
Write a Python function that calculates the benefit from diversification. Test the function on the even positionp0.
Task 3: (50 points)

Write a Python function that calculates the marginal VaR (denoted by ∆VaR) at 95% confi- dencelevel for a given  Test the function on the even position p0.
Write a Python function that calculates the systematic risk (denoted by β) at 95%confidence level for a given asset. Test the function on the even position p0.
Leta = (a1, . . . , a15) represent a change in position (so new position = p + a, where p is the original position). Write a Python function that takes a change in position a and an original position p and calculates exactly the incremental  Test the function on the even position p := p0 and
for  assets  1 to 7 for assets 8 to 14

a = (¸−10,000 , .x.s. , −10,000˛ , ¸5,000, .x.s. , 5,000˛ , 35,000).

Write a Python function that takes a change in position a and an original position p and calculates a ftrst order approximation to the incremental Test the function on the even position p := p0and


for  assets  1 to 7 for assets 8 to 14

a = (¸−10,000 , .x.s. , −10,000˛ , ¸5,000, .x.s. , 5,000˛ , 35,000).

Writea Python function that calculates the Best Hedge


σ2

d∗ = −W βi ,

i 2

i

for a given asset i. Test the function on the even position p0.

Writea Python function that calculates the Component VaR


CVaRi = VaRβiwi,


for a given asset i. Test the function on the even position p0.


Task 4: (75 points)
Do the following:



Use the functions defined in Task 2 and Task 3 to define a function that performs the risk minimizationalgorithmdiscussed in Lecture-8 1.pdf slide 27. Set as a stopping condition:
max ,|βi − βj| i, j ∈ {1, . . . , 15} , < 0.001,

i.e. the maximum absolute difference of any pair of β’s is less than 0.001. Test the function on the even position p0.

在线提交订单