top of page

Python sample assignment

Question 1

We have often heard of the statement “high risk, high return” in risky investments and have taken it to be correct, as it sounds intuitively correct. However, is it reflective of the observed trend of risky investments, such as the stock markets?


In this GBA, we will examine the validity of the "high risk, high return” statement by

constructing risky portfolios from stocks. The portfolios are of varying volatility levels (i.e.

different risk levels) and we will determine the resulting trend observed from the returns of the portfolios.

Return is formulated as

Equation (1)


where Si(t) and Si(t-1) are the prices of stock i on the day t and t-1 respectively. Risk is

measured using the sample standard deviation of the daily returns, i.e.

Equation (2)


r; is the mean return of stock i and N is the number of return data points.


You are given the daily return data for 2000 stocks, for a period of 30 years in the file named ret.csv.

Figure 1 : Python inputs to analysis


Make use of Python, especially the pandas module to implement the portfolio construction described in Appendix A. The breakpoints indicated that you are to construct five (5) portfolios, where the first portfolio consists of all stocks whose volatilities are between the 0 and 20th percentile, the second portfolio consists of all stocks whose volatilities are between the 20th and 40th percentile. The fifth portfolio will consist of all stocks whose volatilities are greater than the 80th percentile.


You are to present your results using a series of plots shown in Appendix B.


If necessary, state clearly any assumptions you have made in your implementation.


You are to conclude clearly if the statement "high risk, high return” is observed in your analysis, using the data given.


For marking and evaluation purposes, you are to document/print the following information in your Jupyter notebook submission:


(a) the name of the main developer for each section of code/function

(b) the daily return of s_0520 and s_1080 on the last trading date of Jun and Sep 2018.

(c) the volatility of daily return for s_0125 and s_1050 in Jan and Dec 2010.

(d) the monthly return of s_0250 and s_1900 in Apr and Nov 2013.

(e) the last 5 stocks in the second portfolio created on Feb 2015.

(f) the realized monthly return of the first and third portfolio in Feb and Nov 2008.

(g) the annualized return and volatility of all portfolios presented in 2 decimal points (i.e.3.24%) for the entire analysis period.


You are reminded to practice good programming habits in your implementation and

your code must be driven entirely off the inputs given in Figure 1.


Appendix A


You are given the daily return information of 2000 stocks and using this information, you are to determine the volatility of all the stocks for month k, at the last trading date in the month, using the daily return information in the month. In month k, the volatility is calculated using Equation (2) and the stocks are then ranked according to their volatility level. The stocks are then sorted into different portfolios, dependent on the breakpoints provided by the user in Figure 1. An equal weighed (EW) portfolio is created using the stocks.


The stocks will be held for a month. In month (k+1), the return of EW portfolio is realized.

The process of sorting stock according to their volatility is repeated and new portfolios will be created. Again, the portfolio will be held for a month.


This process will repeat till the end of the data.


A numerical example is provided for 10 stocks in the universe. To simplify the example, the 10 stocks are assumed to only trade for 3 days in a month. Three portfolios are created with the following breakpoints:


breakpoints = [30,70]


Daily return of stocks in the universe is presented in Table Al.


Table Al: Daily return data of all stocks in the universe


On the 31-Jan-20, the volatilities of all the stocks in the universe is calculated and the stock with the lowest volatility is g, whose volatility is 3.1%. The stock with the highest volatility is h, whose volatility is 22.7%.


The stocks are sorted, and stocks c, g and j are allocated to the first portfolio which

corresponds to the first breakpoint of 30th percentile and the portfolio is constructed with equal allocation from the stocks.


Stocks b, e and h are allocated to the third portfolio which corresponds to the breakpoint

greater than 70th percentile. Again, the allocation of each stock in the portfolio is 33.33%

each.


All the portfolios were held for a month. For stock c in the first portfolio, daily returns of

0.01, -0.05 and -0.04 were experienced in Feb-20. The monthly return for stock c in Feb-20 is - 7.9% (=1.01*0.95*0.96 - 1).


Hence, the monthly return for the first portfolio in Feb-20 is 18.9%.


The stock sorting and portfolio construction is repeated monthly, using the daily return of the stock universe. With the data given, the monthly returns of the three portfolios are

summarized in Table A2.

Table A2: Time series of monthly returns of portfolios


With the given daily return data, 3 portfolios can be constructed on the 31-Mar-20. However, the monthly return of the portfolios constructed on the 31-Mar-20 cannot be evaluated as the data for Apr-20 is not available.


The annualized return of the portfolio can be calculated as follows:

where (r1) is the time series of the monthly returns of portfolios and N is the number of terms in the time series.


The annualized volatility of the portfolio is calculated as follows:

Equation (A2)


where (or) is the standard deviation of the time series of monthly returns of portfolio.



Appendix B


The results of the analysis are to be represented in accordance with Figure Bl for easy

visualization. Note that dummy numbers are used in the generation of Figure Bl.


Figure Bl: Visualization of analysis results


---END OF ASSIGNMENT---


 

Are You are looking for Python Project Help or Homework Help? Codersarts Python expert will provide the best quality plagiarism-free solution at an affordable price. We are available 24 * 7 online to assist you. You may chat with us through website chat or email or can fill the contact form.






Comments


bottom of page