get_prices_from_tickers: Get daily prices of securities.

View source: R/get_prices_from_tickers.R

get_prices_from_tickersR Documentation

Get daily prices of securities.

Description

Returns daily Open or Close prices between start and end date for given tickers.

Usage

get_prices_from_tickers(
  ...,
  start,
  end,
  quote = c("Open", "Close"),
  retclass = c("list", "zoo", "data.frame")
)

Arguments

...

character vectors indicating tickers (should be valid in Yahoo Finance).

start

an object of Date class specifying the first date of the observed time period.

end

an object of Date class specifying the last date of the observed time period.

quote

a character indicating the type of the price: "Open" (default) or "Close".

retclass

a character specifying the return class: "list" (default), "zoo" or "data.frame".

Details

This function uses the function getSymbols form the quantmod package. The provider is set automatically to Yahoo Finance. The function returns the data in different class-containers: list of zoo's, zoo, or data.frame.

Value

Prices of securities as "list", "zoo", or "data.frame".

See Also

getSymbols

Examples

## Download historical prices of seven companies' stocks:
## Not run: 
library("magrittr")
tickers <- c("AMZN", "ZM", "UBER", "NFLX", "SHOP", "FB", "UPWK")
prices <- tickers %>%
    get_prices_from_tickers(start = as.Date("2019-04-01"),
                            end = as.Date("2020-04-01"),
                            quote = "Close",
                            retclass = "zoo")

## End(Not run)
## The result of the above code is stored in:
data(prices)

## Download historical prices of S&P 500 index:
## Not run: 
prices_indx <- get_prices_from_tickers("^GSPC",
                                       start = as.Date("2019-04-01"),
                                       end = as.Date("2020-04-01"),
                                       quote = "Close",
                                       retclass = "zoo")

## End(Not run)
## The result of the above code is stored in:
data(prices_indx)


irudnyts/estudy2 documentation built on April 21, 2022, 10:50 p.m.