[R-SIG-Finance] blotter on 15 min data
kafkaz
kafka at centras.lt
Wed Apr 14 13:47:59 CEST 2010
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).
--
View this message in context: http://n4.nabble.com/blotter-on-15-min-data-tp1839017p1839662.html
Sent from the Rmetrics mailing list archive at Nabble.com.
More information about the R-SIG-Finance
mailing list