This is the third and the final part of the exercises dedicated to analysis of stock prices. In this part we will provide exercises for testing the type of distribution of stock prices and analysing and predicting stock prices using ARIMA models.
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 reuse data frames from exercise 6 and 7 as input for the exercises in part 3.
In this set of exercises we use two packages:
forecast. If you haven’t already installed them, do it using the following code:
and before proceeding with the exercise set load them into the session using the following code:
Answers to the exercises are available here. If you have different solution, feel free to post it.
Test for normality of the distribution of closing prices of YHOO using histogram.
Test for normality of the distribution of closing prices of YHOO using normal q-q plot.
Test for normality of distribution of closing prices of YHOO using Kolmogorov-Smirnov and Shapiro tests.
Based on four tests, what can you say about the closing prices of YHOO?
- Closing prices of YHOO are approximately normaly distributed
- The distribution of closing prices of YHOO does not conform to the normal distribution
Plot on the same chart:
- Closing prices of GE
- 12 days moving average of the closing prices of GE
- 50 days moving average of the closing prices of GE
ts object and display closing prices of BAC on correliogram. Is the time series stationary?
Is the time series of the closing prices of BAC stationary when you differentiate it, based on the correliogram?
Find the best fitting ARIMA model for closing prices of BAC.
Display ACF graph for the residuals of the model from exercise 7.
Use the first 80% of a time series of prices of BAC to make a prediction for the rest 20% of data. Save the values in a variable.
Using data the exercise 9 and function
accuracy from the
forecast package, test the accuracy of the predictions. Is the prediction acceptable? (Tip: Prediction is acceptable if the field
RMSA from the result of
accuray is less than or equal to standard deviation of test data.).
- 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