You dont need to be an expert stock’s trader in order to understand the examples, but you should go through part 1, since we shall use some of the solutions as starting point for some of the exercises.
The data set for the exercises is the same as for part 1 and you can download it here. If you solved the exercises from part 1, you can use data frames from exercise 6 and 7 as input for the exercises in part 2.
Answers to the exercises are available here. If you have a different solution, feel free to post it.
Plot a polygon showing closing prices of stock X for the last 90 trading days.
Suppose you have equal amounts of each stock in the data frame. Calculate and plot the average daily return of your portfolio. (Tip: daily return on stock is calculated in part 1, exercise 7.)
Plot pairwise scatter plots comparing returns on all stocks in data set.
Fit a linear model of the form
Y=a+bX to closing prices of YHOO and plot it on a polygon together with actual closing prices of YHOO.
How much of the variation in closing prices of GE is explained by the linear model of the form
Y=a+bX that fits to daily returns of GE.(Tip: you need to calculate r2.)
When you fit a simple linear model of the form
Y=a+bX to closing prices of YHOO in 2016, is the coefficient b statistically significant on the level of
Find the linear model
Y=a+bX that fits to closing prices of GOOG in 2016.
Calculate 95% confidence interval for linear model
Y=a+bX that fits to closing prices of GOOG in 2016. Save the value in a variable for later use.
With fit linear model
Y=a+bX, predict GOOG closing price with 95% confidence interval for ten days ahead of the last recorded price, based on closing prices in 2016. Save the predicted values in a variable for later use.
Plot on the same graph:
- the closing price of GOOG in 2016
- fitted values for model
Y=a+bXfor closing prices of GOOG in 2016 (from exercise 7)
- 95% confidence interval for model
Y=a+bXfor closing price of GOOG in 2016 (from exercise 8)
- prediction of GOOG closing price for next ten days with 95% confidence interval (from exercise 9)
- Become a Top R Programmer Fast with our Individual Coaching Program
- Explore all our (>4000) R exercises
- Find an R course using our R Course Finder directory
- Subscribe to receive weekly updates and bonus sets by email
- Share with your friends and colleagues using the buttons below