[Blotter-commits] r1033 - in pkg/FinancialInstrument: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed May 30 03:13:24 CEST 2012


Author: gsee
Date: 2012-05-30 03:13:22 +0200 (Wed, 30 May 2012)
New Revision: 1033

Added:
   pkg/FinancialInstrument/man/update_instruments.masterDATA.Rd
Modified:
   pkg/FinancialInstrument/NAMESPACE
   pkg/FinancialInstrument/R/update_instruments.yahoo.R
Log:
 - add function to update ETF instruments using masterdata.com
 - roxygenize

Modified: pkg/FinancialInstrument/NAMESPACE
===================================================================
--- pkg/FinancialInstrument/NAMESPACE	2012-05-29 00:58:54 UTC (rev 1032)
+++ pkg/FinancialInstrument/NAMESPACE	2012-05-30 01:13:22 UTC (rev 1033)
@@ -1,87 +1,94 @@
+S3method(all.equal,instrument)
+S3method(expires,character)
+S3method(expires,instrument)
+S3method(expires,xts)
+S3method(print,id.list)
+S3method(print,instrument)
+S3method(print,suffix.list)
 export(.to_daily)
+export(C2M)
+export(ICS)
+export(ICS_root)
+export(M2C)
+export(MC2N)
 export(add.defined.by)
 export(add.identifier)
+export(bond)
 export(bond_series)
-export(bond)
-export(build_series_symbols)
-export(build_spread_symbols)
 export(buildBasket)
 export(buildHierarchy)
 export(buildRatio)
 export(buildSpread)
+export(build_series_symbols)
+export(build_spread_symbols)
 export(butterfly)
-export(C2M)
 export(currency)
 export(exchange_rate)
 export(expires)
 export(find.instrument)
 export(fn_SpreadBuilder)
+export(formatSpreadPrice)
 export(format_id)
-export(formatSpreadPrice)
 export(fund)
+export(future)
 export(future_series)
-export(future)
 export(getInstrument)
 export(getSymbols.FI)
 export(guaranteed_spread)
-export(ICS_root)
-export(ICS)
-export(instrument_attr)
+export(instrument)
 export(instrument.auto)
 export(instrument.table)
-export(instrument)
+export(instrument_attr)
+export(is.currency)
 export(is.currency.name)
-export(is.currency)
+export(is.instrument)
 export(is.instrument.name)
-export(is.instrument)
 export(load.instruments)
 export(loadInstruments)
 export(ls_AUD)
+export(ls_CAD)
+export(ls_CHF)
+export(ls_EUR)
+export(ls_FX)
+export(ls_GBP)
+export(ls_HKD)
+export(ls_ICS)
+export(ls_ICS_roots)
+export(ls_JPY)
+export(ls_NZD)
+export(ls_SEK)
+export(ls_USD)
 export(ls_bonds)
 export(ls_by_currency)
 export(ls_by_expiry)
-export(ls_CAD)
 export(ls_calls)
-export(ls_CHF)
 export(ls_currencies)
 export(ls_derivatives)
-export(ls_EUR)
 export(ls_exchange_rates)
 export(ls_expires)
 export(ls_expiries)
 export(ls_funds)
 export(ls_future_series)
 export(ls_futures)
-export(ls_FX)
-export(ls_GBP)
 export(ls_guaranteed_spreads)
-export(ls_HKD)
-export(ls_ICS_roots)
-export(ls_ICS)
+export(ls_instruments)
 export(ls_instruments_by)
-export(ls_instruments)
-export(ls_JPY)
 export(ls_non_currencies)
 export(ls_non_derivatives)
-export(ls_NZD)
 export(ls_option_series)
 export(ls_options)
 export(ls_puts)
-export(ls_SEK)
 export(ls_spreads)
 export(ls_stocks)
 export(ls_strikes)
 export(ls_synthetics)
 export(ls_underlyings)
-export(ls_USD)
-export(M2C)
 export(make_spread_id)
-export(MC2N)
 export(month_cycle2numeric)
 export(next.future_id)
+export(option)
+export(option_series)
 export(option_series.yahoo)
-export(option_series)
-export(option)
 export(parse_id)
 export(parse_suffix)
 export(prev.future_id)
@@ -109,19 +116,14 @@
 export(sort_ids)
 export(spread)
 export(stock)
+export(synthetic)
 export(synthetic.instrument)
 export(synthetic.ratio)
-export(synthetic)
 export(to_secBATV)
+export(update_instruments.TTR)
 export(update_instruments.instrument)
-export(update_instruments.TTR)
+export(update_instruments.masterDATA)
+export(update_instruments.md)
 export(update_instruments.yahoo)
 export(volep)
 importFrom(zoo,as.Date)
-S3method(all.equal,instrument)
-S3method(expires,character)
-S3method(expires,instrument)
-S3method(expires,xts)
-S3method(print,id.list)
-S3method(print,instrument)
-S3method(print,suffix.list)

Modified: pkg/FinancialInstrument/R/update_instruments.yahoo.R
===================================================================
--- pkg/FinancialInstrument/R/update_instruments.yahoo.R	2012-05-29 00:58:54 UTC (rev 1032)
+++ pkg/FinancialInstrument/R/update_instruments.yahoo.R	2012-05-30 01:13:22 UTC (rev 1033)
@@ -174,6 +174,88 @@
 }
 
 
+#' Update instrument metadata for ETFs
+#'
+#' Uses the masterDATA.com list of ETFs and ETNs to update previously defined
+#' instruments.
+#' 
+#' \code{update_instruments.md} is an alias.
+#' 
+#' MasterDATA classifies each ETF into one of six Fund.Types.  From their
+#' website:
+#' 
+#' US Equity ETF: All constituents trade on a US exchange. Both ProShares and 
+#' Rydex sponsor ETFs with the objective of achieving the performance (or a 
+#' multiple of the performance) of several major US stock indexes. These ETFs 
+#' currently are included in this category despite the fact that their 
+#' constituent lists are generally not limited to US stocks.
+#' 
+#' Global Equity ETF: One or more of the constituents do not trade on a US 
+#' Exchange.
+#' 
+#' Fixed Income ETF:  The constituent list contains government and / or 
+#' corporate debt instruments. ETFs with this classification will not be 
+#' considered for inclusion in MasterDATA's index / ETF compilation list.
+#' 
+#' Commodity Based ETF:  This classification of ETF has no constituents but is 
+#' structured to reflect the valuation of a commodity such as gold, silver, oil 
+#' or interest rates. ETFs with this classification will not be considered for 
+#' inclusion in MasterDATA's index / ETF compilation list.
+#' 
+#' Exchange Traded Notes: A type of unsecured, unsubordinated debt security that 
+#' was first issued by Barclays Bank PLC. The purpose of ETNs is to create a 
+#' type of security that combines both the aspects of bonds and exchange traded 
+#' funds (ETF). Similar to ETFs, ETNs are traded on a major exchange.
+#' 
+#' @param Symbols character vector of Symbols of ETFs
+#' @param silent silence warnings?
+#' @return called for side-effect. Each ETF that is updated will be given 
+#'   instrument attributes of \dQuote{Name} and \dQuote{Fund.Type}
+#' @author Garrett See
+#' @references \url{http://masterDATA.com} 
+#' (\url{http://www.masterdata.com/helpfiles/ETF_List_Downloads/AllTypes.csv})
+#' @examples
+#' \dontrun{
+#' stock(s <- c("SPY", "DIA"), currency("USD"))
+#' update_instruments.masterDATA(s)
+#' buildHierarchy(s, "Name", "Fund.Type", "defined.by")
+#' }
+#' @export
+update_instruments.masterDATA <- function(Symbols, silent=FALSE) {
+    x <- read.csv("http://www.masterdata.com/helpfiles/ETF_List_Downloads/AllTypes.csv", 
+                  stringsAsFactors=FALSE)
+    if (missing(Symbols)) Symbols <- unique(ls_funds(), ls_stocks())
+    s <- Symbols[Symbols %in% x[["Symbol"]]]
+    if (length(s) > 0) {
+        s <- s[is.instrument.name(s)]
+    }
+    if (length(s) == 0) {
+        if (!isTRUE(silent)) {
+            warning("instruments must be defined before this can update them.")
+        }
+        return(invisible())
+    }
+    x <- x[!duplicated(x[["Symbol"]]), ]  
+    x <- x[x[["Symbol"]] %in% s, ]
+    for (i in seq_len(NROW(x))) {
+        instrument_attr(x[["Symbol"]][i], "Name", x[["Name"]][i])
+        instrument_attr(x[["Symbol"]][i], "Fund.Type", x[["Fund.Type"]][i])
+        db <- getInstrument(x[["Symbol"]][i])[["defined.by"]]
+        db <- if (is.null(db)) {
+            "masterDATA"
+        } else paste(unique(c(strsplit(db, ";")[[1]], "masterDATA")), 
+                 collapse = ";")
+        instrument_attr(x[["Symbol"]][i], "defined.by", db)
+        instrument_attr(x[["Symbol"]][i], "updated", Sys.time())
+    }
+    return(s)
+}
+
+#' @export
+#' @rdname update_instruments.masterDATA
+update_instruments.md <- update_instruments.masterDATA
+
+
 #' Update instruments with metadata from another instrument.
 #'
 #' Update instruments with metadata from another instrument.

Added: pkg/FinancialInstrument/man/update_instruments.masterDATA.Rd
===================================================================
--- pkg/FinancialInstrument/man/update_instruments.masterDATA.Rd	                        (rev 0)
+++ pkg/FinancialInstrument/man/update_instruments.masterDATA.Rd	2012-05-30 01:13:22 UTC (rev 1033)
@@ -0,0 +1,74 @@
+\name{update_instruments.masterDATA}
+\alias{update_instruments.masterDATA}
+\alias{update_instruments.md}
+\title{Update instrument metadata for ETFs}
+\usage{
+  update_instruments.masterDATA(Symbols, silent = FALSE)
+
+  update_instruments.md(Symbols, silent = FALSE)
+}
+\arguments{
+  \item{Symbols}{character vector of Symbols of ETFs}
+
+  \item{silent}{silence warnings?}
+}
+\value{
+  called for side-effect. Each ETF that is updated will be
+  given instrument attributes of \dQuote{Name} and
+  \dQuote{Fund.Type}
+}
+\description{
+  Uses the masterDATA.com list of ETFs and ETNs to update
+  previously defined instruments.
+}
+\details{
+  \code{update_instruments.md} is an alias.
+
+  MasterDATA classifies each ETF into one of six
+  Fund.Types.  From their website:
+
+  US Equity ETF: All constituents trade on a US exchange.
+  Both ProShares and Rydex sponsor ETFs with the objective
+  of achieving the performance (or a multiple of the
+  performance) of several major US stock indexes. These
+  ETFs currently are included in this category despite the
+  fact that their constituent lists are generally not
+  limited to US stocks.
+
+  Global Equity ETF: One or more of the constituents do not
+  trade on a US Exchange.
+
+  Fixed Income ETF: The constituent list contains
+  government and / or corporate debt instruments. ETFs with
+  this classification will not be considered for inclusion
+  in MasterDATA's index / ETF compilation list.
+
+  Commodity Based ETF: This classification of ETF has no
+  constituents but is structured to reflect the valuation
+  of a commodity such as gold, silver, oil or interest
+  rates. ETFs with this classification will not be
+  considered for inclusion in MasterDATA's index / ETF
+  compilation list.
+
+  Exchange Traded Notes: A type of unsecured,
+  unsubordinated debt security that was first issued by
+  Barclays Bank PLC. The purpose of ETNs is to create a
+  type of security that combines both the aspects of bonds
+  and exchange traded funds (ETF). Similar to ETFs, ETNs
+  are traded on a major exchange.
+}
+\examples{
+\dontrun{
+stock(s <- c("SPY", "DIA"), currency("USD"))
+update_instruments.masterDATA(s)
+buildHierarchy(s, "Name", "Fund.Type", "defined.by")
+}
+}
+\author{
+  Garrett See
+}
+\references{
+  \url{http://masterDATA.com}
+  (\url{http://www.masterdata.com/helpfiles/ETF_List_Downloads/AllTypes.csv})
+}
+



More information about the Blotter-commits mailing list