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

Programming in Finance (N1633)

Project assignment 2023/24

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

1.  (15 points) Find the top 50 stocks by the following standards.

(a) Least risky. Risk is measured by the standard deviation of stock returns.

(b) Highest historical growth.  Growth is measured by the size of accumulated stock returns. (c)  Best historical performance. Performance is measured by Sharpe ratio.

2.  (60 points) Use all the stocks and the entire sample  (as long as the dataset allows) in the provided dataset to create the following 12 portfolios. Each portfolio should be created with a clear set of algorithm.  Each step of the algorithm should have illustrated output below the code cell. The descriptive statistics of the portfolio (portfolio mean, standard deviation, Sharpe ratio) should be reported at the end of the algorithm. Graphs of the portfolio value or return timeseries should also be reported, with clear titles/legends, x and y axis labels.

3.  (25 points) Amongst all the above portfolios you created, discuss which of it you would like

to invest in and explain why, using tables or graphs.

Supporting technical details are provided in the technical appendix.

Your submission should be a pdf or word document, including

1.  (The screenshots of) your entire jupyter notebook script with code cells and generated output beneath them;

2.  Coding logic: a step by step explanation in words or equations if you prefer, about how you complete the first three tasks using python;

Note: The outcome of each step in your coding logic document MUST be run and outputted 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 run and outputted in your scripts first.

3.  Portfolio performance: a discussion for the 3rd task using graphs or tables you create using python. In this part it is suggested you quote again (the screen shots of) the graphs or tables

you generated earlier.

Please note that:

1.  Unnecessary coding will be penalized

2.  Penalties for breaking the rules on plagiarism apply.

3. Your PDF or word report should be between 1800 – 2200 words excluding footnotes/endnotes and any tables or figures. Penalties may apply 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[r] = alpha + beta × E[M]

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.