[R-SIG-Finance] fImport, yahooSeries, aggregation

Jeff Ryan jeff.a.ryan at gmail.com
Fri May 23 04:54:30 CEST 2008


Not using Rmetrics, but quantmod (and xts):

library(quantmod)
getSymbols("^FTSE",from="2006-01-01", to="2007-12-31")
to.monthly(FTSE, indexAt='lastof')
           FTSE.Open FTSE.High FTSE.Low FTSE.Close FTSE.Volume FTSE.Adjusted
2006-01-31    5618.8    5796.1   5618.8     5760.3 39158470800        5760.3
2006-02-28    5760.3    5893.3   5681.9     5791.5 37360441800        5791.5
2006-03-31    5791.5    6047.0   5783.9     5964.6 44156358400        5964.6
2006-04-30    5964.6    6137.1   5964.6     6023.1 30775737400        6023.1
2006-05-31    6023.1    6133.5   5510.5     5723.8 40051488800        5723.8
2006-06-30    5723.8    5865.7   5467.4     5833.4 36016490600        5833.4
2006-07-31    5833.4    5982.5   5654.6     5928.3 28208522700        5928.3
2006-08-31    5928.3    5949.8   5752.6     5906.1 29781298600        5906.1
2006-09-30    5906.1    6002.9   5774.5     5960.8 31844286400        5960.8
2006-10-31    5960.8    6244.6   5897.3     6129.2 34756902700        6129.2
2006-11-30    6129.2    6256.8   6011.8     6048.8 35409311600        6048.8
2006-12-31    6048.8    6271.4   5985.2     6220.8 25404342600        6220.8
2007-01-31    6220.8    6335.1   6130.2     6203.1 36903881300        6203.1
2007-02-28    6203.1    6451.4   6166.2     6171.5 33113524500        6171.5
2007-03-31    6171.5    6355.3   5989.6     6308.0 40662588400        6308.0
2007-04-30    6308.0    6516.2   6293.9     6449.2 31552434700        6449.2
2007-05-31    6449.2    6675.0   6395.5     6621.4 40045491500        6621.4
2007-06-30    6621.4    6751.3   6451.4     6607.9 39617754000        6607.9
2007-07-31    6607.9    6754.1   6186.2     6360.1 38493756200        6360.1
2007-08-31    6360.1    6406.3   5821.7     6303.3 38476546500        6303.3
2007-09-30    6303.3    6512.4   6123.1     6466.8 35732251000        6466.8
2007-10-31    6466.8    6751.7   6413.4     6721.6 41485100800        6721.6
2007-11-30    6721.6    6723.7   6026.9     6432.5 32531965100        6432.5
2007-12-31    6432.5    6610.9   6251.8     6456.9 19632325600        6456.9

getSymbols by default will load the data into a symbol FTSE
(automatically stripping the ^ from the Yahoo name)

to.monthly will by default index the series by 'yearmon'.  The indexAt
arg will align the series to
the 'lastof' the calendar period, the 'firstof' the period, the
'startof' the data in the period (the first tie seen) or the 'endof'
the data...

To get just the Close, you can wrap the whole thing in 'Cl'

Cl(to.monthly(FTSE,indexAt='lastof'))

           FTSE.Close
2006-01-31     5760.3
2006-02-28     5791.5
2006-03-31     5964.6
2006-04-30     6023.1
2006-05-31     5723.8
2006-06-30     5833.4
2006-07-31     5928.3
2006-08-31     5906.1
2006-09-30     5960.8
2006-10-31     6129.2
2006-11-30     6048.8
2006-12-31     6220.8
2007-01-31     6203.1
2007-02-28     6171.5
2007-03-31     6308.0
2007-04-30     6449.2
2007-05-31     6621.4
2007-06-30     6607.9
2007-07-31     6360.1
2007-08-31     6303.3
2007-09-30     6466.8
2007-10-31     6721.6
2007-11-30     6432.5
2007-12-31     6456.9

More info about quantmod can be found at http://www.quantmod.com ...
which is expecting an update any day now :)

Jeff
Jeff

On Thu, May 22, 2008 at 9:32 PM, John P. Burkett <burkett at uri.edu> wrote:
> In R version 2.6.1 running under Gentoo Linux, the commands
> library(fImport)
> yahooSeries("^FTSE", from = "2006-01-01", "2007-12-31", quote = "Close",
> aggregation = "m")
> select the first business day of each month.  I would prefer to select the
> last business day of each month.  Suggestions about how to do so would be
> much appreciated.
>
> --
> John P. Burkett
> Department of Environmental and Natural Resource Economics
> and Department of Economics
> University of Rhode Island
> Kingston, RI 02881-0808
> USA
>
> phone (401) 874-9195
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>



-- 
There's a way to do it better - find it.
Thomas A. Edison



More information about the R-SIG-Finance mailing list