Statistics and probability project

Rubric – In order to earn full credit for this project, you must submit all of the data and answers to questions indicated below.

Spread out your work to include multiple pages. Be sure that each individual chart, graph or diagram is not split between pages. Use R for all diagrams, tables, graphs, and computations. You can turn iin by hand in our last class (Monday August 7th) or deliver to my office on Tuesday August 8th, or email to morrows@wit.edu.

1. Chose a company stock such as Microsoft (msft), Amazon (amzn), or a variety of other choices. You could even choose an ETF or index fund. Get the symbol for the stock – you can do this easily with a google search.

a. Copy and paste the following command into your favorite internet browser, such as firefox:

https://www.google.com/finance/historical?output=csv&q=xxx

However, replace the ‘xxx’ at the end with the symbol you have chosen.

b. Once you have the data in excel, delete all the columns except the 2nd column that refers to “Open”. These are the opening prices for the stock over the last year.

c. Create a new column of just the changes from day to day. So at the top of a new column, type the word “changes”, then enter a formula for the change of price from a day versus the previous day. For example, if you type =A2-A3 into cell B2 and hit enter, it will give you the price change from the second to last day to the most recent day. Use the shortcuts in excel to repeat this for the whole column.

d. Now make a column of relative changes. The relative change is (today’s price-yesterday’s price)/yesterday’s price. So, for example, if you type =B2/A3 into cell C2, it will give you the relative change.

e. You then have a sample of 249 or 250 numbers (the relative changes) that represent the growth or decline of your stock. Get these number into a vector in R. How? Do some searches to find out how to import from a file into R. You obviously do not want to type them in by hand. In fact, here is a nice link that alks about doing this: https://www.datacamp.com/community/tutorials/r-tutorial-read-excel-into-r/#gs.dzfiAc4 (By the way, you could do everything in R if you wish. Use the command data <- read.csv(“https://www.google.com/finance/historical?output=csv&q=amzn”,header = TRUE) This will get you the entire original set of data into an object called data, then you can extract the column you want, and then apply the diff() command to get successive differences like we did in excel.

f. Find the mean and standard deviation of this sample of relative price changes. Call the mean “mu” and the standard deviation “sigma” so we can use them later.

g. Create a histogram of the relative price change sample values to see the shape of the distribution. Does it appear it could be from a normal distribution? Explain why or why not.

h. Use the commands qqnorm() and qqline() to do a Normal Quantile Plot to see if the data of relative changes looks to be normal. Read about that test online to see what you should be looking for. Does the data appear that it could be from a normal distribution? Why?

i. Do the Shapiro Wilk test on this same set of data with level of significance alpha = 0.05. What is the conclusion of the test? Be specific about exactly what the conclusion is.

2. Find a 95% confidence interval for the mean of the relative price changes. Show the calculation or the R commands that you use to get this.

3. Try the following in R:

a = 0

b = 10

x = seq(a, b, by=0.05)

n = length(x)

y = c(0, rnorm(n-1, mean=0, sd=.05))

plot(x, y, type= “l”) #note: that symbol in quotes is the lowercase letter ell

What does it look like? Describe the graph you see. Next, try changing the standard deviation and see what happens. This is an example of what’s called “white noise”, or “white Gaussian noise”. This is useful, because if you have a signal x, you could add the y vector to x and simulate a “noisy” signal.

Enter the code: barplot(y) to see they are just random normal outputs

a. There is a continuous process called Brownian Motion which is seen in nature. It represents a continuous form of random movement, unlike the white noise that jumped around. To make the process continuous, do the following:

y2 = cumsum(y) # this adds the values in y successively to create a running total

plot(x, y2, type= “l”)

Compare this plot to the last one. Again, try changing the standard deviation. What happens if you change the mean to 0.1? (You have to recreate the y2 vector after changing the original y vector, or just combine into one command such as y2= c(0, cumsum(rnorm(n-1, mean=0, sd=.05)))

4. Now let’s simulate the stock that you have chosen over the next 4 years. This is approximately 1000 days, since the market is open about 250 days per year. We will use something called geometric Brownian motion, which is essentially an exponential function with the continuous randomness added to the output.

a. Type this code:

x = 1:1000

y = c()

y[1]=200 # Change 200 to the current value of your stock

for (i in 2:1000) {

y[i] = y[i-1]*(1+rnorm(1,mu,sigma))

}

plot(x,y,type= “l”)

b. What happens if the standard deviation is made very small? Try this and plot it (use sigma=.001). It should look like the curve y = e^(mu*t), which is standard exponential growth.

c. Use a loop to make 100 plots of this and find the overall highest value of the stock and overall lowest value. If you can, try to plot all 100 samples on the same graph.

d. Note: Of course this is a simulation, this is only a look at what could happen with the stock price if the same mean and standard deviation of its past performance continues, and even then the randomness makes it impossible to predict. In the business of finance, these simulations are used to find the most extreme ups and downs in order to prepare for the results.

Order from us and get better grades. We are the service you have been looking for.