HW 2: Due Wednesday February 5 by 11:59 pm, via Blackboard
January 31, 2020
Attached you will find a file named hw2.csv. This is a CSV text file containing monthly returns of funds: both open-end mutual funds and ETFs. It has the following columns:
ticker crsp obj cd caldt mret
ticker is the fund¡¯s ticker, crsp obj cd (CRSP objective code) identifies the type of fund, caldt (calendar date) identifies the month of the return, and mret (monthly return) is the return over that month. For example:
FMAGX EDYG 20180131 0.078895
means that the fund whose ticker was FMAGX had a type of Equity-Domestic-Style- Growth (EDYG). It made a return of 7.8895% from 31 December 2017 to 31 January 2018. To understand what the CRSP objective codes mean, you can go here (though it is not re-
quired to do the rest of this assignment): http://www.crsp.org/products/documentation/ crsp-style-code-0.
1. Load this data into R. Put it into an R data frame object named ¡°fundrets¡±.
2. How many different funds are there? How many different types of funds are there?(Hint:
str()).
3. We will only be using equity funds. So keep only funds which have crsp obj cd whose
first two letters are ¡°ED¡±. (Hint: look at the function substr().
4. Transform ticker and crsp obj cd to factors even if they are already1. How many
different funds, and how many different fund types, are represented in the data now?
5. Create two new columns in fundrets, year and month, which are the year and month corresponding to caldt. (Hint: to calculate year, you can use the function trunc(), which drops the decimals. For example, trunc(2018.1230) returns 2018.)
6. Count the number of funds in each month of the data. For example, I want to know the number of funds for which I have returns in Jan2018, Feb2018, and so on (hint: table()).
1If you don¡¯t do this step, R will continue to ¡°include¡± the funds you have dropped, and give you NAs when you calculate means.
1
7. For each fund, find the average return in 2018.
8. Look at the output and manually determine which fund had the highest returns in 2018. Call this fund ¡°fund X¡±. Find the return of fund X in January 2019.
9. Find the average return of all funds in January 2019.
10. In January 2019, did fund X do better than the average fund?
Submission instructions
Create a text file named hw2.txt. Put all your commands in that file. The first line of the file should read
rm(list=ls())
If I copy and paste your commands into my R window, it should run with no errors. Upload this text file to the assignment on Blackboard.
2