[R-SIG-Finance] quotes from cvs file, how to?

BeBa kb2qzv at poczta.wp.pl
Fri Mar 18 13:39:55 CET 2011


Hi,
I need help with using chartSeries from the quantmod package.
The file that is to be used has this structure:


> str(wig20)
'data.frame':	4200 obs. of  7 variables:
 $ X.TICKER.    : Factor w/ 1 level "WIG20": 1 1 1 1 1 1 1 1 1 1 ...
 $ X.DTYYYYMMDD.: int  19940414 19940418  19940509 ...
 $ X.OPEN.      : num  1000 1050 1125 1305 1350 ...
 $ X.HIGH.      : num  1000 1050 1125 1305 1350 ...
 $ X.LOW.       : num  1000 1050 1125 1305 1350 ...
 $ X.CLOSE.     : num  1000 1050 1125 1305 1350 ...
 $ X.VOL.       : num  35800 49975 69030 77076 114219 ...


and here is what it looks like:

> head(wig20)
  X.TICKER. X.DTYYYYMMDD. X.OPEN. X.HIGH. X.LOW. X.CLOSE.   X.VOL.
1     WIG20      19940414  1000.0  1000.0 1000.0   1000.0  35800.0
2     WIG20      19940418  1050.5  1050.5 1050.5   1050.5  49975.0
3     WIG20      19940419  1124.9  1124.9 1124.9   1124.9  69029.5
4     WIG20      19940421  1304.8  1304.8 1304.8   1304.8  77075.5
5     WIG20      19940425  1350.1  1350.1 1350.1   1350.1 114219.0
6     WIG20      19940426  1216.2  1216.2 1216.2   1216.2   8309.0


Since I do not need the TICKER column I chose to proceed as follows:

wig20skipped <- read.table(file="WIG20.mst", colClasses=c("NULL",
"integer", "numeric", "numeric", "numeric", "numeric", "numeric"),
col.names=c("NULL", "date", "o", "h", "l", "c", "vol"), sep=",",
header=T)


Ok, now wig20skipped looks similar to what yahoo finance site provides:
head(wig20skipped)
      date      o      h      l      c      vol
1 19940414 1000.0 1000.0 1000.0 1000.0  35800.0
2 19940418 1050.5 1050.5 1050.5 1050.5  49975.0
3 19940419 1124.9 1124.9 1124.9 1124.9  69029.5
4 19940421 1304.8 1304.8 1304.8 1304.8  77075.5
5 19940425 1350.1 1350.1 1350.1 1350.1 114219.0
6 19940426 1216.2 1216.2 1216.2 1216.2   8309.0




In order for the chartSeries() to draw the data they need to be xtsible.
So:

wig20zoo <- read.zoo(wig20skipped, format="%Y%m%d")
wig20asxts <- as.xts(wig20zoo)

Just to confirm that I do things right:
is.xts(wig20asxts)
[1] TRUE


and Now the problem: neither chartSeries(wig20asxts) nor candleCharts(wig20asxts) can display candlisticks.
I don't know why. Also:
addVolatility() results in
addVolatility()
Error in dim(data) <- dim : attempt to set an attribute on NULL

Perhaps this could help someone to diagnose the problem:

str(wig20asxts)
An ‘xts’ object from 1994-04-14 to 2011-03-09 containing:
  Data: num [1:4200, 1:5] 1000 1050 1125 1305 1350 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:5] "o" "h" "l" "c" ...
  Indexed by objects of class: [Date] TZ: 
  xts Attributes:  
 NULL



Thanks for any help.

BeBa



More information about the R-SIG-Finance mailing list