[Blotter-commits] r666 - in pkg/FinancialInstrument: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Jul 10 17:19:54 CEST 2011
Author: gsee
Date: 2011-07-10 17:19:54 +0200 (Sun, 10 Jul 2011)
New Revision: 666
Modified:
pkg/FinancialInstrument/R/instrument.R
pkg/FinancialInstrument/R/synthetic.R
pkg/FinancialInstrument/man/future_series.Rd
pkg/FinancialInstrument/man/instrument.Rd
Log:
roxygen updates
Modified: pkg/FinancialInstrument/R/instrument.R
===================================================================
--- pkg/FinancialInstrument/R/instrument.R 2011-07-10 00:13:03 UTC (rev 665)
+++ pkg/FinancialInstrument/R/instrument.R 2011-07-10 15:19:54 UTC (rev 666)
@@ -2,7 +2,8 @@
# R (http://r-project.org/) Instrument Class Model
#
# Copyright (c) 2009-2011
-# Peter Carl, Dirk Eddelbuettel, Jeffrey Ryan, Joshua Ulrich and Brian G. Peterson
+# Peter Carl, Dirk Eddelbuettel, Jeffrey Ryan,
+# Joshua Ulrich, Brian G. Peterson, and Garrett See
#
# This library is distributed under the terms of the GNU Public License (GPL)
# for full details see the file COPYING
@@ -54,13 +55,12 @@
#' before assignment.
#'
#' @param primary_id string describing the unique ID for the instrument
-#' @param ... any other passthru parameters
+#' @param ... any other passthru parameters, including underlying_id for derivatives -- the identifier of the instrument that this one is derived from, may be NULL for cash settled instruments
#' @param currency string describing the currency ID of an object of type \code{\link{currency}}
#' @param multiplier numeric multiplier to apply to the price in the instrument currency to get to notional value
#' @param tick_size the tick increment of the instrument price in it's trading venue, as numeric quantity (e.g. 1/8 is .125)
#' @param identifiers named list of any other identifiers that should also be stored for this instrument
#' @param type instrument type to be appended to the class definition, typically not set by user
-#' @param underlying_id for derivatives, the identifier of the instrument that this one is derived from, may be NULL for cash settled instruments
#' @param assign_i TRUE/FALSE if TRUE, assign the instrument to the .instrument environment, default FALSE
#' @aliases
#' stock
@@ -74,6 +74,7 @@
#' \code{\link{exchange_rate}}
#' \code{\link{option_series}}
#' \code{\link{future_series}}
+#' \code{\link{spread}}
#' \code{\link{load.instruments}}
#' @export
instrument<-function(primary_id , ..., currency , multiplier , tick_size=NULL, identifiers = NULL, type=NULL, assign_i=FALSE ){
@@ -165,12 +166,18 @@
#' @param first_traded string coercible to Date for first trading day
#' @param expires string coercible to Date for expiration date
#' @param maturity string coercible to Date for maturity date of bond series
+#' @param callput right of option; call or put
+#' @param payment_schedule not currently being implemented
#' @param identifiers named list of any other identifiers that should also be stored for this instrument
#' @param ... any other passthru parameters
#' @aliases
#' option_series
#' future_series
#' bond_series
+#' @usage
+#' future_series(primary_id , suffix_id, first_traded=NULL, expires=NULL, identifiers = NULL, ...)
+#' option_series(primary_id , suffix_id, first_traded=NULL, expires=NULL, callput=c("call","put"), identifiers = NULL, ...)
+#' bond_series(primary_id , suffix_id, ..., first_traded=NULL, maturity=NULL, identifiers = NULL, payment_schedule=NULL)
#' @export
future_series <- function(primary_id , suffix_id, first_traded=NULL, expires=NULL, identifiers = NULL, ...){
contract<-try(getInstrument(primary_id))
@@ -252,6 +259,33 @@
}
}
+#' constructor for series of options using yahoo data
+#'
+#' Defines a chain or several chains of options by looking up necessary info from yahoo
+#' If \code{Exp} is missing it will define only the nearby options.
+#' If \code{Exp} is NULL it will define all options
+#'
+#' If \code{first_traded} and/or \code{tick_size} should not be the same for all options being defined, they should be left NULL and defined outside of this function.
+#' @param symbol ticker symbol of the underlying instrument (Currently, should only be stock tickers)
+#' @param Exp Expiration date or dates to be passed to getOptionChain
+#' @param currency currency of underlying and options
+#' @param multiplier contract multiplier. Usually 100 for stock options
+#' @param first_traded first date that contracts are tradeable. Probably not applicable if defining several chains.
+#' @param tick_size minimum price change of options.
+#' @return Called for side-effect. The instrument that is created and stored will inherit option_series, option, and instrument classes.
+#' @references Yahoo \url{http://finance.yahoo.com}
+#' @author Garrett See
+#' @note Has only been tested with stock options.
+#' The options' currency should be the same as the underlying's.
+#' @seealso \code{\link{option_series}}, \code{\link{instrument}}, quantmod:::getOptionChain
+#' @examples
+#'
+#' \dontrun{
+#' option_series.yahoo('SPY') #only nearby calls and puts
+#' option_series.yahoo('DIA', Exp=NULL) #all chains
+#' ls(.instrument, all.names=TRUE)
+#' }
+#' @export
option_series.yahoo <- function(symbol, Exp, currency="USD", multiplier=100, first_traded=NULL, tick_size=NULL) {
#FIXME: identifiers?
Modified: pkg/FinancialInstrument/R/synthetic.R
===================================================================
--- pkg/FinancialInstrument/R/synthetic.R 2011-07-10 00:13:03 UTC (rev 665)
+++ pkg/FinancialInstrument/R/synthetic.R 2011-07-10 15:19:54 UTC (rev 666)
@@ -19,6 +19,7 @@
#' constructors for synthetic instruments
#'
+#' THIS FUNCTION HAS BEEN DEPRECATED. Use synthetic.instrument instead.
#' Simple derivatives like \code{\link{option}} or \code{\link{future}} contracts typically have one underlying instrument.
#' While properties like strike and expiration vary for these derivative contracts or series, the underlying is well understood.
#'
@@ -39,14 +40,7 @@
#' @param members character vector of instrument identifiers that make up the synthetic
#' @param memberratio numeric vector of ratio relationships between members, e.g. c(4,3) for a 4:3 spread
#' @param tick_size the tick increment of the instrument price in it's trading venue, as numeric quantity (e.g. 1/8 is .125)
-#' @aliases
-#' synthetic
-#' spread
-#' synthetic.ratio
-#' guaranteed_spread
-#' calendar_spread
-#' synthetic.instrument
-#' butterfly
+#' @note DEPRECATED
#' @export
synthetic.ratio <- function(primary_id , currency , members, memberratio, ..., multiplier=1, identifiers = NULL, type=c("synthetic.ratio","synthetic","instrument"))
{
@@ -84,6 +78,48 @@
synthetic(primary_id=primary_id , currency=currency , multiplier=multiplier , identifiers = identifiers, members=memberlist , memberratio=memberratio, ...=... ,type=type, tick_size=tick_size)
}
+#' synthetic instrument constructors
+#'
+#' define spreads, guaranteed_spreads, butterflies, and other synthetic instruments
+#'
+#' Simple derivatives like \code{\link{option}} or \code{\link{future}} contracts typically have one underlying instrument.
+#' While properties like strike and expiration vary for these derivative contracts or series, the underlying is well understood.
+#'
+#' More complex derivatives are typically modeled as baskets of underlying products, and are typically traded over-the-counter or as proprietary in-house products.
+#'
+#' The general \code{synthetic} function is intended to be extended to support these arbitrary baskets of assets.
+#'
+#' \code{spread} \code{guaranteed_spread} and \code{butterfly} are wrappers for \code{synthetic.instrument}. \code{synthetic.instrument} will make a call to synthetic to create the final instrument.
+#'
+#' We welcome assistance from others to model more complex OTC derivatives such as swap products.
+#'
+#' @aliases synthetic.instrument synthetic spread guaranteed_spread butterfly
+#' @usage
+#' synthetic.instrument(primary_id, currency, members, memberratio, ..., multiplier = 1, tick_size = NULL, identifiers = NULL, type = c("synthetic.instrument", "synthetic", "instrument"))
+#' synthetic(primary_id , currency , multiplier=1, identifiers = NULL, ..., members=NULL, type=c("synthetic", "instrument"))
+#' spread(primary_id, currency = NULL, members, memberratio, tick_size=NULL,
+#' ..., multiplier = 1, identifiers = NULL)
+#'
+#' @param primary_id chr string of primary identifier of instrument to be defined.
+#' @param currency chr string name of currency denomination
+#' @param members vector of primary_ids of member instruments
+#' @param memberratio vector of weights for each leg. negative numbers for selling.
+#' @param \dots any other passthrough parameters
+#' @param mutliplier multiplier of the spread
+#' @param tick_size minimum price change of the spread
+#' @param identifiers identifiers
+#' @param type type of instrument; wrappers do not require this.
+#' @return called for side effect. stores an instrument in .instrument environment
+#' @author author Brian Peterson, Garrett See
+#' @seealso instrument, future, option_series.yahoo
+#' @examples
+#'
+#' \dontrun{
+#' stock('SPY','USD',1)
+#' stock('DIA','USD',1)
+#' spread('SPYDIA','USD',c('SPY','DIA'),c(1,-1))
+#' }
+#' @export
synthetic.instrument <- function (primary_id, currency, members, memberratio, ..., multiplier = 1, tick_size=NULL,
identifiers = NULL, type = c("synthetic.instrument", "synthetic", "instrument"))
{
@@ -124,7 +160,6 @@
}
-
#' @export
spread <- function (primary_id, currency = NULL, members, memberratio, tick_size=NULL,
..., multiplier = 1, identifiers = NULL)
@@ -136,10 +171,10 @@
}
-#TODO: butterfly can refer to expirations (futures) or strikes (options)
#' @export
butterfly <- function(primary_id, currency=NULL, members,tick_size=NULL, identifiers=NULL, ...)
{
+##TODO: butterfly can refer to expirations (futures) or strikes (options)
##TODO: A butterfly could either have 3 members that are outrights, or 2 members that are spreads
if (length(members) == 3) {
synthetic.instrument(primary_id=primary_id,currency=currency,members=members,
Modified: pkg/FinancialInstrument/man/future_series.Rd
===================================================================
--- pkg/FinancialInstrument/man/future_series.Rd 2011-07-10 00:13:03 UTC (rev 665)
+++ pkg/FinancialInstrument/man/future_series.Rd 2011-07-10 15:19:54 UTC (rev 666)
@@ -1,7 +1,8 @@
\name{future_series}
\title{constructors for series contracts on instruments such as options and futures...}
-\usage{future_series(primary_id, suffix_id, first_traded, expires,
- identifiers, ...)}
+\usage{future_series(primary_id , suffix_id, first_traded=NULL, expires=NULL, identifiers = NULL, ...)
+option_series(primary_id , suffix_id, first_traded=NULL, expires=NULL, callput=c("call","put"), identifiers = NULL, ...)
+bond_series(primary_id , suffix_id, ..., first_traded=NULL, maturity=NULL, identifiers = NULL, payment_schedule=NULL)}
\description{constructors for series contracts on instruments such as options and futures}
\details{In custom parameters for these series contracts, we have often found it
useful to store attributes such as local roll-on and roll-off dates
@@ -14,5 +15,7 @@
\item{first_traded}{string coercible to Date for first trading day}
\item{expires}{string coercible to Date for expiration date}
\item{maturity}{string coercible to Date for maturity date of bond series}
+\item{callput}{right of option; call or put}
+\item{payment_schedule}{not currently being implemented}
\item{identifiers}{named list of any other identifiers that should also be stored for this instrument}
\item{...}{any other passthru parameters}}
Modified: pkg/FinancialInstrument/man/instrument.Rd
===================================================================
--- pkg/FinancialInstrument/man/instrument.Rd 2011-07-10 00:13:03 UTC (rev 665)
+++ pkg/FinancialInstrument/man/instrument.Rd 2011-07-10 15:19:54 UTC (rev 666)
@@ -40,13 +40,13 @@
\seealso{\code{\link{exchange_rate}}
\code{\link{option_series}}
\code{\link{future_series}}
+\code{\link{spread}}
\code{\link{load.instruments}}}
\arguments{\item{primary_id}{string describing the unique ID for the instrument}
-\item{...}{any other passthru parameters}
+\item{...}{any other passthru parameters, including underlying_id for derivatives -- the identifier of the instrument that this one is derived from, may be NULL for cash settled instruments}
\item{currency}{string describing the currency ID of an object of type \code{\link{currency}}}
\item{multiplier}{numeric multiplier to apply to the price in the instrument currency to get to notional value}
\item{tick_size}{the tick increment of the instrument price in it's trading venue, as numeric quantity (e.g. 1/8 is .125)}
\item{identifiers}{named list of any other identifiers that should also be stored for this instrument}
\item{type}{instrument type to be appended to the class definition, typically not set by user}
-\item{underlying_id}{for derivatives, the identifier of the instrument that this one is derived from, may be NULL for cash settled instruments}
\item{assign_i}{TRUE/FALSE if TRUE, assign the instrument to the .instrument environment, default FALSE}}
More information about the Blotter-commits
mailing list