Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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: tseries and forecast. If you haven’t already installed them, do it using the following code:

 install.packages(c("tseries", "forecast")) 

and before proceeding with the exercise set load them into the session using the following code:

 library("tseries") library("forecast") 

Answers to the exercises are available here. If you have different solution, feel free to post it.

Exercise 1

Test for normality of the distribution of closing prices of YHOO using histogram.

Exercise 2

Test for normality of the distribution of closing prices of YHOO using normal q-q plot.

Exercise 3

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?

1. Closing prices of YHOO are approximately normaly distributed
2. The distribution of closing prices of YHOO does not conform to the normal distribution

Exercise 4

Plot on the same chart:

1. Closing prices of GE
2. 12 days moving average of the closing prices of GE
3. 50 days moving average of the closing prices of GE

Exercise 5

Create ts object and display closing prices of BAC on correliogram. Is the time series stationary?

• Yes
• No

Exercise 6

Is the time series of the closing prices of BAC stationary when you differentiate it, based on the correliogram?

• Yes
• No

Exercise 7

Find the best fitting ARIMA model for closing prices of BAC.

Exercise 8

Display ACF graph for the residuals of the model from exercise 7.

Exercise 9

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.

Exercise 10

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.).