I am new to R and have just started to use it. I am currently experimenting with the quantmod package.
The quantmod package seems to do most of what I want to do, ho
If you include a ls() in your code, you'll find that you missed a variable:
yhoo <- getSymbols("YHOO", src = "google")
ls()
# [1] "yhoo" "YHOO"
class(yhoo)
# [1] "character"
class(YHOO)
# [1] "xts" "zoo"
So getSymbols() creates 2 variables: the character vector "yhoo" and "YHOO", an object of class extensible time series (xts) which extends the zoo class, for storing irregular time series data.
To see the documentation, use:
?xts # or ?zoo
In particular, the documentation for xts describes the as.xts() function, to convert from a matrix to xts. It should be straightforward from there to read in your own CSV files using read.csv or read.table and convert to xts objects.
I can make it work, but you have to determine which parameters are needed for your setup.
library(quantmod)
# create sample data
getSymbols("SPY")
write.zoo(SPY, file="SPY.csv", sep=",")
# set symbol lookup
setSymbolLookup(SPY=list(src="csv",format="%Y-%m-%d"))
# call getSymbols(.csv) with auto.assign=FALSE
spy <- getSymbols("SPY", auto.assign=FALSE)
barChart(spy)
The common idiom is:
yhoo = as.xts(read.zoo("yhoo.csv",header=T))
If you want to use a quantmod function, then you can tell getSymbols()
to use a csv file. See http://www.quantmod.com/documentation/getSymbols.csv.html I.e.
getSymbols('yhoo',src='csv')
(I've followed your lowercase convention, but remember the filenames will be case-sensitive; directory defaults to current directory and can be specified explicitly with the dir
parameter, see ?getSymbols.csv
)