[R-SIG-Finance] Order book / mktdata cbind issue (offset?)

Mark Knecht markknecht at gmail.com
Wed Oct 1 16:28:50 CEST 2014


Hi,
   Using quantstrat-0.9.1632 I had the idea that I should be able to
cbind mktdata & order book together to trace out what's happening in a
strategy. I wanted to see the orders lined up against strategy
indicators, signals & prices so that I could reconcile in my mind
what's happening. Unfortunately I find that the order book indexes
seem to be offset by a small amount from the mktdata indexes. Is this
by design and if so is there some way for me to line them back up?

   The code below takes a 1 month portion of both xts object as
example. From the order book there is only one trade with an index of
964742409 (really 964742408.64???) which indeed is not in the index
list from mktdata. The mktdata index with the same date is apparently
964742400.

   Why is this happening? Is there some documentation for me to read?

   I will supply a complete strategy if required but it seems to
happen with all the demos. I'm getting the order book using as
appropriate:

oB = getOrders(portfolio.st, stock.str, status="closed")

Thanks in advance,
Mark



library(quantstrat)

oB_Part = structure(c("100", "145.72", "market", "long", NA, "closed",
"2000-07-31 00:00:00", "Open", "ocolong", "0", "LE", ""), class = c("xts",
"zoo"), .indexCLASS = "Date", .indexTZ = "UTC", tclass = "Date",
tzone = "UTC", index = structure(964742408.64, tzone = "UTC", tclass = "Date"),
.Dim = c(1L,
12L), .Dimnames = list(NULL, c("Order.Qty", "Order.Price", "Order.Type",
"Order.Side", "Order.Threshold", "Order.Status", "Order.StatusTime",
"Prefer", "Order.Set", "Txn.Fees", "Rule", "Time.In.Force")))

mktdata_Part = structure(c(145.44, 146.38, 144.94, 146.69, 147.88,
147.47, 149.28,
149.98, 150.44, 150.98, 150.62, 149.47, 149, 149.75, 148.12,
147.75, 146.97, 145.94, 145.72, 142.94, 147.44, 146.66, 146.47,
148.78, 148.91, 149.12, 150.12, 150.38, 151.25, 151.98, 150.62,
149.91, 150.62, 149.75, 148.86, 147.84, 147.16, 146.62, 145.91,
144.12, 145.19, 144.38, 144.22, 146.25, 147.53, 147.16, 148.69,
149.19, 149.67, 150.69, 149.34, 148.25, 148.81, 147.69, 146.56,
146.78, 145.64, 144.69, 141.52, 142.06, 147.28, 144.62, 145.75,
148.09, 147.84, 148.16, 149.12, 149.78, 151.25, 151, 149.77,
148.56, 150.62, 147.69, 146.84, 147.31, 145.88, 145.38, 142.09,
143, 1436600, 2748200, 5963200, 3034800, 2816100, 5431600, 5883000,
5356000, 5341900, 4208300, 4262100, 8506800, 4538900, 5656900,
5628500, 4757100, 12062500, 7652600, 6229500, 5265500, 112.89,
110.86, 111.72, 113.52, 113.33, 113.57, 114.31, 114.81, 115.94,
115.75, 114.8, 113.88, 115.46, 113.21, 112.56, 112.92, 111.82,
111.43, 108.92, 109.61, 0.1308, 0.1308, 0.1308, 0.0756, 0.0756,
0.0756, 0.0756, 0.0756, 0.0537, 0.0537, 0.0537, 0.0537, 0.0537,
0.037, 0.037, 0.037, 0.037, 0.037, 0.0186, 0.0186, 6e-04, 6e-04,
6e-04, 0.0065, 0.0065, 0.0065, 0.0065, 0.0065, 0.0191, 0.0191,
0.0191, 0.0191, 0.0191, 0.0216, 0.0216, 0.0216, 0.0216, 0.0216,
0.0217, 0.0217, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0), class = c("xts", "zoo"), .indexCLASS = "Date",
.indexTZ = "UTC", tclass = "Date", tzone = "UTC", src = "R_ETFAdjust",
updated = structure(1412172075.13977, class = c("POSIXct",
"POSIXt")), index = structure(c(962582400, 962755200, 962841600,
962928000, 963187200, 963273600, 963360000, 963446400, 963532800,
963792000, 963878400, 963964800, 964051200, 964137600, 964396800,
964483200, 964569600, 964656000, 964742400, 965001600), tzone = "UTC",
tclass = "Date"), .Dim = c(20L,
11L), .Dimnames = list(NULL, c("SPY.Open", "SPY.High", "SPY.Low",
"SPY.Close", "SPY.Volume", "SPY.Adjusted", "Best", "Sym", "Long",
"LEsig", "LXsig")))

.index(oB_Part)

.index(mktdata_Part)

.index(oB_Part) %in% .index(mktdata_Part)

tmp1=cbind(mktdata_Part, oB_Part)

.



More information about the R-SIG-Finance mailing list