Skip to content

blotter on 15 min data

4 messages · kafkaz, Brian G. Peterson

#
Q: can I use blotter on 5 min. data? 
In my case, equity goes to 0 after first call of:
updatePortf(ltportfolio, Dates = currentDate)
updateAcct(ltaccount, Dates = currentDate)
updateEndEq(ltaccount, Dates = currentDate)

My data looks like this:
Open   High    Low  Close
2007-01-02 02:05:00 1.3232 1.3234 1.3230 1.3234
2007-01-02 02:10:00 1.3233 1.3233 1.3230 1.3232
2007-01-02 02:15:00 1.3233 1.3234 1.3232 1.3232
2007-01-02 02:20:00 1.3233 1.3234 1.3229 1.3230
2007-01-02 02:25:00 1.3229 1.3232 1.3229 1.3231
2007-01-02 02:30:00 1.3230 1.3232 1.3229 1.3230

Here is blotter related code:
Sys.setenv(TZ="GMT")
initDate=index(eu5min[1])
rm(list=ls(envir=.blotter),envir=.blotter)
symbols<-c('eu5min')
initPortf(ltportfolio,symbols, initDate=initDate)

initAcct(ltaccount,portfolios=c(ltportfolio),
initDate=initDate,initEq=100000)
currency("USD")
stock('eu5min',currency="USD",multiplier=1)
equity = getEndEq(ltaccount, initDate)
print(paste('equity ',equity))

for(i in 2:length(signal))
{
	currentDate= time(signal)[i]
	print(paste('currentDate ',currentDate))
	updatePortf(ltportfolio, Dates = currentDate)
	updateAcct(ltaccount, Dates = currentDate)
	updateEndEq(ltaccount, Dates = currentDate)
	equity = getEndEq(ltaccount, currentDate)
	
	print(paste('equity ',equity))
}

Output of this code is:
[1] "equity  1e+05"
[1] "currentDate  2007-01-02 02:10:00"
[1] "equity  0"
[1] "currentDate  2007-01-02 02:15:00"
[1] "equity  0"
[1] "currentDate  2007-01-02 02:20:00"
[1] "equity  0"
[1] "currentDate  2007-01-02 02:25:00"
[1] "equity  0"
[1] "currentDate  2007-01-02 02:30:00"
[1] "equity  0"
[1] "currentDate  2007-01-02 02:35:00"
[1] "equity  0"

As you can see, equity goes down without any transaction.

str(eu5min)
An ?xts? object from 2007-01-02 02:05:00 to 2007-02-01 23:55:00 containing:
  Data: num [1:6509, 1:4] 1.32 1.32 1.32 1.32 1.32 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:4] "Open" "High" "Low" "Close"
  Indexed by objects of class: [POSIXt,POSIXct] TZ: GMT
  xts Attributes:  
 NULL

str(signal)
An ?xts? object from 2007-01-02 02:05:00 to 2007-02-01 23:55:00 containing:
  Data: num [1:6509, 1] 0 0 0 0 0 0 0 0 0 0 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr "Close"
  Indexed by objects of class: [POSIXt,POSIXct] TZ: GMT
  xts Attributes:  
 NULL

Any ideas about this? Thank you in advance.
#
On 04/13/2010 04:15 PM, kafkaz wrote:
A: Yes.  I use it on high frequency irregular and bar data all the time, 
but I do not use updateEndEq (it's not really important for what I do) 
so the problem may lie there.

Use dput() to output your data, str() does not create a reproducible 
example.  (Thank you for trying.)

Please update to current R-Forge code for blotter (there have been 
several changes recently) and related/required dependencies, and re-post 
a reproducible example.

I'm a little busy leading up to R/Finance in Chicago this week, but I'll 
take a look at it in detail on Monday and we'll work with you to get it 
fixed if you provide something we can run to reproduce your error.

Regards,

     - Brian

  
    
#
Here's "eu5min" object's dump:
structure(c(1.3232, 1.3233, 1.3233, 1.3233, 1.3229, 1.323, 1.3231, 
1.323, 1.3226, 1.3229, 1.323, 1.323, 1.3234, 1.3233, 1.3234, 
1.3234, 1.3232, 1.3232, 1.3231, 1.323, 1.3229, 1.3232, 1.3233, 
1.323, 1.323, 1.323, 1.3232, 1.3229, 1.3229, 1.3229, 1.3228, 
1.3226, 1.3226, 1.3229, 1.3228, 1.3227, 1.3234, 1.3232, 1.3232, 
1.323, 1.3231, 1.323, 1.3229, 1.3227, 1.3228, 1.3231, 1.3229, 
1.3227), index = structure(c(1167703500, 1167703800, 1167704100, 
1167704400, 1167704700, 1167705000, 1167705300, 1167705600, 1167705900, 
1167706200, 1167706500, 1167706800), tzone = "GMT"), .Dim = c(12L, 
4L), .Dimnames = list(NULL, c("Open", "High", "Low", "Close")), .indexCLASS
= c("POSIXt", 
"POSIXct"), .indexTZ = "GMT", class = c("xts", "zoo"))

And the test file:
library(xts)
library(quantmod)
library(blotter)

Sys.setenv(TZ = "GMT")
eu5min<-dget('eu5min')

print(eu5min)

signal<-Cl(eu5min)
signal[which(signal!=0)]<-0

initDate=index(eu5min[1])
currency("USD")
stock('eu5min',currency="USD",multiplier=1)
symbols<-c('eu5min')
ltportfolio='longtrend'
ltaccount='longtrend'
initPortf(ltportfolio,symbols, initDate=initDate)
initAcct(ltaccount,portfolios=c(ltportfolio),
initDate=initDate,initEq=100000)

equity = getEndEq(ltaccount, initDate)
print(paste('equity ',equity))

for(i in 2:length(Cl(eu5min)))
{
	currentDate= time(signal)[i]
	print(paste('currentDate ',currentDate, ' eq ', getEndEq(ltaccount,
currentDate)))
	updatePortf(ltportfolio, Dates = currentDate)
	updateAcct(ltaccount, Dates = currentDate)
	updateEndEq(ltaccount, Dates = currentDate)
	equity = getEndEq(ltaccount, currentDate)
	
	print(paste('equity ',equity))
	if(equity == 0)
		break;
}

tmp<- try(get(paste("account", ltaccount, sep = "."), envir = .blotter))
tail(tmp[[1]][paste("::", currentDate, sep = ""), ])[, "End.Eq"]

I tried on two machines (linux and winXP) and I got the same printout:
                      Open   High    Low  Close
2007-01-02 02:05:00 1.3232 1.3234 1.3230 1.3234
2007-01-02 02:10:00 1.3233 1.3233 1.3230 1.3232
2007-01-02 02:15:00 1.3233 1.3234 1.3232 1.3232
2007-01-02 02:20:00 1.3233 1.3234 1.3229 1.3230
2007-01-02 02:25:00 1.3229 1.3232 1.3229 1.3231
2007-01-02 02:30:00 1.3230 1.3232 1.3229 1.3230
2007-01-02 02:35:00 1.3231 1.3231 1.3228 1.3229
2007-01-02 02:40:00 1.3230 1.3230 1.3226 1.3227
2007-01-02 02:45:00 1.3226 1.3229 1.3226 1.3228
2007-01-02 02:50:00 1.3229 1.3232 1.3229 1.3231
2007-01-02 02:55:00 1.3230 1.3233 1.3228 1.3229
2007-01-02 03:00:00 1.3230 1.3230 1.3227 1.3227
[1] "longtrend"
[1] "longtrend"
[1] "equity  1e+05"
[1] "currentDate  2007-01-02 02:10:00  eq  1e+05"
[1] "equity  0"
                    End.Eq
2007-01-02 02:05:00  1e+05
2007-01-02 02:05:00  0e+00
2007-01-02 02:05:00  0e+00
2007-01-02 02:10:00  0e+00

Then I tried the same test file with yahoo data and SPY ticker. In that case
equity remained at 1e+05. The only difference what I found between two gput
objects was .indexCLASS (Date for daily data vs POSIXct for 5 min. data).
13 days later