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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Oct 23 03:42:52 CEST 2011


Author: gsee
Date: 2011-10-23 03:42:51 +0200 (Sun, 23 Oct 2011)
New Revision: 825

Modified:
   pkg/FinancialInstrument/R/load.instruments.R
   pkg/FinancialInstrument/R/ls_by_expiry.R
   pkg/FinancialInstrument/R/ls_instruments.R
   pkg/FinancialInstrument/R/redenominate.R
   pkg/FinancialInstrument/R/saveSymbols.R
   pkg/FinancialInstrument/R/update_instruments.yahoo.R
   pkg/FinancialInstrument/man/buildRatio.Rd
   pkg/FinancialInstrument/man/currencies.Rd
   pkg/FinancialInstrument/man/ls_by_expiry.Rd
   pkg/FinancialInstrument/man/ls_instruments.Rd
   pkg/FinancialInstrument/man/root_contracts.Rd
   pkg/FinancialInstrument/man/saveSymbols.days.Rd
   pkg/FinancialInstrument/man/update_instruments.yahoo.Rd
Log:
 - ls_by_expiry looks in both expires and expiry, and strips hyphens from input
 - updates to docs


Modified: pkg/FinancialInstrument/R/load.instruments.R
===================================================================
--- pkg/FinancialInstrument/R/load.instruments.R	2011-10-21 00:04:46 UTC (rev 824)
+++ pkg/FinancialInstrument/R/load.instruments.R	2011-10-23 01:42:51 UTC (rev 825)
@@ -351,14 +351,14 @@
 }
 
 
-#' currency metadata to be used by \code{load.instruments}
+#' currency metadata to be used by \code{\link{load.instruments}}
 #'
 #' @name currencies
 #' @docType data
 #' @keywords data
 NULL
 
-#' future metadata to be used by \code{load.instruments}
+#' future metadata to be used by \code{\link{load.instruments}}
 #'
 #' @name root_contracts
 #' @docType data

Modified: pkg/FinancialInstrument/R/ls_by_expiry.R
===================================================================
--- pkg/FinancialInstrument/R/ls_by_expiry.R	2011-10-21 00:04:46 UTC (rev 824)
+++ pkg/FinancialInstrument/R/ls_by_expiry.R	2011-10-23 01:42:51 UTC (rev 825)
@@ -1,25 +1,23 @@
-#TODO: allow for more date formats. 
-
-
-
 #' list or remove instruments by expiration date
 #' 
 #' show names of or remove instruments that expire on a given date
 #' 
-#' 
+#' \code{ls_by_expiry} will find instruments that have a field named either
+#' \dQuote{expiry} or \dQuote{expires} with a value that matches \code{expiry}. 
+#'  
 #' @aliases ls_by_expiry rm_by_expiry
-#' @param expiry expiration date that should correspond to the sQuoteexpires
-#' slot of an instrument
+#' @param expiry expiration date that should correspond to the \sQuote{expires}
+#' field of an instrument
 #' @param pattern an optional regular expression.  Only names matching
-#' sQuotepattern are returned.
+#' \sQuote{pattern} are returned.
 #' @param match exact match of pattern?
 #' @param x what to remove
 #' @return \code{ls_by_expiry} gives a vector of names of instruments that
 #' expire on the given expiry. \code{rm_by_expiry} is called for its
 #' side-effect.
 #' @author Garrett See
-#' @seealso ls_instruments, ls_options, ls_calls, ls_puts, ls_futures,
-#' ls_derivatives
+#' @seealso \code{\link{ls_instruments}}, \code{\link{ls_options}}, \code{\link{ls_calls}}, 
+#' \code{\link{ls_puts}}, \code{\link{ls_futures}}, \code{\link{ls_derivatives}}
 #' @examples
 #' 
 #' \dontrun{
@@ -45,17 +43,18 @@
     } else if (is.null(pattern)) {  #no pattern
         symbols <- ls(.instrument, all.names=TRUE)
     } # else pattern length > 1 & don't match
-        
+
+    expiry <- gsub("-", "", expiry)
     tmp_symbols <- NULL            
     for (symbol in symbols) {
         tmp_instr <- try(get(symbol, pos = .instrument),silent=TRUE)
-        if (is.instrument(tmp_instr) && !is.null(tmp_instr$expires) ) {
-        	if (any(tmp_instr$expires == expiry) ){    
+        if (is.instrument(tmp_instr) ) {
+            if ((!is.null(tmp_instr$expires) && any(gsub("-", "", tmp_instr$expires) == expiry)) ||
+                (!is.null(tmp_instr$expiry) && any(gsub("-", "", tmp_instr$expiry) == expiry)) ) {
 				tmp_symbols <- c(tmp_symbols,symbol)
-    		}	        
+    		}
         }    
     }
-
     tmp_symbols
 }
 

Modified: pkg/FinancialInstrument/R/ls_instruments.R
===================================================================
--- pkg/FinancialInstrument/R/ls_instruments.R	2011-10-21 00:04:46 UTC (rev 824)
+++ pkg/FinancialInstrument/R/ls_instruments.R	2011-10-23 01:42:51 UTC (rev 825)
@@ -1,3 +1,5 @@
+#' List or Remove instrument objects
+#' 
 #' display the names of or delete instruments, stocks, options, futures,
 #' currencies, bonds, funds, spreads, guaranteed_spreads, synthetics,
 #' derivatives, or non-derivatives.
@@ -45,18 +47,17 @@
 #' #rm_instruments(keep.currencies=FALSE) #remove everything from .instrument
 #' 
 #' # First, create some instruments
-#' currency('USD')
-#' currency('EUR')
-#' currency('JPY')
+#' currency(c("USD", "EUR", "JPY"))
 #' #stocks
-#' stock("SEE","USD")
-#' stock("SE","USD")
-#' stock("S","USD")
-#' stock("SPY",'USD')
+#' stock(c("S", "SE", "SEE", "SPY"), 'USD')
+#' synthetic("SPX", "USD", src=list(src='yahoo', name='^GSPC'))
 #' #derivatives
-#' option('.SPY','USD',multiplier=100,expiry='20110618', strike=130, callput='put', underlying_id='SPY')
-#' future('ES', 'USD', multiplier=50, expiry='20110916', underlying_id='ES')
-#' option('.ES','USD',multiplier=1, expiry='201106',strike=1350, right='C', underlying_id='ES')
+#' option('.SPY', 'USD', multiplier=100, underlying_id='SPY')
+#' option_series(root_id="SPY", expires='2011-06-18', callput='put', strike=130)
+#' option_series(root_id="SPY", expires='2011-09-17', callput='put', strike=130)
+#' option_series(root_id="SPY", expires='2011-06-18', callput='call', strike=130)
+#' future('ES', 'USD', multiplier=50, expires='2011-09-16', underlying_id="SPX")
+#' option('.ES','USD',multiplier=1, expires='2011-06',strike=1350, right='C', underlying_id='ES')
 #' 
 #' # Now, the examples
 #' ls_instruments() #all instruments
@@ -70,10 +71,10 @@
 #' ls_derivatives()
 #' ls_puts()
 #' ls_non_derivatives()
-#' #ls_by_expiry('20110618',ls_puts) #put options that expire on Jun 18th, 2011
+#' #ls_by_expiry('20110618',ls_puts()) #put options that expire on Jun 18th, 2011
 #' #ls_puts(ls_by_expiry('20110618')) #same thing
 #' 
-#' rm_options('.SPY')
+#' rm_options('SPY_110618C130')
 #' rm_futures()
 #' ls_instruments()
 #' #rm_instruments('EUR') #Incorrect
@@ -85,9 +86,10 @@
 #' rm_instruments() #remove all but currencies
 #' rm_currencies()
 #' 
-#' #option_series.yahoo('DIA')
+#' option_series.yahoo('DIA')
 #' ls_instruments_by('underlying_id','DIA') #underlying_id must exactly match 'DIA'
 #' ls_derivatives('DIA',match=FALSE) #primary_ids that contain 'DIA'
+#' rm_instruments()
 #' }
 #' @export
 #' @rdname ls_instruments

Modified: pkg/FinancialInstrument/R/redenominate.R
===================================================================
--- pkg/FinancialInstrument/R/redenominate.R	2011-10-21 00:04:46 UTC (rev 824)
+++ pkg/FinancialInstrument/R/redenominate.R	2011-10-23 01:42:51 UTC (rev 825)
@@ -82,7 +82,7 @@
     xts(x, order.by=as.Date(paste(index(x))))
 }
 
-#' contruct price ratios of 2 instruments 
+#' construct price ratios of 2 instruments 
 #'
 #' Calculates time series of ratio of 2 instruments using available data. 
 #' Returned object will be ratios calculated using Bids, Asks, and Mids, or Opens, Closes, and Adjusteds.

Modified: pkg/FinancialInstrument/R/saveSymbols.R
===================================================================
--- pkg/FinancialInstrument/R/saveSymbols.R	2011-10-21 00:04:46 UTC (rev 824)
+++ pkg/FinancialInstrument/R/saveSymbols.R	2011-10-23 01:42:51 UTC (rev 825)
@@ -2,7 +2,13 @@
 #'
 #' save data to disk the way that \code{getSymbols.FI} 
 #' expects it to be saved.
-#' 
+#'
+#' If they do not already exist, subdirectories will be created for each of the \code{Symbols}.
+#' \code{saveSymbols.common} will save a single \sQuote{rda} file for each of the \code{Symbols}
+#' in that symbol's subdirectory.
+#' \code{saveSymbols.days} will split the data up into days and save a separate \sQuote{rda} file
+#' for each day in that symbol's subdirectory.
+#'
 #' @param Symbols vector of character names of objects to be saved
 #' @param base_dir character.  directory in which to store data.
 #' @param env environment that holds the data to be saved (.GlobalEnv by default)

Modified: pkg/FinancialInstrument/R/update_instruments.yahoo.R
===================================================================
--- pkg/FinancialInstrument/R/update_instruments.yahoo.R	2011-10-21 00:04:46 UTC (rev 824)
+++ pkg/FinancialInstrument/R/update_instruments.yahoo.R	2011-10-23 01:42:51 UTC (rev 825)
@@ -2,11 +2,12 @@
 #' 
 #' Adds/updates information in instrument with data downloaded from yahoo
 #' 
-#' if you call \code{update_instruments.yahoo} with one of \sQuote{all} or
-#' \sQuote{stocks}, it is the same as calling it with the relevant ls_ function 
-#' (e.g. \code{ls_stocks()}).  Therefore, functionality can be extended by using 
-#' ls_ functions instead of a descriptive string.
-#' 
+#' Although these functions are intended to update the metadata of
+#' previously defined instruments, \code{update_instruments.TTR} will
+#' define the stocks if they do not already exist.
+#'
+#' \code{update_instruments.TTR} is only to be used on U.S. stocks denominated in USD.
+#'
 #' @aliases update_instruments.yahoo update_instruments.TTR
 #' @param Symbols can be a vector of instrument names, or, can be \sQuote{all}
 #' or \sQuote{stocks} or, for update_instruments.TTR, can be NULL in which case
@@ -16,14 +17,17 @@
 #' @param verbose be verbose?
 #' @return called for side-effect
 #' @author Garrett See
+#' @seealso \code{\link[TTR]{stockSymbols}}, \code{\link{stock}}
 #' @references Yahoo! Finance \url{finance.yahoo.com} YahooQuote
 #' \url{http://dirk.eddelbuettel.com/code/yahooquote.html} 
 #' gummy-stuff.org \url{www.gummy-stuff.org/Yahoo-data.htm} 
 #' @examples
 #' \dontrun{	
 #' 	stock('GS',currency('USD'))
-#'     update_instruments.yahoo('GS')
+#'  update_instruments.yahoo('GS')
 #' 	getInstrument('GS')
+#'  update_instruments.TTR('GS')
+#'  getInstrument('GS')
 #' }
 #' @export
 update_instruments.yahoo <- function(Symbols=c('stocks','all'), verbose=FALSE ) {

Modified: pkg/FinancialInstrument/man/buildRatio.Rd
===================================================================
--- pkg/FinancialInstrument/man/buildRatio.Rd	2011-10-21 00:04:46 UTC (rev 824)
+++ pkg/FinancialInstrument/man/buildRatio.Rd	2011-10-23 01:42:51 UTC (rev 825)
@@ -1,6 +1,6 @@
 \name{buildRatio}
 \alias{buildRatio}
-\title{contruct price ratios of 2 instruments}
+\title{construct price ratios of 2 instruments}
 \usage{
   buildRatio(x, env = .GlobalEnv, silent = FALSE)
 }

Modified: pkg/FinancialInstrument/man/currencies.Rd
===================================================================
--- pkg/FinancialInstrument/man/currencies.Rd	2011-10-21 00:04:46 UTC (rev 824)
+++ pkg/FinancialInstrument/man/currencies.Rd	2011-10-23 01:42:51 UTC (rev 825)
@@ -1,9 +1,10 @@
 \docType{data}
 \name{currencies}
 \alias{currencies}
-\title{currency metadata to be used by \code{load.instruments}}
+\title{currency metadata to be used by \code{\link{load.instruments}}}
 \description{
-  currency metadata to be used by \code{load.instruments}
+  currency metadata to be used by
+  \code{\link{load.instruments}}
 }
 \keyword{data}
 

Modified: pkg/FinancialInstrument/man/ls_by_expiry.Rd
===================================================================
--- pkg/FinancialInstrument/man/ls_by_expiry.Rd	2011-10-21 00:04:46 UTC (rev 824)
+++ pkg/FinancialInstrument/man/ls_by_expiry.Rd	2011-10-23 01:42:51 UTC (rev 825)
@@ -9,10 +9,10 @@
 }
 \arguments{
   \item{expiry}{expiration date that should correspond to
-  the sQuoteexpires slot of an instrument}
+  the \sQuote{expires} field of an instrument}
 
   \item{pattern}{an optional regular expression.  Only
-  names matching sQuotepattern are returned.}
+  names matching \sQuote{pattern} are returned.}
 
   \item{match}{exact match of pattern?}
 
@@ -27,6 +27,11 @@
   show names of or remove instruments that expire on a
   given date
 }
+\details{
+  \code{ls_by_expiry} will find instruments that have a
+  field named either \dQuote{expiry} or \dQuote{expires}
+  with a value that matches \code{expiry}.
+}
 \examples{
 \dontrun{
 ls_by_expiry('20110917')
@@ -37,7 +42,8 @@
   Garrett See
 }
 \seealso{
-  ls_instruments, ls_options, ls_calls, ls_puts,
-  ls_futures, ls_derivatives
+  \code{\link{ls_instruments}}, \code{\link{ls_options}},
+  \code{\link{ls_calls}}, \code{\link{ls_puts}},
+  \code{\link{ls_futures}}, \code{\link{ls_derivatives}}
 }
 

Modified: pkg/FinancialInstrument/man/ls_instruments.Rd
===================================================================
--- pkg/FinancialInstrument/man/ls_instruments.Rd	2011-10-21 00:04:46 UTC (rev 824)
+++ pkg/FinancialInstrument/man/ls_instruments.Rd	2011-10-23 01:42:51 UTC (rev 825)
@@ -33,9 +33,7 @@
 \alias{rm_spreads}
 \alias{rm_stocks}
 \alias{rm_synthetics}
-\title{display the names of or delete instruments, stocks, options, futures,
-currencies, bonds, funds, spreads, guaranteed_spreads, synthetics,
-derivatives, or non-derivatives.}
+\title{List or Remove instrument objects}
 \usage{
   ls_instruments(pattern = NULL, match = TRUE, verbose =
   TRUE)
@@ -133,12 +131,17 @@
   functions are called for side-effect
 }
 \description{
+  display the names of or delete instruments, stocks,
+  options, futures, currencies, bonds, funds, spreads,
+  guaranteed_spreads, synthetics, derivatives, or
+  non-derivatives.
+}
+\details{
   ls functions return the names of all the instruments of
   the class implied by the function name. rm functions
   remove the instruments of the class implied by the
   function name
-}
-\details{
+
   rm_instruments and rm_non_derivatives will not delete
   currencies unless the keep.currencies argument is FALSE.
 
@@ -154,18 +157,17 @@
 #rm_instruments(keep.currencies=FALSE) #remove everything from .instrument
 
 # First, create some instruments
-currency('USD')
-currency('EUR')
-currency('JPY')
+currency(c("USD", "EUR", "JPY"))
 #stocks
-stock("SEE","USD")
-stock("SE","USD")
-stock("S","USD")
-stock("SPY",'USD')
+stock(c("S", "SE", "SEE", "SPY"), 'USD')
+synthetic("SPX", "USD", src=list(src='yahoo', name='^GSPC'))
 #derivatives
-option('.SPY','USD',multiplier=100,expiry='20110618', strike=130, callput='put', underlying_id='SPY')
-future('ES', 'USD', multiplier=50, expiry='20110916', underlying_id='ES')
-option('.ES','USD',multiplier=1, expiry='201106',strike=1350, right='C', underlying_id='ES')
+option('.SPY', 'USD', multiplier=100, underlying_id='SPY')
+option_series(root_id="SPY", expires='2011-06-18', callput='put', strike=130)
+option_series(root_id="SPY", expires='2011-09-17', callput='put', strike=130)
+option_series(root_id="SPY", expires='2011-06-18', callput='call', strike=130)
+future('ES', 'USD', multiplier=50, expires='2011-09-16', underlying_id="SPX")
+option('.ES','USD',multiplier=1, expires='2011-06',strike=1350, right='C', underlying_id='ES')
 
 # Now, the examples
 ls_instruments() #all instruments
@@ -179,10 +181,10 @@
 ls_derivatives()
 ls_puts()
 ls_non_derivatives()
-#ls_by_expiry('20110618',ls_puts) #put options that expire on Jun 18th, 2011
+#ls_by_expiry('20110618',ls_puts()) #put options that expire on Jun 18th, 2011
 #ls_puts(ls_by_expiry('20110618')) #same thing
 
-rm_options('.SPY')
+rm_options('SPY_110618C130')
 rm_futures()
 ls_instruments()
 #rm_instruments('EUR') #Incorrect
@@ -194,9 +196,10 @@
 rm_instruments() #remove all but currencies
 rm_currencies()
 
-#option_series.yahoo('DIA')
+option_series.yahoo('DIA')
 ls_instruments_by('underlying_id','DIA') #underlying_id must exactly match 'DIA'
 ls_derivatives('DIA',match=FALSE) #primary_ids that contain 'DIA'
+rm_instruments()
 }
 }
 \author{

Modified: pkg/FinancialInstrument/man/root_contracts.Rd
===================================================================
--- pkg/FinancialInstrument/man/root_contracts.Rd	2011-10-21 00:04:46 UTC (rev 824)
+++ pkg/FinancialInstrument/man/root_contracts.Rd	2011-10-23 01:42:51 UTC (rev 825)
@@ -1,9 +1,10 @@
 \docType{data}
 \name{root_contracts}
 \alias{root_contracts}
-\title{future metadata to be used by \code{load.instruments}}
+\title{future metadata to be used by \code{\link{load.instruments}}}
 \description{
-  future metadata to be used by \code{load.instruments}
+  future metadata to be used by
+  \code{\link{load.instruments}}
 }
 \keyword{data}
 

Modified: pkg/FinancialInstrument/man/saveSymbols.days.Rd
===================================================================
--- pkg/FinancialInstrument/man/saveSymbols.days.Rd	2011-10-21 00:04:46 UTC (rev 824)
+++ pkg/FinancialInstrument/man/saveSymbols.days.Rd	2011-10-23 01:42:51 UTC (rev 825)
@@ -26,6 +26,15 @@
   save data to disk the way that \code{getSymbols.FI}
   expects it to be saved.
 }
+\details{
+  If they do not already exist, subdirectories will be
+  created for each of the \code{Symbols}.
+  \code{saveSymbols.common} will save a single \sQuote{rda}
+  file for each of the \code{Symbols} in that symbol's
+  subdirectory. \code{saveSymbols.days} will split the data
+  up into days and save a separate \sQuote{rda} file for
+  each day in that symbol's subdirectory.
+}
 \examples{
 \dontrun{
 getSymbols("SPY", src='yahoo')

Modified: pkg/FinancialInstrument/man/update_instruments.yahoo.Rd
===================================================================
--- pkg/FinancialInstrument/man/update_instruments.yahoo.Rd	2011-10-21 00:04:46 UTC (rev 824)
+++ pkg/FinancialInstrument/man/update_instruments.yahoo.Rd	2011-10-23 01:42:51 UTC (rev 825)
@@ -29,18 +29,21 @@
   downloaded from yahoo
 }
 \details{
-  if you call \code{update_instruments.yahoo} with one of
-  \sQuote{all} or \sQuote{stocks}, it is the same as
-  calling it with the relevant ls_ function (e.g.
-  \code{ls_stocks()}).  Therefore, functionality can be
-  extended by using ls_ functions instead of a descriptive
-  string.
+  Although these functions are intended to update the
+  metadata of previously defined instruments,
+  \code{update_instruments.TTR} will define the stocks if
+  they do not already exist.
+
+  \code{update_instruments.TTR} is only to be used on U.S.
+  stocks denominated in USD.
 }
 \examples{
 \dontrun{
 stock('GS',currency('USD'))
 update_instruments.yahoo('GS')
 getInstrument('GS')
+update_instruments.TTR('GS')
+getInstrument('GS')
 }
 }
 \author{
@@ -51,4 +54,7 @@
   \url{http://dirk.eddelbuettel.com/code/yahooquote.html}
   gummy-stuff.org \url{www.gummy-stuff.org/Yahoo-data.htm}
 }
+\seealso{
+  \code{\link[TTR]{stockSymbols}}, \code{\link{stock}}
+}
 



More information about the Blotter-commits mailing list