From noreply at r-forge.r-project.org Sun Mar 3 17:14:56 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 3 Mar 2013 17:14:56 +0100 (CET) Subject: [Blotter-commits] r1406 - in pkg/FinancialInstrument: . R Message-ID: <20130303161457.0416C184883@r-forge.r-project.org> Author: gsee Date: 2013-03-03 17:14:56 +0100 (Sun, 03 Mar 2013) New Revision: 1406 Modified: pkg/FinancialInstrument/DESCRIPTION pkg/FinancialInstrument/NEWS pkg/FinancialInstrument/R/format_id.R Log: sort_ids() is less locale-specific; see NEWS. Thanks to Alexis Petit for the patch Modified: pkg/FinancialInstrument/DESCRIPTION =================================================================== --- pkg/FinancialInstrument/DESCRIPTION 2013-02-26 15:07:51 UTC (rev 1405) +++ pkg/FinancialInstrument/DESCRIPTION 2013-03-03 16:14:56 UTC (rev 1406) @@ -9,9 +9,9 @@ Contributors: Dirk Eddelbuettel, Alexis Petit, Jeffrey Ryan, Joshua Ulrich Description: Infrastructure for defining meta-data and relationships for financial instruments. -Version: 1.1.6 +Version: 1.1.7 URL: https://r-forge.r-project.org/projects/blotter/ -Date: 2013-02-12 +Date: 2013-03-03 Depends: R (>= 2.12.0), quantmod(>= 0.3-17), Modified: pkg/FinancialInstrument/NEWS =================================================================== --- pkg/FinancialInstrument/NEWS 2013-02-26 15:07:51 UTC (rev 1405) +++ pkg/FinancialInstrument/NEWS 2013-03-03 16:14:56 UTC (rev 1406) @@ -19,6 +19,11 @@ instrument object would be used even if the user passed a different currency in the old_base argument. +* sort_ids() only worked in some locales when an instrument is not defined. It + now converts the month (returned by parse_id()) to numeric (with MC2N()) and + uses the "%m" format in the as.Date call instead of using the month name with + the (locale-specific) "%b" format. Thanks to Alexis Petit for the patch. + TESTS ----- Modified: pkg/FinancialInstrument/R/format_id.R =================================================================== --- pkg/FinancialInstrument/R/format_id.R 2013-02-26 15:07:51 UTC (rev 1405) +++ pkg/FinancialInstrument/R/format_id.R 2013-03-03 16:14:56 UTC (rev 1406) @@ -283,7 +283,7 @@ } } pid <- parse_id(x, ...) - as.Date(paste(pid$year, pid$month, 1, sep=''), format="%Y%b%d") + as.Date(paste(pid$year, MC2N(pid$month), 1, sep = "-"), format = "%Y-%m-%d") } out1 <- names(sort(sapply(ids,f, ...))) out2 <- sort(ids[!(ids %in% out1)]) From noreply at r-forge.r-project.org Sat Mar 9 18:48:47 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 9 Mar 2013 18:48:47 +0100 (CET) Subject: [Blotter-commits] r1407 - pkg/blotter/R Message-ID: <20130309174847.8C1BE184A66@r-forge.r-project.org> Author: gsee Date: 2013-03-09 18:48:46 +0100 (Sat, 09 Mar 2013) New Revision: 1407 Modified: pkg/blotter/R/calcPortfWgt.R Log: partial matching fix for R CMD check Modified: pkg/blotter/R/calcPortfWgt.R =================================================================== --- pkg/blotter/R/calcPortfWgt.R 2013-03-03 16:14:56 UTC (rev 1406) +++ pkg/blotter/R/calcPortfWgt.R 2013-03-09 17:48:46 UTC (rev 1407) @@ -34,7 +34,7 @@ if(is.null(Symbols)) Symbols<-names(Portfolio$symbols) pos.value = .getBySymbol(Portfolio = Portfolio, Dates = Dates, Attribute = "Pos.Value", Symbols = Symbols) - portf.value = .getByPortf(Account=getAccount(Account),Attribute = denominator[1], Date = Dates) + portf.value = .getByPortf(Account=getAccount(Account),Attribute = denominator[1], Dates = Dates) weights = zerofill(as.data.frame(lapply(pos.value, FUN = function(x,y){return(x/y)}, y=portf.value))) return(weights) From noreply at r-forge.r-project.org Sun Mar 10 21:43:32 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 10 Mar 2013 21:43:32 +0100 (CET) Subject: [Blotter-commits] r1408 - pkg/blotter/R Message-ID: <20130310204332.A3B08184E8F@r-forge.r-project.org> Author: peter_carl Date: 2013-03-10 21:43:32 +0100 (Sun, 10 Mar 2013) New Revision: 1408 Modified: pkg/blotter/R/chart.Posn.R Log: - fix to pass dots into chart_Series, as promised in the documentation Modified: pkg/blotter/R/chart.Posn.R =================================================================== --- pkg/blotter/R/chart.Posn.R 2013-03-09 17:48:46 UTC (rev 1407) +++ pkg/blotter/R/chart.Posn.R 2013-03-10 20:43:32 UTC (rev 1408) @@ -75,7 +75,7 @@ # scope the Price data by Dates if(!is.null(Dates)) Prices=Prices[Dates] - chart_Series(Prices, name=Symbol, TA=TA) + chart_Series(Prices, name=Symbol, TA=TA, ...) if(!is.null(nrow(Buys)) && nrow(Buys) >=1 ) (add_TA(Buys,pch=2,type='p',col='green', on=1)); if(!is.null(nrow(Sells)) && nrow(Sells) >= 1) (add_TA(Sells,pch=6,type='p',col='red', on=1)); if(nrow(Position)>=1) { From noreply at r-forge.r-project.org Tue Mar 19 13:31:54 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 19 Mar 2013 13:31:54 +0100 (CET) Subject: [Blotter-commits] r1409 - in pkg/quantstrat: R man Message-ID: <20130319123154.EFEF0183912@r-forge.r-project.org> Author: braverock Date: 2013-03-19 13:31:54 +0100 (Tue, 19 Mar 2013) New Revision: 1409 Added: pkg/quantstrat/man/chart.forward.testing.Rd pkg/quantstrat/man/chart.forward.training.Rd pkg/quantstrat/man/put.orderbook.Rd pkg/quantstrat/man/put.strategy.Rd pkg/quantstrat/man/walk.forward.Rd Modified: pkg/quantstrat/R/ruleOrderProc.R pkg/quantstrat/R/rules.R pkg/quantstrat/man/add.rule.Rd pkg/quantstrat/man/addOrder.Rd pkg/quantstrat/man/initStrategy.Rd pkg/quantstrat/man/paramConstraint.Rd Log: - use order price for fill in low-frequency data, thanks to Peter Carl for investigating changes caused by newer xts Date index handling - multiple documentation updates, mostly to walk.forward - props to Chinmay Patil for comments on chain rule descriptions - bump version Modified: pkg/quantstrat/R/ruleOrderProc.R =================================================================== --- pkg/quantstrat/R/ruleOrderProc.R 2013-03-10 20:43:32 UTC (rev 1408) +++ pkg/quantstrat/R/ruleOrderProc.R 2013-03-19 12:31:54 UTC (rev 1409) @@ -109,6 +109,9 @@ #if( NROW(mktdataTimestamp) > 1 ) mktdataTimestamp <- last(mktdataTimestamp) orderType <- ordersubset[ii,"Order.Type"] + + if(hasArg(allowMagicalThinking)) allowMagicalThinking=match.call(expand.dots=TRUE)$allowMagicalThinking + else allowMagicalThinking = FALSE freq = periodicity(mktdata) #switch on frequency @@ -120,7 +123,18 @@ monthly = { txntime=as.character(index(ordersubset[ii,])) # transacts on this bar, e.g. in the intraday cross, or leading into the end of month, quarter, etc. # txntime=as.character(timestamp) # use this if you wanted to transact on the close of the next bar - txnprice=as.numeric(getPrice(mktdataTimestamp, prefer=prefer)[,1]) + # txnprice=as.numeric(getPrice(mktdataTimestamp, prefer=prefer)[,1]) + txnprice = orderPrice + }, + daily = { + if(isTRUE(allowMagicalThinking)){ + txntime=as.character(index(ordersubset[ii,])) # transacts on this bar, e.g. in the intraday cross, or leading into the end of month, quarter, etc. + #txnprice=as.numeric(getPrice(mktdataTimestamp, prefer=prefer)[,1]) + txnprice = orderPrice + } else { + txntime = timestamp + txnprice = as.numeric(getPrice(mktdataTimestamp, prefer=prefer)[,1]) #filled at now-prevailing 'price' + } }, #end daily { txntime = timestamp Modified: pkg/quantstrat/R/rules.R =================================================================== --- pkg/quantstrat/R/rules.R 2013-03-10 20:43:32 UTC (rev 1408) +++ pkg/quantstrat/R/rules.R 2013-03-19 12:31:54 UTC (rev 1409) @@ -15,7 +15,7 @@ #' \item{rebalance}{ rules executed specifically in a portfolio context, unnecessary in univariate strategies} #' \item{exit}{ rules to determine whether to exit a position} #' \item{enter}{ rules to determine whether to enter or increase a position} -#' \item{chain}{ rules executed upon fill of the corresponding order, identified by label } +#' \item{chain}{ rules executed upon fill of an order corresponding to the label of the parent rule identified by the \code{parent} arg. } #' } #' #' The rules will be executed by type, in the order listed above. @@ -65,7 +65,7 @@ #' @param parameters vector of strings naming parameters to be saved for apply-time definition #' @param label arbitrary text label for rule output, NULL default will be converted to '.rule' #' @param type one of "risk","order","rebalance","exit","enter","chain" see Details -#' @param parent the parent rule for a chain rule +#' @param parent the label of the parent rule for a chain rule #' @param ... any other passthru parameters #' @param enabled TRUE/FALSE whether the rule is enabled for use in applying the strategy, default TRUE #' @param indexnum if you are updating a specific rule, the index number in the $rules[type] list to update @@ -104,7 +104,7 @@ tmp_rule$type<-type if(type == 'chain') { - if(is.null(parent)) stop("You must specify a parent if ruletype=='chain'") + if(is.null(parent)) stop("You must specify the label of the parent rule if ruletype=='chain'") tmp_rule$parent<-parent } tmp_rule$enabled<-enabled @@ -541,8 +541,7 @@ cross<-sigThreshold(data=mkt_price_series, label='tmptrail',column=col,threshold=tmpprice,relationship=relationship) # find first index that would cross after this index if (any(cross[trailspan])){ - newidx <- curIndex + which(cross[trailspan])[1] - 1 #curIndex/firsttime was 1 in the subset, we need a -1 offset? - newidx <- index(mktdata[index(which(cross[trailspan])[1]),which.i=TRUE]) + newidx <- curIndex + index(mktdata[index(which(cross[trailspan])[1]),which.i=TRUE]) # insert that into dindex assign.dindex(c(get.dindex(),newidx)) } else { Modified: pkg/quantstrat/man/add.rule.Rd =================================================================== --- pkg/quantstrat/man/add.rule.Rd 2013-03-10 20:43:32 UTC (rev 1408) +++ pkg/quantstrat/man/add.rule.Rd 2013-03-19 12:31:54 UTC (rev 1409) @@ -29,7 +29,8 @@ "risk","order","rebalance","exit","enter","chain" see Details} - \item{parent}{the parent rule for a chain rule} + \item{parent}{the label of the parent rule for a chain + rule} \item{...}{any other passthru parameters} @@ -80,8 +81,9 @@ univariate strategies} \item{exit}{ rules to determine whether to exit a position} \item{enter}{ rules to determine whether to enter or increase a position} - \item{chain}{ rules executed upon fill of the - corresponding order, identified by label } } + \item{chain}{ rules executed upon fill of an order + corresponding to the label of the parent rule identified + by the \code{parent} arg. } } The rules will be executed by type, in the order listed above. Multiple rules of each type may be defined, as Modified: pkg/quantstrat/man/addOrder.Rd =================================================================== --- pkg/quantstrat/man/addOrder.Rd 2013-03-10 20:43:32 UTC (rev 1408) +++ pkg/quantstrat/man/addOrder.Rd 2013-03-19 12:31:54 UTC (rev 1409) @@ -5,7 +5,7 @@ addOrder(portfolio, symbol, timestamp, qty, price, ordertype, side, threshold = NULL, orderset = "", status = "open", statustimestamp = "", prefer = NULL, - delay = 0.00001, tmult = FALSE, replace = TRUE, + delay = 1e-05, tmult = FALSE, replace = TRUE, return = FALSE, ..., TxnFees = 0, label = "") } \arguments{ Added: pkg/quantstrat/man/chart.forward.testing.Rd =================================================================== --- pkg/quantstrat/man/chart.forward.testing.Rd (rev 0) +++ pkg/quantstrat/man/chart.forward.testing.Rd 2013-03-19 12:31:54 UTC (rev 1409) @@ -0,0 +1,14 @@ +\name{chart.forward.testing} +\alias{chart.forward.testing} +\title{Chart to analyse walk.forward() objective function} +\usage{ + chart.forward.testing(audit.filename) +} +\arguments{ + \item{audit.filename}{name of .audit environment file as + produced by walk.forward()} +} +\description{ + Chart to analyse walk.forward() objective function +} + Property changes on: pkg/quantstrat/man/chart.forward.testing.Rd ___________________________________________________________________ Added: svn:mime-type + text/plain Added: pkg/quantstrat/man/chart.forward.training.Rd =================================================================== --- pkg/quantstrat/man/chart.forward.training.Rd (rev 0) +++ pkg/quantstrat/man/chart.forward.training.Rd 2013-03-19 12:31:54 UTC (rev 1409) @@ -0,0 +1,14 @@ +\name{chart.forward.training} +\alias{chart.forward.training} +\title{Chart to analyse walk.forward() objective function} +\usage{ + chart.forward.training(audit.filename) +} +\arguments{ + \item{audit.filename}{name of .audit environment file as + produced by walk.forward()} +} +\description{ + Chart to analyse walk.forward() objective function +} + Property changes on: pkg/quantstrat/man/chart.forward.training.Rd ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: pkg/quantstrat/man/initStrategy.Rd =================================================================== --- pkg/quantstrat/man/initStrategy.Rd 2013-03-10 20:43:32 UTC (rev 1408) +++ pkg/quantstrat/man/initStrategy.Rd 2013-03-19 12:31:54 UTC (rev 1409) @@ -42,8 +42,8 @@ \item{init.Portf}{if TRUE, will call \code{\link[blotter]{initPortf}} to initialize the portfolio object} \item{init.Acct}{if TRUE, will call - \code{\link[blotter]{initAccount}} to initialize the - account object} \item{init.Orders}{if TRUE, will call + \code{\link[blotter]{initAcct}} to initialize the account + object} \item{init.Orders}{if TRUE, will call \code{\link{initOrders}} to initialize the order book for this test} \item{unique}{not yet implemented, will force a unique portfolio and account name if the portfolio, Modified: pkg/quantstrat/man/paramConstraint.Rd =================================================================== --- pkg/quantstrat/man/paramConstraint.Rd 2013-03-10 20:43:32 UTC (rev 1408) +++ pkg/quantstrat/man/paramConstraint.Rd 2013-03-19 12:31:54 UTC (rev 1409) @@ -1,6 +1,6 @@ \name{paramConstraint} \alias{paramConstraint} -\title{Internal function used in applyParameter function for process constraints on relationship between two parameter values. Basicly is the same as sigComparison function in signal.R written by Brian, with miner change.} +\title{Internal function used in applyParameter function for process constraints on relationship between two parameter values. Basicly is the same as sigComparison function in signal.R written by Brian, with minor change.} \usage{ paramConstraint(label, data = mktdata, columns, relationship = c("gt", "lt", "eq", "gte", "lte", "op")) Added: pkg/quantstrat/man/put.orderbook.Rd =================================================================== --- pkg/quantstrat/man/put.orderbook.Rd (rev 0) +++ pkg/quantstrat/man/put.orderbook.Rd 2013-03-19 12:31:54 UTC (rev 1409) @@ -0,0 +1,24 @@ +\name{put.orderbook} +\alias{put.orderbook} +\title{put an orderbook object in .strategy env} +\usage{ + put.orderbook(portfolio.st, orderbook, envir = .strategy) +} +\arguments{ + \item{portfolio.st}{string identifying portfolio} + + \item{orderbook}{orderbook object} + + \item{envir}{the environment to store the orderbook + object in, defaults to .strategy} +} +\description{ + put an orderbook object in .strategy env +} +\seealso{ + getOrderBook +} +\concept{ + order book +} + Property changes on: pkg/quantstrat/man/put.orderbook.Rd ___________________________________________________________________ Added: svn:mime-type + text/plain Added: pkg/quantstrat/man/put.strategy.Rd =================================================================== --- pkg/quantstrat/man/put.strategy.Rd (rev 0) +++ pkg/quantstrat/man/put.strategy.Rd 2013-03-19 12:31:54 UTC (rev 1409) @@ -0,0 +1,20 @@ +\name{put.strategy} +\alias{put.strategy} +\title{put a strategy object in .strategy env} +\usage{ + put.strategy(strategy, envir = .strategy) +} +\arguments{ + \item{strategy}{object; name will be extracted as + strategy$name} + + \item{envir}{the environment to store the strategy in, + defaults to .strategy} +} +\description{ + put a strategy object in .strategy env +} +\seealso{ + getStrategy +} + Property changes on: pkg/quantstrat/man/put.strategy.Rd ___________________________________________________________________ Added: svn:mime-type + text/plain Added: pkg/quantstrat/man/walk.forward.Rd =================================================================== --- pkg/quantstrat/man/walk.forward.Rd (rev 0) +++ pkg/quantstrat/man/walk.forward.Rd 2013-03-19 12:31:54 UTC (rev 1409) @@ -0,0 +1,98 @@ +\name{walk.forward} +\alias{walk.forward} +\title{Rolling Walk Forward Analysis} +\usage{ + walk.forward(strategy.st, paramset.label, portfolio.st, + account.st, period, k.training, nsamples = 0, + audit.prefix = NULL, k.testing, + obj.func = function(x) { which(x == max(x)) }, + obj.args = list(x = quote(tradeStats.list$Net.Trading.PL)), + include.insamples = TRUE, ..., verbose = FALSE) +} +\arguments{ + \item{portfolio.st}{the name of the portfolio object} + + \item{account.st}{the name of the account object} + + \item{strategy.st}{the name of the strategy object} + + \item{paramset.label}{a label uniquely identifying within + the strategy the paramset to be tested} + + \item{period}{the period unit, as a character string, eg. + 'days' or 'months'} + + \item{k.training}{the number of periods to use for + training, eg. '3' months} + + \item{nsamples}{the number of sample param.combos to draw + from the paramset for training; 0 means all samples (see + also apply.paramset)} + + \item{audit.prefix}{prefix to generate filenames for + storage of audit data. For each training set, a separate + file is created, containing an enviroment called .audit, + with all in-sample portfolios and orderbooks as well as + information as to which param.combos were evaluated, and + the result of the objective function. In addition, a + special file is generated that contains portfolio and + orderbook for the concatenated testing param.combos as + selected by the objective function, plus (optionally) + complete in-sample portfolios and orderbooks for + reference (see include.insamples)} + + \item{k.testing}{the number of periods to use for + testing, eg. '1 month'} + + \item{obj.func}{a user provided function returning the + best param.combo from the paramset, based on training + results; defaults to 'max'} + + \item{obj.args}{a user provided argument to obj.func, + defaults to quote(tradeStats.list$Net.Trading.PL)} + + \item{include.insamples}{will optionally run a full + backtest for each param.combo in the paramset, and add + the resulting in-sample portfolios and orderbooks to the + file '.results.RData'; default TRUE} + + \item{...}{optional parameters to pass to + apply.paramset()} + + \item{verbose}{dumps a lot of info during the run if set + to TRUE, defaults to FALSE} +} +\value{ + a list consisting of a slot containing detailed results + for each training + testing period, as well as the + portfolio and the tradeStats() for the portfolio +} +\description{ + A wrapper for apply.paramset() and applyStrategy(), + implementing a Rolling Walk Forward Analysis (WFA). +} +\details{ + walk.forward executes a strategy on a portfolio, while + rolling a re-optimization of one of the strategies + parameter sets during a specified time period (training + window), then selecting an optimal parameter combination + from the parameter set using an obj function, then + applying the selected parameter combo to the next + out-of-sample time period immediately following the + training window (testing window). Once completed, the + training window is shifted forward by a time period equal + to the testing window size, and the process is repeated. + WFA stops when there are insufficient data left for a + full testing window. + + For a complete description, see Jaekle&Tomasini chapter + 6. +} +\author{ + Jan Humme +} +\seealso{ + \code{\link{applyStrategy}} \code{\link{apply.paramset}} + \code{\link{endpoints}} \code{\link{tradeStats}} +} + Property changes on: pkg/quantstrat/man/walk.forward.Rd ___________________________________________________________________ Added: svn:mime-type + text/plain From noreply at r-forge.r-project.org Tue Mar 19 14:10:23 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 19 Mar 2013 14:10:23 +0100 (CET) Subject: [Blotter-commits] r1410 - in pkg/quantstrat: . R man Message-ID: <20130319131023.EC598184F4C@r-forge.r-project.org> Author: braverock Date: 2013-03-19 14:10:23 +0100 (Tue, 19 Mar 2013) New Revision: 1410 Removed: pkg/quantstrat/man/ruleCancel.Rd Modified: pkg/quantstrat/NAMESPACE pkg/quantstrat/R/ruleRevoke.R pkg/quantstrat/man/ruleRevoke.Rd Log: - alias ruleRevoke to ruleCancel, it will make more sense to those with market experience - update NAMESPACE Modified: pkg/quantstrat/NAMESPACE =================================================================== --- pkg/quantstrat/NAMESPACE 2013-03-19 12:31:54 UTC (rev 1409) +++ pkg/quantstrat/NAMESPACE 2013-03-19 13:10:23 UTC (rev 1410) @@ -2,13 +2,13 @@ export(add.distribution) export(add.indicator) export(add.init) +export(addOrder) +export(addPosLimit) export(add.rule) export(add.signal) -export(addOrder) -export(addPosLimit) -export(apply.paramset) export(applyIndicators) export(applyParameter) +export(apply.paramset) export(applyRules) export(applySignals) export(applyStrategy) @@ -31,6 +31,7 @@ export(put.orderbook) export(put.strategy) export(rm.strat) +export(ruleCancel) export(ruleOrderProc) export(rulePctEquity) export(ruleRevoke) Modified: pkg/quantstrat/R/ruleRevoke.R =================================================================== --- pkg/quantstrat/R/ruleRevoke.R 2013-03-19 12:31:54 UTC (rev 1409) +++ pkg/quantstrat/R/ruleRevoke.R 2013-03-19 13:10:23 UTC (rev 1410) @@ -1,10 +1,13 @@ -#' rule to revoke an unfilled limit order on a signal +#' rule to revoke(cancel) an unfilled limit order on a signal #' #' As described elsewhere in the documentation, quantstrat models #' \emph{orders}. All orders in quantstrat are GTC orders, which means that #' unfilled limit orders have to be revokeled manually or replaced by other orders. #' -#' This function is used for revokeing the orders based on a signal. +#' This function is used for revoking or canceling the orders based on a signal. +#' Order status will be changed to 'revoked', to separate it from cancelations or +#' replacements from other causes. THis may make it easier it decipher the order book +#' to figure out what the strategy ewas doing. #' #' @param data an xts object containing market data. depending on rules, may need to be in OHLCV or BBO formats, and may include indicator and signal information #' @param timestamp timestamp coercible to POSIXct that will be the time the order will be inserted on @@ -18,9 +21,9 @@ #' @author Niklas Kolster, Jan Humme #' @seealso \code{\link{osNoOp}} , \code{\link{add.rule}} #' @export -ruleRevoke <- function(data=mktdata, timestamp, sigcol, sigval, orderside=NULL, orderset=NULL, portfolio, symbol, ruletype) +ruleRevoke <- ruleCancel <- function(data=mktdata, timestamp, sigcol, sigval, orderside=NULL, orderset=NULL, portfolio, symbol, ruletype) { - if(ruletype!='risk') stop('Ruletype for ruleRevoke must be risk') + if(ruletype!='risk') stop('Ruletype for ruleRevoke or ruleCancel must be "risk".') pos <- getPosQty(portfolio, symbol, timestamp) if(pos == 0) Deleted: pkg/quantstrat/man/ruleCancel.Rd =================================================================== --- pkg/quantstrat/man/ruleCancel.Rd 2013-03-19 12:31:54 UTC (rev 1409) +++ pkg/quantstrat/man/ruleCancel.Rd 2013-03-19 13:10:23 UTC (rev 1410) @@ -1,52 +0,0 @@ -\name{ruleCancel} -\alias{ruleCancel} -\title{rule to cancel an unfilled limit order on a signal} -\usage{ - ruleCancel(data = mktdata, timestamp, sigcol, sigval, - orderside = NULL, orderset = NULL, portfolio, symbol, - ruletype) -} -\arguments{ - \item{data}{an xts object containing market data. - depending on rules, may need to be in OHLCV or BBO - formats, and may include indicator and signal - information} - - \item{timestamp}{timestamp coercible to POSIXct that will - be the time the order will be inserted on} - - \item{sigcol}{column name to check for signal} - - \item{sigval}{signal value to match against} - - \item{orderside}{one of either "long" or "short", default - NULL, see details} - - \item{orderset}{tag to identify an orderset} - - \item{portfolio}{text name of the portfolio to place - orders in} - - \item{symbol}{identifier of the instrument to cancel - orders for} - - \item{ruletype}{must be 'risk' for ruleCancel, see - \code{\link{add.rule}}} -} -\description{ - As described elsewhere in the documentation, quantstrat - models \emph{orders}. All orders in quantstrat are GTC - orders, which means that unfilled limit orders have to be - cancelled manually or replaced by other orders. -} -\details{ - This function is used for canceling the orders based on a - signal. -} -\author{ - Niklas Kolster -} -\seealso{ - \code{\link{osNoOp}} , \code{\link{add.rule}} -} - Modified: pkg/quantstrat/man/ruleRevoke.Rd =================================================================== --- pkg/quantstrat/man/ruleRevoke.Rd 2013-03-19 12:31:54 UTC (rev 1409) +++ pkg/quantstrat/man/ruleRevoke.Rd 2013-03-19 13:10:23 UTC (rev 1410) @@ -1,6 +1,6 @@ \name{ruleRevoke} \alias{ruleRevoke} -\title{rule to revoke an unfilled limit order on a signal} +\title{rule to revoke(cancel) an unfilled limit order on a signal} \usage{ ruleRevoke(data = mktdata, timestamp, sigcol, sigval, orderside = NULL, orderset = NULL, portfolio, symbol, @@ -40,8 +40,12 @@ revokeled manually or replaced by other orders. } \details{ - This function is used for revokeing the orders based on a - signal. + This function is used for revoking or canceling the + orders based on a signal. Order status will be changed to + 'revoked', to separate it from cancelations or + replacements from other causes. THis may make it easier + it decipher the order book to figure out what the + strategy ewas doing. } \author{ Niklas Kolster, Jan Humme From noreply at r-forge.r-project.org Sun Mar 24 20:21:24 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 24 Mar 2013 20:21:24 +0100 (CET) Subject: [Blotter-commits] r1411 - pkg/quantstrat/R Message-ID: <20130324192124.BA600184D67@r-forge.r-project.org> Author: bodanker Date: 2013-03-24 20:21:24 +0100 (Sun, 24 Mar 2013) New Revision: 1411 Modified: pkg/quantstrat/R/indicators.R Log: - applyIndicators no longer overwrites colnames if they already exist Modified: pkg/quantstrat/R/indicators.R =================================================================== --- pkg/quantstrat/R/indicators.R 2013-03-19 13:10:23 UTC (rev 1410) +++ pkg/quantstrat/R/indicators.R 2013-03-24 19:21:24 UTC (rev 1411) @@ -192,15 +192,9 @@ .formals$... <- NULL tmp_val<-do.call(fun,.formals) - if(is.null(colnames(tmp_val)) || !is.null(indicator$label)) { - if (ncol(tmp_val)==1) { #no names, only one column - colnames(tmp_val)<-indicator$label - } else { #no names, more than one column - colnames(tmp_val) <- paste(indicator$label,seq(1,ncol(tmp_val)),sep='.') - } - } else { #we have column names, so paste - if(ncol(tmp_val)>1) colnames(tmp_val) <- paste(indicator$label,colnames(tmp_val),sep='.') - } + if(is.null(colnames(tmp_val))) + colnames(tmp_val) <- seq(ncol(tmp_val)) + colnames(tmp_val) <- paste(indicator$label,colnames(tmp_val),sep='.') if (nrow(mktdata)==nrow(tmp_val) | length(mktdata)==length(tmp_val)) { # the indicator returned a time series, so we'll name it and cbind it From noreply at r-forge.r-project.org Mon Mar 25 13:26:31 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 25 Mar 2013 13:26:31 +0100 (CET) Subject: [Blotter-commits] r1412 - pkg/quantstrat/R Message-ID: <20130325122631.8450A183BA7@r-forge.r-project.org> Author: bodanker Date: 2013-03-25 13:26:31 +0100 (Mon, 25 Mar 2013) New Revision: 1412 Modified: pkg/quantstrat/R/signals.R Log: - sigFormula now uses .xts constructor and as.list for speed Modified: pkg/quantstrat/R/signals.R =================================================================== --- pkg/quantstrat/R/signals.R 2013-03-24 19:21:24 UTC (rev 1411) +++ pkg/quantstrat/R/signals.R 2013-03-25 12:26:31 UTC (rev 1412) @@ -318,7 +318,7 @@ # Vijay's PAST/AAII/SIPRO example # fieldVals <- try(eval(parse(text=expression), data)) ret_sig=NULL - ret_sig <- try(xts(eval(parse(text=formula), as.data.frame(data)),order.by=index(data))) + ret_sig <- try(.xts(eval(parse(text=formula), as.list(data)),order.by=.index(data))) if(is.xts(ret_sig)){ if(isTRUE(cross)) ret_sig <- diff(ret_sig)==1 colnames(ret_sig)<-label From noreply at r-forge.r-project.org Tue Mar 26 16:29:14 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 26 Mar 2013 16:29:14 +0100 (CET) Subject: [Blotter-commits] r1413 - pkg/blotter/R Message-ID: <20130326152914.1F365184ED7@r-forge.r-project.org> Author: bodanker Date: 2013-03-26 16:29:13 +0100 (Tue, 26 Mar 2013) New Revision: 1413 Modified: pkg/blotter/R/chart.Posn.R Log: - eval match.call output in case 'prefer' is an object Modified: pkg/blotter/R/chart.Posn.R =================================================================== --- pkg/blotter/R/chart.Posn.R 2013-03-25 12:26:31 UTC (rev 1412) +++ pkg/blotter/R/chart.Posn.R 2013-03-26 15:29:13 UTC (rev 1413) @@ -19,7 +19,7 @@ require(quantmod) Prices=get(Symbol) if(!is.OHLC(Prices)) { - if(hasArg(prefer)) prefer=match.call(expand.dots=TRUE)$prefer else prefer=NULL + if(hasArg(prefer)) prefer=eval(match.call(expand.dots=TRUE)$prefer) else prefer=NULL Prices=getPrice(Prices, prefer=prefer) } freq = periodicity(Prices) From noreply at r-forge.r-project.org Tue Mar 26 20:22:56 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 26 Mar 2013 20:22:56 +0100 (CET) Subject: [Blotter-commits] r1414 - pkg/quantstrat/R Message-ID: <20130326192256.6D069184699@r-forge.r-project.org> Author: opentrades Date: 2013-03-26 20:22:56 +0100 (Tue, 26 Mar 2013) New Revision: 1414 Modified: pkg/quantstrat/R/ruleSignal.R Log: - patch to suppress addOrder() call for exit/all rules in case there is no current pos anyway Modified: pkg/quantstrat/R/ruleSignal.R =================================================================== --- pkg/quantstrat/R/ruleSignal.R 2013-03-26 15:29:13 UTC (rev 1413) +++ pkg/quantstrat/R/ruleSignal.R 2013-03-26 19:22:56 UTC (rev 1414) @@ -205,23 +205,26 @@ if(!is.null(orderqty) && orderqty!=0 && !is.null(orderprice)) #orderprice could have length > 1 { - addOrder(portfolio=portfolio, - symbol=symbol, - timestamp=timestamp, - qty=orderqty, - price=as.numeric(orderprice), - ordertype=ordertype, - side=orderside, - orderset=orderset, - threshold=threshold, - status="open", - replace=replace , - delay=delay, - tmult=tmult, - ...=..., - prefer=prefer, - TxnFees=TxnFees, - label=label) + if(orderqty != 'all' || getPosQty(portfolio, symbol, timestamp) != 0) + { + addOrder(portfolio=portfolio, + symbol=symbol, + timestamp=timestamp, + qty=orderqty, + price=as.numeric(orderprice), + ordertype=ordertype, + side=orderside, + orderset=orderset, + threshold=threshold, + status="open", + replace=replace , + delay=delay, + tmult=tmult, + ...=..., + prefer=prefer, + TxnFees=TxnFees, + label=label) + } } } if(sethold) hold <<- TRUE From noreply at r-forge.r-project.org Wed Mar 27 15:18:03 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 27 Mar 2013 15:18:03 +0100 (CET) Subject: [Blotter-commits] r1415 - in pkg/quantstrat: R man Message-ID: <20130327141803.927BA185057@r-forge.r-project.org> Author: braverock Date: 2013-03-27 15:18:03 +0100 (Wed, 27 Mar 2013) New Revision: 1415 Modified: pkg/quantstrat/R/indicators.R pkg/quantstrat/R/match.names.R pkg/quantstrat/R/signals.R pkg/quantstrat/man/add.indicator.Rd pkg/quantstrat/man/applyIndicators.Rd pkg/quantstrat/man/match.names.Rd Log: - update label handling to paste to the end of the column names, consistent with earlier behavior - update match.names to check for general match first, and check for match at end second if multiple matches found - update documentation Modified: pkg/quantstrat/R/indicators.R =================================================================== --- pkg/quantstrat/R/indicators.R 2013-03-26 19:22:56 UTC (rev 1414) +++ pkg/quantstrat/R/indicators.R 2013-03-27 14:18:03 UTC (rev 1415) @@ -35,7 +35,7 @@ #' there already exists an indicator with that label in which case it will be appended #' with a number (i.e. '.ind.2', '.ind.3', etc.). #' If the indicator function returns multiple columns, the label will be -#' \code{\link{paste}}'d to either the returned column names or the +#' \code{\link{paste}}'d to the end of either the returned column names or the #' respective column number when applying it to \code{mktdata}. #' #' @param strategy an object (or the name of an object) type 'strategy' to add the indicator to @@ -102,6 +102,25 @@ } #' apply the indicators in the strategy to arbitrary market data +#' +#' \code{applyIndicators} will take the \code{mktdata} object, +#' and will apply each indicator specified in the strategy definition to it. +#' +#' If the indicator function returns an xts object or a vector of the same length +#' as mktdata, the columns created by the indicator function will be added to the +#' mktdata object via \code{\link{cbind}}. +#' +#' If the indicator function returns multiple columns, the label will be +#' \code{\link{paste}}'d to the end of either the returned column names or the +#' respective column number when applying it to \code{mktdata}. +#' +#' If the indicator returns some more complexobject, it will be added to a list +#' in the $indicators slot inside the \code{\link{applyStrategy}} execution frame. +#' If you want your indicators to return a more complex object, +#' (such as a model specification and output from a regression), be advised +#' that your signal generator, and potentially your rule function, will need +#' to understand, anticipate, and know how to manipulate the internal strategy frame. +#' #' @param strategy an object of type 'strategy' to add the indicator to #' @param mktdata an xts object containing market data. depending on indicators, may need to be in OHLCV or BBO formats #' @param parameters named list of parameters to be applied during evaluation of the strategy @@ -192,9 +211,12 @@ .formals$... <- NULL tmp_val<-do.call(fun,.formals) + + #add label if(is.null(colnames(tmp_val))) colnames(tmp_val) <- seq(ncol(tmp_val)) - colnames(tmp_val) <- paste(indicator$label,colnames(tmp_val),sep='.') + if(!identical(colnames(tmp_val),indicator$label)) + colnames(tmp_val) <- paste(colnames(tmp_val),indicator$label,sep='.') if (nrow(mktdata)==nrow(tmp_val) | length(mktdata)==length(tmp_val)) { # the indicator returned a time series, so we'll name it and cbind it Modified: pkg/quantstrat/R/match.names.R =================================================================== --- pkg/quantstrat/R/match.names.R 2013-03-26 19:22:56 UTC (rev 1414) +++ pkg/quantstrat/R/match.names.R 2013-03-27 14:18:03 UTC (rev 1415) @@ -10,13 +10,23 @@ #' This small utility exists to do the matching in a centralized location #' so that more robust error handling and reporting can be conducted. #' +#' The process to be followed is that first, \code{\link{grep}} will +#' be called without modification, assuming that a unique match has +#' been supplied by the user. If this fails, a match will be attempted +#' by appending '$' to the regex, searching for a match at the end of the +#' column name, as would be constructed by the \code{\link{paste}} in +#' e.g. \code{\link{applyIndicators}}. +#' #' @param data_names names for the data to be matched to #' @param match_names names to match #' @export match.names <- function(match_names,data_names) { loc<-NULL for (mname in match_names){ - t<-grep(paste(mname,"$",sep=""),data_names) + t<-grep(mname,data_names) + if(length(t)>1){ + t<-grep(paste(mname,"$",sep=""),data_names) + } if(is.null(loc)) loc<-t else loc <- c(loc,t) } Modified: pkg/quantstrat/R/signals.R =================================================================== --- pkg/quantstrat/R/signals.R 2013-03-26 19:22:56 UTC (rev 1414) +++ pkg/quantstrat/R/signals.R 2013-03-27 14:18:03 UTC (rev 1415) @@ -133,16 +133,14 @@ .formals$... <- NULL tmp_val<-do.call(fun,.formals) - if(is.null(colnames(tmp_val)) || !is.null(signal$label)) { - if (ncol(tmp_val)==1) { #no names, only one column - colnames(tmp_val)<-signal$label - } else { #no names, more than one column - colnames(tmp_val) <- paste(signal$label,seq(1,ncol(tmp_val)),sep='.') - } - } else { #we have column names, so paste - if(ncol(tmp_val)>1) colnames(tmp_val) <- paste(signal$label,colnames(tmp_val),sep='.') - } - if (nrow(mktdata)==nrow(tmp_val) | length(mktdata)==length(tmp_val)) { + + #add label + if(is.null(colnames(tmp_val))) + colnames(tmp_val) <- seq(ncol(tmp_val)) + if(!identical(colnames(tmp_val),signal$label)) + colnames(tmp_val) <- paste(colnames(tmp_val),signal$label,sep='.') + + if (nrow(mktdata)==nrow(tmp_val) | length(mktdata)==length(tmp_val)) { # the signal returned a time series, so we'll name it and cbind it mktdata<-cbind(mktdata,tmp_val) } else { Modified: pkg/quantstrat/man/add.indicator.Rd =================================================================== --- pkg/quantstrat/man/add.indicator.Rd 2013-03-26 19:22:56 UTC (rev 1414) +++ pkg/quantstrat/man/add.indicator.Rd 2013-03-27 14:18:03 UTC (rev 1415) @@ -101,8 +101,9 @@ appended with a number (i.e. '.ind.2', '.ind.3', etc.). If the indicator function returns multiple columns, the label will be \code{\link{paste}}'d - to either the returned column names or the respective - column number when applying it to \code{mktdata}. + to the end of either the returned column names or the + respective column number when applying it to + \code{mktdata}. } \examples{ \dontrun{ Modified: pkg/quantstrat/man/applyIndicators.Rd =================================================================== --- pkg/quantstrat/man/applyIndicators.Rd 2013-03-26 19:22:56 UTC (rev 1414) +++ pkg/quantstrat/man/applyIndicators.Rd 2013-03-27 14:18:03 UTC (rev 1415) @@ -22,9 +22,30 @@ \code{mktdata} with indicators colums added. } \description{ - apply the indicators in the strategy to arbitrary market - data + \code{applyIndicators} will take the \code{mktdata} + object, and will apply each indicator specified in the + strategy definition to it. } +\details{ + If the indicator function returns an xts object or a + vector of the same length as mktdata, the columns created + by the indicator function will be added to the mktdata + object via \code{\link{cbind}}. + + If the indicator function returns multiple columns, the + label will be \code{\link{paste}}'d to the end of either + the returned column names or the respective column number + when applying it to \code{mktdata}. + + If the indicator returns some more complexobject, it will + be added to a list in the $indicators slot inside the + \code{\link{applyStrategy}} execution frame. If you want + your indicators to return a more complex object, (such as + a model specification and output from a regression), be + advised that your signal generator, and potentially your + rule function, will need to understand, anticipate, and + know how to manipulate the internal strategy frame. +} \examples{ \dontrun{ strategy("example", store=TRUE) Modified: pkg/quantstrat/man/match.names.Rd =================================================================== --- pkg/quantstrat/man/match.names.Rd 2013-03-26 19:22:56 UTC (rev 1414) +++ pkg/quantstrat/man/match.names.Rd 2013-03-27 14:18:03 UTC (rev 1415) @@ -23,5 +23,14 @@ This small utility exists to do the matching in a centralized location so that more robust error handling and reporting can be conducted. + + The process to be followed is that first, + \code{\link{grep}} will be called without modification, + assuming that a unique match has been supplied by the + user. If this fails, a match will be attempted by + appending '$' to the regex, searching for a match at the + end of the column name, as would be constructed by the + \code{\link{paste}} in e.g. + \code{\link{applyIndicators}}. } From noreply at r-forge.r-project.org Fri Mar 29 16:40:50 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 29 Mar 2013 16:40:50 +0100 (CET) Subject: [Blotter-commits] r1416 - in pkg: blotter/R quantstrat/demo Message-ID: <20130329154050.B7840184E1A@r-forge.r-project.org> Author: braverock Date: 2013-03-29 16:40:50 +0100 (Fri, 29 Mar 2013) New Revision: 1416 Modified: pkg/blotter/R/PortfReturns.R pkg/quantstrat/demo/faber.R Log: - update PortfReturns, add daily frequency as default - update faber demo to work with new PortfReturns Modified: pkg/blotter/R/PortfReturns.R =================================================================== --- pkg/blotter/R/PortfReturns.R 2013-03-27 14:18:03 UTC (rev 1415) +++ pkg/blotter/R/PortfReturns.R 2013-03-29 15:40:50 UTC (rev 1416) @@ -11,6 +11,7 @@ #' @param \dots any other passthru parameters (like \code{native} for \code{.getBySymbol} #' @param Dates xts style ISO 8601 date subset to retrieve, default NULL (all dates) #' @param Portfolios concatenated string vector for portfolio names to retrieve returns on, default NULL (all portfolios) +#' @param period one of daily #' @note #' TODO handle portfolio and account in different currencies (not hard, just not done) #' @@ -19,11 +20,14 @@ #' TODO provide additional methods of calculating returns #' #' TODO support additions and withdrawals to available capital -PortfReturns <- function (Account, method=c('contribution'),...,Dates=NULL,Portfolios=NULL) +PortfReturns <- function (Account, method=c('contribution'),...,Dates=NULL,Portfolios=NULL,period=c('daily','none')) { # @author Brian Peterson - aname<-Account + period <- period[1] #use first + aname <- Account + if(!grepl("account\\.",aname)) Account<-try(get(paste("account",aname,sep='.'),envir=.blotter), silent=TRUE) 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.") @@ -31,23 +35,35 @@ if(is.null(Portfolios)) Portfolios = names(Account$portfolios) table=NULL - for(pname in Portfolios){ - Portfolio <- getPortfolio(pname) - if(is.null(Dates)) Dates <- paste("::",last(index(Portfolio$summary)),sep='') - ptable = .getBySymbol(Portfolio = Portfolio, Attribute = "Net.Trading.PL", Dates = Dates,...) - - #TODO check portfolio and account currencies and convert if necessary - - #TODO handle additions and withdrawals in equity - - if(!is.null(attr(Account,'initEq'))){ - initEq<-as.numeric(attr(Account,'initEq')) - if(initEq==0) stop("Initial equity of zero would produce div by zero NaN,Inf,-Inf returns, please fix in initAcct().") - ptable = ptable/initEq + + + if(period=='daily'){ + table = dailyEqPL(Portfolios = Portfolios) + } else { + for(pname in Portfolios){ + Portfolio <- getPortfolio(pname) + + if(is.null(Dates)) Dates <- paste("::",last(index(Portfolio$summary)),sep='') + + #extract + ptable = .getBySymbol(Portfolio = Portfolio, Attribute = "Net.Trading.PL", Dates = Dates,...) + ptable = PerformanceAnalytics:::zerofill(ptable) + #combine + if(is.null(table)) table=ptable + else table=cbind(table,ptable) } - if(is.null(table)) table=ptable - else table=cbind(table,ptable) } + + #TODO check portfolio and account currencies and convert if necessary + + #TODO handle additions and withdrawals in equity + + if(!is.null(attr(Account,'initEq'))){ + initEq<-as.numeric(attr(Account,'initEq')) + if(initEq==0) stop("Initial equity of zero would produce div by zero NaN,Inf,-Inf returns, please fix in initAcct().") + table = table/initEq + } + return(table) } Modified: pkg/quantstrat/demo/faber.R =================================================================== --- pkg/quantstrat/demo/faber.R 2013-03-27 14:18:03 UTC (rev 1415) +++ pkg/quantstrat/demo/faber.R 2013-03-29 15:40:50 UTC (rev 1416) @@ -140,14 +140,13 @@ } ret1 <- PortfReturns('faber') -ret1$total<-rowSums(ret1) -ret1 +View(ret1) if("package:PerformanceAnalytics" %in% search() || require("PerformanceAnalytics",quietly=TRUE)){ getSymbols("SPY", src='yahoo', index.class=c("POSIXt","POSIXct"), from='1999-01-01') SPY<-to.monthly(SPY) SPY.ret<-Return.calculate(SPY$SPY.Close) - index(SPY.ret)<-index(ret1) + index(SPY.ret)<-c(as.Date('1999-01-01'),index(ret1)) dev.new() charts.PerformanceSummary(cbind(ret1$total,SPY.ret), geometric=FALSE, wealth.index=TRUE) } From noreply at r-forge.r-project.org Fri Mar 29 16:49:43 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 29 Mar 2013 16:49:43 +0100 (CET) Subject: [Blotter-commits] r1417 - pkg/blotter Message-ID: <20130329154943.76EB6180676@r-forge.r-project.org> Author: braverock Date: 2013-03-29 16:49:43 +0100 (Fri, 29 Mar 2013) New Revision: 1417 Modified: pkg/blotter/DESCRIPTION Log: - bump version Modified: pkg/blotter/DESCRIPTION =================================================================== --- pkg/blotter/DESCRIPTION 2013-03-29 15:40:50 UTC (rev 1416) +++ pkg/blotter/DESCRIPTION 2013-03-29 15:49:43 UTC (rev 1417) @@ -2,7 +2,7 @@ Type: Package Title: Tools for transaction-oriented trading systems development. -Version: 0.8.13 +Version: 0.8.14 Date: $Date$ Author: Peter Carl, Brian G. Peterson Maintainer: Brian G. Peterson @@ -10,19 +10,19 @@ instruments, transactions, portfolios and accounts for trading systems and simulation. Provides portfolio support for multi-asset class and multi-currency - portfolios. Still in heavy development. + portfolios. Still in development. License: GPL LazyLoad: yes Depends: R (>= 2.15), xts (>= 0.7-6.17), zoo, - FinancialInstrument(>= 0.6.3) + FinancialInstrument(>= 0.6.3), + PerformanceAnalytics, + quantmod Suggests: - PerformanceAnalytics, Hmisc, RUnit, - quantmod Contributors: 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/ From noreply at r-forge.r-project.org Fri Mar 29 16:58:59 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 29 Mar 2013 16:58:59 +0100 (CET) Subject: [Blotter-commits] r1418 - pkg/quantstrat/demo Message-ID: <20130329155859.325F0180676@r-forge.r-project.org> Author: braverock Date: 2013-03-29 16:58:58 +0100 (Fri, 29 Mar 2013) New Revision: 1418 Modified: pkg/quantstrat/demo/faber.R Log: - correct for missing TZ to agree w/ newer xts req. Modified: pkg/quantstrat/demo/faber.R =================================================================== --- pkg/quantstrat/demo/faber.R 2013-03-29 15:49:43 UTC (rev 1417) +++ pkg/quantstrat/demo/faber.R 2013-03-29 15:58:58 UTC (rev 1418) @@ -45,6 +45,11 @@ # Load required libraries require(quantstrat) +#correct for TZ issues if they crop up +oldtz<-Sys.getenv('TZ') +if(oldtz=='') { + Sys.setenv(TZ="GMT") +} # Try to clean up in case the demo was run previously suppressWarnings(rm("account.faber","portfolio.faber",pos=.blotter)) suppressWarnings(rm("ltaccount", "ltportfolio", "ClosePrice", "CurrentDate", "equity", @@ -140,13 +145,14 @@ } ret1 <- PortfReturns('faber') +ret1$total<-rowSums(ret1) View(ret1) if("package:PerformanceAnalytics" %in% search() || require("PerformanceAnalytics",quietly=TRUE)){ getSymbols("SPY", src='yahoo', index.class=c("POSIXt","POSIXct"), from='1999-01-01') SPY<-to.monthly(SPY) SPY.ret<-Return.calculate(SPY$SPY.Close) - index(SPY.ret)<-c(as.Date('1999-01-01'),index(ret1)) + index(SPY.ret)<-index(ret1) dev.new() charts.PerformanceSummary(cbind(ret1$total,SPY.ret), geometric=FALSE, wealth.index=TRUE) } @@ -154,6 +160,7 @@ faber.stats<-tradeStats('faber')[,c('Net.Trading.PL','Max.Drawdown','Num.Trades','Profit.Factor','Std.Dev.Trade.PL','Largest.Winner','Largest.Loser','Max.Equity','Min.Equity')] faber.stats +Sys.setenv(TZ=oldtz) ############################################################################### # R (http://r-project.org/) Quantitative Strategy Model Framework #