getConstituents: Load constituent data for indexes

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Functions to scrape and clean index constituent data from multiple sources for a given index. Current src methods available are: default. Data is loaded silently without user assignment by default.

Usage

1
2
3
4
getConstituents(index, env = .GlobalEnv, simple = TRUE, src = "default",
  auto.assign = TRUE)

getConstituents.simple(index = "SPY")

Arguments

index

Character; string specifying the name of the index. One of "SPY", "NDX", "DJIA".

env

Environment; where to create objects. Setting env=NULL is equal to auto.assign=FALSE. Defaults to .GlobalEnv

simple

Logical; should results include non-ticker data. If TRUE, returns character vector of index's constituents. If FALSE returns a data.frame containing the following columns: stock ticker, last price, index weight. Defaults to TRUE

src

Character; string specifying the source to retrieve the data from. As of 0.1-1, the only source available is "default" which changes depending on the selected index. Defaults to "default"

auto.assign

Logical; should results be loaded to env. If FALSE return results. Defaults to TRUE

Details

getConstituents will try to format the index parameter using cleanIndex. Data is loaded from various sources depending on input arguments:

For S&P 500 data, the source is the SPDR website, price data. For SIMPLE=FALSE, data is also drawn from Yahoo Finance.

For NASDAQ 100 data, the source is the NASDAQ website. For SIMPLE=FALSE, price data is also taken from NASDAQ. Constituent weightings are not available in a form scrapable by R.

For DJIA 30 data, the souce is CNN Money, which updates its data every few months. For SIMPLE=FALSE, up-to-date price data is sourced from Yahoo Finance, and constituent weightings are calculated manually.

Future versions will include Russel indexes with data sourced from Vanguard

Value

a character vector or data.frame of index's constituent tickers(, price, weight)

Author(s)

Alec Kulakowski, alecthekulak@gmail.com

See Also

smif.package, cleanIndex

Examples

1
2
3
4
5
6
7
8
9
## Not run: 

getConstituents(index='S&P 500')
getConstituents(index='NASDAQ 100')
getConstituents(index='DJIA', auto.assign=FALSE)

getConstituents.simple(index='S&P 500')

## End(Not run)

alec25/smif.package documentation built on May 22, 2019, 12:36 p.m.