Skip to content

Quantstrat for backtesting on tickdata (and creating a spread from tick)

3 messages · Joshua Ulrich, bearwithme

#
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)

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).

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?


** 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.
3 days later
#
On Mon, Jun 1, 2015 at 4:00 PM, bearwithme <daneedwards1 at hotmail.com> wrote:
I have some code that builds a similar spread like this:

syms <- c("BRN0615","BRNS120615")
currency('USD')
spread("BRNS","USD",syms,c(1,-3))
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
elaborate.
xts objects don't need a unique index.  Did you actually encounter a
problem, or are you just guessing that there will be one?
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).

  
    
1 day later
#
Thanks Joshua, 

I'll give that a go.. 
what i ended up doing was this.

****loaded the bid, ask separately from csv****

#transform form into xts object
outask <- as.xts(read.zoo(BRN.06.15.Ask,
                          tz='',   
                          format='%Y%m%d %H%M%S'))
outbid <- as.xts(read.zoo(BRN.06.15.Bid,
                          tz='',   
                          format='%Y%m%d %H%M%S'))
calask <- as.xts(read.zoo(BRNS12.12.15.Ask,
                          tz='',   
                          format='%Y%m%d %H%M%S'))
calbid <- as.xts(read.zoo(BRNS12.12.15.Bid,
                          tz='',   
                          format='%Y%m%d %H%M%S'))

#make.index.unique(outask)

#merge the xts files into one
strat  <- merge.xts(outask, outbid, calask, calbid)
head(strat)

#rename columns
names(strat)[names(strat)=="V2"] <- "outask"
names(strat)[names(strat)=="V3"] <- "outaskvol"
names(strat)[names(strat)=="V2.1"] <- "outbid"
names(strat)[names(strat)=="V3.1"] <- "outbidVol"
names(strat)[names(strat)=="V2.2"] <- "calask"
names(strat)[names(strat)=="V3.2"] <- "calaskvol"
names(strat)[names(strat)=="V2.3"] <- "calbid"
names(strat)[names(strat)=="V3.3"] <- "calbidVol"
tail(strat)

#fill down rows
strat  <- na.locf(strat)
tail(strat)

#create strat ask and bid
strat$stratask  <-  strat$outask - (strat$calbid*3)
strat$stratbid  <-  strat$outbid - (strat$calask*3)

which gave me a xts object with everything i need.. i haven't got to back
testing yet but i will let you know how it go.. maybe your way is easier
I'll try that too.

*i havn't had any issues with unique fields yet.



--
View this message in context: http://r.789695.n4.nabble.com/Quantstrat-for-backtesting-on-tickdata-and-creating-a-spread-from-tick-tp4708020p4708278.html
Sent from the Rmetrics mailing list archive at Nabble.com.