Reputation: 2049
I have to import some datas from Yahoo! finance to R.
For example I have to import in R datas about Roche Holding (AG) (Roche Yahoo! link) and The Goldman Sachs Group, Inc. (GS) (Goldman Yahoo! link).
My problem is that Roche Holding (AG) datas are in euros and datas about The Goldman Sachs Group, Inc. (GS) are in dollars.
Now to import my datas in R I'm using:
Goldman_Sachs.z = get.hist.quote(instrument="GS", start=date.start,
end=date.end, quote="AdjClose",origin="1970-01-01",
provider="yahoo",compression = "m", retclass="zoo")
Is possible to import these datas just in dollars or must I implement a function in R to make this job?
And in the second case how can I choose the exchange rate?
Upvotes: 2
Views: 1937
Reputation: 23788
Although Roche Holding is also traded on NASDAQ OTC and you might therefore be able to obtain the current share price in USD, the proper way to handle such situations is to retrieve the data from the main market (which is the Swiss Stock Exchange in Zurich in this case) and calculate the value in dollars using the current exchange rate. The problem with OTC values is their low trading volume which may result in inaccurate prices.
To obtain the exchange rate of the CHF/USD Forex pair you can use the quantmod
package:
library(quantmod)
getFX("CHF/USD")
tail(CHFUSD,1)
# CHF.USD
#2016-04-16 1.0332
The price in EUR does not seem to be a suitable choice in this case, but since you mentioned that you are looking at a market where Roche Holding is traded in EUR you may use in the same way getFX("EUR/USD")
.
To download the EOD data from the Swiss Stock Exchange I would recommend using
Roche_CH <- getSymbols("SWX:RO", src ="google", auto.assign = FALSE)
or
Roche_CH <- getSymbols("RO.SW", src = "yahoo", auto.assign = FALSE)
Hope this helps.
Upvotes: 3