[.stock | R Documentation |
[
on Objects of Class "stock"You can quickly retrieve price, dividend, and split data useing the [
operator on an object of class stock, much like subsetting a matrix or
list in base R.
## S3 method for class 'stock' x[i, j = NULL, silent = FALSE]
x |
an object of class "stock". |
i |
an |
j |
Character vector specifying column names to be included in the output. Available column names are: "DividendAmount", "RecordDate", "DeclaredDate", "Type", "PaymentFrequency", "Open", "High", "Low", "Close", "TWAP", "VWAP", "Volume", "PreviousCloseDate", "PreviousClose", "Denominator", "Numerator", "ExDate", "company", "acquired_by", "multiple", "type", "acquired" |
silent |
Boolean. If FALSE (Default), messages will be displayed for special cases that might produce unexpected behavior; e.g., if no data is available for the date range specified. If TRUE, these messages will not be displayed. |
The rules are:
If a dividend took place during the specified date range, then the column "DividendAmount" will always be included in the output.
If a split took place during the specified date range, then the columns "Denominator" and "Numerator" will always be included in the output. "Denominator" refers to the number of shares AFTER the split and "Numerator" number of shares BEFORE the split; for example, a 2-to-1 split would have "Denominator" = 2 and "Numerator" = 1.
an xts object, or NULL if no data is available for the specified asset within the specified date range.
# If no columns are specified, all available columns are returned. # Single date: stock_data$IVV["2019-06-11"] # Dividends are correctly applied, even when issued on a non-trading day. In # 2012, for example, Texas Instruments (TXN) had scheduled a dividend for the # 29th of October but the exchange was closed due to Hurricane Sandy. The # dividend, then, should be applied to the next trading day (31 October). Here, # we'll select just the closing price for a date range around that time. # Remember, any dividends that occur within the date range are always included. stock_data$TXN["2012-10-25/2012-11-05", "Close"] # Splits are handled as follows for Apple's 7-to-1 split of 2014: stock_data$AAPL["2014-06-05/2014-06-11", c("Open", "Close")] # Not specifying which columns you want can quickly lead to a lot of data, as in # the below subset of IVV for the month of June 2019: stock_data$IVV["2019-06"] ###### M&A Events: Mergers, Acquisitions, Spinoffs, Breakups, etc. # Consider the M&A event that took place on 31 Oct 2018 in which Praxair (PX) # merged with Linde AG (not included in dataset) to form Linde PLC, a new # company traded under the symbol LIN.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.