[R-SIG-Finance] quantstrat - monthly/daily trade execution

Ivan Popivanov ivan.popivanov at gmail.com
Thu Mar 28 05:01:25 CET 2013


Hello, I started using quanstrat recently, and must say the design is
impressive.

My first goal is to back test a strategy on daily data, but it quickly
became apparent that I will need to do some work prior to that. First and
foremost, I will need to modify quanstrat to execute the orders on the end
of day, i.e. the same bar. To achieve that I decided to familiarize myself
with the code and I am having problems figuring out the intended design
even for monthly data.

According to ruleOrderProc.R, it seems that for monthly time series, the
trading should occur at the same bar that the signal was triggered (both on
Close at the end of month), right? If so, my 10-month SMA test which is
attached is contradictory - looking at the market data and the trades, it
seems that the orders are executed at the end of the next month instead.
More specifically (from ruleOrderProc.R):

                                yearly = ,
                                quarterly = ,
                                monthly = {

txntime=as.character(index(ordersubset[ii,])) # transacts on this bar, e.g.
in the intraday cross, or leading into the end of month, quarter, etc.
                                    # txntime=as.character(timestamp) # use
this if you wanted to transact on the close of the next bar

txnprice=as.numeric(getPrice(mktdataTimestamp, prefer=prefer)[,1])
                                }, #end

When this code is entered, mktdataTimestamp is on the next bar and it
delivers the price. Is this an issue, or I am missing something?

While on the topic, would you object adding the functionality (under a
flag) to execute trades on the same bar (of course, if it's feasible - i
will try to do the implementation)? I managed to achieve similar
functionality by lagging the indicator backwards, but that seems like a
hack, and I am suspicious that it may have issues with stoplimit and
trailing stops.

Thanks in advance,
Ivan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20130328/8fb62d41/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: macd.monthly.R
Type: application/octet-stream
Size: 2567 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20130328/8fb62d41/attachment.obj>


More information about the R-SIG-Finance mailing list