09 Nov python project (PLEASE READ FIRST)
!!READ AND NAME YOUR PRICE!! THANKS!!!
Overview:
Part 1: Read the documentation for the following methods:
pandas.DataFrame.mean
pandas.Series.add
pandas.Series.prod
pandas.Series.dropna
Parts 2 to 7: Complete the functions in id_project.py. See the step-by-step instructions below.
Part 8: Create a new module (you can call it anything you want, for instance project2.main.py).
Then use the functions you created in id_project.py to answer the questions in Part 8 below.
Part 1: Read the relevant documentation
For this assessment, read the documentation for the following methods:
pandas.DataFrame.mean (note the parameter axis which will indicate if the mean will be computed
column-wise or row-wise)
pandas.Series.add
pandas.Series.prod
pandas.Series.dropna
Part 2: Include a statement to import the config.py module
Open the config.py file included in this project in PyCharm. Note that this file includes many constants
(e.g., DATADIR, FF_CSV, TICMAP) and a function called standardise_colnames. You should not modify the
file config.py.
To get access these constants and the standardise_colnames function, the config.py module needs to be
imported first.
Complete the import portion of the id_project.py module by creating a new import statement. This
statement should import the module config.py which is part of the zip file provided to you. Make sure you
import this module using the cfg alias (so, as cfg).
After including this import statement, you can use the test function _test_cfg to make sure the config
module is being imported correctly and tho check the location of the files for this project.
Part 3: Complete the read_prc_csv function
Complete the indicated part of the function read_prc_csv. so it produces the data frame described in the
docstring.
You can test this function by calling the _test_read_prc_csv test function.
Part 4: Complete the mk_prc_df function
Complete the indicated part of the function mk_prc_df. Make sure that this function returns a data frame
as described in the docstring. Remember that the sample period for the docstring example may be different
than that in your specific source data.
You can test this function by calling the _test_mk_prc_df function.
Part 5: Complete the mk_ret_df function
Complete the indicated part of the function mk_ret_df. Make sure that this function returns a data frame
with the same format as described in the docstring.
You can test this function by calling the _test_mk_ret_df test function.
Part 6: Complete the mk_aret_df function
Complete the indicated part of the function mk_aret_df. Make sure that this function returns a data frame
with the same format as described in the docstring.
You can test this function by calling the _test_mk_aret_df test function.
Part 7: Complete the auxiliary functions
Complete the following auxiliary functions following the instructions specified in their docstrings:
get_avg: Calculates the average value of a column for a given year
get_ew_rets: Calculates the returns on an equally-weighted portfolio of stocks.
get_ann_ret: Calculate the annualised return for a given period.
You can test these functions by calling appropriate test functions.
Part 8: Answer a few questions
For this part of this project, you should answer the following questions:
Q1: Which stock in your sample has the highest average daily return for the year 2020 (ignoring missing
values)? The sample should include all tickers included in the dictionary config.TICMAP. Your answer
should include the ticker for this stock.
Q2: What is the annualised return for the EW portfolio of all your stocks in the config.TICMAP
dictionary from the beginning of 2010 to the end of 2020?
Q3: What is the annualised daily return for the period from 2010 to 2020 for the stock with the highest
average return in 2020 (the one you identified in the first question above)?
Q4: What is the annualised daily ABNORMAL return for the period from 2010 to 2020 for the stock
with the highest average return in 2020 (the one you identified in the first question Q1 above)? Abnormal
returns are calculated by subtracting the market return from the individual stock return.
Important:
The file id_project.py contains placeholders for your answers.
You should replace the relevant variables in id_project.py file with your answers. For instance,
your answer to Q1 should be included in the variable Q1_ANSWER.
You can create a separate module (you can call it main.py if you want) and then use the functions
defined above to answer the questions below.
HOWEVER, THE ONLY MODULE YOU SHOULD SUBMIT IS id_project.py.
All your answers should be strings. If they represent a number, include 4 decimal places.
Here is an example of how to answer the questions below. Consider the following question:
Q0: Which ticker included in config.TICMAP starts with the letter C? Q0_answer = ?
You should replace the ? with the correct answer:
Q0_answer = CSCO
Hints
Your code should be portable, working in a variety of settings. It should be sufficient to copy your code from
PyCharm to Ed for submission. If your code works on your computer, but not on Ed, then you have not
made your code portable. The following hints should help you correct any portability mistakes:
1. The contents of your id_project.py module must not contain any direct reference to folders
in your computer. In other words, you must use the variables in the config.py and the os module
to create path variables.
2. When writing functions in the file id_project.py:
Do not modify the function names or the parameters.
Only modify the parts indicated by the “<COMPLETE THIS PART>” tag.
You should not import any other module (with the exception of config as described in Part 1.)
