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?

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

**Exercise 4**

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

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

Marcus says

Dear Sljukic,

I´m working in an intraday forex and I´m trying to undestand how to use the highfrequency package, particularly the realized volatility with eGarch.

Do you have any exercises / examples for this case?

Thanks in advance!

Miodrag Sljukic says

Thank you for your idea, Marcus.

Unfortunately, at this moment I don’t have exercises for the

`highfrequency`

package, but I find this topic very interesting in context of analysis of stock prices. You may expect a set of exercises based on`highfrequency`

package soon.Catalin says

Dear Sljukic,

I found your stock prices analysis exercises very useful. You have done a great job with them.

Could you please provide a reference for the tip information in exercise 10?

“Prediction is acceptable if the field RMSA from the result of accuray is less than or equal to standard deviation of test data.”

A published book or article would be great! Thanks in advance!

Catalin