Answered step by step
Verified Expert Solution
Question
1 Approved Answer
R Code, please provide the necessary code based off of the provided lab/assignment. Question: Textbook: 4.7.1 The Stock Market Data Submit: the screenshot of the
R Code, please provide the necessary code based off of the provided lab/assignment.
Question:
Textbook:
4.7.1 The Stock Market Data Submit: the screenshot of the output of the command summary(Smarket). The Stock Market Data We will begin by examining some numerical and graphical summaries of the Smarket data, which is part of the TSLR2 library. This data set consists of percentage returns for the S\&P 500 stock index over 1, 250-days, from the beginning of 2001 until the end of 2005 . For each date, we have recorded the percentage returns for each of the five previous trading days, lagone through lagfive. We have also recorded volune (the number of shares traded on the previous day, in billions), Today (the percentage return on the date in question) and direction (whether the market was Up or Down on this date). Our goal is to predict direction (a qualitative response) using the other features. The cor() function produces a matrix that contains all of the pairwise correlations among the predictors in a data set. The first command below gives an error message because the direction variable is qualitative. cor (Smarket) \#\# Error in cor(Smarket): ' x ' must be numeric cor(Smarket[,9]) ####Year##Lag1##Lag2##Lag3##Lag4##Lag5##Volume0.53900647##Today####Year##Lag1##Lag2##Lag3##Lag4##Lag5##Volume0.022002315##TodayYear1.000000000.029699650.030596420.033194580.035688720.029787990.0409099080.03009523Lag50.0297879950.0056746060.0035579490.0188083380.0270836411.0000000001.000000000.034860083Lag10.0296996491.0000000000.0262943280.0108034020.0029859110.0056746060.0433832150.026155045Volume0.539006470.040909910.043383210.041823690.048414250.022002310.0145918230.01459182Lag20.0305964220.0262943281.0000000000.0258966700.0108535330.0035579490.0418236860.010250033Today0.0300952290.0261550450.0102500330.0024476470.0068995270.0348600831.000000000Lag30.0331945810.0108034020.0258966701.0000000000.0240510360.0188083380.0484142460.002447647Lag40.0356887180.0029859110.0108535330.0240510361.0000000000.0270836410.006899527 As one would expect, the correlations between the lag variables and today's returns are close to zero. In other words, there appears to be little correlation between today's returns and previous days' returns. The only substantial correlation is between Year and volume . By plotting the data, which is ordered chronologically, we see that volume is increasing over time. In other words, the average number of shares traded daily increased from 2001 to 2005Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started