From noreply at r-forge.r-project.org Sat Nov 1 21:32:11 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 1 Nov 2014 21:32:11 +0100 (CET) Subject: [Blotter-commits] r1644 - in pkg/blotter: . R man Message-ID: <20141101203211.D1E681877E9@r-forge.r-project.org> Author: braverock Date: 2014-11-01 21:32:11 +0100 (Sat, 01 Nov 2014) New Revision: 1644 Modified: pkg/blotter/DESCRIPTION pkg/blotter/R/addTxn.R pkg/blotter/man/addTxn.Rd pkg/blotter/man/pennyPerShare.Rd Log: - resolves R-Forge feature request 5968 by adding arguments to TxnFees fn Modified: pkg/blotter/DESCRIPTION =================================================================== --- pkg/blotter/DESCRIPTION 2014-10-27 21:06:03 UTC (rev 1643) +++ pkg/blotter/DESCRIPTION 2014-11-01 20:32:11 UTC (rev 1644) @@ -2,7 +2,7 @@ Type: Package Title: Tools for transaction-oriented trading systems development. -Version: 0.9.1643 +Version: 0.9.1644 Date: $Date$ Author: Peter Carl, Brian G. Peterson Maintainer: Brian G. Peterson Modified: pkg/blotter/R/addTxn.R =================================================================== --- pkg/blotter/R/addTxn.R 2014-10-27 21:06:03 UTC (rev 1643) +++ pkg/blotter/R/addTxn.R 2014-11-01 20:32:11 UTC (rev 1644) @@ -34,6 +34,12 @@ #' have "TxnQty" and "TxnPrice" columns, while the "TxnFees" #' column is optional. #' +#' If \code{TxnFees} is the name of a function, the function +#' will be called with \code{TxnFees(TxnQty, TxnPrice, Symbol)} +#' so a user supplied fee function must at the very least take +#' dots to avoid an error. We have chosen not to use named arguments +#' to reduce issues from user-supplied fee functions. +#' #' @param Portfolio A portfolio name that points to a portfolio object structured with \code{initPortf()} #' @param Symbol An instrument identifier for a symbol included in the portfolio, e.g., "IBM" #' @param TxnDate Transaction date as ISO 8601, e.g., '2008-09-01' or '2010-01-05 09:54:23.12345' @@ -98,8 +104,12 @@ if (!inherits(TF,"try-error")) TxnFees<-TF } # Compute transaction fees if a function was supplied - if (is.function(TxnFees)) txnfees <- TxnFees(TxnQty, TxnPrice) else txnfees<- as.numeric(TxnFees) - + if (is.function(TxnFees)) { + txnfees <- TxnFees(TxnQty, TxnPrice, Symbol) + } else { + txnfees<- as.numeric(TxnFees) + } + if(is.null(txnfees) | is.na(txnfees)) txnfees = 0 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.') @@ -141,8 +151,9 @@ #' Example TxnFee cost function #' @param TxnQty total units (such as shares or contracts) transacted. Positive values indicate a 'buy'; negative values indicate a 'sell' #' This is an example intended to demonstrate how a cost function could be used in place of a flat numeric fee. +#' @param \dots any other passthrough parameters #' @export -pennyPerShare <- function(TxnQty) { +pennyPerShare <- function(TxnQty, ...) { return(abs(TxnQty) * -0.01) } Modified: pkg/blotter/man/addTxn.Rd =================================================================== --- pkg/blotter/man/addTxn.Rd 2014-10-27 21:06:03 UTC (rev 1643) +++ pkg/blotter/man/addTxn.Rd 2014-11-01 20:32:11 UTC (rev 1644) @@ -70,6 +70,12 @@ adding them one at a time. The \code{TxnData} object must have "TxnQty" and "TxnPrice" columns, while the "TxnFees" column is optional. + +If \code{TxnFees} is the name of a function, the function +will be called with \code{TxnFees(TxnQty, TxnPrice, Symbol)} +so a user supplied fee function must at the very least take +dots to avoid an error. We have chosen not to use named arguments +to reduce issues from user-supplied fee functions. } \note{ The addTxn function will eventually also handle other transaction types, Modified: pkg/blotter/man/pennyPerShare.Rd =================================================================== --- pkg/blotter/man/pennyPerShare.Rd 2014-10-27 21:06:03 UTC (rev 1643) +++ pkg/blotter/man/pennyPerShare.Rd 2014-11-01 20:32:11 UTC (rev 1644) @@ -3,11 +3,13 @@ \alias{pennyPerShare} \title{Example TxnFee cost function} \usage{ -pennyPerShare(TxnQty) +pennyPerShare(TxnQty, ...) } \arguments{ \item{TxnQty}{total units (such as shares or contracts) transacted. Positive values indicate a 'buy'; negative values indicate a 'sell' This is an example intended to demonstrate how a cost function could be used in place of a flat numeric fee.} + +\item{\dots}{any other passthrough parameters} } \description{ Example TxnFee cost function From noreply at r-forge.r-project.org Thu Nov 6 21:05:03 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 6 Nov 2014 21:05:03 +0100 (CET) Subject: [Blotter-commits] r1645 - pkg/quantstrat/R Message-ID: <20141106200503.C3C9F187ABF@r-forge.r-project.org> Author: bodanker Date: 2014-11-06 21:05:03 +0100 (Thu, 06 Nov 2014) New Revision: 1645 Modified: pkg/quantstrat/R/rules.R Log: - Fix #5978; thanks to Jonathan Owen for the report and patch Modified: pkg/quantstrat/R/rules.R =================================================================== --- pkg/quantstrat/R/rules.R 2014-11-01 20:32:11 UTC (rev 1644) +++ pkg/quantstrat/R/rules.R 2014-11-06 20:05:03 UTC (rev 1645) @@ -88,11 +88,11 @@ tmp_rule<-list() if(!is.function(name) && isTRUE(storefun)) { if(!is.function(get(name))){ - if(!is.function(get(paste("sig",name,sep='.')))){ + if(!is.function(get(paste("rule",name,sep='.')))){ message(paste("Skipping rule",name,"because there is no function by that name to call")) next() } else { - name<-paste("sig",rule$name,sep='.') + name<-paste("rule",rule$name,sep='.') } } fn<-match.fun(name) @@ -649,11 +649,11 @@ if (!rule$path.dep==path.dep) next() if(!is.function(rule$name)) { if(!is.function(get(rule$name))){ - if(!is.function(get(paste("sig",rule$name,sep='.')))){ + if(!is.function(get(paste("rule",rule$name,sep='.')))){ message(paste("Skipping rule",rule$name,"because there is no function by that name to call")) next() } else { - rule$name<-paste("sig",rule$name,sep='.') + rule$name<-paste("rule",rule$name,sep='.') } } } From noreply at r-forge.r-project.org Fri Nov 7 21:50:12 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 7 Nov 2014 21:50:12 +0100 (CET) Subject: [Blotter-commits] r1646 - pkg/blotter/R Message-ID: <20141107205012.30E50187294@r-forge.r-project.org> Author: bodanker Date: 2014-11-07 21:50:11 +0100 (Fri, 07 Nov 2014) New Revision: 1646 Modified: pkg/blotter/R/updatePosPL.R Log: - Fix .updatePosPL when it's called with only one date and price Modified: pkg/blotter/R/updatePosPL.R =================================================================== --- pkg/blotter/R/updatePosPL.R 2014-11-06 20:05:03 UTC (rev 1645) +++ pkg/blotter/R/updatePosPL.R 2014-11-07 20:50:11 UTC (rev 1646) @@ -105,6 +105,9 @@ #first price is NA, it would be nice to fill it in with a previous last valid price fprice <- last(prices[paste('::',startDate,sep='')]) if (length(fprice)==1) tmpPL[1,'Prices'] <- fprice + # if there's no previous valid price, calculate it from the prior position value + # (can occur if .updatePosPL is called repeatedly with only one date/price) + if (length(fprice)==0) tmpPL[1,'Prices'] <- priorPL[,'Pos.Value'] / priorPL[,'Pos.Qty'] } # na.locf any missing prices with last observation (this assumption seems the only rational one for vectorization) # and na.locf Pos.Qty,Con.Mult,Pos.Avg.Cost to instantiate $posPL new rows From noreply at r-forge.r-project.org Wed Nov 12 15:56:21 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 12 Nov 2014 15:56:21 +0100 (CET) Subject: [Blotter-commits] r1647 - pkg/blotter/R Message-ID: <20141112145621.CACD11874AE@r-forge.r-project.org> Author: bodanker Date: 2014-11-12 15:56:21 +0100 (Wed, 12 Nov 2014) New Revision: 1647 Modified: pkg/blotter/R/updateAcct.R Log: - Fix #5983 typo/bug (not sure if this is a complete fix) Modified: pkg/blotter/R/updateAcct.R =================================================================== --- pkg/blotter/R/updateAcct.R 2014-11-07 20:50:11 UTC (rev 1646) +++ pkg/blotter/R/updateAcct.R 2014-11-12 14:56:21 UTC (rev 1647) @@ -122,7 +122,7 @@ result = if(on=="none") as.xts(sum(Account$Withdrawals[paste("::",obsDates, sep="")]), order.by=index(table)) else{ - if(length(Account$Additions[obsDates])>0) # catch empty sets + if(length(Account$Withdrawals[obsDates])>0) # catch empty sets period.apply(Account$Withdrawals[obsDates], endpoints(Account$Withdrawals[obsDates], on=periodicity(table)$units), sum) else xts(rep(0,obsLength),order.by=obsDates) @@ -132,7 +132,7 @@ result = if(on=="none") as.xts(sum(Account$Interest[paste("::",obsDates, sep="")]),, order.by=index(table)) else{ - if(length(Account$Additions[obsDates])>0) # catch empty sets + if(length(Account$Interest[obsDates])>0) # catch empty sets period.apply(Account$Interest[obsDates], endpoints(Account$Interest[obsDates], on=periodicity(table)$units), sum) else xts(rep(0,obsLength),order.by=obsDates) From noreply at r-forge.r-project.org Tue Nov 18 22:47:57 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 18 Nov 2014 22:47:57 +0100 (CET) Subject: [Blotter-commits] r1648 - in pkg/quantstrat: . man sandbox sandbox/backtest_musings Message-ID: <20141118214757.3625E1876E8@r-forge.r-project.org> Author: braverock Date: 2014-11-18 22:47:56 +0100 (Tue, 18 Nov 2014) New Revision: 1648 Added: pkg/quantstrat/sandbox/backtest_musings/ pkg/quantstrat/sandbox/backtest_musings/.directory pkg/quantstrat/sandbox/backtest_musings/MAE.png pkg/quantstrat/sandbox/backtest_musings/Notes_S_Rush_2014-10-10.txt pkg/quantstrat/sandbox/backtest_musings/OOS_det.png pkg/quantstrat/sandbox/backtest_musings/boxplot.png pkg/quantstrat/sandbox/backtest_musings/building_blocks.png pkg/quantstrat/sandbox/backtest_musings/cc-by-nc-sa.pdf pkg/quantstrat/sandbox/backtest_musings/gamlss.png pkg/quantstrat/sandbox/backtest_musings/gd_pres_backtest.Rmd pkg/quantstrat/sandbox/backtest_musings/gd_pres_backtest.pdf pkg/quantstrat/sandbox/backtest_musings/histogram.png pkg/quantstrat/sandbox/backtest_musings/hypothesis_process.pdf pkg/quantstrat/sandbox/backtest_musings/idea_funnel.svg pkg/quantstrat/sandbox/backtest_musings/param_region.png pkg/quantstrat/sandbox/backtest_musings/resampling1.png pkg/quantstrat/sandbox/backtest_musings/stat_process.bib pkg/quantstrat/sandbox/backtest_musings/strat_dev_proc_Kent_notes_2014-09-21.txt pkg/quantstrat/sandbox/backtest_musings/strat_dev_process.Rmd pkg/quantstrat/sandbox/backtest_musings/strat_dev_process.diff.Rmd pkg/quantstrat/sandbox/backtest_musings/strat_dev_process.pdf pkg/quantstrat/sandbox/backtest_musings/walk_forward_chart.png pkg/quantstrat/sandbox/backtest_musings/walk_forward_gantt.png Modified: pkg/quantstrat/ pkg/quantstrat/DESCRIPTION pkg/quantstrat/NAMESPACE pkg/quantstrat/man/add.distribution.Rd pkg/quantstrat/man/add.distribution.constraint.Rd pkg/quantstrat/man/add.indicator.Rd pkg/quantstrat/man/add.init.Rd pkg/quantstrat/man/add.rule.Rd pkg/quantstrat/man/add.signal.Rd pkg/quantstrat/man/addOrder.Rd pkg/quantstrat/man/addPosLimit.Rd pkg/quantstrat/man/apply.paramset.Rd pkg/quantstrat/man/applyIndicators.Rd pkg/quantstrat/man/applyParameter.Rd pkg/quantstrat/man/applyRules.Rd pkg/quantstrat/man/applySignals.Rd pkg/quantstrat/man/applyStrategy.Rd pkg/quantstrat/man/applyStrategy.rebalancing.Rd pkg/quantstrat/man/chart.forward.Rd pkg/quantstrat/man/chart.forward.training.Rd pkg/quantstrat/man/delete.paramset.Rd pkg/quantstrat/man/enable.rule.Rd pkg/quantstrat/man/get.strategy.Rd pkg/quantstrat/man/getOrderBook.Rd pkg/quantstrat/man/getOrders.Rd pkg/quantstrat/man/getParameterTable.Rd pkg/quantstrat/man/getPosLimit.Rd pkg/quantstrat/man/initOrders.Rd pkg/quantstrat/man/initStrategy.Rd pkg/quantstrat/man/is.strategy.Rd pkg/quantstrat/man/load.strategy.Rd pkg/quantstrat/man/match.names.Rd pkg/quantstrat/man/osMaxPos.Rd pkg/quantstrat/man/osNoOp.Rd pkg/quantstrat/man/paramConstraint.Rd pkg/quantstrat/man/put.orderbook.Rd pkg/quantstrat/man/put.strategy.Rd pkg/quantstrat/man/rm.strat.Rd pkg/quantstrat/man/ruleOrderProc.Rd pkg/quantstrat/man/rulePctEquity.Rd pkg/quantstrat/man/ruleRevoke.Rd pkg/quantstrat/man/ruleSignal.Rd pkg/quantstrat/man/save.strategy.Rd pkg/quantstrat/man/setParameterConstraint.Rd pkg/quantstrat/man/setParameterDistribution.Rd pkg/quantstrat/man/sigComparison.Rd pkg/quantstrat/man/sigCrossover.Rd pkg/quantstrat/man/sigFormula.Rd pkg/quantstrat/man/sigPeak.Rd pkg/quantstrat/man/sigThreshold.Rd pkg/quantstrat/man/sigTimestamp.Rd pkg/quantstrat/man/strategy.Rd pkg/quantstrat/man/tradeGraphs.Rd pkg/quantstrat/man/tradeOrderStats.Rd pkg/quantstrat/man/updateOrders.Rd pkg/quantstrat/man/updateStrategy.Rd pkg/quantstrat/man/walk.forward.Rd Log: - add backtest musings sandbox dir - update roxygen docs Property changes on: pkg/quantstrat ___________________________________________________________________ Added: svn:ignore + .Rproj.user .Rhistory .RData Modified: pkg/quantstrat/DESCRIPTION =================================================================== --- pkg/quantstrat/DESCRIPTION 2014-11-12 14:56:21 UTC (rev 1647) +++ pkg/quantstrat/DESCRIPTION 2014-11-18 21:47:56 UTC (rev 1648) @@ -1,7 +1,7 @@ Package: quantstrat Type: Package Title: Quantitative Strategy Model Framework -Version: 0.9.1632 +Version: 0.9.1648 Date: $Date$ Author: Peter Carl, Brian G. Peterson, Joshua Ulrich, Jan Humme Depends: Modified: pkg/quantstrat/NAMESPACE =================================================================== --- pkg/quantstrat/NAMESPACE 2014-11-12 14:56:21 UTC (rev 1647) +++ pkg/quantstrat/NAMESPACE 2014-11-18 21:47:56 UTC (rev 1648) @@ -1,3 +1,5 @@ +# Generated by roxygen2 (4.0.2): do not edit by hand + export(add.distribution) export(add.distribution.constraint) export(add.indicator) @@ -13,7 +15,7 @@ export(applySignals) export(applyStrategy) export(applyStrategy.rebalancing) -#export(applyStrategy.rebalancing.training) +export(applyStrategy.rebalancing.training) export(chart.forward) export(chart.forward.training) export(delete.paramset) @@ -27,6 +29,7 @@ export(getStrategy) export(initOrders) export(initStrategy) +export(initSymbol) export(is.strategy) export(load.strategy) export(match.names) Modified: pkg/quantstrat/man/add.distribution.Rd =================================================================== --- pkg/quantstrat/man/add.distribution.Rd 2014-11-12 14:56:21 UTC (rev 1647) +++ pkg/quantstrat/man/add.distribution.Rd 2014-11-18 21:47:56 UTC (rev 1648) @@ -1,3 +1,4 @@ +% Generated by roxygen2 (4.0.2): do not edit by hand \name{add.distribution} \alias{add.distribution} \title{Adds a distribution to a paramset in a strategy} @@ -6,39 +7,30 @@ variable, weight = NULL, label, store = TRUE) } \arguments{ - \item{strategy}{the name of the strategy object to add - the distribution to} +\item{strategy}{the name of the strategy object to add the distribution to} - \item{paramset.label}{a label uniquely identifying the - paramset within the strategy} +\item{paramset.label}{a label uniquely identifying the paramset within the strategy} - \item{component.type}{one of c('indicator', 'signal', - 'order', 'enter', 'exit', 'chain')} +\item{component.type}{one of c('indicator', 'signal', 'order', 'enter', 'exit', 'chain')} - \item{component.label}{a label identifying the component. - must be unique per component type} +\item{component.label}{a label identifying the component. must be unique per component type} - \item{variable}{the name of the variable in the - component} +\item{variable}{the name of the variable in the component} - \item{label}{a label uniquely identifying the - distribution within the paramset} +\item{weight}{vector} - \item{weight}{vector} +\item{label}{a label uniquely identifying the distribution within the paramset} - \item{store}{indicates whether to store the strategy in - the .strategy environment} +\item{store}{indicates whether to store the strategy in the .strategy environment} } \description{ -Creates a distribution in paramset, where a distribution -consists of the name of a variable in a strategy component -plus a range of values for this variable. +Creates a distribution in paramset, where a distribution consists of the name of a variable in +a strategy component plus a range of values for this variable. } \author{ Jan Humme } \seealso{ -\code{\link{add.distribution.constraint}}, -\code{\link{delete.paramset}}, \code{\link{apply.paramset}} +\code{\link{add.distribution.constraint}}, \code{\link{delete.paramset}}, \code{\link{apply.paramset}} } Modified: pkg/quantstrat/man/add.distribution.constraint.Rd =================================================================== --- pkg/quantstrat/man/add.distribution.constraint.Rd 2014-11-12 14:56:21 UTC (rev 1647) +++ pkg/quantstrat/man/add.distribution.constraint.Rd 2014-11-18 21:47:56 UTC (rev 1648) @@ -1,3 +1,4 @@ +% Generated by roxygen2 (4.0.2): do not edit by hand \name{add.distribution.constraint} \alias{add.distribution.constraint} \title{Adds a constraint on 2 distributions within a paramset} @@ -6,37 +7,28 @@ distribution.label.2, operator, label, store = TRUE) } \arguments{ - \item{strategy}{the name of the strategy object to add - the constraint to} +\item{strategy}{the name of the strategy object to add the constraint to} - \item{paramset.label}{a label uniquely identifying the - paramset within the strategy} +\item{paramset.label}{a label uniquely identifying the paramset within the strategy} - \item{distribution.label.1}{a label identifying the first - distribution} +\item{distribution.label.1}{a label identifying the first distribution} - \item{distribution.label.2}{a label identifying the - second distribution} +\item{distribution.label.2}{a label identifying the second distribution} - \item{operator}{an operator specifying the relational - constraint between the 2 distributions} +\item{operator}{an operator specifying the relational constraint between the 2 distributions} - \item{label}{a label uniquely identifying the constraint - within the paramset} +\item{label}{a label uniquely identifying the constraint within the paramset} - \item{store}{indicates whether to store the strategy in - the .strategy environment} +\item{store}{indicates whether to store the strategy in the .strategy environment} } \description{ -Creates a constraint on 2 distributions in a paramset, i.e. -a restriction limiting the allowed combinations from the -ranges for distribution 1 and distribution 2. +Creates a constraint on 2 distributions in a paramset, i.e. a restriction limiting the allowed +combinations from the ranges for distribution 1 and distribution 2. } \author{ Jan Humme } \seealso{ -\code{\link{add.distribution}}, -\code{\link{delete.paramset}}, \code{\link{apply.paramset}} +\code{\link{add.distribution}}, \code{\link{delete.paramset}}, \code{\link{apply.paramset}} } Modified: pkg/quantstrat/man/add.indicator.Rd =================================================================== --- pkg/quantstrat/man/add.indicator.Rd 2014-11-12 14:56:21 UTC (rev 1647) +++ pkg/quantstrat/man/add.indicator.Rd 2014-11-18 21:47:56 UTC (rev 1648) @@ -1,3 +1,4 @@ +% Generated by roxygen2 (4.0.2): do not edit by hand \name{add.indicator} \alias{add.indicator} \title{add an indicator to a strategy} @@ -6,101 +7,67 @@ ..., enabled = TRUE, indexnum = NULL, store = FALSE) } \arguments{ - \item{strategy}{an object (or the name of an object) type - 'strategy' to add the indicator to} +\item{strategy}{an object (or the name of an object) type 'strategy' to add the indicator to} - \item{name}{name of the indicator function -- must - correspond to an R function} +\item{name}{name of the indicator function -- must correspond to an R function} - \item{arguments}{default arguments to be passed to an - indicator function when executed} +\item{arguments}{default arguments to be passed to an indicator function when executed} - \item{parameters}{vector of strings naming parameters to - be saved for apply-time definition,default NULL, only - needed if you need special names to avoid argument - collision} +\item{parameters}{vector of strings naming parameters to be saved for apply-time definition,default NULL, only needed if you need special names to avoid argument collision} - \item{label}{arbitrary text label for indicator output. - This will also be used as the name of the indicator list - when it is stored. NULL default will be converted to - '.ind'} +\item{label}{arbitrary text label for indicator output. This will also be used as the +name of the indicator list when it is stored. NULL default will be converted to '.ind'} - \item{...}{any other passthru parameters} +\item{...}{any other passthru parameters} - \item{enabled}{TRUE/FALSE whether the indicator is - enabled for use in applying the strategy, default TRUE} +\item{enabled}{TRUE/FALSE whether the indicator is enabled for use in applying the strategy, default TRUE} - \item{indexnum}{if you are updating a specific indicator, - the \code{label} or the index number in the $indicators - list to update.} +\item{indexnum}{if you are updating a specific indicator, the \code{label} or the index number in the $indicators list to update.} - \item{store}{TRUE/FALSE whether to store the strategy in - the .strategy environment, or return it. default FALSE} +\item{store}{TRUE/FALSE whether to store the strategy in the .strategy environment, or return it. default FALSE} } \value{ -if \code{strategy} was the name of a strategy, the name. It -it was a strategy, the updated strategy. +if \code{strategy} was the name of a strategy, the name. It it was a strategy, the updated strategy. } \description{ -Indicators are typically standard technical or statistical -analysis outputs, such as moving averages, bands, or -pricing models. +Indicators are typically standard technical or statistical analysis outputs, +such as moving averages, bands, or pricing models. } \details{ -Indicators are always path-independent, and should be -constructed from vectorized functions where possible. +Indicators are always path-independent, and should be constructed from vectorized functions where possible. -Indicators are applied before signals and rules, and the -output of indicators may be used as inputs to construct -signals or fire rules. +Indicators are applied before signals and rules, and the output of indicators +may be used as inputs to construct signals or fire rules. -\code{arguments} and \code{parameters} are named lists that -describe the arguments to be passed to the indicator -function. \code{arguments} is for defining any non-default -arguments to be passed to the function named in the -\code{name} of the indicator. For example, the \code{x} -argument to a moving average function may be defined as -\code{x=quote(Cl(mktdata))} +\code{arguments} and \code{parameters} are named lists that describe the arguments to be passed to the indicator function. +\code{arguments} is for defining any non-default arguments to be passed to the function named in the \code{name} of the indicator. +For example, the \code{x} argument to a moving average function may be defined as \code{x=quote(Cl(mktdata))} -If you look at the demo scripts, you'll notice that we -often use \code{quote(mktdata)} in setting up indicators, -signals, or rules. This tells \R to delay evaluation via -\code{quote()}, and to use the special variable -\code{mktdata}. +If you look at the demo scripts, you'll notice that we often use \code{quote(mktdata)} in setting up indicators, signals, or rules. +This tells \R to delay evaluation via \code{quote()}, and to use the special variable \code{mktdata}. -\code{mktdata} is typically created internally to -\code{quantstrat} by looking in the global environment for -a time series of prices or returns. mktdata may also -contain other data you've manipulated outside quantstrat, -though where possible you should use quantstrat to contain -all the logic for the strategy, to aid in maintenance and -modifications. +\code{mktdata} is typically created internally to \code{quantstrat} by looking in the global environment for +a time series of prices or returns. mktdata may also contain other data you've manipulated outside quantstrat, +though where possible you should use quantstrat to contain all the logic for the strategy, +to aid in maintenance and modifications. -The use of \code{quote()} tells R to not evaluate what's -inside the quote until the function is evaluated later. By -the time that code is evaluated, \code{mktdata} will be -populated with the correct price information based on the -contents of whatever portfolio you are evaluating the -strategy on. +The use of \code{quote()} tells R to not evaluate what's inside the quote until the function is evaluated later. +By the time that code is evaluated, \code{mktdata} will be populated with the correct price information based on the contents of whatever portfolio you are evaluating the strategy on. -\code{parameters} is another named list, and normally will -not be needed. If you have multiple indicator, signal, or -rule functions share the that \emph{both} share the same -argument names \emph{and} will need to have different -values passed to those arguments as defined parameters at -apply-time, then you may need to give them unique names so -that delayed evaluation can sort it all out for you at -apply-time. We will endeavor to get an example of named -parameters into the demo scripts. +\code{parameters} is another named list, and normally will not be needed. +If you have multiple indicator, signal, or rule functions share the that +\emph{both} share the same argument names \emph{and} will need to have +different values passed to those arguments as defined parameters at apply-time, +then you may need to give them unique names so that delayed evaluation can +sort it all out for you at apply-time. +We will endeavor to get an example of named parameters into the demo scripts. -if \code{label} is not supplied, NULL default will be -converted to '.ind' unless there already exists an -indicator with that label in which case it will be appended +if \code{label} is not supplied, NULL default will be converted to '.ind' unless +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 the end of either -the returned column names or the respective column number -when applying it to \code{mktdata}. +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}. } \examples{ \dontrun{ @@ -113,7 +80,9 @@ } } \seealso{ -\code{\link{quote}} \code{\link{applyIndicators}} -\code{\link{add.signal}} \code{link{add.rule}} +\code{\link{quote}} +\code{\link{applyIndicators}} +\code{\link{add.signal}} +\code{link{add.rule}} } Modified: pkg/quantstrat/man/add.init.Rd =================================================================== --- pkg/quantstrat/man/add.init.Rd 2014-11-12 14:56:21 UTC (rev 1647) +++ pkg/quantstrat/man/add.init.Rd 2014-11-18 21:47:56 UTC (rev 1648) @@ -1,3 +1,4 @@ +% Generated by roxygen2 (4.0.2): do not edit by hand \name{add.init} \alias{add.init} \title{add arbitrary initialization functions to a strategy} @@ -6,55 +7,39 @@ enabled = TRUE, indexnum = NULL, store = FALSE) } \arguments{ - \item{strategy}{an object (or the name of an object) of - type 'strategy' to add the init function definition to} +\item{strategy}{an object (or the name of an object) of type 'strategy' to add the init function definition to} - \item{name}{name of the init, must correspond to an R - function} +\item{name}{name of the init, must correspond to an R function} - \item{arguments}{named list of default arguments to be - passed to an init function when executed} +\item{arguments}{named list of default arguments to be passed to an init function when executed} - \item{parameters}{vector of strings naming parameters to - be saved for apply-time definition,default NULL, only - needed if you need special names to avoid argument - collision} +\item{parameters}{vector of strings naming parameters to be saved for apply-time definition,default NULL, only needed if you need special names to avoid argument collision} - \item{label}{arbitrary text label for init output, - default NULL} +\item{label}{arbitrary text label for init output, default NULL} - \item{...}{any other passthru parameters} +\item{...}{any other passthru parameters} - \item{enabled}{TRUE/FALSE whether the init is enabled for - use in applying the strategy, default TRUE} +\item{enabled}{TRUE/FALSE whether the init is enabled for use in applying the strategy, default TRUE} - \item{indexnum}{if you are updating a specific init, the - index number in the $init list to update} +\item{indexnum}{if you are updating a specific init, the index number in the $init list to update} - \item{store}{TRUE/FALSE whether to store the strategy in - the .strategy environment, or return it. default FALSE} +\item{store}{TRUE/FALSE whether to store the strategy in the .strategy environment, or return it. default FALSE} } \value{ -if \code{strategy} was the name of a strategy, the name. It -it was a strategy, the updated strategy. +if \code{strategy} was the name of a strategy, the name. It it was a strategy, the updated strategy. } \description{ -\code{\link{initStrategy}} will run a series of common -initialization functions at the beginning of an -\code{\link{applyStrategy}} call. This function allows the -user to add arbitrary initialization functions to the -sequence. +\code{\link{initStrategy}} will run a series of common initialization functions at the +beginning of an \code{\link{applyStrategy}} call. This function allows the user to +add arbitrary initialization functions to the sequence. } \details{ -These arbitrary functions will be added to the \code{init} -slot of the strategy object and when \code{applyStrategy} -is evaluated, the arbitrary initialization functions will +These arbitrary functions will be added to the \code{init} slot of the strategy object +and when \code{applyStrategy} is evaluated, the arbitrary initialization functions will be evaluated after the standardized functions. -For example, if your strategy uses a synthetic basket -instrument, you could use this initialization slot to add a -custom constructor to build the basket instrument time -series and modify the symbols slot(s) of the strategy and -portfolio. +For example, if your strategy uses a synthetic basket instrument, you could use this +initialization slot to add a custom constructor to build the basket instrument time +series and modify the symbols slot(s) of the strategy and portfolio. } Modified: pkg/quantstrat/man/add.rule.Rd =================================================================== --- pkg/quantstrat/man/add.rule.Rd 2014-11-12 14:56:21 UTC (rev 1647) +++ pkg/quantstrat/man/add.rule.Rd 2014-11-18 21:47:56 UTC (rev 1648) @@ -1,3 +1,4 @@ +% Generated by roxygen2 (4.0.2): do not edit by hand \name{add.rule} \alias{add.rule} \title{add a rule to a strategy} @@ -8,131 +9,95 @@ timespan = NULL, store = FALSE, storefun = TRUE) } \arguments{ - \item{strategy}{an object of type 'strategy' to add the - rule to} +\item{strategy}{an object of type 'strategy' to add the rule to} - \item{name}{name of the rule, must correspond to an R - function} +\item{name}{name of the rule, must correspond to an R function} - \item{arguments}{named list of default arguments to be - passed to an rule function when executed} +\item{arguments}{named list of default arguments to be passed to an rule function when executed} - \item{parameters}{vector of strings naming parameters to - be saved for apply-time definition} +\item{parameters}{vector of strings naming parameters to be saved for apply-time definition} - \item{label}{arbitrary text label for rule output, NULL - default will be converted to '.rule'} +\item{label}{arbitrary text label for rule output, NULL default will be converted to '.rule'} - \item{type}{one of - "risk","order","rebalance","exit","enter","chain" see - Details} +\item{type}{one of "risk","order","rebalance","exit","enter","chain" see Details} - \item{parent}{the label of the parent rule for a chain - rule} +\item{parent}{the label of the parent rule for a chain rule} - \item{...}{any other passthru parameters} +\item{...}{any other passthru parameters} - \item{enabled}{TRUE/FALSE whether the rule is enabled for - use in applying the strategy, default TRUE} +\item{enabled}{TRUE/FALSE whether the rule is enabled for use in applying the strategy, default TRUE} - \item{indexnum}{if you are updating a specific rule, the - index number in the $rules[type] list to update} +\item{indexnum}{if you are updating a specific rule, the index number in the $rules[type] list to update} - \item{path.dep}{TRUE/FALSE whether rule is path - dependent, default TRUE, see Details} +\item{path.dep}{TRUE/FALSE whether rule is path dependent, default TRUE, see Details} - \item{timespan}{an xts/ISO-8601 style \emph{time} subset, - like "T08:00/T15:00", see Details} +\item{timespan}{an xts/ISO-8601 style \emph{time} subset, like "T08:00/T15:00", see Details} - \item{store}{TRUE/FALSE whether to store the strategy in - the .strategy environment, or return it. default FALSE} +\item{store}{TRUE/FALSE whether to store the strategy in the .strategy environment, or return it. default FALSE} - \item{storefun}{TRUE/FALSE whether to store the function - in the rule, default TRUE. setting this option to FALSE - may slow the backtest, but makes \code{\link{debug}} - usable} +\item{storefun}{TRUE/FALSE whether to store the function in the rule, default TRUE. setting this option to FALSE may slow the backtest, but makes \code{\link{debug}} usable} } \value{ -if \code{strategy} was the name of a strategy, the name. It -it was a strategy, the updated strategy. +if \code{strategy} was the name of a strategy, the name. It it was a strategy, the updated strategy. } \description{ -Rules will be processed in a very particular manner, so it -bears going over. +Rules will be processed in a very particular manner, so it bears going over. } \details{ -First, rules are either path dependent or -non-path-dependent. Path dependent rules will be processed -in every time increment for the \code{mktdata} passed into -\code{\link{applyStrategy}}. Non path dependent rules will -likely be quite rare in real life, and will be applied -after indicators and signals, and before path-dependent -rules are processed. +First, rules are either path dependent or non-path-dependent. Path dependent rules +will be processed in every time increment for the \code{mktdata} passed into +\code{\link{applyStrategy}}. Non path dependent rules will likely be quite rare in real life, +and will be applied after indicators and signals, and before path-dependent rules are processed. All rules have a \code{type}. These may be any of: -\describe{ \item{risk}{ rules that check and react to risk -of positions, may stop all other rule execution temporarily -or permanently} \item{order}{ rules for order processing of -any open orders at time t, always path-dependent} -\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 an order corresponding to the label of the parent rule -identified by the \code{parent} arg. } } +\describe{ + \item{risk}{ rules that check and react to risk of positions, may stop all other rule execution temporarily or permanently} + \item{order}{ rules for order processing of any open orders at time t, always path-dependent} + \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 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 with -signals and indicators, they will be executed in order by -index number with any other rules sharing the same type. +The rules will be executed by type, in the order listed above. +Multiple rules of each type may be defined, as with signals and indicators, +they will be executed in order by index number with any other rules sharing the same +type. -The rule execution order was constructed because -path-dependent rules may modify the ability of rules that -have not fired yet to be evaluated. For example, a risk -rule may flatten (close out) an entire position and put new -orders on hold, effectively stopping all further execution -of the strategy. Another example would be a rebalancing -rule function that would enter orders to rebalance the -portfolio, and would hold other strategy processing until -the rebalancing period was over. +The rule execution order was constructed because path-dependent rules may modify +the ability of rules that have not fired yet to be evaluated. For example, a +risk rule may flatten (close out) an entire position and put new orders +on hold, effectively stopping all further execution of the strategy. +Another example would be a rebalancing rule function that would enter +orders to rebalance the portfolio, and would hold other strategy processing +until the rebalancing period was over. -The \code{timespan} parameter will limit rule execution by -time of day using time based subsetting. See ISO-8601 -specification and xts documentation for more details. Note -that these are only applicable to intra-day execution, and -will remain that way barring patches (tests and -documentation) from interested parties. The subsetting may -(will likely) work with normal ISO/xts subset ranges, but -consider it unsupported. +The \code{timespan} parameter will limit rule execution by time of day using +time based subsetting. See ISO-8601 specification and xts documentation for +more details. Note that these are only applicable to intra-day execution, +and will remain that way barring patches (tests and documentation) from +interested parties. The subsetting may (will likely) work with normal +ISO/xts subset ranges, but consider it unsupported. -The \code{name} parameter should be a character string -naming the function to be called in the -\code{\link{applyRules}} loop. The \code{add.rule} function -will then call \code{\link{match.fun}}, ands store the -actual function in your strategy object. This will avoid -lookups via \code{\link{match.fun}} at -\code{\link{applyRules}} time, and may provide a -significant speed increase on higher frequency data (20\% -or more). +The \code{name} parameter should be a character string naming the function +to be called in the \code{\link{applyRules}} loop. The \code{add.rule} +function will then call \code{\link{match.fun}}, ands store the actual function +in your strategy object. +This will avoid lookups via \code{\link{match.fun}} at \code{\link{applyRules}} time, +and may provide a significant speed increase on higher frequency data (20\% or more). -We anticipate that rules will be the portion of a strategy -most likely to not have suitable template code included -with this package, as every strategy and environment are -different, especially in this respect. We will attempt to -provide enough examples and generic rules to give strategy +We anticipate that rules will be the portion of a strategy most likely to +not have suitable template code included with this package, as every strategy +and environment are different, especially in this respect. +We will attempt to provide enough examples and generic rules to give strategy authors a place to start. -For quantstrat to be able to (largly) vectorize the -execution of path-dependent rule evaluation, the rule -function is presumed to have a function signature like that -of \code{\link{ruleSignal}}, specifically the arguments -\code{sigcol} and \code{sigval}. If these are present and -function in a manner similar to \code{\link{ruleSignal}} we -can do some preprocessing to significantly reduce the -dimensionality of the index we need to loop over. The -speedup is the ratio of (symbols\*total -observations)/signal observations, so it can be significant -for many strategies. +For quantstrat to be able to (largly) vectorize the execution of path-dependent +rule evaluation, the rule function is presumed to have a function signature +like that of \code{\link{ruleSignal}}, specifically the arguments \code{sigcol} +and \code{sigval}. If these are present and function in a manner similar to +\code{\link{ruleSignal}} we can do some preprocessing to significantly reduce the +dimensionality of the index we need to loop over. The speedup is the ratio of +(symbols\*total observations)/signal observations, so it can be significant for many strategies. } Modified: pkg/quantstrat/man/add.signal.Rd =================================================================== --- pkg/quantstrat/man/add.signal.Rd 2014-11-12 14:56:21 UTC (rev 1647) +++ pkg/quantstrat/man/add.signal.Rd 2014-11-18 21:47:56 UTC (rev 1648) @@ -1,3 +1,4 @@ +% Generated by roxygen2 (4.0.2): do not edit by hand \name{add.signal} \alias{add.signal} \title{add a signal to a strategy} @@ -6,58 +7,50 @@ enabled = TRUE, indexnum = NULL, store = FALSE) } \arguments{ - \item{strategy}{an object (or the name of an object) of - type 'strategy' to add the signal to} +\item{strategy}{an object (or the name of an object) of type 'strategy' to add the signal to} - \item{name}{name of the signal, must correspond to an R - function} +\item{name}{name of the signal, must correspond to an R function} - \item{arguments}{named list of default arguments to be - passed to an signal function when executed} +\item{arguments}{named list of default arguments to be passed to an signal function when executed} - \item{parameters}{vector of strings naming parameters to - be saved for apply-time definition,default NULL, only - needed if you need special names to avoid argument - collision} +\item{parameters}{vector of strings naming parameters to be saved for apply-time definition,default NULL, only needed if you need special names to avoid argument collision} - \item{label}{arbitrary text label for signal output, - default NULL} +\item{label}{arbitrary text label for signal output, default NULL} - \item{...}{any other passthru parameters} +\item{...}{any other passthru parameters} - \item{enabled}{TRUE/FALSE whether the signal is enabled - for use in applying the strategy, default TRUE} +\item{enabled}{TRUE/FALSE whether the signal is enabled for use in applying the strategy, default TRUE} - \item{indexnum}{if you are updating a specific signal, - the index number in the $signals list to update} +\item{indexnum}{if you are updating a specific signal, the index number in the $signals list to update} - \item{store}{TRUE/FALSE whether to store the strategy in - the .strategy environment, or return it. default FALSE} +\item{store}{TRUE/FALSE whether to store the strategy in the .strategy environment, or return it. default FALSE} } \value{ -if \code{strategy} was the name of a strategy, the name. It -it was a strategy, the updated strategy. +if \code{strategy} was the name of a strategy, the name. It it was a strategy, the updated strategy. } \description{ This adds a signal definition to a strategy object. } \details{ -Signals denote times at which the strategy \emph{may} want -to take action. Common signals types from the literature -include crossovers, thresholds, or other interactions -between your \code{mktdata} and your indicators. +Signals denote times at which the strategy \emph{may} want to +take action. Common signals types from the literature include +crossovers, thresholds, or other interactions between your \code{mktdata} +and your indicators. -if \code{label} is not supplied, NULL default will be -converted to '.sig' if the signal function returns -one named column, we use that, and ignore the label. If the -signal function returns multiple columns, the label will be -\code{\link{paste}}'d to either the returned column names -or the respective column number. +if \code{label} is not supplied, NULL default will be converted to '.sig' +if the signal function returns one named column, we use that, and ignore the label. +If the signal function returns multiple columns, the label will be +\code{\link{paste}}'d to either the returned column names or the +respective column number. } \seealso{ -\code{\link{applySignals}} \code{\link{add.indicator}} -\code{link{add.rule}} \code{\link{sigComparison}} -\code{\link{sigCrossover}} \code{\link{sigFormula}} -\code{\link{sigPeak}} \code{\link{sigThreshold}} +\code{\link{applySignals}} +\code{\link{add.indicator}} +\code{link{add.rule}} +\code{\link{sigComparison}} +\code{\link{sigCrossover}} +\code{\link{sigFormula}} +\code{\link{sigPeak}} +\code{\link{sigThreshold}} } Modified: pkg/quantstrat/man/addOrder.Rd =================================================================== --- pkg/quantstrat/man/addOrder.Rd 2014-11-12 14:56:21 UTC (rev 1647) +++ pkg/quantstrat/man/addOrder.Rd 2014-11-18 21:47:56 UTC (rev 1648) @@ -1,3 +1,4 @@ +% Generated by roxygen2 (4.0.2): do not edit by hand \name{addOrder} \alias{addOrder} \title{add an order to the order book} @@ -4,189 +5,128 @@ \usage{ [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/blotter -r 1648 From noreply at r-forge.r-project.org Wed Nov 19 13:14:26 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 19 Nov 2014 13:14:26 +0100 (CET) Subject: [Blotter-commits] r1649 - pkg/quantstrat/sandbox/backtest_musings Message-ID: <20141119121426.C90EF183C85@r-forge.r-project.org> Author: braverock Date: 2014-11-19 13:14:26 +0100 (Wed, 19 Nov 2014) New Revision: 1649 Modified: pkg/quantstrat/sandbox/backtest_musings/gd_pres_backtest.Rmd pkg/quantstrat/sandbox/backtest_musings/gd_pres_backtest.pdf pkg/quantstrat/sandbox/backtest_musings/stat_process.bib Log: - updates to Global Derivatives presentation Modified: pkg/quantstrat/sandbox/backtest_musings/gd_pres_backtest.Rmd =================================================================== --- pkg/quantstrat/sandbox/backtest_musings/gd_pres_backtest.Rmd 2014-11-18 21:47:56 UTC (rev 1648) +++ pkg/quantstrat/sandbox/backtest_musings/gd_pres_backtest.Rmd 2014-11-19 12:14:26 UTC (rev 1649) @@ -42,7 +42,7 @@ - build a hypothesis for the system - build the system in pieces - test the system in pieces -- measure how likely it is that you've overfit +- measure how likely it is that you have overfit Constraints and Objectives ============================= @@ -122,11 +122,11 @@ ### Indicators - quantitative values derived from market data +- includes all common "technicals" such as moving averages, relative value, etc. ### Signals -- describe the interaction between filters, market data, -and indicators +- describe the interaction between filters, market data, and indicators - can be viewed as a prediction at a point in time ### Rules @@ -206,9 +206,9 @@ If your signal process doesn't have predictive power, stop now. \end{center} -- rules should refine the way the strategy 'listens' to signals + - rules should refine the way the strategy 'listens' to signals - entries may be passive or aggressive, or may level or pyramid into a position - - exits may have their own signal process, or may be empirical + - exits may have their own signal process, or may be derived empirically - risk rules should be added near the end, for empirical 'stops' or to meet business constraints Parameter Optimization @@ -286,7 +286,7 @@ - hiding the most common outcomes - focusing on extremes - not enough trades or history for validity - - colinearities of overlapping "trades" + - collinearities of overlapping "trades" Using Returns ============================= @@ -331,7 +331,7 @@ - **CSCV sampling** (combinatorially symmetric cross validation): "generate $S/2$ testing sets of size $T/2$ by recombining the $S$ slices of the overall sample of size $T$ ". [@Bailey2014probability, p.17] - **Multiple Hypothesis Testing** looks at Type I vs Type II error in evaluating - backtests and look at appropriate haircuts based on this. [@Harvey2013backtesting ; - at Harvey2013multiple ; - at Harvey2014 ] + backtests and at appropriate haircuts based on these probabilities. [@Harvey2013backtesting ; - at Harvey2013multiple ; - at Harvey2014 ] Conclusion & Questions @@ -371,16 +371,16 @@ \vfill Code to apply the techniques discussed here may be found in the -**R** *quantstrat* and *PerformanceAnalytics* packages. [@quantstrat2014; @perfa2014] +**R** *quantstrat*, *PerformanceAnalytics*, and *PortfolioAnalytics* packages. [@quantstrat2014; @perfa2014; @porta2014] \vfill -All remaining errors or omissions should be -attributed to the author. All views expressed in this presentation are -those of Brian Peterson, and do not necessarily reflect the opinions or -policies of DV Trading or DV Asset Management. +All remaining errors or omissions should be attributed to the author. +All views expressed in this presentation are those of Brian Peterson, +and do not necessarily reflect the opinions or policies of DV Trading +or DV Asset Management. Resources ========================================================= -\fontsize{5}{1}\selectfont \ No newline at end of file +\fontsize{4.5}{.75}\selectfont \ No newline at end of file Modified: pkg/quantstrat/sandbox/backtest_musings/gd_pres_backtest.pdf =================================================================== (Binary files differ) Modified: pkg/quantstrat/sandbox/backtest_musings/stat_process.bib =================================================================== --- pkg/quantstrat/sandbox/backtest_musings/stat_process.bib 2014-11-18 21:47:56 UTC (rev 1648) +++ pkg/quantstrat/sandbox/backtest_musings/stat_process.bib 2014-11-19 12:14:26 UTC (rev 1649) @@ -171,6 +171,14 @@ url = {http://CRAN.R-project.org/package=PerformanceAnalytics}, } + at Manual{porta2014, + title = {PortfolioAnalytics: Portfolio Analysis, including Numerical Methods for Optimization of Portfolios}, + author = {Brian G. Peterson and Peter Carl and Ross Bennett and Kris Boudt}, + year = {2014}, + subtitle = {R package version 0.9.0}, + url={http://r-forge.r-project.org/projects/returnanalytics/} +} + @Manual{quantstrat2014, title = {quantstrat: Quantitative Strategy Model Framework}, author = {Brian G. Peterson and Joshua Ulrich and Jan Humme and Peter Carl }, From noreply at r-forge.r-project.org Wed Nov 19 14:59:38 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 19 Nov 2014 14:59:38 +0100 (CET) Subject: [Blotter-commits] r1650 - pkg/quantstrat/sandbox/backtest_musings Message-ID: <20141119135938.32A121871EB@r-forge.r-project.org> Author: braverock Date: 2014-11-19 14:59:37 +0100 (Wed, 19 Nov 2014) New Revision: 1650 Modified: pkg/quantstrat/sandbox/backtest_musings/gd_pres_backtest.pdf pkg/quantstrat/sandbox/backtest_musings/stat_process.bib pkg/quantstrat/sandbox/backtest_musings/strat_dev_process.Rmd pkg/quantstrat/sandbox/backtest_musings/strat_dev_process.pdf Log: - Global Derivatives final presentation Modified: pkg/quantstrat/sandbox/backtest_musings/gd_pres_backtest.pdf =================================================================== (Binary files differ) Modified: pkg/quantstrat/sandbox/backtest_musings/stat_process.bib =================================================================== --- pkg/quantstrat/sandbox/backtest_musings/stat_process.bib 2014-11-19 12:14:26 UTC (rev 1649) +++ pkg/quantstrat/sandbox/backtest_musings/stat_process.bib 2014-11-19 13:59:37 UTC (rev 1650) @@ -138,6 +138,14 @@ year={2013} } + at book{Horowitz2014, + title={The Hard Thing about Hard Things}, + subtitle={Building a Business when There are No Easy Answers}, + author={Horowitz, Ben}, + year={2014}, + publisher={HarperCollins} +} + @book{Kestner2003, title={Quantitative trading strategies: {H}arnessing the power of quantitative techniques to create a winning trading program}, author={Kestner, Lars}, Modified: pkg/quantstrat/sandbox/backtest_musings/strat_dev_process.Rmd =================================================================== --- pkg/quantstrat/sandbox/backtest_musings/strat_dev_process.Rmd 2014-11-19 12:14:26 UTC (rev 1649) +++ pkg/quantstrat/sandbox/backtest_musings/strat_dev_process.Rmd 2014-11-19 13:59:37 UTC (rev 1650) @@ -147,7 +147,7 @@ *SharpeRatio*'s, *FactorAnalytics*, and more are well represented in **R**. -## Choosing an Objective {#objectives} +## Choosing an Objective {#objectives} ^[*When measuring results against objectives, start by making sure the objectives are correct.* - Ben @Horowitz2014] In strategy creation, it is very dangerous to start without a clear objective. Modified: pkg/quantstrat/sandbox/backtest_musings/strat_dev_process.pdf =================================================================== (Binary files differ) From noreply at r-forge.r-project.org Wed Nov 19 15:13:14 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 19 Nov 2014 15:13:14 +0100 (CET) Subject: [Blotter-commits] r1651 - pkg/blotter/R Message-ID: <20141119141314.B957E18450B@r-forge.r-project.org> Author: bodanker Date: 2014-11-19 15:13:14 +0100 (Wed, 19 Nov 2014) New Revision: 1651 Modified: pkg/blotter/R/updateAcct.R Log: - Remove duplicates from Account$portfolios[[pname]] when updateAcct is called more than once Modified: pkg/blotter/R/updateAcct.R =================================================================== --- pkg/blotter/R/updateAcct.R 2014-11-19 13:59:37 UTC (rev 1650) +++ pkg/blotter/R/updateAcct.R 2014-11-19 14:13:14 UTC (rev 1651) @@ -22,6 +22,7 @@ return(name) #trim to only time prior to Dates + whichi = NROW(Account$summary) if(last(index(Account$summary))>.parseISO8601(Dates)$first.time){ whichi<-first(Account$summary[paste(.parseISO8601(Dates)$first.time,'::',sep=''), which.i = TRUE]) if(!is.null(whichi)) whichi=whichi-1 @@ -81,7 +82,7 @@ psummary<-psummary*CcyMult } # now bind it - Account$portfolios[[pname]] = rbind(Account$portfolios[[pname]],psummary) + Account$portfolios[[pname]] = rbind(Account$portfolios[[pname]][1:whichi,],psummary) } summary = NULL From noreply at r-forge.r-project.org Wed Nov 19 17:51:18 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 19 Nov 2014 17:51:18 +0100 (CET) Subject: [Blotter-commits] r1652 - pkg/quantstrat Message-ID: <20141119165118.3D3C2187581@r-forge.r-project.org> Author: bodanker Date: 2014-11-19 17:51:17 +0100 (Wed, 19 Nov 2014) New Revision: 1652 Modified: pkg/quantstrat/NAMESPACE Log: - Remove phantom function roxygen created Modified: pkg/quantstrat/NAMESPACE =================================================================== --- pkg/quantstrat/NAMESPACE 2014-11-19 14:13:14 UTC (rev 1651) +++ pkg/quantstrat/NAMESPACE 2014-11-19 16:51:17 UTC (rev 1652) @@ -1,4 +1,4 @@ -# Generated by roxygen2 (4.0.2): do not edit by hand +# Generated by hand: do not edit with roxygen2 export(add.distribution) export(add.distribution.constraint) @@ -15,7 +15,6 @@ export(applySignals) export(applyStrategy) export(applyStrategy.rebalancing) -export(applyStrategy.rebalancing.training) export(chart.forward) export(chart.forward.training) export(delete.paramset) From noreply at r-forge.r-project.org Wed Nov 19 21:09:39 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 19 Nov 2014 21:09:39 +0100 (CET) Subject: [Blotter-commits] r1653 - pkg/quantstrat/sandbox/backtest_musings Message-ID: <20141119200939.46D6018045C@r-forge.r-project.org> Author: braverock Date: 2014-11-19 21:09:38 +0100 (Wed, 19 Nov 2014) New Revision: 1653 Removed: pkg/quantstrat/sandbox/backtest_musings/Notes_S_Rush_2014-10-10.txt pkg/quantstrat/sandbox/backtest_musings/strat_dev_proc_Kent_notes_2014-09-21.txt Log: - remove notes Deleted: pkg/quantstrat/sandbox/backtest_musings/Notes_S_Rush_2014-10-10.txt =================================================================== --- pkg/quantstrat/sandbox/backtest_musings/Notes_S_Rush_2014-10-10.txt 2014-11-19 16:51:17 UTC (rev 1652) +++ pkg/quantstrat/sandbox/backtest_musings/Notes_S_Rush_2014-10-10.txt 2014-11-19 20:09:38 UTC (rev 1653) @@ -1,50 +0,0 @@ -Main Idea: Setting out the correct process for a systemic trading system - -- Be careful with the "archetypal strategy" benchmark. If the strategy is loosely -implemented, it starts to look a lot like the straw man arguements similar to -the tests against buy and hold. This is also an area where I very quickly lose -interest in the rest of the paper/presentation because the author doesn't -understand the alternative strategy that he/she is arguing against. - -- I like the advise to measure yourself against multiple benchmarks even if -you think the benchmark is inappropriate because someone else will probably -do it anyway. - -- Page 4, bottom "tradeStats()" Are you assuming the readers will be familiar -with quantstrat? - -- Page 5 I agree with what you are saying on creating a testable hypothesis -but I think that I would be careful to use the word "prediction". There are -many rigorous tests that work well in the cross section and provide some -meanful insight as to how market work but are not useful in predicting what -will happen in the next period. I might argue that in the context of systemic -trading strategy development, it is the prediction that matters. A good -hypothesis does not need to be predictive in the time dimension but does need -to have a testable conclusion. This might seem like splitting hairs but if -are targeting anyone with a scientific background, there is a difference -between an experiment that has a predictable outcome and an experiment -that verifies a natural process. In physical sciences, they look the same -but in social sciences, they are different. An example is the correlation vs -causation problem of people carrying umbrellas before it rains. Clearly -umbrellas don't cause rain but if you knew nothing about the world, observing -people carrying umbrellas would be an excellent predictor of rain. In strategy -development, it would most likely be better to assume that umbrellas cause -rain rather than produce a global weather model. This is bad science but -probably more profitable. - -- Page 9 In look ahead bias, I would add that even assuming that a rule has -access to and can act on contemporaneous information may be too optimistic. -No matter how fast you are, there is a time cost to observing and acting. -Marine Corps officers used to be taught the "OODA Loop" Observe, Orient, -Decide, Act. You cannot execute the loop instantaneously so your actions will -always lag observable information. - -- Page 11 The figures on this page are not large enough to add value to the -paper. - -- Page 11 I like the description of evaluating signals with distributions. - -- Page 16 Bottom figure may look good on a good printer but is unreadable -in a 30" monitor. - - Deleted: pkg/quantstrat/sandbox/backtest_musings/strat_dev_proc_Kent_notes_2014-09-21.txt =================================================================== --- pkg/quantstrat/sandbox/backtest_musings/strat_dev_proc_Kent_notes_2014-09-21.txt 2014-11-19 16:51:17 UTC (rev 1652) +++ pkg/quantstrat/sandbox/backtest_musings/strat_dev_proc_Kent_notes_2014-09-21.txt 2014-11-19 20:09:38 UTC (rev 1653) @@ -1,24 +0,0 @@ - -Subject: -Re: Strategy development process draft -From: -Kent Hoxsey -Date: -09/21/2014 08:10 PM -To: -"Brian G. Peterson" - -Interesting stuff. One initial scoping question comes to mind: what kind of experience do you expect your audience to bring to this? I can picture quite a range (leaving out experienced professionals for now): -- raw newbies trying to figure out the business (Ilya and passionate learners everywhere) -- screen traders attempting to systematize (me, maybe Paul T) -- experienced finance people figuring out prop (Simon, perhaps Josh) -- academics (Marc, Matthew) -Plenty of overlap between these groups, particularly given a large slice of "raw noob" in all of us who have never known a system with edge and thus never traded actual size. And it gets even more interesting if you allow for experienced professionals who *do* know systems with edge and *have* traded real size. - -I think the emphasis shifts depending on whether you are aiming to include the experienced professionals or not. Budding/aspirational strategists such as me/Josh/Simon and anyone working within the context of a prop or management firm will likely have constraints and objectives defined in advance. In contrast, an academic like Marc will benefit from the example trading system objectives (in your FIXME) as he attempts to define indicators/signals for consulting clients. - -Thinking back on my experience with both MDFA and CRSI, I have to say I never formulated a testable hypothesis. My only tests were whether the strategy was positive or negative. Based on my own experience as well as what I have seen of other people attempting to design strategies (or even Simon, attempting to integrate and validate a "working" strategy he purchased), this is a common approach or perhaps the only approach. So when you state "most strategy ideas will be rejected during hypothesis creation and testing", you are saying something both obvious to all and deeply counter-intuitive, if not outright subversive. So I am looking forward to further exposition later in the document. Because "creating and confirming a hypothesis" sounds a lot like "identifying an edge". - -As we get into the outline, the one obvious feature I would request is some explicit discussion of the bar-vs-tick data issue. With both MDFA and CRSI, I had promising bar-data indicators fall apart when faced with actual order books. The stats didn't give a good indication this would happen, but were just too close to the edge of profitability to survive any adverse data. (Identifying edge is my current hurdle, so more is better IMHO). - -Looking good so far, excited to see what comes next. From noreply at r-forge.r-project.org Thu Nov 20 18:37:04 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 20 Nov 2014 18:37:04 +0100 (CET) Subject: [Blotter-commits] r1654 - pkg/quantstrat/R Message-ID: <20141120173704.1D0B8180965@r-forge.r-project.org> Author: bodanker Date: 2014-11-20 18:37:03 +0100 (Thu, 20 Nov 2014) New Revision: 1654 Modified: pkg/quantstrat/R/osFUNs.R Log: - Fix osMaxPos bug; thanks to Offer Markovich for the report Modified: pkg/quantstrat/R/osFUNs.R =================================================================== --- pkg/quantstrat/R/osFUNs.R 2014-11-19 20:09:38 UTC (rev 1653) +++ pkg/quantstrat/R/osFUNs.R 2014-11-20 17:37:03 UTC (rev 1654) @@ -201,7 +201,7 @@ if(orderqty<0 & orderside=='short'){ if ((orderqty+pos)>PosLimit[,"MinPos"]) { #we have room to expand the position - if(orderqty<=(PosLimit[,"MinPos"]/PosLimit[,"ShortLevels"]) ) { + if(orderqty>=(PosLimit[,"MinPos"]/PosLimit[,"ShortLevels"]) ) { orderqty=orderqty } else { orderqty = round(PosLimit[,"MinPos"]/PosLimit[,"ShortLevels"],0) #note no round lots From noreply at r-forge.r-project.org Sun Nov 23 23:53:26 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 23 Nov 2014 23:53:26 +0100 (CET) Subject: [Blotter-commits] r1655 - in pkg/FinancialInstrument: . R man Message-ID: <20141123225326.97EC2187645@r-forge.r-project.org> Author: gsee Date: 2014-11-23 23:53:26 +0100 (Sun, 23 Nov 2014) New Revision: 1655 Modified: pkg/FinancialInstrument/NAMESPACE pkg/FinancialInstrument/R/FinancialInstrument-package.R pkg/FinancialInstrument/R/all.equal.instrument.R pkg/FinancialInstrument/R/expires.R pkg/FinancialInstrument/R/instrument.R pkg/FinancialInstrument/R/parse_id.R pkg/FinancialInstrument/man/all.equal.instrument.Rd pkg/FinancialInstrument/man/expires.spread.Rd Log: remove @S3method, which is deprecated. import from packages in Depends. Modified: pkg/FinancialInstrument/NAMESPACE =================================================================== --- pkg/FinancialInstrument/NAMESPACE 2014-11-20 17:37:03 UTC (rev 1654) +++ pkg/FinancialInstrument/NAMESPACE 2014-11-23 22:53:26 UTC (rev 1655) @@ -1,6 +1,6 @@ # Generated by roxygen2 (4.0.2): do not edit by hand -S3method(all.equal,instrument) +S3method(all,equal.instrument) S3method(expires,character) S3method(expires,instrument) S3method(expires,xts) @@ -164,3 +164,8 @@ importFrom(quantmod,setSymbolLookup) importFrom(quantmod,yahooQF) importFrom(zoo,as.Date) +importFrom(zoo,as.zoo) +importFrom(zoo,coredata) +importFrom(zoo,index) +importFrom(zoo,is.zoo) +importFrom(zoo,na.locf) Modified: pkg/FinancialInstrument/R/FinancialInstrument-package.R =================================================================== --- pkg/FinancialInstrument/R/FinancialInstrument-package.R 2014-11-20 17:37:03 UTC (rev 1654) +++ pkg/FinancialInstrument/R/FinancialInstrument-package.R 2014-11-23 22:53:26 UTC (rev 1655) @@ -4,6 +4,7 @@ #' 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 +#' @importFrom zoo na.locf as.zoo coredata is.zoo index NULL #' Construct, manage and store contract specifications for trading Modified: pkg/FinancialInstrument/R/all.equal.instrument.R =================================================================== --- pkg/FinancialInstrument/R/all.equal.instrument.R 2014-11-20 17:37:03 UTC (rev 1654) +++ pkg/FinancialInstrument/R/all.equal.instrument.R 2014-11-23 22:53:26 UTC (rev 1655) @@ -25,8 +25,6 @@ #' \code{char.n}. Unless \code{collapse} is \code{NULL}, it will be used in a #' call to \code{\link{paste}}. If \code{collapse} is \code{NULL}, each element #' of the character vector will be compared separately. -#' @method all.equal instrument -#' @S3method all.equal instrument #' @author Garrett See #' @seealso \code{\link{getInstrument}}, \code{\link{instrument.table}}, #' \code{\link{buildHierarchy}} @@ -45,6 +43,7 @@ #' #' all.equal(getInstrument("DIA"), getInstrument("USD")) #' } +#' @export all.equal.instrument <- function (target, current, char.n=2, collapse=";", ...) { stopifnot(is.instrument(target)) if (char.n < 0) char.n <- Inf Modified: pkg/FinancialInstrument/R/expires.R =================================================================== --- pkg/FinancialInstrument/R/expires.R 2014-11-20 17:37:03 UTC (rev 1654) +++ pkg/FinancialInstrument/R/expires.R 2014-11-23 22:53:26 UTC (rev 1655) @@ -81,11 +81,10 @@ #' \code{FALSE} the first one after \code{Date} will be returned. Note that #' if \code{expires} is a single value, \code{expired} will be ignored. #' @param silent silence warnings? -#' @method expires instrument -#' @S3method expires instrument #' @seealso \code{\link{expires}} #' @author Garrett See #' @keywords internal +#' @export expires.instrument <- function(x, Date, expired=TRUE, silent=FALSE, ...) { if (is.instrument(x)) { if (missing(Date)) Date <- Sys.Date() @@ -142,11 +141,10 @@ #' returned will be the last one before \code{Date}. If \code{expired} is #' \code{FALSE} the first one after \code{Date} will be returned. #' @param silent silence warnings? -#' @method expires character -#' @S3method expires character #' @seealso \code{\link{expires.instrument}} #' @author Garrett See #' @keywords internal +#' @export expires.character <- function(x, Date, expired=TRUE, silent=FALSE, ...) { xi <- getInstrument(x, silent=TRUE) if (is.instrument(xi)) { @@ -179,11 +177,10 @@ #' \code{expires} is a vector. If \code{expired} is \code{TRUE} the date #' returned will be the last one before \code{Date}. If \code{expired} is #' \code{FALSE} the first one after \code{Date} will be returned. -#' @method expires character -#' @S3method expires character #' @seealso \code{\link{expires.instrument}} #' @author Garrett See #' @keywords internal +#' export expires.spread <- function(x, Date, expired=TRUE, silent=FALSE, ...) { if (inherits(x, "spread")) { if (!is.null(x$expires)) { @@ -220,11 +217,10 @@ #' #' If \code{src} is \dQuote{instrument} the symbol of the xts object will #' be passed to \code{\link{expires.character}} -#' @method expires xts -#' @S3method expires xts #' @seealso \code{\link{expires.instrument}}, \code{\link{expires}} #' @author Garrett See #' @keywords internal +#' @export expires.xts <- function(x, Date, expired=TRUE, silent=FALSE, src=c("data", "instrument"), ...) { src <- c("data", "instrument")[pmatch(src, c("data", "instrument"))[[1L]]] Modified: pkg/FinancialInstrument/R/instrument.R =================================================================== --- pkg/FinancialInstrument/R/instrument.R 2014-11-20 17:37:03 UTC (rev 1654) +++ pkg/FinancialInstrument/R/instrument.R 2014-11-23 22:53:26 UTC (rev 1655) @@ -1520,10 +1520,9 @@ #' instrument class print method #' -#' @method print instrument -#' @S3method print instrument #' @author Joshua Ulrich, Garrett See #' @keywords internal +#' @export print.instrument <- function(x, ...) { str(unclass(x), comp.str="", no.list=TRUE, give.head=FALSE, give.length=FALSE, give.attr=FALSE, nest.lev=-1, indent.str="") @@ -1532,10 +1531,9 @@ #' instrument class sort method #' -#' @method sort instrument -#' @S3method sort instrument #' @author Garrett See #' @keywords internal +#' @export sort.instrument <- function(x, decreasing=FALSE, na.last=NA, ...) { anchored <- x[c("primary_id", "currency", "multiplier", "tick_size", "identifiers", "type")] Modified: pkg/FinancialInstrument/R/parse_id.R =================================================================== --- pkg/FinancialInstrument/R/parse_id.R 2014-11-20 17:37:03 UTC (rev 1654) +++ pkg/FinancialInstrument/R/parse_id.R 2014-11-23 22:53:26 UTC (rev 1655) @@ -452,9 +452,8 @@ #' id.list class print method #' -#' @method print id.list -#' @S3method print id.list #' @keywords internal +#' @export print.id.list <- function(x, ...) { str(x, comp.str="", give.length=FALSE, give.attr=FALSE) invisible(x) @@ -462,9 +461,8 @@ #' suffix.list class print method #' -#' @method print suffix.list -#' @S3method print suffix.list #' @keywords internal +#' @export print.suffix.list <- function(x, ...) { str(x, comp.str="", give.length=FALSE, give.attr=FALSE) invisible(x) Modified: pkg/FinancialInstrument/man/all.equal.instrument.Rd =================================================================== --- pkg/FinancialInstrument/man/all.equal.instrument.Rd 2014-11-20 17:37:03 UTC (rev 1654) +++ pkg/FinancialInstrument/man/all.equal.instrument.Rd 2014-11-23 22:53:26 UTC (rev 1655) @@ -3,7 +3,7 @@ \alias{all.equal.instrument} \title{instrument all.equal method} \usage{ -\method{all.equal}{instrument}(target, current, char.n = 2, collapse = ";", +\method{all}{equal.instrument}(target, current, char.n = 2, collapse = ";", ...) } \arguments{ Modified: pkg/FinancialInstrument/man/expires.spread.Rd =================================================================== --- pkg/FinancialInstrument/man/expires.spread.Rd 2014-11-20 17:37:03 UTC (rev 1654) +++ pkg/FinancialInstrument/man/expires.spread.Rd 2014-11-23 22:53:26 UTC (rev 1655) @@ -3,7 +3,7 @@ \alias{expires.spread} \title{spread expires extraction method} \usage{ -\method{expires}{character}(x, Date, expired = TRUE, silent = FALSE, ...) +\method{expires}{spread}(x, Date, expired = TRUE, silent = FALSE, ...) } \arguments{ \item{Date}{Can be a Date or character string. When \code{expires} is a @@ -27,5 +27,6 @@ \seealso{ \code{\link{expires.instrument}} } +\keyword{export} \keyword{internal} From noreply at r-forge.r-project.org Fri Nov 28 02:07:58 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 28 Nov 2014 02:07:58 +0100 (CET) Subject: [Blotter-commits] r1656 - in pkg/FinancialInstrument: . R Message-ID: <20141128010758.4F17D187610@r-forge.r-project.org> Author: gsee Date: 2014-11-28 02:07:57 +0100 (Fri, 28 Nov 2014) New Revision: 1656 Modified: pkg/FinancialInstrument/DESCRIPTION pkg/FinancialInstrument/NAMESPACE pkg/FinancialInstrument/R/FinancialInstrument-package.R pkg/FinancialInstrument/R/load.instruments.R Log: use Defaults again (>= 2.0.0) Modified: pkg/FinancialInstrument/DESCRIPTION =================================================================== --- pkg/FinancialInstrument/DESCRIPTION 2014-11-23 22:53:26 UTC (rev 1655) +++ pkg/FinancialInstrument/DESCRIPTION 2014-11-28 01:07:57 UTC (rev 1656) @@ -17,7 +17,8 @@ zoo (>= 1.7-5), xts Imports: - TTR + TTR, + Defaults (>= 2.0.0) Suggests: foreach, XML (>= 3.96.1.1), Modified: pkg/FinancialInstrument/NAMESPACE =================================================================== --- pkg/FinancialInstrument/NAMESPACE 2014-11-23 22:53:26 UTC (rev 1655) +++ pkg/FinancialInstrument/NAMESPACE 2014-11-28 01:07:57 UTC (rev 1656) @@ -138,6 +138,7 @@ export(update_instruments.yahoo) export(volep) import(xts) +importFrom(Defaults,importDefaults) importFrom(TTR,runSum) importFrom(TTR,stockSymbols) importFrom(quantmod,Ad) Modified: pkg/FinancialInstrument/R/FinancialInstrument-package.R =================================================================== --- pkg/FinancialInstrument/R/FinancialInstrument-package.R 2014-11-23 22:53:26 UTC (rev 1655) +++ pkg/FinancialInstrument/R/FinancialInstrument-package.R 2014-11-28 01:07:57 UTC (rev 1656) @@ -5,8 +5,12 @@ #' getSymbolLookup setSymbolLookup yahooQF has.Vo Vo getOptionChain #' @importFrom TTR stockSymbols runSum #' @importFrom zoo na.locf as.zoo coredata is.zoo index +#' @importFrom Defaults importDefaults NULL +# for packages in Suggests: +globalVariables(c("timeSeries", "readHTMLTable", "%dopar%", "foreach")) + #' Construct, manage and store contract specifications for trading #' #' Transaction-oriented infrastructure for defining tradable instruments based Modified: pkg/FinancialInstrument/R/load.instruments.R =================================================================== --- pkg/FinancialInstrument/R/load.instruments.R 2014-11-23 22:53:26 UTC (rev 1655) +++ pkg/FinancialInstrument/R/load.instruments.R 2014-11-28 01:07:57 UTC (rev 1656) @@ -345,7 +345,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 From noreply at r-forge.r-project.org Sat Nov 29 14:39:24 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 29 Nov 2014 14:39:24 +0100 (CET) Subject: [Blotter-commits] r1657 - in pkg/quantstrat: . R man sandbox/backtest_musings Message-ID: <20141129133925.0C069183D37@r-forge.r-project.org> Author: braverock Date: 2014-11-29 14:39:24 +0100 (Sat, 29 Nov 2014) New Revision: 1657 Modified: pkg/quantstrat/DESCRIPTION pkg/quantstrat/NAMESPACE pkg/quantstrat/R/parameters.R pkg/quantstrat/man/applyParameter.Rd pkg/quantstrat/man/getParameterTable.Rd pkg/quantstrat/man/paramConstraint.Rd pkg/quantstrat/man/setParameterConstraint.Rd pkg/quantstrat/man/setParameterDistribution.Rd pkg/quantstrat/sandbox/backtest_musings/gamlss.png pkg/quantstrat/sandbox/backtest_musings/stat_process.bib pkg/quantstrat/sandbox/backtest_musings/strat_dev_process.Rmd pkg/quantstrat/sandbox/backtest_musings/strat_dev_process.pdf Log: - update roxygen docs - deprecate old applyParameter code - update backtest paper Modified: pkg/quantstrat/DESCRIPTION =================================================================== --- pkg/quantstrat/DESCRIPTION 2014-11-28 01:07:57 UTC (rev 1656) +++ pkg/quantstrat/DESCRIPTION 2014-11-29 13:39:24 UTC (rev 1657) @@ -1,12 +1,12 @@ Package: quantstrat Type: Package Title: Quantitative Strategy Model Framework -Version: 0.9.1648 +Version: 0.9.1657 Date: $Date$ Author: Peter Carl, Brian G. Peterson, Joshua Ulrich, Jan Humme Depends: xts(>= 0.8-2),TTR(>= 0.2), - blotter(>= 0.7.2), + blotter(>= 0.9), FinancialInstrument(>= 0.12.5), foreach(>= 1.4.0) Suggests: Modified: pkg/quantstrat/NAMESPACE =================================================================== --- pkg/quantstrat/NAMESPACE 2014-11-28 01:07:57 UTC (rev 1656) +++ pkg/quantstrat/NAMESPACE 2014-11-29 13:39:24 UTC (rev 1657) @@ -1,4 +1,4 @@ -# Generated by hand: do not edit with roxygen2 +# Generated by roxygen2 (4.0.2): do not edit by hand export(add.distribution) export(add.distribution.constraint) @@ -10,7 +10,6 @@ export(addPosLimit) export(apply.paramset) export(applyIndicators) -export(applyParameter) export(applyRules) export(applySignals) export(applyStrategy) @@ -23,7 +22,6 @@ export(get.strategy) export(getOrderBook) export(getOrders) -export(getParameterTable) export(getPosLimit) export(getStrategy) export(initOrders) @@ -42,8 +40,6 @@ export(ruleRevoke) export(ruleSignal) export(save.strategy) -export(setParameterConstraint) -export(setParameterDistribution) export(sigComparison) export(sigCrossover) export(sigFormula) Modified: pkg/quantstrat/R/parameters.R =================================================================== --- pkg/quantstrat/R/parameters.R 2014-11-28 01:07:57 UTC (rev 1656) +++ pkg/quantstrat/R/parameters.R 2014-11-29 13:39:24 UTC (rev 1657) @@ -1,83 +1,3 @@ -## add parameters to strategy objects: ALPHA CODE USE WITH CARE -#add.parameter <- -# function (strategy, -# type = c('indicator','signal'), -# add.to.name, -# method = c('lookup','lookup.range','calc'), -# arguments = NULL, -# label = NULL, -# ..., -# store=FALSE) -#{ -# if(!is.strategy(strategy)) stop("You must pass in a strategy object to manipulate") -# # perhaps I should add parameters and parameter.args as arguments to the constructors... -# -# tmp.param<-list() -# -# type=type[1] #this should probably come out eventually -# -# method = method[1] #only use the first if the user didn't specify, or over-specified -# -# if(is.null(label)) { -# label<-method -# } -# tmp.param$label <- label -# tmp.param$method <- method -# tmp.param$call <- match.call() -# tmp.param$arguments <- arguments -# class(tmp.param)<-'quantstrat.parameter' -# -# switch(type, -# indicator = {type='indicators'}, -# signal = {type='signals'}, -# rule = {type='rules'}) #NOTE rules not supported yet, since they need a rule type too -# -# # need to think about how to create a 'parameters' list, and whether -# # it should be at the strategy level or lower down, on the individual -# # signal/indicator/rule -# -# if(!is.list(strategy[[type]][[add.to.name]]$parameters)){ -# strategy[[type]][[add.to.name]]$parameters <- list() -# } -# strategy[[type]][[add.to.name]][['parameters']][[method]] <- tmp.param -# -# if (store) assign(strategy$name,strategy,envir=as.environment(.strategy)) -# else return(strategy) -#} -# -# -## add parameters to strategy objects: ALPHA CODE USE WITH CARE -#paramLookup <- function(strategy, symbol , type, name, parameter, ...) { -# # should take in a strategy and parameter object, and return an argument list for 'symbol' -# #as.pairlist(paramTable[,symbol] -# paramTable<-get(paste(strategy,type,name,'table',pos=.strategy)) -# as.pairlist(paramTable[,symbol]) -#} -# -## add parameters to strategy objects: ALPHA CODE USE WITH CARE -#add.paramLookupTable <- function(strategy, type, name, paramTable){ -# assign(paste(strategy,type,name,'table',pos=.strategy),paramTable) -#} -# -## get parameterized arguments list out of the strategy environment -#getParams <- function (strategy, symbol, type, name) -#{ -# -# params <- strategy[[type]][[name]]$parameters -# param.ret<-list() -# for (param in params) { -# switch(param$method, -# lookup = {param.ret<-c(param.ret,paramLookup(strategy,symbol,parameter=param))}, -# lookup.range = {}, -# calc = {}, -# {warning("parameter method",param$method,'not recognized for',type,name); next()} -# ) -# } -# # return an arguments list back to the 'apply*' fn -# return(param.ret) -#} - - ############################################################################### # R (http://r-project.org/) Quantitative Strategy Model Framework # @@ -136,7 +56,7 @@ #retrieve the needed parameters and existing values after add* -#' Extract the parameter structure from a strategy object. +#' Extract the parameter structure from a strategy object. (deprecated) #' #' Users can use this function to extract the parameters used in a strategy, and use the output as a reminder/ cheatsheet #' when they create the parameter distribution or parameter constraints. But it's not required to run to specify the distribution or constraints of parameters. @@ -156,7 +76,6 @@ #' } #' @param strategy The strategy object. #' @author Yu Chen -#' @export getParameterTable<-function (strategy) #,staticSwitch) { @@ -235,19 +154,9 @@ return(paramPack) } -# -# -#getParameterInfo<-function(paramStructure){ -# paramInfo<-list() -# for(paraLine in paramStructure){ -# paraInfo[[1]]<-paraLine$paramType -# } -#} -#getParameterMatrix<-function(paraStructure){ -# -#} -#' Function used to create an object that contains the distribution of parameters to be generated from, before testing parameters of a strategy. + +#' Function used to create an object that contains the distribution of parameters to be generated from, before testing parameters of a strategy. (deprecated) #' #' #' Each call to the function will set/update the distribution of ONE parameter in the 'parameter distribution object' that is associated with a specific strategy. @@ -279,7 +188,6 @@ #' @param psindex A number specify the index within the parameter distribution object, it is used to make change/ repalce a parameter distribution in the object. #' @return The returned object is a structure contains the distribution of parameters, if the input argument 'paramDist' is provided, the function update the input paramDist object and return the updated one. When specify the distribution of several parameters, usually the first returned object is passed to the next several call of the function as input argument 'paramDist'. See example. #' @author Yu Chen -#' @export setParameterDistribution<-function(paramDist=NULL, strategy, component.type, component.label, distribution=NULL, weight, label, psindex=NULL) #All is needed, set to illegal values { missing.msg <- ': missing in call to setParameterDistribution' @@ -336,7 +244,7 @@ return(paramDist) } -#' Generate parameter sets for a specific strategy, test the strategy on each set of parameters, output result package. +#' Generate parameter sets for a specific strategy, test the strategy on each set of parameters, output result package. (deprecated) #' #' The function do several things in one call, to test different parameters on a strategy. It generates parameter sets based on specified distribution (a defined parameter distribution object generated by setParameterDistribution function) and constraints (A defined parameter constraint object generated by setParameterConstraint function), #' apply the generated parameter sets to the specified strategy and return the results package, put the generated portfolio objects and account objects in .blotter environment. @@ -392,11 +300,13 @@ #' @seealso \code{\link{setParameterDistribution}}, \code{\link{setParameterConstraint}} #' #' @author Yu Chen -#' @export applyParameter<-function(strategy,portfolios,parameterPool,parameterConstraints,method,sampleSize,verbose=FALSE,...) { + .Deprecated("apply.paramsets","The original parameter code in applyParameter hase been deprecated. Use apply.paramsets instead.") + #need to create combination of distribution values in each slot of the parameterPool + initialPortf<-.getPortfolio(portfolios) symbols<-ls(initialPortf$symbols) @@ -720,13 +630,11 @@ } -#for(pname in names(as.list(ss$blotter))){ -# assign(paste(pname,'p',23,sep='.'),get(paste('ss$blotter$',pname,sep='')),envir=as.environment(.blotter)) -#} - -#' 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. +#' Internal function used in applyParameter function for process constraints on relationship between two parameter values. (deprecated) #' +#' Basically is the same as sigComparison function in signal.R written by Brian, with minor change. +#' #' Currently, this function compares two columns. #' Patches to compare an arbitrary number of columns would be gladly accepted. #' @@ -781,7 +689,7 @@ } -#' Function to construct parameter constraint object. +#' Function to construct parameter constraint object. (deprecated) #' #' Function to construct parameter constraint object. The returned value will be one of the inputs to the applyParameter function. #' @@ -802,7 +710,6 @@ #' @param relationship relationship between the 1st parameter and 2nd one. ('gt' means 1st parameter > 2nd parameter). #' @return The returned object is a structure contains the constraints on pairs of parameters, if the input argument 'paramConstraintObj' is provided, the function update the input paramConstraintObj object and return the updated one. When specify the constraints of several pairs of parameters, usually the first returned object is passed to the next several call of the function as input argument 'paramConstraintObj'. See example. #' @author Yu Chen -#' @export setParameterConstraint<-function(paramConstraintObj=list(),constraintLabel,paramList,relationship) { if(!hasArg(paramConstraintObj) || !exists(as.character(substitute(paramConstraintObj)))) Modified: pkg/quantstrat/man/applyParameter.Rd =================================================================== --- pkg/quantstrat/man/applyParameter.Rd 2014-11-28 01:07:57 UTC (rev 1656) +++ pkg/quantstrat/man/applyParameter.Rd 2014-11-29 13:39:24 UTC (rev 1657) @@ -1,7 +1,7 @@ % Generated by roxygen2 (4.0.2): do not edit by hand \name{applyParameter} \alias{applyParameter} -\title{Generate parameter sets for a specific strategy, test the strategy on each set of parameters, output result package.} +\title{Generate parameter sets for a specific strategy, test the strategy on each set of parameters, output result package. (deprecated)} \usage{ applyParameter(strategy, portfolios, parameterPool, parameterConstraints, method, sampleSize, verbose = FALSE, ...) Modified: pkg/quantstrat/man/getParameterTable.Rd =================================================================== --- pkg/quantstrat/man/getParameterTable.Rd 2014-11-28 01:07:57 UTC (rev 1656) +++ pkg/quantstrat/man/getParameterTable.Rd 2014-11-29 13:39:24 UTC (rev 1657) @@ -1,7 +1,7 @@ % Generated by roxygen2 (4.0.2): do not edit by hand \name{getParameterTable} \alias{getParameterTable} -\title{Extract the parameter structure from a strategy object.} +\title{Extract the parameter structure from a strategy object. (deprecated)} \usage{ getParameterTable(strategy) } Modified: pkg/quantstrat/man/paramConstraint.Rd =================================================================== --- pkg/quantstrat/man/paramConstraint.Rd 2014-11-28 01:07:57 UTC (rev 1656) +++ pkg/quantstrat/man/paramConstraint.Rd 2014-11-29 13:39:24 UTC (rev 1657) @@ -1,7 +1,7 @@ % Generated by roxygen2 (4.0.2): do not edit by hand \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 minor change.} +\title{Internal function used in applyParameter function for process constraints on relationship between two parameter values. (deprecated)} \usage{ paramConstraint(label, data = mktdata, columns, relationship = c("gt", "lt", "eq", "gte", "lte", "op")) @@ -16,10 +16,12 @@ \item{relationship}{one of c("gt","lt","eq","gte","lte","op") or reasonable alternatives} } \description{ +Basically is the same as sigComparison function in signal.R written by Brian, with minor change. +} +\details{ Currently, this function compares two columns. Patches to compare an arbitrary number of columns would be gladly accepted. -} -\details{ + Comparison will be applied from the first to the second column in the \code{columns} vector. Relationship 'op' means 'opposite' side. Reasonable attempt will be made to match. Modified: pkg/quantstrat/man/setParameterConstraint.Rd =================================================================== --- pkg/quantstrat/man/setParameterConstraint.Rd 2014-11-28 01:07:57 UTC (rev 1656) +++ pkg/quantstrat/man/setParameterConstraint.Rd 2014-11-29 13:39:24 UTC (rev 1657) @@ -1,7 +1,7 @@ % Generated by roxygen2 (4.0.2): do not edit by hand \name{setParameterConstraint} \alias{setParameterConstraint} -\title{Function to construct parameter constraint object.} +\title{Function to construct parameter constraint object. (deprecated)} \usage{ setParameterConstraint(paramConstraintObj = list(), constraintLabel, paramList, relationship) Modified: pkg/quantstrat/man/setParameterDistribution.Rd =================================================================== --- pkg/quantstrat/man/setParameterDistribution.Rd 2014-11-28 01:07:57 UTC (rev 1656) +++ pkg/quantstrat/man/setParameterDistribution.Rd 2014-11-29 13:39:24 UTC (rev 1657) @@ -1,7 +1,7 @@ % Generated by roxygen2 (4.0.2): do not edit by hand \name{setParameterDistribution} \alias{setParameterDistribution} -\title{Function used to create an object that contains the distribution of parameters to be generated from, before testing parameters of a strategy.} +\title{Function used to create an object that contains the distribution of parameters to be generated from, before testing parameters of a strategy. (deprecated)} \usage{ setParameterDistribution(paramDist = NULL, strategy, component.type, component.label, distribution = NULL, weight, label, psindex = NULL) Modified: pkg/quantstrat/sandbox/backtest_musings/gamlss.png =================================================================== (Binary files differ) Modified: pkg/quantstrat/sandbox/backtest_musings/stat_process.bib =================================================================== --- pkg/quantstrat/sandbox/backtest_musings/stat_process.bib 2014-11-28 01:07:57 UTC (rev 1656) +++ pkg/quantstrat/sandbox/backtest_musings/stat_process.bib 2014-11-29 13:39:24 UTC (rev 1657) @@ -25,7 +25,7 @@ @article{Bailey2014pm, title={Pseudomathematics and financial charlatanism: The effects of backtest {O}ver fitting on out-of-sample performance}, - author={Bailey, David H and Borwein, Jonathan M and L{\'o}pez de Prado, Marcos and Zhu, Qiji Jim}, + author={Bailey, David H and Borwein, Jonathan M and {L{\'o}pez de Prado}, Marcos and Zhu, Qiji Jim}, journal={Notices of the AMS}, volume={61}, number={5}, Modified: pkg/quantstrat/sandbox/backtest_musings/strat_dev_process.Rmd =================================================================== --- pkg/quantstrat/sandbox/backtest_musings/strat_dev_process.Rmd 2014-11-28 01:07:57 UTC (rev 1656) +++ pkg/quantstrat/sandbox/backtest_musings/strat_dev_process.Rmd 2014-11-29 13:39:24 UTC (rev 1657) @@ -14,7 +14,7 @@ footer: Copyright 2014 Brian G. Peterson CC-BY-NC-SA. Please do not distribute this draft without permission. copyright: Copyright 2014 Brian G. Peterson CC-BY-NC-SA. Please do not distribute this draft without permission. -abstract: Analysts and portfolio managers face many challenges in developing new systematic trading systems. This paper provides a detailed, repeatable process to aid in evaluating new ideas, developing those ideas into testable hypotheses, measuring results in comparable ways, and avoiding and measuring the ever-present risks of over-fitting. ^[ *Back-testing. I hate it ?- it's just optimizing over history. You never see a bad back-test. Ever. In any strategy.* - Josh Diedesch [- at Diedesch2014] ] +abstract: Analysts and portfolio managers face many challenges in developing new systematic trading systems. This paper provides a detailed, repeatable process to aid in evaluating new ideas, developing those ideas into testable hypotheses, measuring results in comparable ways, and avoiding and measuring the ever-present risks of over-fitting. ^[ *Back-testing. I hate it ?- it's just optimizing over history. You never see a bad back-test. Ever. In any strategy.* - Josh Diedesch[- at Diedesch2014] ] --- ___ @@ -147,7 +147,7 @@ *SharpeRatio*'s, *FactorAnalytics*, and more are well represented in **R**. -## Choosing an Objective {#objectives} ^[*When measuring results against objectives, start by making sure the objectives are correct.* - Ben @Horowitz2014] +## Choosing an Objective ^[*When measuring results against objectives, start by making sure the objectives are correct.* - Ben @Horowitz2014] In strategy creation, it is very dangerous to start without a clear objective. @@ -597,7 +597,6 @@ \begin{marginfigure} \includegraphics{gamlss} -\caption{source:gamlss} \end{marginfigure} The signals generated by the backtest(s) are also able to be empirically @@ -632,15 +631,15 @@ signals, holding period, etc.) to the process you are evaluating, to ensure that you are really looking at comparable things. -In the analysis of signal processes, since every signal is a prediction, is -where we can begin to fully apply the literature on model specification -and testing of predictions. From the simplest available methods such -as mean squared model error or kernel distance from an ideal process, -through extensive evaluation as suggested for BIC, effective number of -parameters, and cross validation of @Hastie2009, and including time series -specific models such as the data driven approach "revealed performance" -approach of @Racine2009, all available tools from the forecasting literature -should be considered for evaluating proposed signal processes. +Because every signal is a prediction, when analysing of signal processes, we +can begin to fully apply the literature on model specification and testing of +predictions. From the simplest available methods such as mean squared model +error or kernel distance from an ideal process, through extensive evaluation +as suggested for BIC, effective number of parameters, and cross validation of + at Hastie2009, and including time series specific models such as the data driven +approach "revealed performance" approach of @Racine2009, all available tools +from the forecasting literature should be considered for evaluating proposed +signal processes. It should be clear that evaluating the signal generating process offers multiple opportunities to re-evaluate assumptions about the method of @@ -655,11 +654,15 @@ information about the instruments you are examining. If not, stop and go back and reexamine your hypotheses. Assuming that you do have both a theoretical and empirical basis on which to proceed, it is time to define the -strategy's trading rules. +strategy's trading rules. Much of the work involved in evaluating "technical trading rules" described in the literature is really an evaluation of signal processes, described -in depth above. +in depth above. Rules should refine the way the strategy 'listens' to signals, +producing path-dependent actions based on the current state of the market, +your portfolio, and the indicators and signals. Separate from whether a +signal has predictive power or not, as described above, evaluation of rules +is an evaluation of the actions taken in response to the rule. ## entry rules @@ -1579,7 +1582,7 @@ [@Bailey2014probability, p.17] - prior remarks about overlapping periods, parameter autocorrelation, and *i.i.d.* assumptions apply here as well -- @harvey2013backtesting , @harvey2014 , @harvey2013multiple look at Type I vs Type II error in evaluating +- @Harvey2013backtesting , @Harvey2014 , @Harvey2013multiple look at Type I vs Type II error in evaluating backtests and look at appropriate haircuts based on this. Modified: pkg/quantstrat/sandbox/backtest_musings/strat_dev_process.pdf =================================================================== (Binary files differ)