Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

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 »
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 a
anged in this way. Every line co
esponds 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 cha
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 e
or like
could not find function "days"
have you activated the right li
ary?
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 wo
y 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 unde
“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
m(list=ls())
If I copy and paste your commands into my R window, it should run with no e
ors. Assume
that the dataset stockrets.Rdata and the CSV file stock chars from dailydata.csv are
in the cu
ent folder.
Upload this file to the assignment on Canvas.
If your code gives me e
ors 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 e
ors is: close R, reopen R, navigate to the
directory containing the Rdata file, paste your code. If it runs with no e
ors or warnings,
great! If not, you need to change things.
There are points for following instructions, so please be careful.
5
Answered Same Day Apr 28, 2021

Solution

Subhanbasha answered on Apr 29 2021
147 Votes
# Remove all objects in workspace
m(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 lu
idate package
li
ary(lu
idate)
# 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