From noreply at r-forge.r-project.org Tue Oct 7 17:45:59 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 7 Oct 2014 17:45:59 +0200 (CEST) Subject: [Blotter-commits] r1635 - pkg/blotter/R Message-ID: <20141007154559.3D4B61874BC@r-forge.r-project.org> Author: braverock Date: 2014-10-07 17:45:59 +0200 (Tue, 07 Oct 2014) New Revision: 1635 Modified: pkg/blotter/R/tradeStats.R Log: - check for div by zero error, patch suggested by Daniel Cegielka Modified: pkg/blotter/R/tradeStats.R =================================================================== --- pkg/blotter/R/tradeStats.R 2014-09-19 19:14:12 UTC (rev 1634) +++ pkg/blotter/R/tradeStats.R 2014-10-07 15:45:59 UTC (rev 1635) @@ -147,7 +147,7 @@ GrossProfits <- sum(PL.gt0) GrossLosses <- sum(PL.lt0) - ProfitFactor <- abs(GrossProfits/GrossLosses) + ProfitFactor <- ifelse(GrossLosses == 0, NA, abs(GrossProfits/GrossLosses)) AvgTradePL <- mean(PL.ne0) MedTradePL <- median(PL.ne0) From noreply at r-forge.r-project.org Tue Oct 7 17:47:10 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 7 Oct 2014 17:47:10 +0200 (CEST) Subject: [Blotter-commits] r1636 - pkg/blotter Message-ID: <20141007154710.481FE186978@r-forge.r-project.org> Author: braverock Date: 2014-10-07 17:47:09 +0200 (Tue, 07 Oct 2014) New Revision: 1636 Modified: pkg/blotter/DESCRIPTION Log: - change version mechanism to major.minor.svnrev to match PerfA and quantstrat Modified: pkg/blotter/DESCRIPTION =================================================================== --- pkg/blotter/DESCRIPTION 2014-10-07 15:45:59 UTC (rev 1635) +++ pkg/blotter/DESCRIPTION 2014-10-07 15:47:09 UTC (rev 1636) @@ -2,7 +2,7 @@ Type: Package Title: Tools for transaction-oriented trading systems development. -Version: 0.8.19 +Version: 0.9.1636 Date: $Date$ Author: Peter Carl, Brian G. Peterson Maintainer: Brian G. Peterson From noreply at r-forge.r-project.org Tue Oct 7 17:51:22 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 7 Oct 2014 17:51:22 +0200 (CEST) Subject: [Blotter-commits] r1637 - in pkg/blotter: . R Message-ID: <20141007155122.2A0B21874D2@r-forge.r-project.org> Author: braverock Date: 2014-10-07 17:51:21 +0200 (Tue, 07 Oct 2014) New Revision: 1637 Modified: pkg/blotter/DESCRIPTION pkg/blotter/R/tradeStats.R Log: - divide by zero checks for implausibly perfect systems suggested by Daniel Cegielka Modified: pkg/blotter/DESCRIPTION =================================================================== --- pkg/blotter/DESCRIPTION 2014-10-07 15:47:09 UTC (rev 1636) +++ pkg/blotter/DESCRIPTION 2014-10-07 15:51:21 UTC (rev 1637) @@ -2,7 +2,7 @@ Type: Package Title: Tools for transaction-oriented trading systems development. -Version: 0.9.1636 +Version: 0.9.1637 Date: $Date$ Author: Peter Carl, Brian G. Peterson Maintainer: Brian G. Peterson @@ -23,7 +23,7 @@ Suggests: Hmisc, RUnit, -Contributors: Dirk Eddelbuettel, Jan Humme, Lance Levenson, +Contributors: Daniel Cegielka, Dirk Eddelbuettel, Jan Humme, Lance Levenson, Ben McCann, Jeff Ryan, Garrett See, Joshua Ulrich, Wolfgang Wu URL: https://r-forge.r-project.org/projects/blotter/ Copyright: (c) 2008-2014 Modified: pkg/blotter/R/tradeStats.R =================================================================== --- pkg/blotter/R/tradeStats.R 2014-10-07 15:47:09 UTC (rev 1636) +++ pkg/blotter/R/tradeStats.R 2014-10-07 15:51:21 UTC (rev 1637) @@ -152,7 +152,7 @@ AvgTradePL <- mean(PL.ne0) MedTradePL <- median(PL.ne0) StdTradePL <- sd(as.numeric(as.vector(PL.ne0))) - AnnSharpe <- AvgDailyPL/StdDailyPL * sqrt(252) + AnnSharpe <- ifelse(StdDailyPL == 0, NA, AvgDailyPL/StdDailyPL * sqrt(252)) NumberOfTxns <- nrow(txn)-1 NumberOfTrades <- length(PL.ne0) @@ -168,8 +168,8 @@ AvgLossTrade <- mean(PL.lt0) MedLossTrade <- median(PL.lt0) - AvgWinLoss <- AvgWinTrade/-AvgLossTrade - MedWinLoss <- MedWinTrade/-MedLossTrade + AvgWinLoss <- ifelse(AvgLossTrade == 0, NA, AvgWinTrade/-AvgLossTrade) + MedWinLoss <- ifelse(MedLossTrade == 0, NA, MedWinTrade/-MedLossTrade) Equity <- cumsum(posPL$Net.Trading.PL) if(!nrow(Equity)){ @@ -194,7 +194,7 @@ #TODO we should back out position value if we've got an open position and double check here.... MaxDrawdown <- -max(Equity.max - Equity) - ProfitToMaxDraw <- -TotalNetProfit / MaxDrawdown + ProfitToMaxDraw <- ifelse(MaxDrawdown == 0, NA, -TotalNetProfit / MaxDrawdown) names(ProfitToMaxDraw) <- 'Profit.To.Max.Draw' #TODO add skewness, kurtosis, and positive/negative semideviation if PerfA is available. From noreply at r-forge.r-project.org Wed Oct 8 05:43:17 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 8 Oct 2014 05:43:17 +0200 (CEST) Subject: [Blotter-commits] r1638 - in pkg/FinancialInstrument: . R inst/parser man Message-ID: <20141008034317.4889A1874EE@r-forge.r-project.org> 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 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 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 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 From noreply at r-forge.r-project.org Wed Oct 8 15:38:23 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 8 Oct 2014 15:38:23 +0200 (CEST) Subject: [Blotter-commits] r1639 - pkg/FinancialInstrument Message-ID: <20141008133823.323DD1876F3@r-forge.r-project.org> Author: gsee Date: 2014-10-08 15:38:22 +0200 (Wed, 08 Oct 2014) New Revision: 1639 Modified: pkg/FinancialInstrument/DESCRIPTION Log: move zoo and xts from Imports to Depends. Require higher version of quantmod. Modified: pkg/FinancialInstrument/DESCRIPTION =================================================================== --- pkg/FinancialInstrument/DESCRIPTION 2014-10-08 03:43:16 UTC (rev 1638) +++ pkg/FinancialInstrument/DESCRIPTION 2014-10-08 13:38:22 UTC (rev 1639) @@ -13,10 +13,10 @@ Date: 2014-10-07 Depends: R (>= 2.12.0), - quantmod(>= 0.3-17), + quantmod (>= 0.4-2), + zoo (>= 1.7-5), + xts Imports: - zoo(>= 1.7-5), - xts, TTR Suggests: foreach, From noreply at r-forge.r-project.org Sat Oct 11 23:54:36 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 11 Oct 2014 23:54:36 +0200 (CEST) Subject: [Blotter-commits] r1640 - in pkg/FinancialInstrument: . R man Message-ID: <20141011215436.589211879BB@r-forge.r-project.org> Author: gsee Date: 2014-10-11 23:54:35 +0200 (Sat, 11 Oct 2014) New Revision: 1640 Modified: pkg/FinancialInstrument/NEWS pkg/FinancialInstrument/R/load.instruments.R pkg/FinancialInstrument/man/getSymbols.FI.Rd Log: allow for options() to be set, which getSymbols.FI() will check. See NEWS. Modified: pkg/FinancialInstrument/NEWS =================================================================== --- pkg/FinancialInstrument/NEWS 2014-10-08 13:38:22 UTC (rev 1639) +++ pkg/FinancialInstrument/NEWS 2014-10-11 21:54:35 UTC (rev 1640) @@ -7,6 +7,13 @@ * No longer using Defaults package (which is now archived on CRAN) in getSymbols.FI. +* getSymbols.FI() allows the user to set default values by checking for + options(). For example, the default value for from= is now + getOption("getSymbols.FI.from", "2010-01-01"). So, if you do not set the + "getSymbols.FI.from" option, the value will be what it always has been + ("2010-01-01"), but if you did set a value (e.g. + options(getSymbols.FI.from="2014-01-01")), then that value will be used. + * remove some `:::` calls to unexported functions from quantmod. * saveInstruments() gains a "compress" argument to allow for different Modified: pkg/FinancialInstrument/R/load.instruments.R =================================================================== --- pkg/FinancialInstrument/R/load.instruments.R 2014-10-08 13:38:22 UTC (rev 1639) +++ pkg/FinancialInstrument/R/load.instruments.R 2014-10-11 21:54:35 UTC (rev 1640) @@ -287,19 +287,23 @@ #' } #' @export getSymbols.FI <- function(Symbols, - from='2010-01-01', - to=Sys.Date(), + from=getOption("getSymbols.FI.from", "2010-01-01"), + to=getOption("getSymbols.FI.to", Sys.Date()), ..., - dir="", - return.class="xts", - extension="rda", - split_method = c("days", "common"), - use_identifier = NA, - date_format=NULL, - verbose=TRUE, - days_to_omit=c("Saturday", "Sunday"), - indexTZ=NA - ) + dir=getOption("getSymbols.FI.dir", ""), + return.class=getOption("getSymbols.FI.return.class", + "xts"), + extension=getOption("getSymbols.FI.extension", "rda"), + split_method=getOption("getSymbols.FI.split_method", + c("days", "common")), + use_identifier=getOption("getSymbols.FI.use_identifier", + NA), + date_format=getOption("getSymbols.FI.date_format"), + verbose=getOption("getSymbols.FI.verbose", TRUE), + days_to_omit=getOption("getSymbols.FI.days_to_omit", + c("Saturday", "Sunday")), + indexTZ=getOption("getSymbols.FI.indexTZ", NA) + ) { if (is.null(date_format)) date_format <- "%Y.%m.%d" if (is.null(days_to_omit)) days_to_omit <- 'NULL' Modified: pkg/FinancialInstrument/man/getSymbols.FI.Rd =================================================================== --- pkg/FinancialInstrument/man/getSymbols.FI.Rd 2014-10-08 13:38:22 UTC (rev 1639) +++ pkg/FinancialInstrument/man/getSymbols.FI.Rd 2014-10-11 21:54:35 UTC (rev 1640) @@ -3,11 +3,17 @@ \alias{getSymbols.FI} \title{getSymbols method for loading data from split files} \usage{ -getSymbols.FI(Symbols, from = "2010-01-01", to = Sys.Date(), ..., - dir = "", return.class = "xts", extension = "rda", - split_method = c("days", "common"), use_identifier = NA, - date_format = NULL, verbose = TRUE, days_to_omit = c("Saturday", - "Sunday"), indexTZ = NA) +getSymbols.FI(Symbols, from = getOption("getSymbols.FI.from", "2010-01-01"), + to = getOption("getSymbols.FI.to", Sys.Date()), ..., + dir = getOption("getSymbols.FI.dir", ""), + return.class = getOption("getSymbols.FI.return.class", "xts"), + extension = getOption("getSymbols.FI.extension", "rda"), + split_method = getOption("getSymbols.FI.split_method", c("days", "common")), + use_identifier = getOption("getSymbols.FI.use_identifier", NA), + date_format = getOption("getSymbols.FI.date_format"), + verbose = getOption("getSymbols.FI.verbose", TRUE), + days_to_omit = getOption("getSymbols.FI.days_to_omit", c("Saturday", + "Sunday")), indexTZ = getOption("getSymbols.FI.indexTZ", NA)) } \arguments{ \item{Symbols}{a character vector specifying the names of each symbol to be From noreply at r-forge.r-project.org Tue Oct 21 04:57:12 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 21 Oct 2014 04:57:12 +0200 (CEST) Subject: [Blotter-commits] r1641 - pkg/blotter/R Message-ID: <20141021025712.AAA5C187750@r-forge.r-project.org> Author: bodanker Date: 2014-10-21 04:57:11 +0200 (Tue, 21 Oct 2014) New Revision: 1641 Modified: pkg/blotter/R/AcctReturns.R pkg/blotter/R/PortfReturns.R pkg/blotter/R/extractTests.R pkg/blotter/R/getEndEq.R pkg/blotter/R/getPortfAcct.R pkg/blotter/R/getPortfolio.R pkg/blotter/R/getTxn.R pkg/blotter/R/initAcct.R pkg/blotter/R/initPortf.R pkg/blotter/R/updateEndEq.R Log: - Standardize spacing in account/portfolio messages for name "already exists"/"not found" errors Modified: pkg/blotter/R/AcctReturns.R =================================================================== --- pkg/blotter/R/AcctReturns.R 2014-10-11 21:54:35 UTC (rev 1640) +++ pkg/blotter/R/AcctReturns.R 2014-10-21 02:57:11 UTC (rev 1641) @@ -65,8 +65,7 @@ Account <- try(get(aname, envir = .blotter)) } if(inherits(Account, "try-error")){ - stop(paste("Account ", aname, " not found, use initAcct() to create a new - account")) + stop("Account ", aname, " not found, use initAcct() to create a new account") } if(!inherits(Account, "account")){ stop("Account ", aname, " passed is not the name of an account object.") Modified: pkg/blotter/R/PortfReturns.R =================================================================== --- pkg/blotter/R/PortfReturns.R 2014-10-11 21:54:35 UTC (rev 1640) +++ pkg/blotter/R/PortfReturns.R 2014-10-21 02:57:11 UTC (rev 1641) @@ -29,8 +29,9 @@ else Account<-try(get(aname,envir=.blotter), silent=TRUE) if(inherits(Account,"try-error")) - stop(paste("Account ",aname," not found, use initAcct() to create a new account")) - if(!inherits(Account,"account")) stop("Account ",aname," passed is not the name of an account object.") + stop("Account ", aname, " not found, use initAcct() to create a new account") + if(!inherits(Account,"account")) + stop("Account ", aname, " passed is not the name of an account object.") if(is.null(Portfolios)) Portfolios = names(Account$portfolios) Modified: pkg/blotter/R/extractTests.R =================================================================== --- pkg/blotter/R/extractTests.R 2014-10-11 21:54:35 UTC (rev 1640) +++ pkg/blotter/R/extractTests.R 2014-10-21 02:57:11 UTC (rev 1641) @@ -23,7 +23,7 @@ pname <- Portfolio Portfolio<-get(paste("portfolio",pname,sep='.'),envir=.blotter) if(inherits(Portfolio,"try-error")) - stop(paste("Portfolio",pname," not found, use initPortf() to create a new portfolio first")) + stop("Portfolio ", pname, " not found, use initPortf() to create a new portfolio first") out<-NULL symbolnames<-ls(Portfolio[['symbols']]) for (Symbol in symbolnames) { Modified: pkg/blotter/R/getEndEq.R =================================================================== --- pkg/blotter/R/getEndEq.R 2014-10-11 21:54:35 UTC (rev 1640) +++ pkg/blotter/R/getEndEq.R 2014-10-21 02:57:11 UTC (rev 1641) @@ -8,7 +8,7 @@ aname<-Account Account<-try(get(paste("account",aname,sep='.'), envir=.blotter), silent=TRUE) if(inherits(Account,"try-error")) - stop(paste("Account",aname," not found, use initAcct() to create a new account")) + stop("Account ", aname, " not found, use initAcct() to create a new account") toDate = paste('::', Date, sep="") EndEq = as.numeric(tail(Account$summary[toDate,], n=1)[,"End.Eq"]) Modified: pkg/blotter/R/getPortfAcct.R =================================================================== --- pkg/blotter/R/getPortfAcct.R 2014-10-11 21:54:35 UTC (rev 1640) +++ pkg/blotter/R/getPortfAcct.R 2014-10-21 02:57:11 UTC (rev 1641) @@ -7,11 +7,11 @@ { # @author Brian Peterson acct<-suppressWarnings(try(get(paste("account",Account,sep='.'),envir=.blotter),silent=TRUE)) if(inherits(acct,"try-error")) - stop(paste("Account",Account,"not found, use initAcct() to create a new account.")) + stop("Account ", Account, " not found, use initAcct() to create a new account.") pname=Portfolio Portfolio<-suppressWarnings(try(acct[[paste("portfolio",pname,sep='.')]],silent=TRUE)) if(inherits(Portfolio,"try-error")) - stop(paste("Portfolio",pname,"not found, use initPortf() to create a new portfolio or initAcct() to place it in",Account)) + stop("Portfolio ", pname, " not found, use initPortf() to create a new portfolio or initAcct() to place it in ",Account) if(!is.null(Dates)){ Portfolio<-Portfolio[Dates] Modified: pkg/blotter/R/getPortfolio.R =================================================================== --- pkg/blotter/R/getPortfolio.R 2014-10-11 21:54:35 UTC (rev 1640) +++ pkg/blotter/R/getPortfolio.R 2014-10-21 02:57:11 UTC (rev 1641) @@ -48,8 +48,9 @@ if(!grepl("portfolio\\.",pname)) Portfolio<-suppressWarnings(try(get(paste("portfolio",pname,sep='.'),envir=envir),silent=TRUE)) else Portfolio<-suppressWarnings(try(get(pname,envir=envir),silent=TRUE)) if(inherits(Portfolio,"try-error")) - stop(paste("Portfolio",pname," not found, use initPortf() to create a new portfolio")) - if(!inherits(Portfolio,"portfolio")) stop("Portfolio",pname,"passed is not the name of a portfolio object.") + stop("Portfolio ", pname, " not found, use initPortf() to create a new portfolio") + if(!inherits(Portfolio,"portfolio")) + stop("Portfolio ", pname, " passed is not the name of a portfolio object.") return(Portfolio) } Modified: pkg/blotter/R/getTxn.R =================================================================== --- pkg/blotter/R/getTxn.R 2014-10-11 21:54:35 UTC (rev 1640) +++ pkg/blotter/R/getTxn.R 2014-10-21 02:57:11 UTC (rev 1641) @@ -16,7 +16,7 @@ pname<-Portfolio Portfolio<-get(paste("portfolio",pname,sep='.'), envir=.blotter) if(inherits(Portfolio,"try-error")) - stop(paste("Portfolio",pname," not found, use initPortf() to create a new portfolio first")) + stop("Portfolio ", pname, " not found, use initPortf() to create a new portfolio first") TxnData = Portfolio$symbols[[Symbol]]$txn Txns = TxnData[Dates,c('Txn.Qty', 'Txn.Price', 'Txn.Fees', 'Txn.Value', 'Txn.Avg.Cost', 'Net.Txn.Realized.PL')] Modified: pkg/blotter/R/initAcct.R =================================================================== --- pkg/blotter/R/initAcct.R 2014-10-11 21:54:35 UTC (rev 1640) +++ pkg/blotter/R/initAcct.R 2014-10-21 02:57:11 UTC (rev 1641) @@ -52,7 +52,7 @@ { # @author Peter Carl if(exists(paste("account",name,sep='.'), envir=.blotter,inherits=TRUE)) - stop(paste("Account",name,"already exists, use updateAcct() or create a new account.")) + stop("Account ", name, " already exists, use updateAcct() or create a new account.") # FUNCTION account=list() Modified: pkg/blotter/R/initPortf.R =================================================================== --- pkg/blotter/R/initPortf.R 2014-10-11 21:54:35 UTC (rev 1640) +++ pkg/blotter/R/initPortf.R 2014-10-21 02:57:11 UTC (rev 1641) @@ -61,7 +61,7 @@ initPortf <- function(name="default", symbols, initPosQty = 0, initDate = '1950-01-01', currency='USD', ...) { # @author Peter Carl if(exists(paste("portfolio",name,sep='.'), envir=.blotter,inherits=TRUE)) - stop(paste("Portfolio",name,"already exists, use updatePortf() or addPortfInstr() to update it.")) + stop("Portfolio ", name, " already exists, use updatePortf() or addPortfInstr() to update it.") # FUNCTION Modified: pkg/blotter/R/updateEndEq.R =================================================================== --- pkg/blotter/R/updateEndEq.R 2014-10-11 21:54:35 UTC (rev 1640) +++ pkg/blotter/R/updateEndEq.R 2014-10-21 02:57:11 UTC (rev 1641) @@ -15,7 +15,7 @@ aname<-Account Account<-try(get(paste("account",aname,sep='.'), envir=.blotter), silent=TRUE) if(inherits(Account,"try-error")) - stop(paste("Account",aname," not found, use initAcct() to create a new account")) + stop("Account ", aname, " not found, use initAcct() to create a new account") if(is.null(Dates)) # if no date is specified, get all available dates Dates = index(Account$summary)[-1] From noreply at r-forge.r-project.org Sun Oct 26 18:34:20 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 26 Oct 2014 18:34:20 +0100 (CET) Subject: [Blotter-commits] r1642 - pkg/blotter/sandbox Message-ID: <20141026173420.6C8AC187728@r-forge.r-project.org> Author: bodanker Date: 2014-10-26 18:34:20 +0100 (Sun, 26 Oct 2014) New Revision: 1642 Added: pkg/blotter/sandbox/blotter_R6.R Log: - add R6 blotter prototype Added: pkg/blotter/sandbox/blotter_R6.R =================================================================== --- pkg/blotter/sandbox/blotter_R6.R (rev 0) +++ pkg/blotter/sandbox/blotter_R6.R 2014-10-26 17:34:20 UTC (rev 1642) @@ -0,0 +1,295 @@ +# R6 repo: https://github.com/wch/R6 + +# Current blotter structure: +# .blotter +# $account (.blotter$account.`name`) +# $portfolios +# $`name` +# $summary +# $Additions +# $Withdrawals +# $Interest +# $portfolio (.blotter$portfolio.`name`) +# $summary +# $symbols +# $posPL +# $posPL.ccy +# $txn + +# Proposed blotter structure (comments welcome): +# > Account (R6 'Account' object) +# -> Portfolios (list|env of R6 'Portfolio' objects) +# -> Positions (list|env of R6 'Position' objects) +# -> Instrument +# -> Transaction +# - trades, splits, dividends, expirations, assignments, etc. +# -> PnL +# -> Position (R6 'Position' object) +# +# +# I'm not sure of the best way to implement the "list" of portfolios in an +# account, and the "list" of instruments in a portfolio. +# +# Should users be able to add portfolios via +# Account$`name` <- Portfolio$new() +# or should we make that a method in the Account object? +# Account$add_portfolio() +# +# If we choose either one, we need to ensure that the "name" member of the +# new Portfolio object matches the "name" of the Account$portfolios "list". + +library(R6) +library(blotter) + +# I'm not sure "Position" is the correct name for this thing, but I was trying +# to create the most basic component of the blotter structure. +Position <- R6Class(classname = "Position", + public = list( + #initialize = function(instrument, transactions) { + initialize = function(symbol, transactions, currency) { + if(!missing(symbol)) private$.symbol <- symbol + if(!missing(currency)) private$.currency <- currency + }, + # addTxn {{{ + addTxn = function(date, quantity, price, fees=0, ..., ConMult=1, verbose=TRUE) { + null.txn <- is.null(private$.txn) + #PrevPosQty <- getPos(date, 'Pos.Qty') # returns position 'as-of' date + if(null.txn) + PrevPosQty <- 0 + else { + PrevPosQty <- private$.txn[paste0("/",date), 'Pos.Qty'] + PrevPosQty <- PrevPosQty[nrow(PrevPosQty),] + } + + # split transactions that would cross through zero + if(PrevPosQty != 0 && + sign(PrevPosQty + quantity) != sign(PrevPosQty) && + PrevPosQty != -quantity) { + # calculate fees pro-rata by quantity + txnFeeQty <- fees/abs(quantity) + self$addTxn(date, -PrevPosQty, price, txnFeeQty*abs(PrevPosQty), ...) + # transactions need unique timestamps + date <- date + sqrt(.Machine$double.eps) + quantity <- quantity + PrevPosQty + PrevPosQty <- 0 + fees <- txnFeeQty * abs(quantity + PrevPosQty) + } + + # Coerce the transaction fees to a function if a string was supplied + if(is.character(fees)) { + tmp <- try(match.fun(fees), silent=TRUE) + if(!inherits(tmp, "try-error")) + fees <- tmp + } + # Compute transaction fees if a function was supplied + if(is.function(fees)) + txnfees <- fees(quantity, price) + else + txnfees <- as.numeric(fees) + + if(is.null(txnfees) || is.na(txnfees)) + txnfees <- 0 + if(txnfees > 0) + warning('Positive transaction fees should only be used in the case of broker/exchange rebates for TxnFees ',TxnFees,'. See Documentation.') + + # Calculate the value and average cost of the transaction + TxnValue <- quantity * price * ConMult # Gross of Fees + TxnAvgCost <- TxnValue / (quantity * ConMult) + + # Calculate the change in position + PosQty <- PrevPosQty + quantity + + # Calculate the resulting position's average cost + #PrevPosAvgCost <- getPos(date, 'Pos.Avg.Cost') # returns position 'as-of' date + if(null.txn) + PrevPosAvgCost <- 0 + else { + PrevPosAvgCost <- private$.txn[paste0("/",date), 'Pos.Avg.Cost'] + PrevPosAvgCost <- PrevPosAvgCost[nrow(PrevPosAvgCost),] + } + PosAvgCost <- blotter:::.calcPosAvgCost(PrevPosQty, PrevPosAvgCost, TxnValue, PosQty, ConMult) + + # Calculate any realized profit or loss (net of fees) from the transaction + GrossTxnRealizedPL <- quantity * ConMult * (PrevPosAvgCost - TxnAvgCost) + + # if the previous position is zero, RealizedPL = 0 + # if previous position is positive and position is larger, RealizedPL =0 + # if previous position is negative and position is smaller, RealizedPL =0 + if(abs(PrevPosQty) < abs(PosQty) || PrevPosQty == 0) + GrossTxnRealizedPL = 0 + + NetTxnRealizedPL <- GrossTxnRealizedPL + txnfees + + # Store the transaction and calculations + txn <- c(quantity, price, TxnValue, TxnAvgCost, PosQty, PosAvgCost, + GrossTxnRealizedPL, txnfees, NetTxnRealizedPL, ConMult) + txnCols <- c("Txn.Qty", "Txn.Price", "Txn.Value", "Txn.Avg.Cost", + "Pos.Qty", "Pos.Avg.Cost", "Gross.Txn.Realized.PL", "Txn.Fees", + "Net.Txn.Realized.PL", "Con.Mult") + private$.txn <- rbind(private$.txn, xts(t(txn), date, dimnames=list(NULL, txnCols))) + + if(verbose) + print(paste(format(date, "%Y-%m-%d %H:%M:%S"), private$.symbol, quantity, "@", price, sep=" ")) + + invisible(self) + } #}}} + ), + private = list( + .symbol = NA_character_, + .currency = NA_character_, + .txn = NULL + ), + # use active bindings for type-checking; is there a better way? + active = list( + symbol = function(value) { + if(missing(value)) { + private$.symbol + } else { + stop("symbol is read-only") + } + }, + currency = function(value) { + if(missing(value)) { + private$.currency + } else { + if(is.character(value) && length(value)==1) + private$.currency <- value + else + stop(deparse(substitute(value)), " is an invalid currency name") + } + }, + transactions = function(value) { + if(missing(value)) { + if(!is.null(private$.txn)) + private$.txn[,c("Txn.Qty", "Txn.Price", "Txn.Fees", + "Txn.Value", "Txn.Avg.Cost", "Net.Txn.Realized.PL")] + } else { + stop("use addTxn to add a transaction") + } + }, + txns = function(value) { + if(missing(value)) { + if(!is.null(private$.txn)) + private$.txn[,c("Txn.Qty", "Txn.Price", "Txn.Fees", + "Txn.Value", "Txn.Avg.Cost", "Net.Txn.Realized.PL")] + } else { + stop("use addTxn to add a transaction") + } + }, + txn = function(value) { + if(missing(value)) { + private$.txn + } else { + stop("txn is read-only") + } + } + ) +) +pos <- Position$new('foo') +pos$addTxn(Sys.Date()-1L, 10, 90, 0) +pos$addTxn(Sys.Date(), -10, 100, 0) +pos$txns + + + +if(FALSE){ + # blotter amzn demo provides an example of the basic functionality + data("amzn") + currency("USD") + stock("amzn",currency="USD",multiplier=1) + # Initialize the Portfolio + initPortf("amzn_port",symbols="amzn",initDate="2010-01-14") + initAcct("amzn_acct",portfolios="amzn_port",initDate="2010-01-14", initEq=10000) + # look at the transactions data + amzn.trades + # Add the transactions to the portfolio + blotter:::addTxns("amzn_port","amzn",TxnData=amzn.trades,verbose=TRUE) + # update the portfolio stats + updatePortf("amzn_port",Dates="2010-01-14") + # update the account P&L + updateAcct("amzn_acct",Dates="2010-01-14") + # and look at it + chart.Posn("amzn_port","amzn",Dates="2010-01-14") +} + + + +# other stuff; not sure it's useful +if(FALSE){ +Portfolio <- R6Class(classname = "Portfolio", + public = list( + initialize = function(name, positions, currency) { + if(!missing(name)) + private$.name <- name + if(!missing(positions)) { + if(is.list(positions)) + for(p in positions) + assign(p$symbol, p, private$.positions) + else + assign(positions$symbol, positions, private$.positions) + } + }, + update = function(symbols, dates, prices, interval) { } + ), + private = list( + .positions = new.env(hash=TRUE), + .name = "default" + ), + active = list( + name = function(value) { + if(missing(value)) { + private$.name + } else { + if(is.character(value) && length(value)==1) + private$.name <- value + else + stop(deparse(substitute(value)), " is an invalid portfolio name") + } + }, + positions = function(value) { + value_name <- deparse(substitute(value)) + if(missing(value)) { + #if(value_name!="") + # return a copy of the .positions environment as a list, because + # we do not want users to be able to change positions manually + # as.list(get(value_name, private$.positions, inherits=FALSE)) + as.list(private$.positions) + #else + # NULL + } else { + if(inherits(value, "Position")) { + assign(value_name, value, private$.positions) + } else { + stop(value_name, " is not a Position object", call.=FALSE) + } + } + } + ) +) +pos <- Position$new('foo') +pos$addTxn(Sys.Date()-1L, 10, 90, 0) +pos$addTxn(Sys.Date(), -10, 100, 0) +pos$txns +p <- Portfolio$new("hello_world", pos, "USD") +p$positions + +# prototype +Positions <- R6Class(classname = "Positions", + public = list( + add = function(position) { + if(missing(position)) + invisible() + if(inherits(position, "Position")) { + assign(position$symbol, position, private$.positions) + } else { + position_name <- deparse(substitute(position)) + stop(position_name, " is not a Position object", call.=FALSE) + } + } + ), + private = list( + .positions = new.env(hash=TRUE) + ) +) +} + From noreply at r-forge.r-project.org Mon Oct 27 22:06:03 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 27 Oct 2014 22:06:03 +0100 (CET) Subject: [Blotter-commits] r1643 - in pkg/blotter: . R man Message-ID: <20141027210603.8461518754A@r-forge.r-project.org> Author: braverock Date: 2014-10-27 22:06:03 +0100 (Mon, 27 Oct 2014) New Revision: 1643 Modified: pkg/blotter/DESCRIPTION pkg/blotter/NAMESPACE pkg/blotter/R/addTxn.R pkg/blotter/man/AcctReturns.Rd pkg/blotter/man/PortfReturns.Rd pkg/blotter/man/addAcctTxn.Rd pkg/blotter/man/addDiv.Rd pkg/blotter/man/addPortfInstr.Rd pkg/blotter/man/addTxn.Rd pkg/blotter/man/calcPortfWgt.Rd pkg/blotter/man/calcPosAvgCost.Rd pkg/blotter/man/calcTxnAvgCost.Rd pkg/blotter/man/calcTxnValue.Rd pkg/blotter/man/chart.ME.Rd pkg/blotter/man/chart.Posn.Rd pkg/blotter/man/chart.Reconcile.Rd pkg/blotter/man/chart.Spread.Rd pkg/blotter/man/dailyTxnPL.Rd pkg/blotter/man/extractTxns.Rd pkg/blotter/man/getAccount.Rd pkg/blotter/man/getByPortf.Rd pkg/blotter/man/getBySymbol.Rd pkg/blotter/man/getEndEq.Rd pkg/blotter/man/getPortfAcct.Rd pkg/blotter/man/getPortfolio.Rd pkg/blotter/man/getPos.Rd pkg/blotter/man/getPosAvgCost.Rd pkg/blotter/man/getPosQty.Rd pkg/blotter/man/getTxns.Rd pkg/blotter/man/initAcct.Rd pkg/blotter/man/initPortf.Rd pkg/blotter/man/initPosPL.Rd pkg/blotter/man/initSummary.Rd pkg/blotter/man/initTxn.Rd pkg/blotter/man/is.account.Rd pkg/blotter/man/is.portfolio.Rd pkg/blotter/man/pennyPerShare.Rd pkg/blotter/man/perTradeStats.Rd pkg/blotter/man/put.account.Rd pkg/blotter/man/put.portfolio.Rd pkg/blotter/man/tradeQuantiles.Rd pkg/blotter/man/tradeStats.Rd pkg/blotter/man/updateAcct.Rd pkg/blotter/man/updateEndEq.Rd pkg/blotter/man/updatePortf.Rd pkg/blotter/man/updatePosPL.Rd Log: - add allowRebates argument to addTxn, default FALSE and stop with error - update roxygen docs - bump version Modified: pkg/blotter/DESCRIPTION =================================================================== --- pkg/blotter/DESCRIPTION 2014-10-26 17:34:20 UTC (rev 1642) +++ pkg/blotter/DESCRIPTION 2014-10-27 21:06:03 UTC (rev 1643) @@ -2,7 +2,7 @@ Type: Package Title: Tools for transaction-oriented trading systems development. -Version: 0.9.1637 +Version: 0.9.1643 Date: $Date$ Author: Peter Carl, Brian G. Peterson Maintainer: Brian G. Peterson Modified: pkg/blotter/NAMESPACE =================================================================== --- pkg/blotter/NAMESPACE 2014-10-26 17:34:20 UTC (rev 1642) +++ pkg/blotter/NAMESPACE 2014-10-27 21:06:03 UTC (rev 1643) @@ -1,3 +1,5 @@ +# Generated by roxygen2 (4.0.2): do not edit by hand + export(.getPortfolio) export(AcctReturns) export(PortfReturns) Modified: pkg/blotter/R/addTxn.R =================================================================== --- pkg/blotter/R/addTxn.R 2014-10-26 17:34:20 UTC (rev 1642) +++ pkg/blotter/R/addTxn.R 2014-10-27 21:06:03 UTC (rev 1643) @@ -41,6 +41,7 @@ #' @param TxnPrice Price at which the transaction was done #' @param \dots Any other passthrough parameters #' @param TxnFees Fees associated with the transaction, e.g. commissions., See Details +#' @param allowRebates whether to allow positive (rebate) TxnFees, default FALSE #' @param ConMult Contract/instrument multiplier for the Symbol if it is not defined in an instrument specification #' @param verbose If TRUE (default) the function prints the elements of the transaction in a line to the screen, e.g., "2007-01-08 IBM 50 @@ 77.6". Suppress using FALSE. #' @param eps value to add to force unique indices @@ -54,7 +55,7 @@ #' @author Peter Carl, Brian G. Peterson #' @export addTxn #' @export addTxns -addTxn <- function(Portfolio, Symbol, TxnDate, TxnQty, TxnPrice, ..., TxnFees=0, ConMult=NULL, verbose=TRUE, eps=1e-06) +addTxn <- function(Portfolio, Symbol, TxnDate, TxnQty, TxnPrice, ..., TxnFees=0, allowRebates=FALSE, ConMult=NULL, verbose=TRUE, eps=1e-06) { pname <- Portfolio #If there is no table for the symbol then create a new one @@ -100,7 +101,7 @@ if (is.function(TxnFees)) txnfees <- TxnFees(TxnQty, TxnPrice) else txnfees<- as.numeric(TxnFees) if(is.null(txnfees) | is.na(txnfees)) txnfees = 0 - if(txnfees>0) warning('Positive Transaction Fees should only be used in the case of broker/exchange rebates for TxnFees ',TxnFees,'. See Documentation.') + if(txnfees>0 && !isTRUE(allowRebates)) stop('Positive Transaction Fees should only be used in the case of broker/exchange rebates for TxnFees ',TxnFees,'. See Documentation.') # Calculate the value and average cost of the transaction TxnValue = .calcTxnValue(TxnQty, TxnPrice, 0, ConMult) # Gross of Fees @@ -147,7 +148,7 @@ #' @rdname addTxn #' @export -addTxns<- function(Portfolio, Symbol, TxnData , verbose=FALSE, ..., ConMult=NULL, eps=1e-06) +addTxns<- function(Portfolio, Symbol, TxnData , verbose=FALSE, ..., ConMult=NULL, allowRebates=FALSE, eps=1e-06) { pname <- Portfolio #If there is no table for the symbol then create a new one @@ -184,6 +185,11 @@ } else { NewTxns$Txn.Fees <- 0 } + + if(any(NewTxns$Txn.Fees > 0) && !isTRUE(allowRebates)){ + stop('Positive Transaction Fees should only be used in the case of broker/exchange rebates. See Documentation.') + } + # split transactions that would cross through zero Pos <- drop(cumsum(NewTxns$Txn.Qty)) Pos <- merge(Qty=Pos, PrevQty=lag(Pos)) Modified: pkg/blotter/man/AcctReturns.Rd =================================================================== --- pkg/blotter/man/AcctReturns.Rd 2014-10-26 17:34:20 UTC (rev 1642) +++ pkg/blotter/man/AcctReturns.Rd 2014-10-27 21:06:03 UTC (rev 1643) @@ -1,3 +1,4 @@ +% Generated by roxygen2 (4.0.2): do not edit by hand \name{AcctReturns} \alias{AcctReturns} \title{Calculate account returns} @@ -6,64 +7,56 @@ method = c("timeweighted", "dietz"), ...) } \arguments{ - \item{Account}{string name of the account to generate - returns for} +\item{Account}{string name of the account to generate returns for} - \item{\dots}{any other passthru parameters (like - \code{native} for \code{.getBySymbol}} +\item{Dates}{xts style ISO 8601 date subset to retrieve, default NULL +(all dates)} - \item{Dates}{xts style ISO 8601 date subset to retrieve, - default NULL (all dates)} +\item{Portfolios}{concatenated string vector for portfolio names to retrieve +returns on, default NULL (all portfolios)} - \item{Portfolios}{concatenated string vector for - portfolio names to retrieve returns on, default NULL (all - portfolios)} +\item{method}{Used to select between time-weighted and linked modified Dietz +returns. May be any of: \itemize{\item timeweighted \item dietz} By default +time-weighted is selected} - \item{method}{Used to select between time-weighted and - linked modified Dietz returns. May be any of: - \itemize{\item timeweighted \item dietz} By default - time-weighted is selected} +\item{\dots}{any other passthru parameters (like \code{native} for +\code{.getBySymbol}} } \value{ returns xts with account returns } \description{ -Similar to the \code{PortfReturns} function, but gives -returns for the entire account and takes into account -external cashflows. External cashflows are defined as -contributions to or withdrawals from the account. Allows -selecting between time-weighted returns and linked modified -Dietz approach. If time-weighted method is selected, -returns at time \eqn{t} are computed using: -\deqn{r_{t}=\frac{V_{t}}{V_{t-1}+C_{t}}-1} where -\eqn{V_{t}} - account value at time \eqn{t}, \eqn{C_{t}} - -cashflow at time \eqn{t}. The implicit assumption made here -is that the cash flow is available for the portfolio -manager to invest from the beginning of the day. These -returns then can be chain linked with geometric compounding -(for instance using \code{Return.cumulative} function from -the \code{PerformanceAnalytics} package) to yield -cumulative multi-period returns: +Similar to the \code{PortfReturns} function, but gives returns for the +entire account and takes into account external cashflows. External cashflows +are defined as contributions to or withdrawals from the account. Allows +selecting between time-weighted returns and linked modified Dietz approach. +If time-weighted method is selected, returns at time \eqn{t} are computed +using: \deqn{r_{t}=\frac{V_{t}}{V_{t-1}+C_{t}}-1} +where \eqn{V_{t}} - account value at time \eqn{t}, \eqn{C_{t}} - cashflow at +time \eqn{t}. The implicit assumption made here is that the cash flow is +available for the portfolio manager to invest from the beginning of the day. +These returns then can be chain linked with geometric compounding (for +instance using \code{Return.cumulative} function from the +\code{PerformanceAnalytics} package) to yield cumulative multi-period +returns: \deqn{1+r=\prod_{t=1}^{T}(1+r_{t})=\prod_{t=1}^{T}\frac{V_{t}}{V_{t-1}+C_{t}}} -In the case if there were no cashflows, the result reduces -to simple one-period returns. Time-weighted returns has -also an interpretation in terms of unit value pricing. If -Modified Dietz method is selected, monthly returns are -computed taking into account cashflows within each month: -\deqn{r = -\frac{V_{t}-V_{t-1}-C}{V_{t-1}+\sum_{t}C_{t}\times W_{t}}} +In the case if there were no cashflows, the result reduces to simple +one-period returns. Time-weighted returns has also an interpretation in +terms of unit value pricing. +If Modified Dietz method is selected, monthly returns are computed taking +into account cashflows within each month: +\deqn{r = \frac{V_{t}-V_{t-1}-C}{V_{t-1}+\sum_{t}C_{t}\times W_{t}}} where \eqn{C} - total external cash flows within a month, \eqn{C_{t}} - external cashflow at time \eqn{t}, -\deqn{W_{t}=\frac{TD-D_{t}}{TD}} - weighting ratio to be -applied to external cashflow on day \eqn{t}, \eqn{TD} - -total number of days within the month, \eqn{D_{t}} - number -of days since the beginning of the month including weekends -and public holidays. Finally monthly Modified Dietz returns -can also be linked geometrically. +\deqn{W_{t}=\frac{TD-D_{t}}{TD}} - weighting ratio to be applied to external +cashflow on day \eqn{t}, +\eqn{TD} - total number of days within the month, +\eqn{D_{t}} - number of days since the beginning of the month including +weekends and public holidays. +Finally monthly Modified Dietz returns can also be linked geometrically. } \note{ -TODO handle portfolio and account in different currencies -(not hard, just not done) +TODO handle portfolio and account in different currencies (not hard, just not done) TODO explicitly handle portfolio weights @@ -74,10 +67,9 @@ } \references{ Christopherson, Jon A., Carino, David R., Ferson, Wayne E. -\emph{Portfolio Performance Measurement and Benchmarking}. -McGraw-Hill. 2009. Chapter 5 \cr Bacon, C. \emph{Practical -Portfolio Performance Measurement and Attribution}. Wiley. -2004. Chapter 2 \cr +\emph{Portfolio Performance Measurement and Benchmarking}. McGraw-Hill. +2009. Chapter 5 \cr Bacon, C. \emph{Practical Portfolio Performance +Measurement and Attribution}. Wiley. 2004. Chapter 2 \cr } \seealso{ PortfReturns Modified: pkg/blotter/man/PortfReturns.Rd =================================================================== --- pkg/blotter/man/PortfReturns.Rd 2014-10-26 17:34:20 UTC (rev 1642) +++ pkg/blotter/man/PortfReturns.Rd 2014-10-27 21:06:03 UTC (rev 1643) @@ -1,3 +1,4 @@ +% Generated by roxygen2 (4.0.2): do not edit by hand \name{PortfReturns} \alias{PortfReturns} \title{Calculate portfolio instrument returns} @@ -6,41 +7,32 @@ Portfolios = NULL, period = c("daily", "none")) } \arguments{ - \item{Account}{string name of the account to generate - returns for} +\item{Account}{string name of the account to generate returns for} - \item{method}{for now, only 'contribution' is supported} +\item{method}{for now, only 'contribution' is supported} - \item{\dots}{any other passthru parameters (like - \code{native} for \code{.getBySymbol}} +\item{Dates}{xts style ISO 8601 date subset to retrieve, default NULL (all dates)} - \item{Dates}{xts style ISO 8601 date subset to retrieve, - default NULL (all dates)} +\item{Portfolios}{concatenated string vector for portfolio names to retrieve returns on, default NULL (all portfolios)} - \item{Portfolios}{concatenated string vector for - portfolio names to retrieve returns on, default NULL (all - portfolios)} +\item{period}{one of daily} - \item{period}{one of daily} +\item{\dots}{any other passthru parameters (like \code{native} for \code{.getBySymbol}} } \description{ -This function (for now) calculates return on initial equity -for each instrument in the portfolio or portfolios that -make up an account. These columns will be additive to -return on capital of each portfolio, or of the entire -account. +This function (for now) calculates return on initial equity for each instrument +in the portfolio or portfolios that make up an account. These columns will be additive +to return on capital of each portfolio, or of the entire account. } \details{ -This function exists because of R/Finance community -requests by Mark Breman and Thomas Bolton +This function exists because of R/Finance community requests by Mark Breman and Thomas Bolton } \note{ -TODO handle portfolio and account in different currencies -(not hard, just not done) +TODO handle portfolio and account in different currencies (not hard, just not done) TODO explicitly handle portfolio weights -TODO provide additional methods of calculating returns +TODO provide additional methods of calculating returns TODO support additions and withdrawals to available capital } Modified: pkg/blotter/man/addAcctTxn.Rd =================================================================== --- pkg/blotter/man/addAcctTxn.Rd 2014-10-26 17:34:20 UTC (rev 1642) +++ pkg/blotter/man/addAcctTxn.Rd 2014-10-27 21:06:03 UTC (rev 1643) @@ -1,3 +1,4 @@ +% Generated by roxygen2 (4.0.2): do not edit by hand \name{addAcctTxn} \alias{addAcctTxn} \title{Add capital account transactions, such as capital additions and withdrawals or interest income (expense)} @@ -6,55 +7,30 @@ "Interest"), Amount, ..., verbose = TRUE) } \arguments{ - \item{Account}{Account name, as string} +\item{Account}{Account name, as string} - \item{TxnDate}{transaction date as ISO 8601, e.g., - '2008-09-01' or '2010-01-05 09:54:23.12345'} +\item{TxnDate}{transaction date as ISO 8601, e.g., '2008-09-01' or '2010-01-05 09:54:23.12345'} - \item{TxnType}{string indicating the type of account - transaction, only "Addition", "Withdrawal", or "Interest" - are currently supported} +\item{TxnType}{string indicating the type of account transaction, only "Addition", "Withdrawal", or "Interest" are currently supported} - \item{Amount}{As of now, the currency of the transaction - MUST MATCH the currency of the Account. Patches - welcome.} +\item{Amount}{As of now, the currency of the transaction MUST MATCH the currency of the Account. Patches welcome.} - \item{\dots}{any other passthrough parameters} +\item{verbose}{If TRUE (default) the function prints the elements of the transaction in a line to the screen, e.g., "2007-01-08 Withdrawal 15,012,235". Suppress using FALSE.} - \item{verbose}{If TRUE (default) the function prints the - elements of the transaction in a line to the screen, - e.g., "2007-01-08 Withdrawal 15,012,235". Suppress using - FALSE.} +\item{\dots}{any other passthrough parameters} } \description{ -For the specified Account, take in the date, amount, and -type of transaction and append it to the correct list in -the account object +For the specified Account, take in the date, amount, and type of transaction and append it to the correct list in the account object } \details{ -Adds capital transactions to a rudimentary transactions -table in the Account object. This may be useful when -tracking the denominator of returns when there are changes -to the account's capital or significant interest income. In -the Account$summary table, there are several placeholder -columns that mimic the CFTC's 13-column report. Columns of -interest here are "Additions", "Withdrawals", and -"Interest". Transactions added with this function will be -added into the appropriate one of three slots in the -Account object (Account$additions, Account$withdrawals, or -Account$Interest), which contains an xts object of -individual transactions with a date and amount. The -\code{\link{updateAcct}} function will read the -transactions from each list in turn, aggregate them by the -specified date scope, and slot them into the -\code{Account$summary} table as it's built. -\code{\link{updateEndEq}} should then just work. +Adds capital transactions to a rudimentary transactions table in the Account object. This may be useful when tracking the denominator of returns when there are changes to the account's capital or significant interest income. +In the Account$summary table, there are several placeholder columns that mimic the CFTC's 13-column report. Columns of interest here are "Additions", "Withdrawals", and "Interest". +Transactions added with this function will be added into the appropriate one of three slots in the Account object (Account$additions, Account$withdrawals, or Account$Interest), which contains an xts object of individual transactions with a date and amount. The \code{\link{updateAcct}} function will read the transactions from each list in turn, aggregate them by the specified date scope, and slot them into the \code{Account$summary} table as it's built. \code{\link{updateEndEq}} should then just work. } \author{ Peter Carl } \seealso{ -\code{\link{initAcct}}, \code{\link{updateAcct}}, -\code{\link{updateEndEq}} +\code{\link{initAcct}}, \code{\link{updateAcct}}, \code{\link{updateEndEq}} } Modified: pkg/blotter/man/addDiv.Rd =================================================================== --- pkg/blotter/man/addDiv.Rd 2014-10-26 17:34:20 UTC (rev 1642) +++ pkg/blotter/man/addDiv.Rd 2014-10-27 21:06:03 UTC (rev 1643) @@ -1,3 +1,4 @@ +% Generated by roxygen2 (4.0.2): do not edit by hand \name{addDiv} \alias{addDiv} \title{Add cash dividend transactions to a portfolio.} @@ -6,35 +7,24 @@ ConMult = NULL, verbose = TRUE) } \arguments{ - \item{Portfolio}{A portfolio name that points to a - portfolio object structured with - \code{\link{initPortf}}.} +\item{Portfolio}{A portfolio name that points to a portfolio object structured with \code{\link{initPortf}}.} - \item{Symbol}{An instrument identifier for a symbol - included in the portfolio, e.g., IBM.} +\item{Symbol}{An instrument identifier for a symbol included in the portfolio, e.g., IBM.} - \item{TxnDate}{Transaction date as ISO 8601, e.g., - '2008-09-01' or '2010-01-05 09:54:23.12345'.} +\item{TxnDate}{Transaction date as ISO 8601, e.g., '2008-09-01' or '2010-01-05 09:54:23.12345'.} - \item{DivPerShare}{The amount of the cash dividend paid - per share or per unit quantity.} +\item{DivPerShare}{The amount of the cash dividend paid per share or per unit quantity.} - \item{\dots}{Any other passthrough parameters.} +\item{TxnFees}{Fees associated with the transaction, e.g. commissions. See Details.} - \item{TxnFees}{Fees associated with the transaction, e.g. - commissions. See Details.} +\item{ConMult}{Contract or instrument multiplier for the Symbol if it is not defined in an instrument specification.} - \item{verbose}{If TRUE (default) the function prints the - elements of the transaction in a line to the screen, - e.g., "2007-01-08 IBM 50 @ 77.6". Suppress using FALSE.} +\item{verbose}{If TRUE (default) the function prints the elements of the transaction in a line to the screen, e.g., "2007-01-08 IBM 50 @ 77.6". Suppress using FALSE.} - \item{ConMult}{Contract or instrument multiplier for the - Symbol if it is not defined in an instrument - specification.} +\item{\dots}{Any other passthrough parameters.} } \description{ -Adding a cash dividend does not affect position quantity, -like a split would. +Adding a cash dividend does not affect position quantity, like a split would. } \note{ # TODO add TxnTypes to $txn table Modified: pkg/blotter/man/addPortfInstr.Rd =================================================================== --- pkg/blotter/man/addPortfInstr.Rd 2014-10-26 17:34:20 UTC (rev 1642) +++ pkg/blotter/man/addPortfInstr.Rd 2014-10-27 21:06:03 UTC (rev 1643) @@ -1,3 +1,4 @@ +% Generated by roxygen2 (4.0.2): do not edit by hand \name{addPortfInstr} \alias{addPortfInstr} \title{add an instrument to a portfolio} @@ -5,12 +6,11 @@ addPortfInstr(Portfolio, symbols, ...) } \arguments{ - \item{Portfolio}{portfolio identifier string} +\item{Portfolio}{portfolio identifier string} - \item{symbols}{character vector of symbols to add to the - portfolio} +\item{symbols}{character vector of symbols to add to the portfolio} - \item{\dots}{any other passthru parameters} +\item{\dots}{any other passthru parameters} } \description{ thanks to WolfGang Wu for making this function more usable Modified: pkg/blotter/man/addTxn.Rd =================================================================== --- pkg/blotter/man/addTxn.Rd 2014-10-26 17:34:20 UTC (rev 1642) +++ pkg/blotter/man/addTxn.Rd 2014-10-27 21:06:03 UTC (rev 1643) @@ -1,3 +1,4 @@ +% Generated by roxygen2 (4.0.2): do not edit by hand \name{addTxn} \alias{addTxn} \alias{addTxns} @@ -4,59 +5,49 @@ \title{Add transactions to a portfolio.} \usage{ addTxn(Portfolio, Symbol, TxnDate, TxnQty, TxnPrice, ..., TxnFees = 0, - ConMult = NULL, verbose = TRUE, eps = 1e-06) + allowRebates = FALSE, ConMult = NULL, verbose = TRUE, eps = 1e-06) addTxns(Portfolio, Symbol, TxnData, verbose = FALSE, ..., ConMult = NULL, - eps = 1e-06) + allowRebates = FALSE, eps = 1e-06) } \arguments{ - \item{Portfolio}{A portfolio name that points to a - portfolio object structured with \code{initPortf()}} +\item{Portfolio}{A portfolio name that points to a portfolio object structured with \code{initPortf()}} - \item{Symbol}{An instrument identifier for a symbol - included in the portfolio, e.g., "IBM"} +\item{Symbol}{An instrument identifier for a symbol included in the portfolio, e.g., "IBM"} - \item{TxnDate}{Transaction date as ISO 8601, e.g., - '2008-09-01' or '2010-01-05 09:54:23.12345'} +\item{TxnDate}{Transaction date as ISO 8601, e.g., '2008-09-01' or '2010-01-05 09:54:23.12345'} - \item{TxnQty}{Total units (such as shares or contracts) - transacted. Positive values indicate a 'buy'; negative - values indicate a 'sell'} +\item{TxnQty}{Total units (such as shares or contracts) transacted. Positive values indicate a 'buy'; negative values indicate a 'sell'} - \item{TxnPrice}{Price at which the transaction was done} +\item{TxnPrice}{Price at which the transaction was done} - \item{\dots}{Any other passthrough parameters} +\item{TxnFees}{Fees associated with the transaction, e.g. commissions., See Details} - \item{TxnFees}{Fees associated with the transaction, e.g. - commissions., See Details} +\item{allowRebates}{whether to allow positive (rebate) TxnFees, default FALSE} - \item{ConMult}{Contract/instrument multiplier for the - Symbol if it is not defined in an instrument - specification} +\item{ConMult}{Contract/instrument multiplier for the Symbol if it is not defined in an instrument specification} - \item{verbose}{If TRUE (default) the function prints the - elements of the transaction in a line to the screen, - e.g., "2007-01-08 IBM 50 @ 77.6". Suppress using FALSE.} +\item{verbose}{If TRUE (default) the function prints the elements of the transaction in a line to the screen, e.g., "2007-01-08 IBM 50 @ 77.6". Suppress using FALSE.} - \item{eps}{value to add to force unique indices} +\item{eps}{value to add to force unique indices} - \item{TxnData}{An xts object containing all required txn - fields (for addTxns)} +\item{TxnData}{An xts object containing all required txn fields (for addTxns)} + +\item{\dots}{Any other passthrough parameters} } \description{ -When a trade or adjustment is made to the Portfolio, the -addTxn function calculates the value and average cost of -the transaction, the change in position, the resulting -positions average cost, and any realized profit or loss -(net of fees) from the transaction. Then it stores the -transaction and calculations in the Portfolio object. +When a trade or adjustment is made to the Portfolio, the addTxn function +calculates the value and average cost of the transaction, the change in +position, the resulting positions average cost, and any realized profit +or loss (net of fees) from the transaction. Then it stores the transaction +and calculations in the Portfolio object. } \details{ Fees are indicated as negative values and will be subtracted from the transaction value. TxnFees can either be a fixed numeric amount, or a function (or charavcter -name of a function) in which case the function is evaluated -to determine the fee amount. +name of a function) in which case the function is +evaluated to determine the fee amount. The \code{\link{pennyPerShare}} function provides a simple example of a transaction cost function. @@ -70,9 +61,9 @@ This transaction splitting vastly simplifies realized P&L calculations elsewhere in the code. Such splitting also -mirrors many execution platforms and brokerage requirements -in particular asset classes where the side of a trade needs -to be specified with the order. +mirrors many execution platforms and brokerage +requirements in particular asset classes where the side +of a trade needs to be specified with the order. The \code{addTxns} function allows you to add multiple transactions to the portfolio, which is much faster than @@ -81,16 +72,14 @@ column is optional. } \note{ -The addTxn function will eventually also handle other -transaction types, such as adjustments for corporate -actions or expire/assign for options. See -\code{\link{addDiv}} +The addTxn function will eventually also handle other transaction types, +such as adjustments for corporate actions or expire/assign for options. +See \code{\link{addDiv}} } \author{ Peter Carl, Brian G. Peterson } \seealso{ -\code{\link{addTxns}}, \code{\link{pennyPerShare}}, -\code{\link{initPortf}} +\code{\link{addTxns}}, \code{\link{pennyPerShare}}, \code{\link{initPortf}} } Modified: pkg/blotter/man/calcPortfWgt.Rd =================================================================== --- pkg/blotter/man/calcPortfWgt.Rd 2014-10-26 17:34:20 UTC (rev 1642) +++ pkg/blotter/man/calcPortfWgt.Rd 2014-10-27 21:06:03 UTC (rev 1643) @@ -1,3 +1,4 @@ +% Generated by roxygen2 (4.0.2): do not edit by hand \name{calcPortfWgt} \alias{calcPortfWgt} \title{Calculates the portfolio weights for positions within a given portfolio.} @@ -7,31 +8,24 @@ Account) } \arguments{ - \item{Portfolio}{a portfolio object structured with - initPortf()} +\item{Portfolio}{a portfolio object structured with initPortf()} - \item{Symbols}{an instrument identifier for a symbol - included in the portfolio} +\item{Symbols}{an instrument identifier for a symbol included in the portfolio} - \item{Dates}{dates to return the calculation over - formatted as xts range} +\item{Dates}{dates to return the calculation over formatted as xts range} - \item{denominator}{string describing the deniminator, see - Description} +\item{denominator}{string describing the deniminator, see Description} - \item{Account}{an Account object containing Portfolio - summaries} +\item{Account}{an Account object containing Portfolio summaries} } \value{ -xts timeseries object with weights by date in rows and -symbolname in columns +xts timeseries object with weights by date in rows and symbolname in columns } \description{ -Portfolio weights may be calculated differently depending -on their use. By default, this function uses denominator of -'Gross.Value', the second most common option will likely be -'Net.Value'. For separating long and short weights, -'Long.Value' and 'Short.Value' may be needed as -denominators. +Portfolio weights may be calculated differently depending on their use. +By default, this function uses denominator of 'Gross.Value', the second most common +option will likely be 'Net.Value'. +For separating long and short weights, 'Long.Value' and 'Short.Value' may be +needed as denominators. } Modified: pkg/blotter/man/calcPosAvgCost.Rd =================================================================== --- pkg/blotter/man/calcPosAvgCost.Rd 2014-10-26 17:34:20 UTC (rev 1642) +++ pkg/blotter/man/calcPosAvgCost.Rd 2014-10-27 21:06:03 UTC (rev 1643) @@ -1,3 +1,4 @@ +% Generated by roxygen2 (4.0.2): do not edit by hand \name{.calcPosAvgCost} \alias{.calcPosAvgCost} \title{Calculates the average cost of a resulting position from a transaction} @@ -5,24 +6,20 @@ .calcPosAvgCost(PrevPosQty, PrevPosAvgCost, TxnValue, PosQty, ConMult = 1) } \arguments{ - \item{PrevPosQty}{quantity of the previous position} +\item{PrevPosQty}{quantity of the previous position} - \item{PrevPosAvgCost}{average position cost of the - previous position} +\item{PrevPosAvgCost}{average position cost of the previous position} - \item{TxnValue}{total value of the transaction, including - fees} +\item{TxnValue}{total value of the transaction, including fees} - \item{PosQty}{total units (shares) of the resulting - position} +\item{PosQty}{total units (shares) of the resulting position} - \item{ConMult}{multiplier from instrument data} +\item{ConMult}{multiplier from instrument data} } \value{ PosAvgCost: average cost of the resulting position } \description{ -Calculates the average cost of a resulting position from a -transaction +Calculates the average cost of a resulting position from a transaction } Modified: pkg/blotter/man/calcTxnAvgCost.Rd =================================================================== --- pkg/blotter/man/calcTxnAvgCost.Rd 2014-10-26 17:34:20 UTC (rev 1642) +++ pkg/blotter/man/calcTxnAvgCost.Rd 2014-10-27 21:06:03 UTC (rev 1643) @@ -1,3 +1,4 @@ +% Generated by roxygen2 (4.0.2): do not edit by hand \name{.calcTxnAvgCost} \alias{.calcTxnAvgCost} \title{Calculates a per share or per contract cost of the transaction to match the units the price is quoted in} @@ -5,19 +6,16 @@ .calcTxnAvgCost(TxnValue, TxnQty, ConMult = 1) } \arguments{ - \item{TxnValue}{total value of the transaction, including - fees} +\item{TxnValue}{total value of the transaction, including fees} - \item{TxnQty}{total units (shares) of the transaction} +\item{TxnQty}{total units (shares) of the transaction} - \item{ConMult}{multiplier from instrument data} +\item{ConMult}{multiplier from instrument data} } \value{ -TxnAvgCost: unit normalized (per share) cost implied by the -transaction +TxnAvgCost: unit normalized (per share) cost implied by the transaction } \description{ -Calculates a per share or per contract cost of the -transaction to match the units the price is quoted in +Calculates a per share or per contract cost of the transaction to match the units the price is quoted in } Modified: pkg/blotter/man/calcTxnValue.Rd =================================================================== --- pkg/blotter/man/calcTxnValue.Rd 2014-10-26 17:34:20 UTC (rev 1642) +++ pkg/blotter/man/calcTxnValue.Rd 2014-10-27 21:06:03 UTC (rev 1643) @@ -1,3 +1,4 @@ +% Generated by roxygen2 (4.0.2): do not edit by hand \name{.calcTxnValue} \alias{.calcTxnValue} \title{Calculates the total value of a transaction or trade} @@ -5,18 +6,16 @@ .calcTxnValue(TxnQty, TxnPrice, TxnFees, ConMult = 1) } \arguments{ - \item{TxnQty}{total units (shares) of the transaction} +\item{TxnQty}{total units (shares) of the transaction} - \item{TxnPrice}{price at which the transaction was done} +\item{TxnPrice}{price at which the transaction was done} - \item{TxnFees}{fees associated with the transaction, e.g. - commissions} +\item{TxnFees}{fees associated with the transaction, e.g. commissions} - \item{ConMult}{multiplier from instrument data} +\item{ConMult}{multiplier from instrument data} } \value{ -TxnValue: total dollar value of the transaction, including -fees +TxnValue: total dollar value of the transaction, including fees } \description{ Calculates the total value of a transaction or trade Modified: pkg/blotter/man/chart.ME.Rd =================================================================== --- pkg/blotter/man/chart.ME.Rd 2014-10-26 17:34:20 UTC (rev 1642) +++ pkg/blotter/man/chart.ME.Rd 2014-10-27 21:06:03 UTC (rev 1643) @@ -1,3 +1,4 @@ +% Generated by roxygen2 (4.0.2): do not edit by hand \name{chart.ME} \alias{chart.ME} \title{Chart Maximum Adverse/Favorable Excursion} @@ -6,39 +7,29 @@ "percent", "tick"), ...) } \arguments{ - \item{Portfolio}{string identifying the portfolio to - chart} +\item{Portfolio}{string identifying the portfolio to chart} - \item{Symbol}{string identifying the symbol to chart. If - missing, the first symbol found in the \code{Portfolio} - portfolio will be used} +\item{Symbol}{string identifying the symbol to chart. If missing, the first symbol found in the \code{Portfolio} portfolio will be used} - \item{type}{string specifying MAE (Adverse) or MFE - (Favourable) chart type} +\item{type}{string specifying MAE (Adverse) or MFE (Favourable) chart type} - \item{scale}{string specifying 'cash', or 'percent' for - percentage of investment, or 'tick'} +\item{scale}{string specifying 'cash', or 'percent' for percentage of investment, or 'tick'} - \item{\dots}{any other passthrough parameters, in - particular includeOpenTrades (see perTradeStats())} +\item{\dots}{any other passthrough parameters, in particular includeOpenTrades (see perTradeStats())} } \description{ -Produces a scatterplot with one point per trade, with -x-axis: absolute value of Drawdown (Adverse), or Run Up -(Favourable), and y-axis: absolute value of Net Profit or -Loss +Produces a scatterplot with one point per trade, with x-axis: absolute +value of Drawdown (Adverse), or Run Up (Favourable), +and y-axis: absolute value of Net Profit or Loss } \author{ Jan Humme } \references{ -Tomasini, E. and Jaekle, U. \emph{Trading Systems - A new -approach to system development and portfolio optimisation} -(ISBN 978-1-905641-79-6), section 3.5 +Tomasini, E. and Jaekle, U. \emph{Trading Systems - A new approach to system development and portfolio optimisation} (ISBN 978-1-905641-79-6), section 3.5 } \seealso{ -\code{\link{perTradeStats}} for the calculations used by -this chart, and \code{\link{tradeStats}} for a summary view -of the performance +\code{\link{perTradeStats}} for the calculations used by this chart, +and \code{\link{tradeStats}} for a summary view of the performance } Modified: pkg/blotter/man/chart.Posn.Rd =================================================================== --- pkg/blotter/man/chart.Posn.Rd 2014-10-26 17:34:20 UTC (rev 1642) +++ pkg/blotter/man/chart.Posn.Rd 2014-10-27 21:06:03 UTC (rev 1643) @@ -1,3 +1,4 @@ +% Generated by roxygen2 (4.0.2): do not edit by hand \name{chart.Posn} \alias{chart.Posn} [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/blotter -r 1643