[Blotter-commits] r1638 - in pkg/FinancialInstrument: . R inst/parser man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Oct 8 05:43:17 CEST 2014


Author: gsee
Date: 2014-10-08 05:43:16 +0200 (Wed, 08 Oct 2014)
New Revision: 1638

Modified:
   pkg/FinancialInstrument/DESCRIPTION
   pkg/FinancialInstrument/NAMESPACE
   pkg/FinancialInstrument/NEWS
   pkg/FinancialInstrument/R/FinancialInstrument-package.R
   pkg/FinancialInstrument/R/buildSpread.R
   pkg/FinancialInstrument/R/build_symbols.R
   pkg/FinancialInstrument/R/load.instruments.R
   pkg/FinancialInstrument/R/redenominate.R
   pkg/FinancialInstrument/R/update_instruments.yahoo.R
   pkg/FinancialInstrument/inst/parser/download.tblox.R
   pkg/FinancialInstrument/man/C2M.Rd
   pkg/FinancialInstrument/man/CompareInstrumentFiles.Rd
   pkg/FinancialInstrument/man/FinancialInstrument-package.Rd
   pkg/FinancialInstrument/man/FindCommonInstrumentAttributes.Rd
   pkg/FinancialInstrument/man/Notionalize.Rd
   pkg/FinancialInstrument/man/Tick2Sec.Rd
   pkg/FinancialInstrument/man/add.defined.by.Rd
   pkg/FinancialInstrument/man/add.identifier.Rd
   pkg/FinancialInstrument/man/all.equal.instrument.Rd
   pkg/FinancialInstrument/man/buildHierarchy.Rd
   pkg/FinancialInstrument/man/buildRatio.Rd
   pkg/FinancialInstrument/man/buildSpread.Rd
   pkg/FinancialInstrument/man/build_series_symbols.Rd
   pkg/FinancialInstrument/man/build_spread_symbols.Rd
   pkg/FinancialInstrument/man/currencies.Rd
   pkg/FinancialInstrument/man/exchange_rate.Rd
   pkg/FinancialInstrument/man/expires.Rd
   pkg/FinancialInstrument/man/expires.character.Rd
   pkg/FinancialInstrument/man/expires.instrument.Rd
   pkg/FinancialInstrument/man/expires.spread.Rd
   pkg/FinancialInstrument/man/expires.xts.Rd
   pkg/FinancialInstrument/man/find.instrument.Rd
   pkg/FinancialInstrument/man/fn_SpreadBuilder.Rd
   pkg/FinancialInstrument/man/formatSpreadPrice.Rd
   pkg/FinancialInstrument/man/format_id.Rd
   pkg/FinancialInstrument/man/getInstrument.Rd
   pkg/FinancialInstrument/man/getSymbols.FI.Rd
   pkg/FinancialInstrument/man/get_rate.Rd
   pkg/FinancialInstrument/man/instrument.Rd
   pkg/FinancialInstrument/man/instrument.auto.Rd
   pkg/FinancialInstrument/man/instrument.table.Rd
   pkg/FinancialInstrument/man/instrument_attr.Rd
   pkg/FinancialInstrument/man/is.currency.Rd
   pkg/FinancialInstrument/man/is.currency.name.Rd
   pkg/FinancialInstrument/man/is.instrument.Rd
   pkg/FinancialInstrument/man/is.instrument.name.Rd
   pkg/FinancialInstrument/man/load.instruments.Rd
   pkg/FinancialInstrument/man/ls_by_currency.Rd
   pkg/FinancialInstrument/man/ls_by_expiry.Rd
   pkg/FinancialInstrument/man/ls_expiries.Rd
   pkg/FinancialInstrument/man/ls_instruments.Rd
   pkg/FinancialInstrument/man/ls_instruments_by.Rd
   pkg/FinancialInstrument/man/ls_strikes.Rd
   pkg/FinancialInstrument/man/ls_underlyings.Rd
   pkg/FinancialInstrument/man/make_spread_id.Rd
   pkg/FinancialInstrument/man/month_cycle2numeric.Rd
   pkg/FinancialInstrument/man/next.future_id.Rd
   pkg/FinancialInstrument/man/option_series.yahoo.Rd
   pkg/FinancialInstrument/man/parse_id.Rd
   pkg/FinancialInstrument/man/parse_suffix.Rd
   pkg/FinancialInstrument/man/print.id.list.Rd
   pkg/FinancialInstrument/man/print.instrument.Rd
   pkg/FinancialInstrument/man/print.suffix.list.Rd
   pkg/FinancialInstrument/man/redenominate.Rd
   pkg/FinancialInstrument/man/root_contracts.Rd
   pkg/FinancialInstrument/man/saveInstruments.Rd
   pkg/FinancialInstrument/man/saveSymbols.days.Rd
   pkg/FinancialInstrument/man/series_instrument.Rd
   pkg/FinancialInstrument/man/setSymbolLookup.FI.Rd
   pkg/FinancialInstrument/man/sort.instrument.Rd
   pkg/FinancialInstrument/man/sort_ids.Rd
   pkg/FinancialInstrument/man/synthetic.instrument.Rd
   pkg/FinancialInstrument/man/to_daily.Rd
   pkg/FinancialInstrument/man/update_instruments.iShares.Rd
   pkg/FinancialInstrument/man/update_instruments.instrument.Rd
   pkg/FinancialInstrument/man/update_instruments.masterDATA.Rd
   pkg/FinancialInstrument/man/update_instruments.morningstar.Rd
   pkg/FinancialInstrument/man/update_instruments.yahoo.Rd
   pkg/FinancialInstrument/man/volep.Rd
Log:
Updates for CRAN (remove importDefaults(), remove `:::` calls). upgrade roxygen2.

Modified: pkg/FinancialInstrument/DESCRIPTION
===================================================================
--- pkg/FinancialInstrument/DESCRIPTION	2014-10-07 15:51:21 UTC (rev 1637)
+++ pkg/FinancialInstrument/DESCRIPTION	2014-10-08 03:43:16 UTC (rev 1638)
@@ -1,4 +1,4 @@
-Copyright: (c) 2004 - 2013
+Copyright: (c) 2004 - 2014
 Package: FinancialInstrument
 Maintainer: G See <gsee000 at gmail.com>
 License: GPL
@@ -8,50 +8,19 @@
 Author: Peter Carl, Brian G. Peterson, Garrett See
 Description: Infrastructure for defining meta-data and
     relationships for financial instruments.
-Version: 1.1.9
+Version: 1.2.0
 URL: https://r-forge.r-project.org/projects/blotter/
-Date: 2013-05-26
+Date: 2014-10-07
 Depends:
     R (>= 2.12.0),
     quantmod(>= 0.3-17),
+Imports:
+    zoo(>= 1.7-5),
     xts,
-    zoo(>= 1.7-5)
+    TTR
 Suggests:
     foreach,
     XML (>= 3.96.1.1),
-    testthat
-Collate:
-    'buildHierarchy.R'
-    'buildSpread.R'
-    'build_symbols.R'
-    'instrument.R'
-    'instrument.table.R'
-    'load.instruments.R'
-    'redenominate.R'
-    'splice.R'
-    'splooth.R'
-    'synthetic.R'
-    'volep.R'
-    'parse_id.R'
-    'MonthCodes.R'
-    'format_id.R'
-    'ls_by_expiry.R'
-    'ls_instruments_by.R'
-    'ls_instruments.R'
-    'ls_strikes.R'
-    'ls_underlyings.R'
-    'update_instruments.yahoo.R'
-    'ls_by_currency.R'
-    'saveInstruments.R'
-    'ls_expiries.R'
-    'saveSymbols.R'
-    'Tick2Sec.R'
-    'all.equal.instrument.R'
-    'expires.R'
-    'find.instrument.R'
-    'FinancialInstrument-package.R'
-    'FindCommonInstrumentAttributes.R'
-    'Notionalize.R'
-    'update_instruments.iShares.R'
-    'update_instruments.morningstar.R'
-    'CompareInstrumentFiles.R'
+    testthat,
+    its,
+    timeSeries

Modified: pkg/FinancialInstrument/NAMESPACE
===================================================================
--- pkg/FinancialInstrument/NAMESPACE	2014-10-07 15:51:21 UTC (rev 1637)
+++ pkg/FinancialInstrument/NAMESPACE	2014-10-08 03:43:16 UTC (rev 1638)
@@ -1,3 +1,22 @@
+# Generated by roxygen2 (4.0.2): do not edit by hand
+
+S3method(all.equal,instrument)
+S3method(expires,character)
+S3method(expires,instrument)
+S3method(expires,xts)
+S3method(print,id.list)
+S3method(print,instrument)
+S3method(print,suffix.list)
+S3method(sort,instrument)
+export(.to_daily)
+export(C2M)
+export(CompareInstrumentFiles)
+export(Denotionalize)
+export(ICS)
+export(ICS_root)
+export(M2C)
+export(MC2N)
+export(Notionalize)
 export(add.defined.by)
 export(add.identifier)
 export(bond)
@@ -5,32 +24,27 @@
 export(buildBasket)
 export(buildHierarchy)
 export(buildRatio)
+export(buildSpread)
 export(build_series_symbols)
-export(buildSpread)
 export(build_spread_symbols)
 export(butterfly)
-export(C2M)
-export(CompareInstrumentFiles)
 export(currency)
-export(Denotionalize)
 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(getInstrument)
 export(getSymbols.FI)
 export(guaranteed_spread)
-export(ICS)
-export(ICS_root)
 export(instrument)
-export(instrument_attr)
 export(instrument.auto)
 export(instrument.table)
+export(instrument_attr)
 export(is.currency)
 export(is.currency.name)
 export(is.instrument)
@@ -38,49 +52,46 @@
 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_future_series)
-export(ls_FX)
-export(ls_GBP)
 export(ls_guaranteed_spreads)
-export(ls_HKD)
-export(ls_ICS)
-export(ls_ICS_roots)
 export(ls_instruments)
 export(ls_instruments_by)
-export(ls_JPY)
 export(ls_non_currencies)
 export(ls_non_derivatives)
-export(ls_NZD)
+export(ls_option_series)
 export(ls_options)
-export(ls_option_series)
 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(Notionalize)
 export(option)
 export(option_series)
 export(option_series.yahoo)
@@ -89,6 +100,7 @@
 export(prev.future_id)
 export(redenominate)
 export(reloadInstruments)
+export(rm_FX)
 export(rm_bonds)
 export(rm_by_currency)
 export(rm_by_expiry)
@@ -96,13 +108,12 @@
 export(rm_derivatives)
 export(rm_exchange_rates)
 export(rm_funds)
+export(rm_future_series)
 export(rm_futures)
-export(rm_future_series)
-export(rm_FX)
 export(rm_instruments)
 export(rm_non_derivatives)
+export(rm_option_series)
 export(rm_options)
-export(rm_option_series)
 export(rm_spreads)
 export(rm_stocks)
 export(rm_synthetics)
@@ -115,25 +126,41 @@
 export(stock)
 export(synthetic)
 export(synthetic.instrument)
-export(.to_daily)
 export(to_secBATV)
+export(update_instruments.SPDR)
+export(update_instruments.TTR)
+export(update_instruments.iShares)
 export(update_instruments.instrument)
-export(update_instruments.iShares)
 export(update_instruments.masterDATA)
 export(update_instruments.md)
 export(update_instruments.morningstar)
 export(update_instruments.ms)
-export(update_instruments.SPDR)
-export(update_instruments.TTR)
 export(update_instruments.yahoo)
 export(volep)
+import(xts)
+importFrom(TTR,runSum)
+importFrom(TTR,stockSymbols)
+importFrom(quantmod,Ad)
+importFrom(quantmod,Cl)
+importFrom(quantmod,OHLC)
+importFrom(quantmod,Op)
+importFrom(quantmod,Vo)
+importFrom(quantmod,getOptionChain)
+importFrom(quantmod,getPrice)
+importFrom(quantmod,getQuote)
+importFrom(quantmod,getSymbolLookup)
+importFrom(quantmod,getSymbols)
+importFrom(quantmod,has.Ad)
+importFrom(quantmod,has.Ask)
+importFrom(quantmod,has.Bid)
+importFrom(quantmod,has.Cl)
+importFrom(quantmod,has.Op)
+importFrom(quantmod,has.Price)
+importFrom(quantmod,has.Trade)
+importFrom(quantmod,has.Vo)
+importFrom(quantmod,is.BBO)
+importFrom(quantmod,is.HLC)
+importFrom(quantmod,is.OHLC)
+importFrom(quantmod,setSymbolLookup)
+importFrom(quantmod,yahooQF)
 importFrom(zoo,as.Date)
-import(xts)
-S3method(all.equal,instrument)
-S3method(expires,character)
-S3method(expires,instrument)
-S3method(expires,xts)
-S3method(print,id.list)
-S3method(print,instrument)
-S3method(print,suffix.list)
-S3method(sort,instrument)

Modified: pkg/FinancialInstrument/NEWS
===================================================================
--- pkg/FinancialInstrument/NEWS	2014-10-07 15:51:21 UTC (rev 1637)
+++ pkg/FinancialInstrument/NEWS	2014-10-08 03:43:16 UTC (rev 1638)
@@ -4,6 +4,11 @@
 USER VISIBLE CHANGES
 --------------------
 
+* No longer using Defaults package (which is now archived on CRAN) in
+  getSymbols.FI.
+
+* remove some `:::` calls to unexported functions from quantmod.
+
 * saveInstruments() gains a "compress" argument to allow for different 
   compression than the default ("gzip")
 

Modified: pkg/FinancialInstrument/R/FinancialInstrument-package.R
===================================================================
--- pkg/FinancialInstrument/R/FinancialInstrument-package.R	2014-10-07 15:51:21 UTC (rev 1637)
+++ pkg/FinancialInstrument/R/FinancialInstrument-package.R	2014-10-08 03:43:16 UTC (rev 1638)
@@ -1,3 +1,11 @@
+
+
+#' @importFrom quantmod getQuote is.HLC is.OHLC OHLC is.BBO has.Bid has.Ask 
+#'  has.Op has.Ad has.Trade has.Price getPrice Op Cl Ad has.Cl getSymbols   
+#'  getSymbolLookup setSymbolLookup yahooQF has.Vo Vo getOptionChain
+#' @importFrom TTR stockSymbols runSum
+NULL
+
 #' Construct, manage and store contract specifications for trading
 #'
 #' Transaction-oriented infrastructure for defining tradable instruments based 
@@ -246,3 +254,62 @@
 #'}
 NULL
 
+# Copied from quantmod because it's not exported
+has.Mid <- function (x, which = FALSE) {
+    colAttr <- attr(x, "Mid")
+    if (!is.null(colAttr)) 
+        return(if (which) colAttr else TRUE)
+    loc <- grep("Mid", colnames(x), ignore.case = TRUE)
+    if (!identical(loc, integer(0))) 
+        return(ifelse(which, loc, TRUE))
+    ifelse(which, loc, FALSE)
+}
+
+# copied from quantmod:::convert.time.series since it is not exported
+convert.time.series <- function (fr, return.class) {
+    if ("quantmod.OHLC" %in% return.class) {
+        class(fr) <- c("quantmod.OHLC", "zoo")
+        return(fr)
+    }
+    else if ("xts" %in% return.class) {
+        return(fr)
+    }
+    if ("zoo" %in% return.class) {
+        return(as.zoo(fr))
+    }
+    else if ("ts" %in% return.class) {
+        fr <- as.ts(fr)
+        return(fr)
+    }
+    else if ("data.frame" %in% return.class) {
+        fr <- as.data.frame(fr)
+        return(fr)
+    }
+    else if ("matrix" %in% return.class) {
+        fr <- as.data.frame(fr)
+        return(fr)
+    }
+    else if ("its" %in% return.class) {
+        if ("package:its" %in% search() || suppressMessages(require("its", 
+            quietly = TRUE))) {
+            fr.dates <- as.POSIXct(as.character(index(fr)))
+            fr <- its::its(coredata(fr), fr.dates)
+            return(fr)
+        }
+        else {
+            warning(paste("'its' from package 'its' could not be loaded:", 
+                " 'xts' class returned"))
+        }
+    }
+    else if ("timeSeries" %in% return.class) {
+        if ("package:timeSeries" %in% search() || suppressMessages(require("timeSeries", 
+            quietly = TRUE))) {
+            fr <- timeSeries(coredata(fr), charvec = as.character(index(fr)))
+            return(fr)
+        }
+        else {
+            warning(paste("'timeSeries' from package 'timeSeries' could not be loaded:", 
+                " 'xts' class returned"))
+        }
+    }
+}

Modified: pkg/FinancialInstrument/R/buildSpread.R
===================================================================
--- pkg/FinancialInstrument/R/buildSpread.R	2014-10-07 15:51:21 UTC (rev 1637)
+++ pkg/FinancialInstrument/R/buildSpread.R	2014-10-08 03:43:16 UTC (rev 1638)
@@ -50,8 +50,6 @@
 #' @export
 buildSpread <- function(spread_id, Dates = NULL, onelot=TRUE, prefer = NULL, 
                         auto.assign=TRUE, env=.GlobalEnv) {
-    has.Mid <- quantmod:::has.Mid #FIXME: this should be exported from quatmod
-    
     spread_instr <- try(getInstrument(spread_id))
     if (inherits(spread_instr, "try-error") | !is.instrument(spread_instr)) {
         stop(paste("Instrument", spread_instr, " not found, please create it first."))
@@ -219,10 +217,13 @@
 #' stock("SPY", "USD")
 #' stock("DIA", "USD")
 #' getSymbols(c("SPY","DIA"))
-#' fSB <- fn_SpreadBuilder("SPY","DIA") #can call with names of instrument/xts ojects
+#' 
+#' #can call with names of instrument/xts ojects
+#' fSB <- fn_SpreadBuilder("SPY","DIA") 
 #' fSB2 <- fn_SpreadBuilder(SPY,DIA) # or you can pass xts objects
 #'
-#' fSB3 <- fn_SpreadBuilder("SPY","DIA",1.1) #assuming you first somehow calculated the ratio to be a constant 1.1
+#' #assuming you first somehow calculated the ratio to be a constant 1.1
+#' fSB3 <- fn_SpreadBuilder("SPY","DIA",1.1) 
 #' head(fSB)
 #'
 #' # Call fn_SpreadBuilder with vector of 2 instrument names

Modified: pkg/FinancialInstrument/R/build_symbols.R
===================================================================
--- pkg/FinancialInstrument/R/build_symbols.R	2014-10-07 15:51:21 UTC (rev 1637)
+++ pkg/FinancialInstrument/R/build_symbols.R	2014-10-08 03:43:16 UTC (rev 1638)
@@ -1,209 +1,209 @@
-#' construct a series of symbols based on root symbol and suffix letters
-#'
-#' The columns needed by this version of the function are \code{primary_id}
-#' and \code{month_cycle}. \code{primary_id} should match the \code{primary_id}
-#' of the instrument describing the root contract.
-#' \code{month_cycle} should contain a comma delimited string describing the
-#' month sequence to use, e.g. \code{"F,G,H,J,K,M,N,Q,U,V,X,Z"} for all months
-#' using the standard futures letters, or \code{"H,M,U,Z"} for quarters, or
-#' \code{"Mar,Jun,Sep,Dec"} for quarters as three-letter month abbreviations, etc.
-#' The correct values will vary based on your data source.
-#'
-#' TODO add more flexibility in input formats for \code{roots}
-#' #' @param yearlist vector of year suffixes to be applied, see Details
-#' @param roots data.frame containing at least columns \code{primary_id} and \code{month_cycle}, see Details
-#' @author Brian G. Peterson
-#' @seealso \code{\link{load.instruments}}
-#' @export
-build_series_symbols <- function(roots, yearlist=c(0,1)) {
-        symbols<-''
-        id_col<-grep('primary_id',colnames(roots)) #TODO: check length
-	date_col<-grep('month_cycle',colnames(roots)) #TODO: check length
-	for (year_code in yearlist){
-		for(i in 1:nrow(roots)) {
-			symbols <- c(symbols, paste(paste(roots[i,id_col], strsplit(as.character(roots[i,date_col]),",")[[1]],sep=''),year_code,sep=''))
-		}
-	}
-	return(symbols[-1])
-}
-
-#' build symbols for exchange guaranteed (calendar) spreads
-#'
-#' The columns needed by this version of the function are \code{primary_id},
-#'  \code{month_cycle}, and code \code{contracts_ahead}.
-#'
-#' \code{primary_id} should match the \code{primary_id}
-#' of the instrument describing the root contract.
-#'
-#' \code{month_cycle} should contain a comma delimited string describing the
-#' month sequence to use, e.g. \code{"F,G,H,J,K,M,N,Q,U,V,X,Z"} for all months
-#' using the standard futures letters, or \code{"H,M,U,Z"} for quarters, or
-#' \code{"Mar,Jun,Sep,Dec"} for quarters as three-letter month abbreviations, etc.
-#' The correct values will vary based on your data source.
-#'
-#' \code{contracts_ahead} should contain a comma-delimited string describing
-#' the cycle on which the guaranteed calendar spreads are to be consructed,
-#' e.g. '1' for one-month spreads, '1,3' for one and three month spreads,
-#' '1,6,12' for 1, 6, and 12 month spreads, etc.  
-#' For quarterly symbols, the correct \code{contracts_ahead} may be 
-#' something like '1,2,3' for quarterly, bi-annual, and annual spreads.  
-#'
-#' \code{active_months} is a numeric field indicating how many months including  
-#' the month of the \code{start_date} the contract is available to trade.  
-#' This number will be used as the upper limit for symbol generation.
-#' 
-#' If \code{type} is also specified, it should be a specific instrument type, 
-#' e.g. 'future_series','option_series','guaranteed_spread' or 'calendar_spread' 
-#'
-#' One of \code{data} or \code{file} must be populated for input data.
-#'
-#' @param data data.frame containing at least columns \code{primary_id}, \code{month_cycle}, amd \code{contracts_ahead}, see Details
-#' @param file if not NULL, will read input data from the file named by this argument, in the same folrmat as \code{data}, above
-#' @param outputfile if not NULL, will write out put to this file as a CSV
-#' @param start_date date to start building from, of type \code{Date} or an ISO-8601 date string, defaults to \code{\link{Sys.Date}}
-#' @author Ilya Kipnis <Ilya.Kipnis<at>gmail.com>
-#' @seealso
-#' \code{\link{load.instruments}}
-#' \code{\link{build_series_symbols}}
-#' @examples 
-#' build_spread_symbols(data=data.frame(primary_id='CL',
-#'                                      month_sequence="F,G,H,J,K,M,N,Q,U,V,X,Z",
-#'                                      contracts_ahead="1,2,3",
-#'                                      type='calendar_spread')
-#' @export
-build_spread_symbols <- function(data=NULL,file=NULL,outputfile=NULL,start_date=Sys.Date())
-{
-        if(!is.null(data)) {
-                Data<-data
-        } else if(!is.null(file)) {
-                Data<-read.csv(file,header=TRUE,stringsAsFactors=FALSE)
-        } else {
-                stop("you must either pass a data.frame as the 'data' parameter or pass the 'file' parameter")
-        }
-
-
-
-	yearCheck<-function(monthNum,yearNum){
-		if(monthNum>12){
-			yearNum=yearNum+1
-		} else if(monthNum<0){
-			yearNum=yearNum-1
-		} else {
-			yearNum=yearNum
-		}
-		return(yearNum)
-	}
-
-	makeNameCal<-function(primary_id,MonthOne,YearOne,MonthTwo,YearTwo){
-		contractName<-NULL
-		contractName<-paste(primary_id,MonthOne,YearOne,"-",MonthTwo,YearTwo,sep="")
-		return(contractName)
-	}
-
-	makeCalRows<-function(dataRow){
-		calFrame<-NULL
-		calContracts<-as.numeric(unlist(strsplit(dataRow$contracts_ahead[1],",",fixed=TRUE)))
-		contractIndex<-c(1:length(monthsTraded))
-		contractTable<-cbind(monthsTraded,contractIndex)
-		for(k in 1:length(calContracts)){
-            if(length(monthsTraded)==12 & calContracts[k]>1){
-                yearsAhead = trunc((calContracts[k]-1)/length(monthsTraded))%%10
-                monthContractsAhead=(calContracts[k]-1)%%length(monthsTraded)
-            } else {
-                yearsAhead=trunc(calContracts[k]/length(monthsTraded))%%10
-                monthContractsAhead=calContracts[k]%%length(monthsTraded)
-            }
-			workingContractNum<-as.numeric(contractTable[which(contractTable[,1]==workingContractMonthLet),2])
-			monthIndex=workingContractNum+monthContractsAhead
-			if(monthIndex>length(monthsTraded)){
-				yearsAhead<-(yearsAhead+1)%%10
-				monthIndex=monthIndex-length(monthsTraded)
-			}
-                        newCalMonthLetter<-contractTable[monthIndex,1]
-                        newCalYearNumber<-workingContractYearNum+yearsAhead%%10
-                        contractName<-makeNameCal(Data$primary_id[i],workingContractMonthLet,workingContractYearNum,newCalMonthLetter,newCalYearNumber)
-                        calRow<-cbind(contractName,dataRow$type[1])
-                        #Other data would be added here.  Take in a row from root contracts, add other details (EG timezone, currency, etc...)
-                        calFrame<-rbind(calFrame,calRow)
-                }
-                return(calFrame)
-        }
-
-	PPFNames<-c("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
-	PPFNums<-c(-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24)
-        PPFLets<-c("F","G","H","J","K","M","N","Q","U","V","X","Z","F","G","H","J","K","M","N","Q","U","V","X","Z","F","G","H","J","K","M","N","Q","U","V","X","Z")
-        PPFFrame<-as.data.frame(cbind(PPFNames,PPFNums,PPFLets),stringsAsFactors=FALSE)  #PPF=Past, Present, Future
-
-        contractFrame<-NULL
-        today<-start_date
-        for(i in 1:nrow(Data)){
-		currentMonthNum<-as.numeric(substr(today,6,7))
-		monthsTraded<-unlist(strsplit(Data$month_cycle[i],",",fixed=TRUE))
-		monthNumsTraded<-as.numeric(PPFFrame[which(PPFFrame[,3] %in% monthsTraded),2])
-		currentContractMonthNum<-as.numeric(monthNumsTraded[(min(which(monthNumsTraded>=currentMonthNum)))])
-		currentContractMonthLet<-PPFFrame[currentContractMonthNum,3]
-		currentYearNum<-as.numeric(substr(today,4,4))
-		currentContractYearNum<-yearCheck(currentContractMonthNum,currentYearNum)
-
-		workingContractMonthNum<-currentContractMonthNum
-		workingContractMonthLet<-currentContractMonthLet
-		workingContractYearNum<-currentContractYearNum
-
-		contractIndex<-c(1:length(monthsTraded))
-		contractTable<-cbind(monthsTraded,contractIndex)
-
-		if(Data$type[i]=="calendar_spread" || Data$type[i]=='guaranteed_spread'){
-			calFrame<-makeCalRows(Data[i,])
-			contractFrame<-rbind(contractFrame,calFrame)
-		} else {
-			#make name for non-calendar
-			#add other details to the row
-			#rbind it to the contractFrame
-		}
-
-        for(j in 1:(Data$active_months[i]-1)){
-            yearsAhead=trunc(j/length(monthsTraded))%%10 #aka if it's 10+ years ahead, since the year is one digit, for contracts further out than 10 years, you'll get 0, 1, 2, 3 instead of 10, 11, 12, etc.
-            monthContractsAhead=j%%length(monthsTraded)
-            currentContractNum<-as.numeric(contractTable[which(contractTable[,1]==currentContractMonthLet),2])
-            monthIndex=currentContractNum+monthContractsAhead
-            if(monthIndex>length(monthsTraded)){
-				yearsAhead<-(yearsAhead+1)%%10
-				monthIndex=monthIndex-length(monthsTraded)
-			}
-			workingContractMonthLet<-contractTable[monthIndex,1]
-			workingContractYearNum<-currentContractYearNum+yearsAhead
-			if(Data$type[i]=="calendar_spread" || Data$type[i]=='guaranteed_spread'){
-				calFrame<-makeCalRows(Data[i,])
-				contractFrame<-rbind(contractFrame,calFrame)
-			} else {
-				#make name for non-calendar
-				#add other details to the row
-				#rbind it to the contractFrame
-			}
-		}
-    }
-
-    rownames(contractFrame)<-NULL
-    colnames(contractFrame)<-c("symbol","type")
-
-    if(!is.null(outputfile)){
-            write.csv(contractFrame,outputfile) 
-    } else {
-            return(contractFrame)
-    }
-}
-
-###############################################################################
-# R (http://r-project.org/) Instrument Class Model
-#
-# Copyright (c) 2009-2012
-# Peter Carl, Dirk Eddelbuettel, Jeffrey Ryan, 
-# Joshua Ulrich, Brian G. Peterson, and Garrett See
-#
-# This code is distributed under the terms of the GNU Public License (GPL)
-# for full details see the file COPYING
-#
-# $Id$
-#
-###############################################################################
-
+#' construct a series of symbols based on root symbol and suffix letters
+#'
+#' The columns needed by this version of the function are \code{primary_id}
+#' and \code{month_cycle}. \code{primary_id} should match the \code{primary_id}
+#' of the instrument describing the root contract.
+#' \code{month_cycle} should contain a comma delimited string describing the
+#' month sequence to use, e.g. \code{"F,G,H,J,K,M,N,Q,U,V,X,Z"} for all months
+#' using the standard futures letters, or \code{"H,M,U,Z"} for quarters, or
+#' \code{"Mar,Jun,Sep,Dec"} for quarters as three-letter month abbreviations, etc.
+#' The correct values will vary based on your data source.
+#'
+#' TODO add more flexibility in input formats for \code{roots}
+#' #' @param yearlist vector of year suffixes to be applied, see Details
+#' @param roots data.frame containing at least columns \code{primary_id} and \code{month_cycle}, see Details
+#' @author Brian G. Peterson
+#' @seealso \code{\link{load.instruments}}
+#' @export
+build_series_symbols <- function(roots, yearlist=c(0,1)) {
+        symbols<-''
+        id_col<-grep('primary_id',colnames(roots)) #TODO: check length
+	date_col<-grep('month_cycle',colnames(roots)) #TODO: check length
+	for (year_code in yearlist){
+		for(i in 1:nrow(roots)) {
+			symbols <- c(symbols, paste(paste(roots[i,id_col], strsplit(as.character(roots[i,date_col]),",")[[1]],sep=''),year_code,sep=''))
+		}
+	}
+	return(symbols[-1])
+}
+
+#' build symbols for exchange guaranteed (calendar) spreads
+#'
+#' The columns needed by this version of the function are \code{primary_id},
+#'  \code{month_cycle}, and code \code{contracts_ahead}.
+#'
+#' \code{primary_id} should match the \code{primary_id}
+#' of the instrument describing the root contract.
+#'
+#' \code{month_cycle} should contain a comma delimited string describing the
+#' month sequence to use, e.g. \code{"F,G,H,J,K,M,N,Q,U,V,X,Z"} for all months
+#' using the standard futures letters, or \code{"H,M,U,Z"} for quarters, or
+#' \code{"Mar,Jun,Sep,Dec"} for quarters as three-letter month abbreviations, etc.
+#' The correct values will vary based on your data source.
+#'
+#' \code{contracts_ahead} should contain a comma-delimited string describing
+#' the cycle on which the guaranteed calendar spreads are to be consructed,
+#' e.g. '1' for one-month spreads, '1,3' for one and three month spreads,
+#' '1,6,12' for 1, 6, and 12 month spreads, etc.  
+#' For quarterly symbols, the correct \code{contracts_ahead} may be 
+#' something like '1,2,3' for quarterly, bi-annual, and annual spreads.  
+#'
+#' \code{active_months} is a numeric field indicating how many months including  
+#' the month of the \code{start_date} the contract is available to trade.  
+#' This number will be used as the upper limit for symbol generation.
+#' 
+#' If \code{type} is also specified, it should be a specific instrument type, 
+#' e.g. 'future_series','option_series','guaranteed_spread' or 'calendar_spread' 
+#'
+#' One of \code{data} or \code{file} must be populated for input data.
+#'
+#' @param data data.frame containing at least columns \code{primary_id}, \code{month_cycle}, amd \code{contracts_ahead}, see Details
+#' @param file if not NULL, will read input data from the file named by this argument, in the same folrmat as \code{data}, above
+#' @param outputfile if not NULL, will write out put to this file as a CSV
+#' @param start_date date to start building from, of type \code{Date} or an ISO-8601 date string, defaults to \code{\link{Sys.Date}}
+#' @author Ilya Kipnis <Ilya.Kipnis<at>gmail.com>
+#' @seealso
+#' \code{\link{load.instruments}}
+#' \code{\link{build_series_symbols}}
+# @examples 
+# build_spread_symbols(data=data.frame(primary_id='CL',
+#                                      month_sequence="F,G,H,J,K,M,N,Q,U,V,X,Z",
+#                                      contracts_ahead="1,2,3",
+#                                      type='calendar_spread')
+#' @export
+build_spread_symbols <- function(data=NULL,file=NULL,outputfile=NULL,start_date=Sys.Date())
+{
+        if(!is.null(data)) {
+                Data<-data
+        } else if(!is.null(file)) {
+                Data<-read.csv(file,header=TRUE,stringsAsFactors=FALSE)
+        } else {
+                stop("you must either pass a data.frame as the 'data' parameter or pass the 'file' parameter")
+        }
+
+
+
+	yearCheck<-function(monthNum,yearNum){
+		if(monthNum>12){
+			yearNum=yearNum+1
+		} else if(monthNum<0){
+			yearNum=yearNum-1
+		} else {
+			yearNum=yearNum
+		}
+		return(yearNum)
+	}
+
+	makeNameCal<-function(primary_id,MonthOne,YearOne,MonthTwo,YearTwo){
+		contractName<-NULL
+		contractName<-paste(primary_id,MonthOne,YearOne,"-",MonthTwo,YearTwo,sep="")
+		return(contractName)
+	}
+
+	makeCalRows<-function(dataRow){
+		calFrame<-NULL
+		calContracts<-as.numeric(unlist(strsplit(dataRow$contracts_ahead[1],",",fixed=TRUE)))
+		contractIndex<-c(1:length(monthsTraded))
+		contractTable<-cbind(monthsTraded,contractIndex)
+		for(k in 1:length(calContracts)){
+            if(length(monthsTraded)==12 & calContracts[k]>1){
+                yearsAhead = trunc((calContracts[k]-1)/length(monthsTraded))%%10
+                monthContractsAhead=(calContracts[k]-1)%%length(monthsTraded)
+            } else {
+                yearsAhead=trunc(calContracts[k]/length(monthsTraded))%%10
+                monthContractsAhead=calContracts[k]%%length(monthsTraded)
+            }
+			workingContractNum<-as.numeric(contractTable[which(contractTable[,1]==workingContractMonthLet),2])
+			monthIndex=workingContractNum+monthContractsAhead
+			if(monthIndex>length(monthsTraded)){
+				yearsAhead<-(yearsAhead+1)%%10
+				monthIndex=monthIndex-length(monthsTraded)
+			}
+                        newCalMonthLetter<-contractTable[monthIndex,1]
+                        newCalYearNumber<-workingContractYearNum+yearsAhead%%10
+                        contractName<-makeNameCal(Data$primary_id[i],workingContractMonthLet,workingContractYearNum,newCalMonthLetter,newCalYearNumber)
+                        calRow<-cbind(contractName,dataRow$type[1])
+                        #Other data would be added here.  Take in a row from root contracts, add other details (EG timezone, currency, etc...)
+                        calFrame<-rbind(calFrame,calRow)
+                }
+                return(calFrame)
+        }
+
+	PPFNames<-c("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
+	PPFNums<-c(-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24)
+        PPFLets<-c("F","G","H","J","K","M","N","Q","U","V","X","Z","F","G","H","J","K","M","N","Q","U","V","X","Z","F","G","H","J","K","M","N","Q","U","V","X","Z")
+        PPFFrame<-as.data.frame(cbind(PPFNames,PPFNums,PPFLets),stringsAsFactors=FALSE)  #PPF=Past, Present, Future
+
+        contractFrame<-NULL
+        today<-start_date
+        for(i in 1:nrow(Data)){
+		currentMonthNum<-as.numeric(substr(today,6,7))
+		monthsTraded<-unlist(strsplit(Data$month_cycle[i],",",fixed=TRUE))
+		monthNumsTraded<-as.numeric(PPFFrame[which(PPFFrame[,3] %in% monthsTraded),2])
+		currentContractMonthNum<-as.numeric(monthNumsTraded[(min(which(monthNumsTraded>=currentMonthNum)))])
+		currentContractMonthLet<-PPFFrame[currentContractMonthNum,3]
+		currentYearNum<-as.numeric(substr(today,4,4))
+		currentContractYearNum<-yearCheck(currentContractMonthNum,currentYearNum)
+
+		workingContractMonthNum<-currentContractMonthNum
+		workingContractMonthLet<-currentContractMonthLet
+		workingContractYearNum<-currentContractYearNum
+
+		contractIndex<-c(1:length(monthsTraded))
+		contractTable<-cbind(monthsTraded,contractIndex)
+
+		if(Data$type[i]=="calendar_spread" || Data$type[i]=='guaranteed_spread'){
+			calFrame<-makeCalRows(Data[i,])
+			contractFrame<-rbind(contractFrame,calFrame)
+		} else {
+			#make name for non-calendar
+			#add other details to the row
+			#rbind it to the contractFrame
+		}
+
+        for(j in 1:(Data$active_months[i]-1)){
+            yearsAhead=trunc(j/length(monthsTraded))%%10 #aka if it's 10+ years ahead, since the year is one digit, for contracts further out than 10 years, you'll get 0, 1, 2, 3 instead of 10, 11, 12, etc.
+            monthContractsAhead=j%%length(monthsTraded)
+            currentContractNum<-as.numeric(contractTable[which(contractTable[,1]==currentContractMonthLet),2])
+            monthIndex=currentContractNum+monthContractsAhead
+            if(monthIndex>length(monthsTraded)){
+				yearsAhead<-(yearsAhead+1)%%10
+				monthIndex=monthIndex-length(monthsTraded)
+			}
+			workingContractMonthLet<-contractTable[monthIndex,1]
+			workingContractYearNum<-currentContractYearNum+yearsAhead
+			if(Data$type[i]=="calendar_spread" || Data$type[i]=='guaranteed_spread'){
+				calFrame<-makeCalRows(Data[i,])
+				contractFrame<-rbind(contractFrame,calFrame)
+			} else {
+				#make name for non-calendar
+				#add other details to the row
+				#rbind it to the contractFrame
+			}
+		}
+    }
+
+    rownames(contractFrame)<-NULL
+    colnames(contractFrame)<-c("symbol","type")
+
+    if(!is.null(outputfile)){
+            write.csv(contractFrame,outputfile) 
+    } else {
+            return(contractFrame)
+    }
+}
+
+###############################################################################
+# R (http://r-project.org/) Instrument Class Model
+#
+# Copyright (c) 2009-2012
+# Peter Carl, Dirk Eddelbuettel, Jeffrey Ryan, 
+# Joshua Ulrich, Brian G. Peterson, and Garrett See
+#
+# This code is distributed under the terms of the GNU Public License (GPL)
+# for full details see the file COPYING
+#
+# $Id$
+#
+###############################################################################
+

Modified: pkg/FinancialInstrument/R/load.instruments.R
===================================================================
--- pkg/FinancialInstrument/R/load.instruments.R	2014-10-07 15:51:21 UTC (rev 1637)
+++ pkg/FinancialInstrument/R/load.instruments.R	2014-10-08 03:43:16 UTC (rev 1638)
@@ -245,10 +245,7 @@
 #' value for an argument, that value will be used.  If the user did not provide
 #' a value for an argument, but there is a value for that argument for the 
 #' given \code{Symbol} in the Symbol Lookup Table (see 
-#' \code{\link{setSymbolLookup.FI}}), that value will be used.  Otherwise,
-#' if \code{\link[Defaults]{setDefaults}} has been applied to this function 
-#' (\code{getSymbols.FI}) for the argument, the value that was set with 
-#' \code{setDefaults} will be used.  Finally, if none of the above are true,
+#' \code{\link{setSymbolLookup.FI}}), that value will be used.  Otherwise, 
 #' the formal defaults will be used.
 #'
 #' @param Symbols a character vector specifying the names of each symbol to be 
@@ -344,7 +341,7 @@
         .days_to_omit <- days_to_omit
     if (hasArg.indexTZ <- hasArg(indexTZ)) .indexTZ <- indexTZ
 
-    importDefaults("getSymbols.FI")
+    #importDefaults("getSymbols.FI")
 
     # Now get the values for each formal that we'll use if not provided
     # by the user and not found in the SymbolLookup table
@@ -455,7 +452,7 @@
                         }
                     } # end 'common'/default method (same as getSymbols.rda)    
                 ) # end split_method switch
-            fr <- quantmod:::convert.time.series(fr=fr,return.class=return.class)
+            fr <- convert.time.series(fr=fr,return.class=return.class)
             Symbols[[i]] <-make.names(Symbols[[i]]) 
             tmp <- list()
             tmp[[Symbols[[i]]]] <- fr

Modified: pkg/FinancialInstrument/R/redenominate.R
===================================================================
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/blotter -r 1638


More information about the Blotter-commits mailing list