关键词 > N1633/Python代写

Programming in Finance (N1633) Project assignment 2022/23

发布时间:2022-12-02

Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Programming in Finance (N1633)

Project assignment 2022/23

In this assignment you complete the following tasks using real data and Python. No excel file or calculation is allowed. Supporting technical details are provided in the technical appendix.

1.  [10 pointss Find the top 50 best performing stocks using the stock price data provided.

2. Create three portfolios using the 50 stocks you found. Asset characteristics are measured in a Markowitz world.

(a)  [10 pointss The first portfolio has equal weights across all 50 stocks.

(b)  [15 pointss The second portfolio is an all-long (i.e.   all weights have to be positive)

portfolio that is constructed with optimised weights; the optimised portfolio should have the best possible performance over the entire time period.

(c)  [15 pointss The third portfolio is constructed with optimised weights; the optimised portfolio should have the best possible performance over the entire time period.  Now short-selling is allowed (i.e. weights can go negative).

3.  [40 pointss Repeat task 2 using a different model, that is, when asset characteristics are NOT measured in a Markowitz world but built using the CAPM model.

4.  [10 pointss Amongst all the above portfolios you created, discuss which one or more you would like to invest in and explain why, using tables or graphs generated by your python scripts.

Your submission should include the following TWO documents. Both documents would be marked and your final mark is the average of the two marks:

1. Your jupyter notebook script (which can be saved as .html, .ipynb.txt, .pdf); and

2. A word or PDF report document that has 2 sections:

(a) Coding logic: a step by step explanation in words or equations if you prefer, about how

you complete the first three tasks using python;

(b) Portfolio performance:  a discussion for the 4th task using graphs or tables you create

using python.  To include graphs or tables into the report document, you do not nec- essarily need to export graphs or tables from python and instead, screenshots of the graphs or tables from jupyter notebook outputs can be used as an alternative.

The outcome of each step in your coding logic document MUST be outputed in your jupyter notebook script correspondingly.  All supporting information (eg.  tables and figures) you use in your word or PDF doc that comes from running your jupyter notebook scripts MUST be outputed in your scripts first.

Please note the rules on plagiarism at the end of these instructions and the penalties for breaking them.

Your PDF or word report should be between 1800 – 2200 words excluding footnotes/endnotes and any tables or figures.  Penalties are applied for reports that are excessively long.  No penalty for reports being excessively short.

Technical appendix

1. A portfolio is a combination of assets.  Portfolio weights define the proportions of the total investment to the portfolio, allocated to the stocks. The sum of portfolio weights is 1.

2. You can use EITHER the normal (discrete) rate of returns definition OR the log (continuous) returns definition to compute stock returns.

3. At each point in time, the portfolio return is the weighted average of stock returns. Consider a portfolio of 50 stocks, if the stock returns on n days are obtained, the stock return panel, R s, can be treated as a n by 50 matrix. The portfolio weights, W, can be treated as a 50 by 1 matrix. The portfolio returns, R p, can be computed as:

R p R s ˆ W

Alternatively, if the portfolio weights is treated as a 1 by 50 matrix, the portfolio returns can be computed as:

R p R s ˆ W\

where W\ is the transpose of W. Either way, mathematically, R p would be a n by 1 matrix.

4. For this assignment, the performance of any asset, such as a portfolio or a stock, is represented by the Sharpe Ratio (assuming the risk free rate is 0), i.e. the expected return of the asset divided by the standard deviation of the asset returns.

5. The portfolio’s expected return is the weighted average of the expected returns of the stocks.

6. The portfolio’s standard deviation can be constructed as following. Consider the covariance matrix of 50 stocks, Cov, which should be a 50 by 50 matrix. If the portfolio weights are set as a 50 by 1 matrix, then the portfolio’s variance, V, is:

V W\  ˆ Cov ˆ W

Alternatively, if the portfolio weights are a 1 by 50 matrix, the portfolio variance is: V “ W ˆ Cov ˆ W\

Either way, mathematically, V is a 1 by 1 matrix, i.e.  a number.  The portfolio’s standard deviation is the square root of the portfolio variance.

7. Asset characteristics include asset expected returns and risks in asset returns.

8. In a Markowitz world, assets’ expected returns are essentially their average returns. Assets’ risks are described by their historical standard deviation, variance, cross-asset correlations  and covariances.

9. In a CAPM world, the returns of an asset, r, can be decomposed in the following way:

r alpha ` beta ˆ r M ` epsilon                                         (1)

where r M is the returns on a market portfolio. For this assignment, you can use the S&P500 index as the market portfolio.

Therefore, the expected return of an asset, E[r], follows the following construct. E[rs = alpha + beta ˆ E[Ms

where E[M] is the average return on the market portfolio.

The covariance of two different assets A and B, Cov ab, follows the following construct. Cov ab = beta a ˆ beta b ˆ V M

where beta a and beta b is the betas of asset A and asset B. V M is the variance of the returns on the market portfolio.

The variance of the asset A, V a, which can be treated as the covariance of the asset A and A, follows a slightly different construct:

V a = Cov aa = beta a2  ˆ V M + V epsilon

where V epsilon is the variance of the residual returns of asset A obtained from the CAPM model (1).

10. Without specification, ˆ denotes matrix multiplication.