class0320170826151236.html

# class0320170826151236.html - Class 3 Monte Carlo...

• Notes
• 12

This preview shows pages 1–3. Sign up to view the full content.

Class 3 Monte Carlo simulations and bootstrapping CAPM, estimation and resampling methods Estimating CER and CAPM models Value-at-Risk: MC and bootstraping Monte Carlo simulations and bootstrapping To run this script, we first need to load the data that we prepared in the previous class. # this chunk is dedicated to the loading of the necessary data data01 <- read.table("/Users/robertamorelli/Desktop/Econometrics /L5-6/data01.csv", stringsAsFactors = F, header = T, sep = ",") The first step is to see how the realized cumulative returns performed. Let us consider the arc of time from the beginning of 1950 to the end of 2015. TT <- 12*(2015 - 1950 + 1) data02 <- data.frame(array(1, TT)) colnames(data02) <- c("port_c") data02[, 2] <- subset(data01, select = ret_m_c, date >= 1950 & date < 2016) # the subset command is tricky, as it passes also the name of the column # to calculate the cumulative return, we can a loop for (i in 2:TT){ data02\$port_c[i] <- data02\$port_c[i-1] * (1+data02\$ret_m_c[i]) } dygraph(ts(data02\$port_c, start = c(1950, 1), end = c(2015, 12), frequency = 12)) Now we will simulate the series. This permits to see how (im)plausible the assumptions of the absence of serial correlation and of return normality are. # parameter estimation and choice of the number of replications in the simulation vol <- sd(data02\$ret_m_c) alpha <- mean(data02\$ret_m_c) nrep <- 10^3 # here I create the containers to be filled with the generated data. y_bt <- y_mc <- array(1, c(TT, nrep)) x_bt <- x_mc <- array(alpha, c(TT, nrep)) # now, the loop for (i in 1:nrep){ u <- rnorm(TT-1) res <- sample(data02\$ret_m_c[-1], replace = T) # this (re)samples from the data x_mc[-1, i] <- alpha + vol * u # the Monte Carlo way x_bt[-1, i] <- res # the bootstrap way # now we simply construct and store the bootstrapped and MC cumulative returns for (j in 2:TT){ y_mc[j, i] <- y_mc[j-1, i] * (1 + x_mc[j, i]) y_bt[j, i] <- y_bt[j-1, i] * (1 + x_bt[j, i]) } } # now we want to construct the series of means and quantiles of the resulting

This preview has intentionally blurred sections. Sign up to view the full version.

collection of drawn series for (i in 1:TT){ # obtaining the means data02\$y_bt_mean[i] <- mean(y_bt[i, ]) data02\$x_bt_mean[i] <- mean(x_bt[i, ]) data02\$y_mc_mean[i] <- mean(y_mc[i, ]) data02\$x_mc_mean[i] <- mean(x_mc[i, ]) # and the quantiles data02\$y_bt_q05[i] <- quantile(y_bt[i, ], 0.05) data02\$x_bt_q05[i] <- quantile(x_bt[i, ], 0.05) data02\$y_mc_q05[i] <- quantile(y_mc[i, ], 0.05)
This is the end of the preview. Sign up to access the rest of the document.
• Spring '10
• C.Favero

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern