r - Implementing the bootstrap method for resampling the data set. Assuming that log prices follow random walk but using ARMA model -


#install.packages("quantmod") #install.packages("dataframes2xls") #install.packages("bootstrap") #install.packages("farma") library(bootstrap) library(quantmod) library(dataframes2xls) library(farma)  require(ttr)  getsymbols("sne",src="yahoo",from = as.date("2011-04-20"), =as.date("2015-04-22"))   snelog <- diff( log( cl( sne ) ) ) snelog <- snelog[-1,]  snelogt <- as.ts( tail(snelog, 1000))  snelogtimearma <- armafit( formula=~arima(0,1,0), data=snelogt )  sne.adjusted.boot.sum <- numeric(1000) for(i in 1:1000) {   this.samp <- snelog [ sample(1000,1000,replace=t, prob=??? )]   sne.adjusted.boot.sum[i] <- sum(this.samp) } 

this code.

my professor requirement: implement bootstrap method resampling data set, assuming log prices follow random walk using arma model.

random walk reminds of arima(0,1,0), have no idea how combine bootstrap arma model.

simply put, bootstrap recursively generating samples replacement fit model. performance aggregated.

below quick trial obtain bootstrap coefficients, assuming arima(1, 0, 1). not specified clearly, i'm not sure actual requirement.

library(farma) set.seed(1237) price <- diff(sample(log(100:120), 101, replace = true))  # bootstrap boot <- function(trial, formula, data) {   mod <- armafit(formula, sample(data, trial, replace = true))   c(mod@fit$coef) }  coef <- do.call(rbind, lapply(rep(length(price), 2), boot, formula = ~ arima(1,0,1), data = price)) apply(coef, 2, mean)          ar1         ma1   intercept  -0.66724275  0.67331811 -0.00551791  

note made 2 random samples (rep(length(price), 2)) , result different different setup or same setup - recall bootstrap generates random samples.

the key idea of bootstrap in armafit(formula, sample(data, trial, replace = true)) model fit bootstrap sample, not actual data.

i hope helpful.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -