adapting quantstrat/demo/luxor code
Yes, omitting the Prices parameter doesn't the trick. I can use
col_names = c('Open','High','Low','Close','Volume')
instead of:
colnames(data.xts) <-
c('AUDUSD.Open','AUDUSD.High','AUDUSD.Low','AUDUSD.Close','AUDUSD.Volume')
Thank you!
On Sun, Jul 1, 2012 at 11:51 PM, OpenTrades <jan at opentrades.nl> wrote:
I think that the problem is in the following line in Luxor:
updatePortf(p, Symbols='GBPUSD',
,Dates=paste('::',as.Date(Sys.time()),sep=''), Prices=GBPUSD)
Can you try and omit the prices parameter?
updatePortf(p, Symbols='GBPUSD',
,Dates=paste('::',as.Date(Sys.time()),sep=''))
On 01-07-12 15:05, Heling Yao wrote:
Before applying to.hourly() and align.time():
class(AUDUSD)
[1] "xts" "zoo"
head(AUDUSD)
? ? ? ? ? ? ? ? ? ? ? Open ? High ? ?Low ?Close Volume
2004-10-25 00:00:00 0.7429 0.7446 0.7426 0.7438 ? 1445
2004-10-25 01:00:00 0.7436 0.7447 0.7430 0.7436 ? 1209
2004-10-25 02:00:00 0.7436 0.7444 0.7431 0.7440 ? 1011
2004-10-25 03:00:00 0.7438 0.7448 0.7433 0.7444 ? 1078
2004-10-25 04:00:00 0.7444 0.7449 0.7436 0.7442 ? ?838
2004-10-25 05:00:00 0.7443 0.7454 0.7431 0.7444 ? 1126
and after: ? ? ? ? ? ? ? ? ? ?AUDUSD.Open AUDUSD.High AUDUSD.Low
AUDUSD.Close
2004-10-25 01:00:00 ? ? ?0.7429 ? ? ?0.7446 ? ? 0.7426 ? ? ? 0.7438
2004-10-25 02:00:00 ? ? ?0.7436 ? ? ?0.7447 ? ? 0.7430 ? ? ? 0.7436
2004-10-25 03:00:00 ? ? ?0.7436 ? ? ?0.7444 ? ? 0.7431 ? ? ? 0.7440
2004-10-25 04:00:00 ? ? ?0.7438 ? ? ?0.7448 ? ? 0.7433 ? ? ? 0.7444
2004-10-25 05:00:00 ? ? ?0.7444 ? ? ?0.7449 ? ? 0.7436 ? ? ? 0.7442
2004-10-25 06:00:00 ? ? ?0.7443 ? ? ?0.7454 ? ? 0.7431 ? ? ? 0.7444
AUDUSD.Volume
2004-10-25 01:00:00 ? ? ? ? ?1445
2004-10-25 02:00:00 ? ? ? ? ?1209
2004-10-25 03:00:00 ? ? ? ? ?1011
2004-10-25 04:00:00 ? ? ? ? ?1078
2004-10-25 05:00:00 ? ? ? ? ? 838
2004-10-25 06:00:00 ? ? ? ? ?1126
Length of AUDUSD's the same. So I changed the following line:
col_names = c('Open','High','Low','Close','Volume')
to:
colnames(data.xts) <-
c('AUDUSD.Open','AUDUSD.High','AUDUSD.Low','AUDUSD.Close','AUDUSD.Volume')
and viola, it works now without using to.hourly() and align.time()!
I don't know if this is the correct way though.
Thanks for your help,
On Sun, Jul 1, 2012 at 7:31 PM, OpenTrades <jan at opentrades.nl> wrote:
Did you compare AUDUSD before and after applying to.hourly() and align.time() ? After reading from csv, try:
head(AUDUSD) AUDUSD=to.hourly(AUDUSD) AUDUSD=align.time(AUDUSD, 60*60) head(AUDUSD)
HTH, Jan Humme. On 01-07-12 11:40, Heling Yao wrote:
Hi,
I'm trying to adapt luxor to load audusd H1 data, and changed the
symbol loading code to the following:
fx_str = 'AUDUSD'
exchange_rate(c(fx_str), tick_size=0.0001)
#getSymbols('AUDUSD', from=.from, to=.to, verbose=FALSE)
data.csv = read.csv('/opt/data/H1/tp/AUDUSD.csv', sep=',', header=TRUE)
data.xts = as.xts(data.csv[,2:6], as.POSIXct(strptime(data.csv[,1],
'%Y-%m-%d %H:%M:%S')))
colnames(data.xts) <- c('Open','High','Low','Close','Volume')
assign(fx_str, data.xts)
When I ran the code, I get:
[1] "AUD" "USD"
[1] "AUDUSD"
[1] "forex"
[1] "IB1"
[1] "2004-11-02 07:00:00 AUDUSD -1e+05 @ 0.7434"
[1] "2004-11-03 13:00:00 AUDUSD 1e+05 @ 0.7556"
[1] "2004-11-03 13:00:00 AUDUSD 1e+05 @ 0.754"
[1] "2004-11-08 23:00:00 AUDUSD -1e+05 @ 0.757"
[1] "2004-11-10 10:00:00 AUDUSD 1e+05 @ 0.7612"
[1] "2004-11-11 11:00:00 AUDUSD -1e+05 @ 0.7583"
[1] "2004-11-11 15:00:00 AUDUSD 1e+05 @ 0.7617"
[1] "2004-11-23 05:00:00 AUDUSD -1e+05 @ 0.7795"
[1] "2004-11-24 08:00:00 AUDUSD 1e+05 @ 0.7883"
[1] "2004-11-29 04:00:00 AUDUSD -1e+05 @ 0.7865"
[1] "2004-11-29 09:00:00 AUDUSD -1e+05 @ 0.7837"
[1] "2004-12-04 04:00:00 AUDUSD 1e+05 @ 0.7818"
Error in getPrice(Prices, Symbol) :
? subscript out of bounds: no column name containing AUDUSD
Calls: updatePortf -> .updatePosPL -> getPrice
Execution halted
But when I add:
AUDUSD = to.hourly(AUDUSD)
AUDUSD = align.time(to.hourly(AUDUSD), 60*60)
It runs fine. But I guess the above is not necessary for H1 data?
sample data:
Time,Open,High,Low,Close,Volume
2004-10-25 00:00:00,0.7429,0.7446,0.7426,0.7438,1445.0
2004-10-25 01:00:00,0.7436,0.7447,0.743,0.7436,1209.0
2004-10-25 02:00:00,0.7436,0.7444,0.7431,0.744,1011.0
2004-10-25 03:00:00,0.7438,0.7448,0.7433,0.7444,1078.0
2004-10-25 04:00:00,0.7444,0.7449,0.7436,0.7442,838.0
2004-10-25 05:00:00,0.7443,0.7454,0.7431,0.7444,1126.0
2004-10-25 06:00:00,0.7445,0.7456,0.7437,0.7443,1542.0
2004-10-25 07:00:00,0.7443,0.7469,0.7433,0.7468,1834.0
2004-10-25 08:00:00,0.7469,0.7486,0.7466,0.7483,2098.0
After googling, I guess it could be timezone related. But still could
not solve the problem.
Thanks in advance,
Heling
_______________________________________________ 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.
-- Jan Humme - OpenTrades WWW: ? ? http://www.opentrades.nl Email: ? jan at opentrades.nl Twitter: @opentrades
-- Jan Humme - OpenTrades WWW: ? ? http://www.opentrades.nl Email: ? jan at opentrades.nl Twitter: @opentrades