Hi Mike I can take a closer look. Would you mind logging your questions as issues on the project repo?
https://github.com/braverock/quantstrat/issues/new Thanks Jasen On Fri, Sep 23, 2022 at 8:58 AM Mike <[email protected]> wrote: > I reduced my yesterday's strategy to isolate an issue with delayed > orders. > > The following strategy I would expect to issue an order at > 2021-01-26 09:30:00 but (in the 2. run) to delay execution by one day. > But although the order is being delayed in the order book the trade is > still executed at 2021-01-26 09:30:00. > > Why does setting 'delay' in 'ruleSignal' have no effect on execution > time? > > Thanks! > > Mike > ---------- > > > source('test_strategy2.R') > [1] "delay=1e-04" > ^^^^^ > [1] "2021-01-26 09:30:00 SYM 100 @ 61.24" > ^^ok > $str2 > $str2$SYM > Order.Qty Order.Price Order.Type Order.Side > Order.Threshold > 2021-01-25 15:30:00 "100" "60.58" "market" "long" NA > > ^^ok > Order.Status Order.StatusTime Prefer Order.Set > 2021-01-25 15:30:00 "closed" "2021-01-26 09:30:00" "High" NA > Txn.Fees Rule Time.In.Force > 2021-01-25 15:30:00 "0" "EnterLONG" "" > > > > source('test_strategy2.R') > [1] "delay=86400" > ^^^^^ > [1] "2021-01-26 09:30:00 SYM 100 @ 61.24" > ^^^^^^^^^^^? > $str2 > $str2$SYM > Order.Qty Order.Price Order.Type Order.Side > Order.Threshold > 2021-01-26 15:30:00 "100" "60.58" "market" "long" NA > > ^^^^^^^^^^^ok > Order.Status Order.StatusTime Prefer Order.Set > 2021-01-26 15:30:00 "closed" "2021-01-26 09:30:00" "High" NA > Txn.Fees Rule Time.In.Force > 2021-01-26 15:30:00 "0" "EnterLONG" "" > ---------- > > test_strategy2.R: > library(quantstrat) > > suppressWarnings(rm("account.str2","portfolio.str2",pos=.blotter)) > suppressWarnings(rm("order_book.str2",pos=.strategy)) > > oldtz<-Sys.getenv("TZ") > if(oldtz=="") Sys.setenv(TZ="UTC") > > sy <- 'SYM' > fn <- paste0(sy,".csv") > tmp <- as.xts (read.csv2.zoo (fn, header=T, stringsAsFactors=F, > dec = ".", FUN=as.POSIXct)) > assign(sy, tmp) > > tradeSize <- 5000 > initEq <- 100000 > delay_seconds <- 1 * 24*60*60 > > currency("USD") > stock(sy, currency="USD",multiplier=1) > > initPortf('str2', symbols=sy) > initAcct('str2', portfolios='str2', initEq=initEq) > initOrders(portfolio='str2') > > strategy.st <- 'str2' > strategy (strategy.st, store=TRUE) > > > add.rule(strategy.st, name='ruleSignal', arguments = list( > sigcol = "Long", > sigval = TRUE, > ordertype = 'market', > prefer = 'High', > orderside = 'long', > delay = delay_seconds, > orderqty = 100), > type='enter', > label='EnterLONG') > > > print(paste0("delay=", delay_seconds)) > out<-try(applyStrategy(strategy='str2' , portfolios='str2')) > print(getOrderBook('str2')) > > updatePortf(Portfolio='str2') > updateAcct('str2') > updateEndEq('str2') > > Sys.setenv(TZ=oldtz) > ---------- > > SYM.csv: > Index;Open;High;Low;Close;Volume;Long > 2021-01-25 09:30:00;60.67;60.77;59.705;59.98;4841167;0 > 2021-01-25 10:00:00;59.98;60.31;59.955;59.992;2331090;0 > 2021-01-25 10:30:00;59.99;60.155;59.64;59.69;2011158;0 > 2021-01-25 11:00:00;59.6771;59.76;59.26;59.38;2717999;0 > 2021-01-25 11:30:00;59.38;59.79;59.17;59.67;1758438;0 > 2021-01-25 12:00:00;59.675;59.85;59.4601;59.4601;1536049;0 > 2021-01-25 12:30:00;59.475;59.93;59.47;59.9;1212432;0 > 2021-01-25 13:00:00;59.9;60.37;59.875;60.32;1461132;0 > 2021-01-25 13:30:00;60.32;60.42;60.185;60.23;970523;0 > 2021-01-25 14:00:00;60.24;60.29;59.94;60;971210;0 > 2021-01-25 14:30:00;60;60.24;59.88;60.06;1038065;0 > 2021-01-25 15:00:00;60.055;60.4;60.04;60.345;931919;0 > 2021-01-25 15:30:00;60.35;60.58;60.3;60.56;2135034;1 > 2021-01-26 09:30:00;61.2;61.24;60.087;60.335;2512210;0 > 2021-01-26 10:00:00;60.335;60.9;60.29;60.78;1768021;0 > 2021-01-26 10:30:00;60.78;60.87;60.408;60.445;1173861;0 > 2021-01-26 11:00:00;60.45;60.56;60.15;60.52;1085131;0 > 2021-01-26 11:30:00;60.51;60.53;60.19;60.33;919405;0 > 2021-01-26 12:00:00;60.33;60.68;60.31;60.65;1130399;0 > 2021-01-26 12:30:00;60.645;60.95;60.63;60.915;756772;0 > 2021-01-26 13:00:00;60.92;61.04;60.81;60.875;848270;0 > 2021-01-26 13:30:00;60.87;60.95;60.73;60.805;822825;0 > 2021-01-26 14:00:00;60.8;61.15;60.78;60.95;989872;0 > 2021-01-26 14:30:00;60.95;60.98;60.81;60.9;1001693;0 > 2021-01-26 15:00:00;60.9;60.93;60.73;60.86;854300;0 > 2021-01-26 15:30:00;60.85;60.93;60.67;60.91;3214855;0 > 2021-01-27 09:30:00;59.9;59.99;58.53;58.98;3972687;0 > 2021-01-27 10:00:00;58.97;59.43;58.74;59.37;2386966;0 > 2021-01-27 10:30:00;59.375;59.85;59.13;59.81;2147582;0 > 2021-01-27 11:00:00;59.82;59.86;59.44;59.69;1273143;0 > 2021-01-27 11:30:00;59.6998;59.76;59.4;59.45;1183463;0 > 2021-01-27 12:00:00;59.45;60;59.35;59.41;1359946;0 > 2021-01-27 12:30:00;59.41;59.62;59.31;59.565;570512;0 > 2021-01-27 13:00:00;59.565;59.868;59.44;59.76;761216;0 > 2021-01-27 13:30:00;59.76;59.765;59.45;59.58;623576;0 > 2021-01-27 14:00:00;59.585;59.7;59.37;59.42;897427;0 > 2021-01-27 14:30:00;59.425;59.625;59.21;59.3283;2123241;0 > 2021-01-27 15:00:00;59.33;59.83;59.2;59.67;1558001;0 > 2021-01-27 15:30:00;59.66;59.7;59.17;59.4;3507501;0 > > _______________________________________________ > [email protected] 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]] _______________________________________________ [email protected] 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.
