# Stock Prices Analysis part 3 – Exercises

**R-exercises**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

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?

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

**leave a comment**for the author, please follow the link and comment on their blog:

**R-exercises**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

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