[R-SIG-Finance] Quantstrat for backtesting on tickdata (and creating a spread from tick)

Joshua Ulrich josh.m.ulrich at gmail.com
Fri Jun 5 01:52:23 CEST 2015

On Mon, Jun 1, 2015 at 4:00 PM, bearwithme <daneedwards1 at hotmail.com> wrote:
> Hi, could someone please point me in the right direction. It can be high
> level and i can do the research (which have already done but i seem to be
> going around in circles right now haha)
> I have tick data for two instruments bid/vol & ask/vol.
> Example data : Bid for BRN0615 (Brent june 2015)
> 20150421 175951;61.87;4
> 20150421 175955;61.87;3
> 20150421 175955;61.87;1
> 1) I would like create a spread between 2 instruments using this tick data.
> (can fn_spreadbuilder do this?)
> spread ask = BRN0615(ask) - (BRNS120615(bid) *3)
> spread bid = BRN0615(bid) - (BRNS120615(ask) *3)
I have some code that builds a similar spread like this:

syms <- c("BRN0615","BRNS120615")
bid <- buildSpread("BRNS",onelot=FALSE,prefer="Bid",auto.assign=FALSE)
ask <- buildSpread("BRNS",onelot=FALSE,prefer="Ask",auto.assign=FALSE)
BRNS <- merge(bid, ask)

This code is a couple years old and I don't remember the precise
reason for constructing the spread that way... I think it had
something to do with not assuming you would be able to get the passive
price on both legs of the spread.  Hopefully someone else can

> 2) unfortunately in the tick data some of the date rows have duplicate time
> stamps (i hope to get better data) is there a way of dealing with this
> (without going to 1 second data).
xts objects don't need a unique index.  Did you actually encounter a
problem, or are you just guessing that there will be one?

> 3) once i have the spread, it will be in bid/ask format still, I know how to
> access the columns in quanstrat using $columnname but what is the best way
> to get it a certain format?
Use column names, Bid.Price and Ask.Price, respectively.  Then set
prefer = "Bid" or prefer = "Ask" in your quantstrat calls that care
about the side of the market (e.g. ruleSignal).

> ** my strategy will use the bid and ask of the resulting spread, when the
> ask goes below a certain level i will long, when the bid goes above a
> certain level i will go short (mean reversion).
> thanks!!
> --
> View this message in context: http://r.789695.n4.nabble.com/Quantstrat-for-backtesting-on-tickdata-and-creating-a-spread-from-tick-tp4708020.html
> Sent from the Rmetrics mailing list archive at Nabble.com.
> _______________________________________________
> R-SIG-Finance at 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.

Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com
R/Finance 2015 | www.rinfinance.com

More information about the R-SIG-Finance mailing list