n <- 10^4
x <- rnorm(n, mean = 0, sd = 1)
plot(1:n, x, type = "l", lty = 1, xlab = "Observation number", ylab = "Observed values")3 Worksheet 03: Start formulating a model for stock prices and stock returns
Before proceeding, make sure that you have finished the preceding worksheet.
Here I need you to think of the data that we see as one possible set of draws from some process or as the observed values of some process that is operating in the background. In the previous worksheet, we collected prices and returns as observed.
To really make use of these data for decision-making and even just for understanding financial markets, it helps to think of what we observed as just one of the many possible paths we could have seen. The idea is related to what you may have encountered in a probability and statistics course. So, we want to treat the prices and returns as random variables and the observed prices and returns as realizations of said random variables. There is a more technical term for the situation where we osberve random variables over time, but I postpone this for another worksheet.
3.1 Exercise A
In this exercise, you will be making sense of the following lines of R code and to explore what happens if you alter the code.
Run all the lines of code and describe what would be displayed. What do you think
nmeans here?Focus on the time series plot you have obtained. Run all the lines of code once again. What do you notice? Re-run a couple more times to get a sense of what you would expect to see if you re-run the code.
Spend some time reflecting on what you have done so far and its connection to the introductory remarks to this worksheet. How are the ideas in the introductory remarks related to the code? Form your thoughts and discuss with your classmate(s).
You will now be performing some limited alterations to the lines of R code.
- Try adjusting the value of
nholding everything else constant. Before running the lines of code with the modification, what do you expect will happen? Confirm by running the lines of code after the modification. - Now, return
nto its original value. Holding everything constant, try adjustingmean = 0tomean = 2(or perhaps some other value of interest). Before running the lines of code with the modification, what do you expect will happen? Confirm by running the lines of code after the modification. - Return to the original values and this time change
sd. What do you find?
- Try adjusting the value of
3.2 What you have seen is a simulation
Perhaps the most crucial thing to observe at this point is that without specifying rnorm(), you will not even be able to complete the previous exercise. Therefore, that specific line of code is the source for the time series plots you have observed. In effect, you are producing simulated draws from some source.
At this point, you could connect the previous paragraph to what you have encountered in a probability and statistics course. If not, then working through the worksheet yourself and a partner would be effective in regaining what was lost or even just starting from scratch.
Another thing to observe is what happens when you run the lines of R code multiple times. It is as if we went back in time and produced another set of simulated draws. That means that we could have observed a different picture if we “went back in time”.
Even though every time we “go back in time” we produce a different set of simulated values, there is some form of regularity and some form of predictability. Ask yourself the following question: If I stop re-running the lines of R code and see the lines of R code once again without running them, would you have an idea of what to expect to see? If you increase n to a larger value and do NOT run the lines of R code, would you be able to predict what the time series plot would look like?
Now how could artificially generated data or simulated draws bring insight to real-life data? The next exercise asks you to explore this question.
3.3 Exercise B
In this exercise, you will be altering the lines of R code below and to try matching it with the time series plot of returns you have obtained in the previous worksheet.
n <- 10^4
x <- rnorm(n, mean = 0, sd = 1)
plot(1:n, x, type = "l", lty = 1, xlab = "Observation number", ylab = "Observed values")Given your experience with the previous lines of R code, why do you think I am asking you to match to returns rather than prices?
Return to your time series plot of returns.
- Discuss with your classmate how to choose values for
n,mean, andsd. Play around with these assignments and attempt to mimic the patterns you see for your time series plot of returns. - Choose suitable values which “best” matches your observed pattern. Run multiple times the lines of R code with the modifications to get a feel. Pay attention to the axes.
- Discuss with your classmate how to choose values for
Comment on your difficulties in obtaining a “good” match.
- Ask your classmate to show you their example and the difficulties they encountered achieving a “good” match. Did you have the same difficulties? Discuss these difficulties and document them.
- Given the difficulties, what do you think should be present but is missing from
rnorm?
Now modify your original time series plot by changing the observation dates to that your settings for
n,mean,sdso that it becomes hard to distinguish between your original time series plot and the time series plot of the simulated draws fromrnorm().
3.4 An “imperfect” model
Congratulations! You actually have participated in the creation of a model for stock returns. If you were working on the exercise, you will have realized that it is not a perfect model. Nevertheless, it is a good start.
But before we start talking about how to improve the model,
3.5 Exercise C
While working through the exercises so far, we have not exactly specified in full what the model is. For now, reflect on why a model will actually be useful in understanding financial markets and for decision-making.
- Imagine you are an ordinary consumer with a app from a bank. That app has a push notification asking you to consider saving up for the future by investing in one of their funds. How will a model for stock returns help you there?
- Imagine you are a custodian of someone else’s funds (whether that person or organization is reputable is another thing). You have been given the power to decide what to do with those funds, but your principal asks you to make sure that you are producing good returns. How will a model for stock returns help you there?
- Think of a different role other than the first two I have described, but making sure that information from a model for stock returns would somehow be useful or could add value. Write down a description of this role and discuss this description with a partner. What role did they pick? How similar or different were the roles both of you picked?
3.6 Exercise D
We have not explored a possible model for stock prices. Let us build on our “imperfect” model and look at its implications for stock prices.
n <- 10^4
x <- rnorm(n, mean = 0, sd = 1)
plot(1:n, x, type = "l", lty = 1, xlab = "Observation number", ylab = "Observed values")
y <- cumsum(x)
plot(1:n, y, type = "l", lty = 1, xlab = "Observation number", ylab = "Observed values")Don’t run the lines of R code yet.
- Pay attention to the new lines of R code relative to the old lines of R code. What What are the similarities and differences?
- Explore what
cumsum()does by making your own example of a vector in R and applyingcumsum()to it. - Comment on what you think will be displayed in the time series plot.
Now run the lines of R code to verify your preceding comments.
- Does the plot resemble anything you have seen before?
- Before doing anything else, can you imagine what the plot would look like if you “went back in time” and drew another set of simulated draws? Dicuss with your classmate.
Re-run the lines of R code and pay attention to the plots. What do you notice?
- Compare and contrast the time series plots of
ywith the time series plots of simulatedx. Pay attention to the axes. - Comment on the “predictability” of the patterns in the time series plots.
- Compare and contrast the time series plots of