Question

part of my code for downloading financial data:

library(quantmod)

tickers <- c("XOM", "DIS")
stock1 <- getSymbols(tickers[1], from="2010-03-01", to="2011-02-28", auto.assign=F)
stock2 <- getSymbols(tickers[2], from="2010-03-01", to="2011-02-28", auto.assign=F)

pair <- merge(Ad(stock1), Ad(stock2), all=F)             # 'xts' object, merge adjusted close
pair.DF <- data.frame(pair)                              #  data frame

But I want to call function like this:

tickers <- function(x, y) {
stock1 <- getSymbols(x, from="2010-03-01", to="2011-02-28", auto.assign=F)
stock2 <- getSymbols(y, from="2010-03-01", to="2011-02-28", auto.assign=F)

pair <- merge(Ad(stock1), Ad(stock2), all=F)            
pair.DF <- data.frame(pair)       
}

And then:

tickers("XOM", "DIS")

Or something similar. But what I get is bad result. In this case "x" and "y" aren´t numeric, but character. It seems to be easy, but.. Thanks for any suggestions.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top