Skip to content
Prev 8496 / 15274 Next

quantmod‏ - getSymbols for csv files

rex
Jun Sheng Tan <thyreus56344612 at hotmail.com> [2011-09-14 02:28]:
~$ R
R version 2.13.0 (2011-04-13)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-pc-linux-gnu (64-bit)
[...]
[Previously saved workspace restored]
Loading required package: Defaults
Loading required package: xts
Loading required package: zoo

Attaching package: 'zoo'

The following object(s) are masked from 'package:base':

      as.Date

Loading required package: TTR
[1] "SBUX"
SBUX.Open SBUX.High SBUX.Low SBUX.Close SBUX.Volume  SBUX.Adjusted
2007-01-03     35.60     36.20    34.64      35.25     9017300     34.39                                                                               
2007-01-04     35.37     35.50    34.79      35.29     7328000     34.43                                                                               
2007-01-05     35.12     35.29    34.97      35.14     6565700     34.28                                                                               
2007-01-08     34.91     35.26    34.90      35.01     5807200     34.16                                                                               
2007-01-09     35.00     35.39    34.70      34.86     7152500     34.01
2007-01-10     34.70     34.78    34.17      34.75     9329200     33.90
[1] "2011-09-07" "2011-09-08" "2011-09-09" "2011-09-12" "2011-09-13"
"2011-09-14"
As you can see from the above, there's no need for a CSV file, but if
you want to read the data from a local CSV file that looks like::

~$ less subx.csv
Date,Open,High,Low,Close,Volume,Adj Close
2011-09-13,37.71,38.31,37.67,38.19,6159400,38.19
2011-09-12,36.69,37.88,36.69,37.65,8122500,37.65
2011-09-09,38.62,38.75,37.05,37.31,10514600,37.31
[...]

Then, in R do:
Open  High   Low Close    Volume Adj.Close
1992-06-26 21.00 22.25 20.50 21.50 112281600      0.66
1992-06-29 21.75 23.50 21.25 23.00  29504000      0.70
1992-06-30 23.50 23.75 22.00 22.25  17449600      0.68
1992-07-01 22.50 23.00 21.75 22.75   9270400      0.69
1992-07-02 23.00 23.00 22.25 22.75   7155200      0.69
1992-07-06 22.50 22.75 22.25 22.75   3056000      0.69
HTH,

-rex