[R] Bootstrap using ARIMA model

David Winsemius dwinsemius at comcast.net
Sun Dec 4 02:55:46 CET 2016


> On Dec 1, 2016, at 1:58 PM, Ashwini Patil <ash369ster at gmail.com> wrote:
> 
> Hi David,
> 
> here is my code including what i did for the tsboot:
> rm(list = ls())
> library(boot)
> library(tseries)
> library(TTR)
> library(quantmod)
> library(scales)
> library(forecast)
> library(zoo)
> library(TSA)
> security<-"NFLX"
> startDate<-"2012-06-01"
> endDate<-"2016-10-31"
> qte_list<-c("AdjClose")
> 
> data=get.hist.quote(instrument = security, startDate, endDate, quote =
> qte_list,   provider = "yahoo" )
> 
> func.ar<- ar(logret)

> func.ar<- ar(logret)
Error in ar.yw(x, aic = aic, order.max = order.max, na.action = na.action,  : 
  object 'logret' not found


> func.model<-list(order = c(func.ar$order,0,0),ar=func.ar$ar)
> func.res<- func.ar$resid[!is.na(func.ar$resid)]
> func.res<-func.res - mean()
> func<- function(logret,formula){
>  d = logret
>  return(RSI(exp(logret)))
> }
> func.sim<-function(res,n.sim,ran.args){
>  rg1<- function(n, res) sample(res, n, replace=TRUE)
>  ts.orig<-ran.args$ts
>  ts.mod<-ran.args$model
>  mean(ts.orig)+ts(arima.sim(model=ts.mod,n=n.sim, ran.gen=rg1,
> res=as.vestor(res)))
> }
> myboot<-tsboot(exp(logret),func,R=500,sim="model", ran.gen=func.sim,
> ran.args = List(ts=log(data[,1],model=func.sim))
> 
> 
> Best,
> Ash
> 
> 
> On Thu, Dec 1, 2016 at 1:50 PM, Bert Gunter <bgunter.4567 at gmail.com> wrote:
> 
>> Just briefly to follow up David's comment, though this is mainly about
>> statistics and therefore off topic here...
>> 
>> Bootstrapping time series is a subtle issue that requires familiarity
>> with the technical details-- and maybe even current research. The
>> tsboot() function gives you several options from which you must choose
>> *appropriately* -- or maybe choose something else entirely. The Help
>> doc gives you a sense of the difficulties:
>> 
>> ***************
>> Model based resampling is very similar to the parametric bootstrap and
>> all simulation must be in one of the user specified functions. This
>> avoids the complicated problem of choosing the block length but relies
>> on an accurate model choice being made.
>> 
>> Phase scrambling is described in Section 8.2.4 of Davison and Hinkley
>> (1997). The types of statistic for which this method produces
>> reasonable results is very limited and the other methods seem to do
>> better in most situations. Other types of resampling in the frequency
>> domain can be accomplished using the function boot with the argument
>> sim = "parametric".
>> ****
>> 
>> Moral: If you don't know what you're doing, seek local expertise to
>> help -- remote sites offering suggestions from those who aren't
>> familiar with the details of your data and analysis goals (maybe you
>> don't need to do this at all!) may lead you to irreproducible
>> nonsense.
>> 
>> Cheers,
>> Bert
>> Bert Gunter
>> 
>> "The trouble with having an open mind is that people keep coming along
>> and sticking things into it."
>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>> 
>> 
>> On Thu, Dec 1, 2016 at 7:45 AM, Ashwini Patil <ash369ster at gmail.com>
>> wrote:
>>> Hi,
>>> 
>>> I want to implement a bootstrap method for time series.
>>> I am taking the adj close values from yahoo for NFLX and now I need to
>>> bootstrap these values using ARIMA model.
>>> 
>>> here is my code so far:
>>> rm(list = ls())
>>> library(boot)
>>> library(tseries)
>>> library(TTR)
>>> library(quantmod)
>>> library(scales)
>>> library(forecast)
>>> library(zoo)
>>> library(TSA)
>>> security<-"NFLX"
>>> startDate<-"2012-06-01"
>>> endDate<-"2016-10-31"
>>> qte_list<-c("AdjClose")
>>> 
>>> data=get.hist.quote(instrument = security, startDate, endDate, quote =
>>> qte_list,   provider = "yahoo" )
>>> logret<-diff(log(data[,1]))
>>> fit11<-auto.arima(logret, max.order=10)
>>> 
>>> When i use auto.arima, I get an order of (0,0,0) with non-zero mean.
>> After
>>> this, I tried to use tsboot function but it is not yielding any answers.
>>> 
>>> Any and all help is appreciated.
>>> 
>>> Thank you!
>>> 
>>>        [[alternative HTML version deleted]]
>>> 
>>> ______________________________________________
>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/
>> posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list