[R-SIG-Finance] get data in quantmod

Jeff Ryan jeff.a.ryan at gmail.com
Wed Feb 25 16:40:17 CET 2009


To add to what Brian has said:

> SS600089 <- getSymbols("600089.SS", auto.assign=FALSE)

auto.assign is the current workaround.  Other options I will have to
work on.  Maybe a "name" arg or a "prefix" arg.

As far as periodicity.  I will add the option to getSymbols.yahoo to
allow for that to be specified.  A more flexible approach (as you
can't easily make daily data from monthly...) is to use the
*to.period* functions now in xts.

?to.monthly

> str(SS600089)
An 'xts' object from 2007-01-01 to 2009-02-24 containing:
  Data: num [1:536, 1:6] 14.9 14.9 14.9 15.2 15.5 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:6] "600089.SS.Open" "600089.SS.High" "600089.SS.Low"
"600089.SS.Close" ...
  Indexed by objects of class: [Date]
   xts Attributes:
List of 2
 $ src    : chr "yahoo"
 $ updated: POSIXct[1:1], format: "2009-02-25 09:25:48"

> periodicity(SS600089)
Daily periodicity from 2007-01-01 to 2009-02-24

> periodicity(to.weekly(SS600089))
Weekly periodicity from 2007-01-05 to 2009-02-24

> periodicity(to.monthly(SS600089))
Monthly periodicity from Jan 2007 to Feb 2009

> head(to.monthly(SS600089))
         SS600089.Open SS600089.High SS600089.Low SS600089.Close
Jan 2007         14.95         23.54        14.95          20.74
Feb 2007         20.15         21.00        19.00          20.41
Mar 2007         20.41         20.41        20.41          20.41
Apr 2007         20.41         20.41        20.41          20.41
May 2007         20.41         20.41        20.41          20.41
Jun 2007         20.41         35.89        20.41          30.75
         SS600089.Volume SS600089.Adjusted
Jan 2007       177635800             20.62
Feb 2007        10694100             20.29
Mar 2007               0             20.29
Apr 2007               0             20.29
May 2007               0             20.29
Jun 2007        58088500             30.72


HTH,
Jeff
On Wed, Feb 25, 2009 at 9:30 AM, Rowe, Brian Lee Yung (Portfolio
Analytics) <B_Rowe at ml.com> wrote:
> 1: From the code for getSymbols.yahoo this appears to be hardcoded. The
> parameter to set the series frequency on yahoo is 'g':
>
> http://chart.yahoo.com/table.csv?s=FXP&a=0&b=01&c=2007&d=1&e=25&f=2009&g
> =m&q=q&y=0&z=FXP&x=.csv - returns monthly
>
> http://chart.yahoo.com/table.csv?s=FXP&a=0&b=01&c=2007&d=1&e=25&f=2009&g
> =d&q=q&y=0&z=FXP&x=.csv - returns daily
>
> Here is the code in getSymbols.yahoo:
>        download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=",
>            from.m, "&b=", sprintf("%.2d", from.d), "&c=", from.y,
>            "&d=", to.m, "&e=", sprintf("%.2d", to.d), "&f=",
>            to.y, "&g=d&q=q&y=0", "&z=", Symbols.name, "&x=.csv",
>            sep = ""), destfile = tmp, quiet = !verbose)
>
> Note the "&g=d" is hardcoded (at least in my versions 0.3-6, 0.3-7)
>
> 2: This has been asked before (see attached).
>
> HTH,
> Brian
>
> -----Original Message-----
> From: r-sig-finance-bounces at stat.math.ethz.ch
> [mailto:r-sig-finance-bounces at stat.math.ethz.ch] On Behalf Of BearXu
> Sent: Wednesday, February 25, 2009 10:11 AM
> To: r-sig-finance at stat.math.ethz.ch
> Subject: [R-SIG-Finance] get data in quantmod
>
>
> I have two questions about how to get data in quantmod
> 1)Yahoo Finance provide us with data in daily, weekly, monthly. When we
> are
> using getSymbols can we choose the time spectrum?
>
> 2)I want to download some Chinese Stock Data, So I use this command:
> getSymbols("600089.SS"), but when I want to use command
> barChart(600089.SS),
> it's wrong. Maybe the problem is the name of the object "600089.SS". So
> can
> I give another name to the object from the getSymbols?
>
> Thanks
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> 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.
>
> --------------------------------------------------------------------------
> This message w/attachments (message) may be privileged, confidential or proprietary, and if you are not an intended recipient, please notify the sender, do not use or share it and delete it. Unless specifically indicated, this message is not an offer to sell or a solicitation of any investment products or other financial product or service, an official confirmation of any transaction, or an official statement of Merrill Lynch. Subject to applicable law, Merrill Lynch may monitor, review and retain e-communications (EC) traveling through its networks/systems. The laws of the country of each sender/recipient may impact the handling of EC, and EC may be archived, supervised and produced in countries other than the country in which you are located. This message cannot be guaranteed to be secure or error-free. References to "Merrill Lynch" are references to any company in the Merrill Lynch & Co., Inc. group of companies, which are wholly-owned by Bank of America Corporation. Securities and Insurance Products: * Are Not FDIC Insured * Are Not Bank Guaranteed * May Lose Value * Are Not a Bank Deposit * Are Not a Condition to Any Banking Service or Activity * Are Not Insured by Any Federal Government Agency. Attachments that are part of this E-communication may have additional important disclosures and disclaimers, which you should read. This message is subject to terms available at the following link: http://www.ml.com/e-communications_terms/. By messaging with Merrill Lynch you consent to the foregoing.
> --------------------------------------------------------------------------
>
>
>
> ---------- Forwarded message ----------
> From: "Brian Lee Yung Rowe" <brian at muxspace.com>
> To: "L.-Y. Hin" <lyhin at netvigator.com>
> Date: Tue, 30 Dec 2008 22:31:39 -0500
> Subject: Re: [R-SIG-Finance] Newbie question on getSymbols() in quantmod
> Try:
>
> HSBC <- getSymbols("0005.HK",src="yahoo", auto.assign=FALSE)
>
> Brian
>
>
> On Wed, 2008-12-31 at 10:58 +0800, L.-Y. Hin wrote:
>> Dear gurus,
>>
>> I am learning the quantmod library, and trying to download
>> the equity series for HSBC from yahoo.
>>
>> I checked from yahoo finance that the symbol is 0005.HK,
>> and then I used
>>
>>
>> > library(quantmod)
>> > getSymbols("0005.HK",src="yahoo")
>> [1] "0005.HK"
>> > candleChart(0005.HK)
>> Error: unexpected symbol in "candleChart(0005.HK"
>> > chartSeries(0005.HK)
>> Error: unexpected symbol in "chartSeries(0005.HK"
>> > Cl(0005.HK)
>> Error: unexpected symbol in "Cl(0005.HK"
>>
>> It seems like probably no data has been loaded by the
>> approach above.
>>
>>
>> However, the same scripts work for NYSE equities like
>> > getSymbols("A",src="yahoo")
>> [1] "A"
>> > chartSeries(A)
>> > length(Cl(A))   #To check whether OHLC data has been loaded
>> [1] 503
>>
>>
>> I suspect the problem is in the way I tried to load 0005.HK....
>>
>>
>> I'll be very grateful for your kind advice.
>>
>>
>> Many thanks
>>
>> Lin
>>
>> _______________________________________________
>> 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.
>
> _______________________________________________
> 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.
>
>
> ---------- Forwarded message ----------
> From: "Jeff Ryan" <jeff.a.ryan at gmail.com>
> To: "Brian Lee Yung Rowe" <brian at muxspace.com>
> Date: Wed, 31 Dec 2008 00:04:21 -0500
> Subject: Re: [R-SIG-Finance] Newbie question on getSymbols() in quantmod
> An alternate approach uses setSymbolLookup
>
> setSymbolLookup(HSBC=list(src='yahoo', name="0005.HK"))
>
> You can put this in a start up file for future R sessions.  See ?setSymbolLookup
>
>> getSymbols("HSBC")
> [1] "HSBC"
>> str(HSBC)
> An 'xts' object from 2007-01-01 to 2008-12-29 containing:
>  Data: num [1:510, 1:6] 142 143 144 145 144 ...
>  - attr(*, "dimnames")=List of 2
>  ..$ : NULL
>  ..$ : chr [1:6] "0005.HK.Open" "0005.HK.High" "0005.HK.Low"
> "0005.HK.Close" ...
>  Indexed by objects of class: [Date]
>   xts Attributes:
> List of 2
>  $ src    : chr "yahoo"
>  $ updated: POSIXct[1:1], format: "2008-12-31 05:02:43"
>
> HTH
> Jeff
>
> On Tue, Dec 30, 2008 at 9:31 PM, Brian Lee Yung Rowe <brian at muxspace.com> wrote:
>> Try:
>>
>> HSBC <- getSymbols("0005.HK",src="yahoo", auto.assign=FALSE)
>>
>> Brian
>>
>>
>> On Wed, 2008-12-31 at 10:58 +0800, L.-Y. Hin wrote:
>>> Dear gurus,
>>>
>>> I am learning the quantmod library, and trying to download
>>> the equity series for HSBC from yahoo.
>>>
>>> I checked from yahoo finance that the symbol is 0005.HK,
>>> and then I used
>>>
>>>
>>> > library(quantmod)
>>> > getSymbols("0005.HK",src="yahoo")
>>> [1] "0005.HK"
>>> > candleChart(0005.HK)
>>> Error: unexpected symbol in "candleChart(0005.HK"
>>> > chartSeries(0005.HK)
>>> Error: unexpected symbol in "chartSeries(0005.HK"
>>> > Cl(0005.HK)
>>> Error: unexpected symbol in "Cl(0005.HK"
>>>
>>> It seems like probably no data has been loaded by the
>>> approach above.
>>>
>>>
>>> However, the same scripts work for NYSE equities like
>>> > getSymbols("A",src="yahoo")
>>> [1] "A"
>>> > chartSeries(A)
>>> > length(Cl(A))   #To check whether OHLC data has been loaded
>>> [1] 503
>>>
>>>
>>> I suspect the problem is in the way I tried to load 0005.HK....
>>>
>>>
>>> I'll be very grateful for your kind advice.
>>>
>>>
>>> Many thanks
>>>
>>> Lin
>>>
>>> _______________________________________________
>>> 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.
>>
>> _______________________________________________
>> 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.
>>
>
>
>
> --
> Jeffrey Ryan
> jeffrey.ryan at insightalgo.com
>
> ia: insight algorithmics
> www.insightalgo.com
>
> _______________________________________________
> 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.
>
> _______________________________________________
> 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.
>



-- 
Jeffrey Ryan
jeffrey.ryan at insightalgo.com

ia: insight algorithmics
www.insightalgo.com



More information about the R-SIG-Finance mailing list