[R-SIG-Finance] adapting quantstrat/demo/luxor code

OpenTrades jan at opentrades.nl
Sun Jul 1 13:31:34 CEST 2012


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



More information about the R-SIG-Finance mailing list