HW Week 12: Due Wednesday Apr 28 by 11:59 pm, via Canvas April 23, 2021 Instructions In this HW, we will see if stock performance can be predicted by a characteristic you choose. Here is the general...

1 answer below »
This assignment involves both financial statistics/R Programming. Please submit this task in a text file. There is no specific referencing style required, again, a text file.


HW Week 12: Due Wednesday Apr 28 by 11:59 pm, via Canvas April 23, 2021 Instructions In this HW, we will see if stock performance can be predicted by a characteristic you choose. Here is the general outline: 1. Pick a characteristic you think is related to future returns. 2. Get the next month’s returns for all stocks. 3. Regress the next month’s return on the characteristic This is very similar to what you have done in HW 6. There you used sorts and buckets and portfolios to determine whether a characteristic predicted future returns. Now you will use regressions. I provide a number of characteristics in the file at this URL: http://pages.stern.nyu.edu/~adesouza/FIN664/stock_chars_from_dailydata.csv The file is arranged in this way. Every line corresponds to a particular permno and “monthdate”. For example, the first line is for permno 10001 and monthdate 31JAN2005. The remaining columns are data about that stock in that month. The variables are: • FREQ : The number of days that stock had returns • vol: volume as a fraction of shares outstanding. A vol of 0.25 means that 25% of the shares outstanding were traded in that month. A high vol means that the stock was traded a lot. • numtrd: number of trades in that stock. A numtrd of 200 means that there were 200 trades. Note that this variable is only available for NASDAQ stocks. • meanret: the mean return of the stock in that month • meanbidask: the mean value of the bid-ask spread. A high bid-ask spread means the stock is illiquid. 1 http://pages.stern.nyu.edu/~adesouza/FIN664/stock_chars_from_dailydata.csv • maxret: the maximum of the daily returns in the month. A maxret of 0.1 means that on its “best day” in that month, the stock made 10%. • minret: the minimum of the daily returns in the month. A minret of -0.1 means that on its “worst day” in that month, the stock lost 10%. • stdevret: the standard deviation of the daily returns • capmalpha: the alpha from the CAPM. A capmalpha of 0.005 means that the stock made 0.5% per day more than the CAPM says it should have. • capmbeta: the beta from the CAPM. A beta of 1.5 means that when the market moves 2%, this stock moves 2 × 1.5 = 3% in the same direction as the market • capmrsq: the r-square from the CAPM. A capmrsq of 0.8 means that 80% of the movement in this stock is because the market moved, and only 20% is the stock moving on its own. • divyld: The dividend yield of the stock in that month and the two previous months. A divyld of 0.005, for example, means that the stock paid a dividend of 0.5% of its price during the 3 months ending on monthdate. A high divyld means that the stock paid a lot of dividend. • size: the usual size (prc times shrout). Program 1. Load the file stockrets.Rdata into R This file contains the usual data frame stockrets. The dates are already in date format and moved to the end of the month. There is a new variable, mktret, which tells you what the market made in that month. 2. Load the CSV file stock chars from dailydata.csv into R as a data frame stockchars. You can download the file (outside R) first. 3. Create a data frame named main from stockchars which contains ONLY the following information: permno monthdate char where char is one characteristic you have chosen. For example, you could choose capmbeta. Make monthdate a date variable. Try and use a characteristic you think should affect future returns. For example, if you want to use capmbeta, ask yourself: why should stocks with high values of capmbeta have high returns in future? 2 Drop any observations for which the characteristic is missing. (To see if a characteristic is missing, you can do table(is.na(main$char)) where char is the name of the characteristic you choose). 4. Create a new variable named nextmonthsdate, which is the end of month following the month in monthdate. So a row which has a monthdate of 31Jan2005, for example, will have a nextmonthsdate of 28Feb2005. If you get an error like could not find function "days" have you activated the right library? 5. From the data frame stockrets, get the return and the mktret for each permno- nextmonthsdate combination. Call these nextmonthsreturn and nextmonthsmktret. Hint: merge() and then rename(). You only need to do one merge. Which two datasets are you merging? What are the by-variables on the first dataset? What are the by-variables on the second dataset? 6. Calculate the regression coefficients a and b using the formulas we learned in class. What is the X-variable? What is the Y-variable? Also calculate the R2. Depending on the variable you use, you might get weird-looking numbers. For example, you might get b of 1.67e-05. Don’t worry too much about the size of b. 7. Type the command x_25thpctl=quantile(main$char, 0.25) x_75thpctl=quantile(main$char, 0.75) where char is the name of the characteristic you are using. This command tells you the 25th percentile of that variable (the value below which 25% of the values lie), and also the 75th percentile. When char is equal to x 25thpctl, what should y be according to the line? When char is equal to x 75thpctl, what should y be according to the line? How much return would you have gained if you held the 75th percentile stock instead of the 25th percentile one? 8. Use R’s regression package to run the regression instead. The command is: myregressionresult<-lm(y~x, main) summary(myregressionresult) 3 replace y with the y-variable you’re using, and x with the x-variable you’re using. the numbers you get for a, b, and r2 should agree with what you calculated in the previous question. to find a, look under “estimate”, at the row marked “intercept”. to find b, look under “estimate” at the row named the x variable (here meanbidask). to find the r2, look at the “multiple r-squared” figure 1: output from lm 4 9. from main, create a scatter graph of nextmonthsreturn (y-axis) against char. use geom vline and geom hline to include the y and x axis. use geom abline to in- clude the line you have fit. see the slides on “fittingexample” (about slide 47 in 07 regression.pptx for an example). does the graph “agree” with your calculated coefficients? 10. (no points, don’t write anything) what do the coefficients tell you about the charac- teristic? do stocks which have high values on this characteristic do well? 11. create a new variable in main, called nextmonthsexret, which is the excess return of the stock over the market, i.e, just nextmonthsret-nextmonthsmktret. 12. use lm to regress nextmonthsexret on your char. 13. (no points, don’t write anything) is your result different from when you used nextmonthsret? how? why? submission instructions you will submit only one text file for this part. do not submit any .rdata or .csv or excel files. create a text file named hwweek12.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. assume that the dataset stockrets.rdata and the csv file stock chars from dailydata.csv are in the current folder. upload this file to the assignment on canvas. if your code gives me errors when i run it, i will not check your assignment and you will get no credit. for real! a good way to make sure there are no errors is: close r, reopen r, navigate to the directory containing the rdata file, paste your code. if it runs with no errors or warnings, great! if not, you need to change things. there are points for following instructions, so please be careful. 5 main)="" summary(myregressionresult)="" 3="" replace="" y="" with="" the="" y-variable="" you’re="" using,="" and="" x="" with="" the="" x-variable="" you’re="" using.="" the="" numbers="" you="" get="" for="" a,="" b,="" and="" r2="" should="" agree="" with="" what="" you="" calculated="" in="" the="" previous="" question.="" to="" find="" a,="" look="" under="" “estimate”,="" at="" the="" row="" marked="" “intercept”.="" to="" find="" b,="" look="" under="" “estimate”="" at="" the="" row="" named="" the="" x="" variable="" (here="" meanbidask).="" to="" find="" the="" r2,="" look="" at="" the="" “multiple="" r-squared”="" figure="" 1:="" output="" from="" lm="" 4="" 9.="" from="" main,="" create="" a="" scatter="" graph="" of="" nextmonthsreturn="" (y-axis)="" against="" char.="" use="" geom="" vline="" and="" geom="" hline="" to="" include="" the="" y="" and="" x="" axis.="" use="" geom="" abline="" to="" in-="" clude="" the="" line="" you="" have="" fit.="" see="" the="" slides="" on="" “fittingexample”="" (about="" slide="" 47="" in="" 07="" regression.pptx="" for="" an="" example).="" does="" the="" graph="" “agree”="" with="" your="" calculated="" coefficients?="" 10.="" (no="" points,="" don’t="" write="" anything)="" what="" do="" the="" coefficients="" tell="" you="" about="" the="" charac-="" teristic?="" do="" stocks="" which="" have="" high="" values="" on="" this="" characteristic="" do="" well?="" 11.="" create="" a="" new="" variable="" in="" main,="" called="" nextmonthsexret,="" which="" is="" the="" excess="" return="" of="" the="" stock="" over="" the="" market,="" i.e,="" just="" nextmonthsret-nextmonthsmktret.="" 12.="" use="" lm="" to="" regress="" nextmonthsexret="" on="" your="" char.="" 13.="" (no="" points,="" don’t="" write="" anything)="" is="" your="" result="" different="" from="" when="" you="" used="" nextmonthsret?="" how?="" why?="" submission="" instructions="" you="" will="" submit="" only="" one="" text="" file="" for="" this="" part.="" do="" not="" submit="" any="" .rdata="" or="" .csv="" or="" excel="" files.="" create="" a="" text="" file="" named="" hwweek12.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.="" assume="" that="" the="" dataset="" stockrets.rdata="" and="" the="" csv="" file="" stock="" chars="" from="" dailydata.csv="" are="" in="" the="" current="" folder.="" upload="" this="" file="" to="" the="" assignment="" on="" canvas.="" if="" your="" code="" gives="" me="" errors="" when="" i="" run="" it,="" i="" will="" not="" check="" your="" assignment="" and="" you="" will="" get="" no="" credit.="" for="" real!="" a="" good="" way="" to="" make="" sure="" there="" are="" no="" errors="" is:="" close="" r,="" reopen="" r,="" navigate="" to="" the="" directory="" containing="" the="" rdata="" file,="" paste="" your="" code.="" if="" it="" runs="" with="" no="" errors="" or="" warnings,="" great!="" if="" not,="" you="" need="" to="" change="" things.="" there="" are="" points="" for="" following="" instructions,="" so="" please="" be="" careful.="">
Answered Same DayApr 28, 2021

Answer To: HW Week 12: Due Wednesday Apr 28 by 11:59 pm, via Canvas April 23, 2021 Instructions In this HW, we...

Subhanbasha answered on Apr 29 2021
145 Votes
# Remove all objects in workspace
rm(list = ls())
## Q1
load('stockrets.Rdata') # Load "stockrets
.Rdata" dataset
## Q2
# Reading the dataset
stockchars <- read.csv("stock_chars_from_dailydata.csv")
## Q3
# Selcting required columns
main <- subset(stockchars, select = c(permno, monthdate, maxret))
# Checking missing values
table(is.na(main $ maxret))
## Q4
# Calling lubridate package
library(lubridate)
# Create a new variable called "nextmonthsdate"
main $ nextmonthsdate <- ceiling_date(as.Date(main $ monthdate, "%d%b%Y"),"month")
main $ nextmonthsdate <- ceiling_date(main $ nextmonthsdate, "month")...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here