The same way, this issue unresolved from July http://r.789695.n4.nabble.com/demo-quot-luxor-8-walk-forward-quot-Error-in-if-all-i-lt-0-stop-quot-only-zeros-may-be-mixed-with-ned-td4694382.html
Amarjit ----Original message---- >From : a.chandh...@btinternet.com Date : 01/09/2014 - 08:11 (GMTST) To : gyol...@r-programming.org Cc : r-sig-finance@r-project.org Subject : Re: [R-SIG-Finance] quantstrat - luxor.8 periodic optimization & walk-forward procedure Many thanks for getting back to me Guy. I should have noticed the frequency! Anyways it's got me started on proper strategy design in quantstrat. UBUNTU ---------- Running on Ubuntu 14.10, I get past the 1st in-sample training and 1st out-of-sample WFA testing, however an error thereafter [1] "=== training WFA on 2002-10-21 00:30:00/2002-10-22 23:30:00" [1] "=== testing param.combo 1 on 2002-10-23/2002-10-23 23:30:00" nFAST nSLOW 1 1 42 [1] "=== training WFA on 2002-10-22/2002-10-23 23:30:00" error calling combine function: <simpleError in fun(result.1, result.2, result.3, result.4, result.5, result.6, result.7, result.8, result.9, result.10, result.11, result.12, result.13, result.14, result.15): attempt to select less than one element> Error in walk.forward(strategy.st, paramset.label = "WFA", portfolio.st = portfolio.st, : obj.func() returned empty result In addition: Warning message: In max(x$tradeStats$Net.Trading.PL) : no non-missing arguments to max; returning -Inf WINDOWS ------------ Running on Windows, I get past the 1st in-sample training then get problems at the 1st out-of-sample testing with the file 'wfa.GBPUSD.2002-10-21 00:30:00.2002-10-22 23:30:00.RData' [1] "=== training WFA on 2002-10-21 00:30:00/2002-10-22 23:30:00" nFAST nSLOW 1 1 42 [1] "2002-10-22 02:00:00 GBPUSD 1e+05 @ 1.545" [1] "2002-10-22 16:30:00 GBPUSD -1e+05 @ 1.5453" [1] "2002-10-22 17:30:00 GBPUSD -1e+05 @ 1.5448" nFAST nSLOW 2 3 42 [1] "2002-10-22 04:00:00 GBPUSD 1e+05 @ 1.547" [1] "2002-10-22 17:00:00 GBPUSD -1e+05 @ 1.5453" [1] "2002-10-22 17:30:00 GBPUSD -1e+05 @ 1.5447" nFAST nSLOW 3 5 42 [1] "2002-10-22 04:00:00 GBPUSD 1e+05 @ 1.547" [1] "2002-10-22 17:30:00 GBPUSD -1e+05 @ 1.5435" [1] "2002-10-22 17:30:00 GBPUSD -1e+05 @ 1.5447" nFAST nSLOW 4 7 42 [1] "2002-10-22 04:00:00 GBPUSD 1e+05 @ 1.547" [1] "2002-10-22 18:00:00 GBPUSD -1e+05 @ 1.543" [1] "2002-10-22 19:00:00 GBPUSD -1e+05 @ 1.5426" nFAST nSLOW 5 9 42 [1] "2002-10-22 04:00:00 GBPUSD 1e+05 @ 1.5469" [1] "2002-10-22 18:30:00 GBPUSD -1e+05 @ 1.543" [1] "2002-10-22 19:00:00 GBPUSD -1e+05 @ 1.5425" nFAST nSLOW 6 1 44 [1] "2002-10-22 02:00:00 GBPUSD 1e+05 @ 1.545" [1] "2002-10-22 17:00:00 GBPUSD -1e+05 @ 1.5453" [1] "2002-10-22 17:30:00 GBPUSD -1e+05 @ 1.5447" nFAST nSLOW 7 3 44 [1] "2002-10-22 04:00:00 GBPUSD 1e+05 @ 1.547" [1] "2002-10-22 17:30:00 GBPUSD -1e+05 @ 1.5435" [1] "2002-10-22 17:30:00 GBPUSD -1e+05 @ 1.5447" nFAST nSLOW 8 5 44 [1] "2002-10-22 04:00:00 GBPUSD 1e+05 @ 1.5469" [1] "2002-10-22 18:00:00 GBPUSD -1e+05 @ 1.543" [1] "2002-10-22 19:00:00 GBPUSD -1e+05 @ 1.5426" nFAST nSLOW 9 7 44 [1] "2002-10-22 04:00:00 GBPUSD 1e+05 @ 1.5469" [1] "2002-10-22 18:00:00 GBPUSD -1e+05 @ 1.543" [1] "2002-10-22 19:00:00 GBPUSD -1e+05 @ 1.5426" nFAST nSLOW 10 9 44 [1] "2002-10-22 04:00:00 GBPUSD 1e+05 @ 1.5469" [1] "2002-10-22 18:30:00 GBPUSD -1e+05 @ 1.543" [1] "2002-10-22 19:00:00 GBPUSD -1e+05 @ 1.5425" nFAST nSLOW 11 1 46 [1] "2002-10-22 02:00:00 GBPUSD 1e+05 @ 1.545" [1] "2002-10-22 17:30:00 GBPUSD -1e+05 @ 1.5435" [1] "2002-10-22 17:30:00 GBPUSD -1e+05 @ 1.5447" nFAST nSLOW 12 3 46 [1] "2002-10-22 04:00:00 GBPUSD 1e+05 @ 1.547" [1] "2002-10-22 18:00:00 GBPUSD -1e+05 @ 1.543" [1] "2002-10-22 19:00:00 GBPUSD -1e+05 @ 1.5426" nFAST nSLOW 13 5 46 [1] "2002-10-22 04:00:00 GBPUSD 1e+05 @ 1.5469" [1] "2002-10-22 18:00:00 GBPUSD -1e+05 @ 1.543" [1] "2002-10-22 19:00:00 GBPUSD -1e+05 @ 1.5426" nFAST nSLOW 14 7 46 [1] "2002-10-22 04:00:00 GBPUSD 1e+05 @ 1.5469" [1] "2002-10-22 18:00:00 GBPUSD -1e+05 @ 1.543" [1] "2002-10-22 19:00:00 GBPUSD -1e+05 @ 1.5426" nFAST nSLOW 15 9 46 [1] "2002-10-22 04:00:00 GBPUSD 1e+05 @ 1.5466" [1] "2002-10-22 18:30:00 GBPUSD -1e+05 @ 1.543" [1] "2002-10-22 19:00:00 GBPUSD -1e+05 @ 1.5425" [1] "=== testing param.combo 1 on 2002-10-23/2002-10-23 23:30:00" nFAST nSLOW 1 1 42 Error in gzfile(file, "wb") : cannot open the connection In addition: Warning messages: 1: executing %dopar% sequentially: no parallel backend registered 2: In gzfile(file, "wb") : cannot open compressed file 'wfa.GBPUSD.2002-10-21 00:30:00.2002-10-22 23:30:00.RData', probable reason 'Invalid argument' However, if I commet out #audit.prefix='wfa', the following error at the end of the 2nd in-sample training error calling combine function: <simpleError in fun(result.1, result.2, result.3, result.4, result.5, result.6, result.7, result.8, result.9, result.10, result.11, result.12, result.13, result.14, result.15): attempt to select less than one element> Error in walk.forward(strategy.st, paramset.label = "WFA", portfolio.st = portfolio.st, : obj.func() returned empty result In addition: Warning messages: 1: executing %dopar% sequentially: no parallel backend registered 2: In covMcd(as.matrix(R), alpha = 1 - alpha) : Initial scale 0 because more than 'h' (=9) observations are identical. 3: In covMcd(as.matrix(R), alpha = 1 - alpha) : Initial scale 0 because more than 'h' (=9) observations are identical. 4: In covMcd(as.matrix(R), alpha = 1 - alpha) : Initial scale 0 because more than 'h' (=9) observations are identical. 5: In max(x$tradeStats$Net.Trading.PL) : no non-missing arguments to max; returning -Inf Please help! ################################################################################################ Here's the program: ############################## # MUST RUN LUXOR.5.ORDERSETS # ############################## setwd(" your directory ") require(quantstrat) source(paste0(path.package("quantstrat"),"/demo/luxor.include.R")) source(paste0(path.package("quantstrat"),"/demo/luxor.getSymbols.R")) #IMPORTANT NOTE #--------------------- # As of 2013-08-12, apply.paramset does not appear to run properly in parallel on # Windows. To run on a Windows platform, load the doParallel package but do not call # the registerDoParallel function; apply.paramset will then be able to run in sequential # rather than parallel mode. library(parallel) detectCores() if( Sys.info()['sysname'] == "Windows" ) { library(doParallel) # registerDoParallel(cores=detectCores()) } else { library(doMC) registerDoMC(cores=detectCores()) } ############################################################################################### #usual stuff #----------- initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD') initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD', initEq=100000) initOrders(portfolio.st, initDate=initDate) load.strategy(strategy.st) #chain rules #----------- #enable.rule(strategy.st, 'chain', 'StopLoss') #enable.rule(strategy.st, 'chain', 'StopTrailing') enable.rule(strategy.st, 'chain', 'TakeProfit') addPosLimit(portfolio=portfolio.st,symbol='GBPUSD',timestamp=initDate, maxpos=.orderqty) ############################################################################################### #objective function #------------------ ess <- function(account.st, portfolio.st) { require(robustbase, quietly=TRUE) require(PerformanceAnalytics, quietly=TRUE) portfolios.st <- ls(pos=.blotter, pattern=paste('portfolio', portfolio.st, '[0-9]*',sep='.')) pr <- PortfReturns(Account = account.st, Portfolios=portfolios.st) my.es <- ES(R=pr, clean='boudt') return(my.es) } ########## #walk.forward #------------ my.obj.func <- function(x){ #pick one of the following objective functions (uncomment) #return(max(x$tradeStats$Max.Drawdown) == x$tradeStats$Max.Drawdown) return(max(x$tradeStats$Net.Trading.PL) == x$tradeStats$Net.Trading.PL) #return(max(x$user.func$GBPUSD.DailyEndEq) == x$user.func$GBPUSD.DailyEndEq) } r <- walk.forward(strategy.st, paramset.label='WFA', portfolio.st=portfolio.st, account.st=account.st, period='days', k.training=2, k.testing=1, obj.func=my.obj.func, obj.args=list(x=quote(result$apply.paramset)), user.func=ess, user.args=list('account.st'=account.st, 'portfolio.st'=portfolio.st), audit.prefix='wfa', anchored=FALSE, verbose=FALSE) ############################################################################################### #Results #------- pdf(paste('GBPUSD', .from, .to, 'pdf', sep='.')) chart.Posn(portfolio.st) dev.off() ts <- tradeStats(portfolio.st) save(ts, file=paste('GBPUSD', .from, .to, 'RData', sep='.')) Amarjit ----Original message---- >From : gyol...@r-programming.org Date : 31/08/2014 - 18:54 (GMTST) To : r-sig-finance@r-project.org Subject : Re: [R-SIG-Finance] quantstrat - luxor.8 periodic optimization & walk-forward procedure Amarjit, I'm pretty sure that you can get the luxor.8.walk.forward.R script to run successfully as follows: 1. execute luxor.5.strategy.ordersets.R which saves the strategy 2. modify the the period argument in the call to walk.forward() to be period='days' Good luck with this. G On 8/31/2014 12:13 AM, amarjit chandhial wrote: > > > I cannot get quantstrat's luxor.8 periodic optimization & walk-forward > procedure, in the demos working. > > > The idea being akin to the following diagram: > > http://www.tradestation.com/trading-technology/tradestation-platform/analyze/walk-forward-optimizer > > > The error I get is, > > Error in if (!all(i <= 0)) stop("only zeros may be mixed with negative > subscripts") : > missing value where TRUE/FALSE needed > > > If anybody can please email a working program. > > > > Otherwise, what I am really after is a demo with the workflow: > - a simple vanilla technical stratgey - I can do > - In-sample optimization of parameter(s) of simple strategy, > Out-of-sample run - I can do > - periodic optimization & walk-forward procedure > > > > > Amarjit > > > > > > > > _______________________________________________ > R-SIG-Finance@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-sig-finance > -- Subscriber-posting only. If you want to post, subscribe first. > -- Also note that this is not the r-help list where general R questions > should go. [[alternative HTML version deleted]] _______________________________________________ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. _______________________________________________ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go. _______________________________________________ R-SIG-Finance@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-finance -- Subscriber-posting only. If you want to post, subscribe first. -- Also note that this is not the r-help list where general R questions should go.