From noreply at r-forge.r-project.org Sun Nov 1 18:01:52 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 1 Nov 2015 18:01:52 +0100 (CET) Subject: [Blotter-commits] r1707 - in pkg/quantstrat: . R man Message-ID: <20151101170152.DA581187718@r-forge.r-project.org> Author: bodanker Date: 2015-11-01 18:01:52 +0100 (Sun, 01 Nov 2015) New Revision: 1707 Added: pkg/quantstrat/R/quantstrat-package.R Modified: pkg/quantstrat/DESCRIPTION pkg/quantstrat/NAMESPACE pkg/quantstrat/man/quantstrat-package.Rd Log: Import package dependencies into namespace This was prompted by the nonsense that is dplyr::lag, which masks the stats::lag generic and does not do any method dispatch. dplyr also masks the first and last generics defined in xts. This should avoid any issues in quantstrat if dplyr is loaded after xts. Note that user's non-packaged code will still be affected by package load/attach order. The above is achieved by creating R/quantstrat-package.R by calling Rd2roxygen on man/quantstrat-package.Rd, and then adding the necessary @import directives. Also add the "Generated by roxygen2" to quantstrat- package.Rd so roxygen will update the file. Update Depends and Imports in DESCRIPTION (and add a period at the end of the Description so R CMD check won't pedantically complain). Modified: pkg/quantstrat/DESCRIPTION =================================================================== --- pkg/quantstrat/DESCRIPTION 2015-10-30 13:20:08 UTC (rev 1706) +++ pkg/quantstrat/DESCRIPTION 2015-11-01 17:01:52 UTC (rev 1707) @@ -5,10 +5,13 @@ Date: $Date$ Author: Peter Carl, Brian G. Peterson, Joshua Ulrich, Jan Humme Depends: - xts(>= 0.8-2),TTR(>= 0.2), + quantmod, + xts(>= 0.8-2), blotter(>= 0.9), FinancialInstrument(>= 0.12.5), foreach(>= 1.4.0) +Imports: + zoo Suggests: PerformanceAnalytics, PortfolioAnalytics, @@ -20,7 +23,7 @@ beanplot Maintainer: Brian G. Peterson Description: Specify, build, and back-test quantitative - financial trading and portfolio strategies + financial trading and portfolio strategies. Contributors: Yu Chen, Joe Dunn, Dirk Eddelbuettel, Michael Guan, Jeffrey A. Ryan, Garrett See LazyLoad: yes Modified: pkg/quantstrat/NAMESPACE =================================================================== --- pkg/quantstrat/NAMESPACE 2015-10-30 13:20:08 UTC (rev 1706) +++ pkg/quantstrat/NAMESPACE 2015-11-01 17:01:52 UTC (rev 1707) @@ -61,4 +61,9 @@ export(updateOrders) export(updateStrategy) export(walk.forward) +import(FinancialInstrument) +import(blotter) +import(quantmod) +import(xts) +import(zoo) useDynLib(quantstrat) Added: pkg/quantstrat/R/quantstrat-package.R =================================================================== --- pkg/quantstrat/R/quantstrat-package.R (rev 0) +++ pkg/quantstrat/R/quantstrat-package.R 2015-11-01 17:01:52 UTC (rev 1707) @@ -0,0 +1,106 @@ +#' Quantitative Strategy Model Framework +#' +#' Transaction-oriented infrastructure for constructing trading systems and +#' simulation. Provides support for multi-asset class and multi-currency +#' portfolios for backtesting and other financial research. Still in heavy +#' development. +#' +#' quantstrat provides a generic infrastructure to model and backtest +#' signal-based quantitative strategies. It is a high-level abstraction layer +#' (built on xts, FinancialInstrument, blotter, etc.) that allows you to build +#' and test strategies in very few lines of code. quantstrat is still under +#' heavy development but is being used every day on real portfolios. We +#' encourage you to send contributions and test cases to the project forums. +#' +#' \emph{Generic Signal-Based Strategy Modeling} +#' +#' A signal-based strategy model first generates indicators. Indicators are +#' quantitative values derived from market data (e.g. moving averages, RSI, +#' volatility bands, channels, momentum, etc.). Indicators should be applied +#' to market data in a vectorized (for fast backtesting) or streaming (for live +#' execution) fashion, and are assumed to be path-independent (i.e. they do not +#' depend on account / portfolio characteristics, current positions, or +#' trades). +#' +#' The interaction between indicators and market data are used to generate +#' signals (e.g. crossovers, thresholds, multiples, etc.). These signals are +#' points in time at which you may want to take some action, even though you +#' may not be able to. Like indicators, signals may be applied in a vectorized +#' or streaming fashion, and are assumed to be path-independent. +#' +#' Rules use market data, indicators, signals, and current account / portfolio +#' characteristics to generate orders. Notice that rules about position +#' sizing, fill simulation, order generation / management, etc. are separate +#' from the indicator and signal generation process. Unlike indicators and +#' signals, rules are generally evaluated in a path-dependent fashion +#' (path-independent rules are supported but are rare in real life) and are +#' aware of all prior market data and current positions at the time of +#' evaluation. Rules may either generate new or modify existing orders (e.g. +#' risk management, fill, rebalance, entry, exit). +#' +#' \emph{How quantstrat Models Strategies} +#' +#' quantstrat uses FinancialInstrument to specify instruments (including their +#' currencies) and uses blotter to keep track of transactions, valuations, and +#' P&amp;L across portfolios and accounts. +#' +#' Indicators are often standard technical analysis functions like those found +#' in TTR; and signals are often specified by the quantstrat sig* functions +#' (i.e. sigComparison, sigCrossover, sigFormula, sigPeak, sigThreshold). +#' Rules are typically specified with the quantstrat ruleSignal function. +#' +#' The functions used to specify indicators, signals, and rules are not limited +#' to those mentioned previously. The name parameter to add.indicator, +#' add.signal, and add.rule can be any R function. Because the supporting +#' toolchain is built using xts objects, custom functions will integrate most +#' easily if they return xts objects. +#' +#' The strategy model is created in layers and makes use of delayed execution. +#' This means strategies can be applied--unmodified--to several different +#' portfolios. Before execution, quantstrat strategy objects do not know what +#' instruments they will be applied to or what parameters will be passed to +#' them. +#' +#' For example, indicator parameters such as moving average periods or +#' thresholds are likely to affect strategy performance. Default values for +#' parameters may (optionally) be set in the strategy object, or set at +#' call-time via the parameters argument of applyStrategy (parameters is a +#' named list, used like the arguments lists). +#' +#' quantstrat models orders, which may or may not become transactions. This +#' provides a lot of extra ability to evaluate how the strategy is actually +#' working, not working, or could be improved. For example, the performance of +#' strategies are often affected by how often resting limit orders are changed +#' / replaced / canceled. An order book allows the quantitative strategist to +#' examine market conditions at the time these decisions are made. Also, the +#' order history allows for easy computation of things that are important for +#' many strategies, like order-to-fill ratios. +#' +#' \emph{Argument Matching} +#' +#' Many places in quantstrat apply arguments passed in the strategy +#' specification, the parameters list, or in \code{...} to an indicator, +#' signal, or rule function. These arguments are matched in this order, with +#' the last math overriding. Specifically, this order is: +#' +#' \enumerate{ \item the \code{arguments=list(...)} assigned to each indicator, +#' signal, or rule \item the \code{parameters=list{...}} applied when +#' \code{\link{applyStrategy}} is called \item any additional arguments passed +#' in \code{...} in the call to \code{applyStrategy} } +#' +#' @name quantstrat-package +#' @aliases quantstrat-package quantstrat +#' @docType package +#' @author Peter Carl, Brian G. Peterson, Joshua Ulrich, Garrett See, Yu Chen +#' +#' Maintainer: Brian G. Peterson +#' @seealso \code{\link[quantmod:quantmod-package]{quantmod}}, +#' \code{\link[blotter:blotter-package]{blotter}}, +#' \code{\link[FinancialInstrument:FinancialInstrument-package]{FinancialInstrument}}, +#' \code{\link[blotter:blotter-package]{blotter}}, +#' \code{\link[PerformanceAnalytics:PerformanceAnalytics-package]{PerformanceAnalytics}} +#' @keywords package +# @examples +#' +#' @import blotter FinancialInstrument quantmod xts zoo +NULL Modified: pkg/quantstrat/man/quantstrat-package.Rd =================================================================== --- pkg/quantstrat/man/quantstrat-package.Rd 2015-10-30 13:20:08 UTC (rev 1706) +++ pkg/quantstrat/man/quantstrat-package.Rd 2015-11-01 17:01:52 UTC (rev 1707) @@ -1,3 +1,4 @@ +% Generated by roxygen2 (4.0.2): do not edit by hand \name{quantstrat-package} \alias{quantstrat-package} \alias{quantstrat} From noreply at r-forge.r-project.org Sun Nov 1 18:40:34 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 1 Nov 2015 18:40:34 +0100 (CET) Subject: [Blotter-commits] r1708 - in pkg/quantstrat: . R Message-ID: <20151101174034.D0AF4183CE2@r-forge.r-project.org> Author: bodanker Date: 2015-11-01 18:40:34 +0100 (Sun, 01 Nov 2015) New Revision: 1708 Modified: pkg/quantstrat/NAMESPACE pkg/quantstrat/R/quantstrat-package.R Log: Missed foreach import Modified: pkg/quantstrat/NAMESPACE =================================================================== --- pkg/quantstrat/NAMESPACE 2015-11-01 17:01:52 UTC (rev 1707) +++ pkg/quantstrat/NAMESPACE 2015-11-01 17:40:34 UTC (rev 1708) @@ -63,6 +63,7 @@ export(walk.forward) import(FinancialInstrument) import(blotter) +import(foreach) import(quantmod) import(xts) import(zoo) Modified: pkg/quantstrat/R/quantstrat-package.R =================================================================== --- pkg/quantstrat/R/quantstrat-package.R 2015-11-01 17:01:52 UTC (rev 1707) +++ pkg/quantstrat/R/quantstrat-package.R 2015-11-01 17:40:34 UTC (rev 1708) @@ -102,5 +102,5 @@ #' @keywords package # @examples #' -#' @import blotter FinancialInstrument quantmod xts zoo +#' @import blotter FinancialInstrument foreach quantmod xts zoo NULL From noreply at r-forge.r-project.org Sun Nov 1 22:36:29 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 1 Nov 2015 22:36:29 +0100 (CET) Subject: [Blotter-commits] r1709 - in pkg/quantstrat: . R demo man Message-ID: <20151101213629.ADD3518761C@r-forge.r-project.org> Author: bodanker Date: 2015-11-01 22:36:29 +0100 (Sun, 01 Nov 2015) New Revision: 1709 Added: pkg/quantstrat/man/signal.path.plot.Rd pkg/quantstrat/man/signal.plot.Rd Removed: pkg/quantstrat/man/add.constraint.Rd pkg/quantstrat/man/applyStrategy.rebalancing.training.Rd pkg/quantstrat/man/plot.signal.path.Rd pkg/quantstrat/man/plot.signals.Rd Modified: pkg/quantstrat/DESCRIPTION pkg/quantstrat/NAMESPACE pkg/quantstrat/R/initialize.R pkg/quantstrat/R/paramsets.R pkg/quantstrat/R/signals.R pkg/quantstrat/R/tradeOrderStats.R pkg/quantstrat/R/walk.forward.R pkg/quantstrat/demo/signal.SMA.R 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/apply.paramset.signal.analysis.Rd pkg/quantstrat/man/applyIndicatorSignals.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/beanplot.signals.Rd pkg/quantstrat/man/chart.forward.Rd pkg/quantstrat/man/chart.forward.training.Rd pkg/quantstrat/man/delete.paramset.Rd pkg/quantstrat/man/distributional.boxplot.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/initSymbol.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/post.signal.returns.Rd pkg/quantstrat/man/put.orderbook.Rd pkg/quantstrat/man/put.strategy.Rd pkg/quantstrat/man/quantstrat-package.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/signal.generate.statistics.Rd pkg/quantstrat/man/signal.obj.slope.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: Fix docs/missed-renaming issues, roxygenize Document '...' usage in several functions. Add description to tradeOrderStats. Remove unicode characters from signal plotting docs. Remove inadvertently committed applyStrategy.rebalancing.training.Rd. Remove unnecessary quantstrat::: when calling install.param.combo. Fix typos in signal plotting code and delete.paramset docs. Apply the following renamings that were missed: r1499: s/add.constraint/add.distribution.constraint/ (rm .Rd file) r1673: s/plot.signals/signal.plot/ r1673: s/plot.signal.path/signal.path.plot/ Bump version. Modified: pkg/quantstrat/DESCRIPTION =================================================================== --- pkg/quantstrat/DESCRIPTION 2015-11-01 17:40:34 UTC (rev 1708) +++ pkg/quantstrat/DESCRIPTION 2015-11-01 21:36:29 UTC (rev 1709) @@ -1,7 +1,7 @@ Package: quantstrat Type: Package Title: Quantitative Strategy Model Framework -Version: 0.9.1702 +Version: 0.9.1709 Date: $Date$ Author: Peter Carl, Brian G. Peterson, Joshua Ulrich, Jan Humme Depends: @@ -30,3 +30,4 @@ License: GPL-3 Copyright: (c) 2009-2015 ByteCompile: TRUE +RoxygenNote: 5.0.0 Modified: pkg/quantstrat/NAMESPACE =================================================================== --- pkg/quantstrat/NAMESPACE 2015-11-01 17:40:34 UTC (rev 1708) +++ pkg/quantstrat/NAMESPACE 2015-11-01 21:36:29 UTC (rev 1709) @@ -1,4 +1,4 @@ -# Generated by roxygen2 (4.0.2): do not edit by hand +# Generated by roxygen2: do not edit by hand export(add.distribution) export(add.distribution.constraint) Modified: pkg/quantstrat/R/initialize.R =================================================================== --- pkg/quantstrat/R/initialize.R 2015-11-01 17:40:34 UTC (rev 1708) +++ pkg/quantstrat/R/initialize.R 2015-11-01 21:36:29 UTC (rev 1709) @@ -185,7 +185,7 @@ #' #' @param strategy an object (or the name of an object) of type 'strategy' to add the init function definition to #' @param symbol symbol -#' @param ... +#' @param \dots any other passthrough parameters #' @export initSymbol <- function(strategy, symbol, ...){ Modified: pkg/quantstrat/R/paramsets.R =================================================================== --- pkg/quantstrat/R/paramsets.R 2015-11-01 17:40:34 UTC (rev 1708) +++ pkg/quantstrat/R/paramsets.R 2015-11-01 21:36:29 UTC (rev 1709) @@ -225,7 +225,7 @@ #' #' @author Jan Humme #' @export -#' @seealso \code{\link{add.distibution}}, \code{\link{add.distribution.constraint}}, \code{\link{apply.paramset}} +#' @seealso \code{\link{add.distribution}}, \code{\link{add.distribution.constraint}}, \code{\link{apply.paramset}} delete.paramset <- function(strategy, paramset.label, store=TRUE) { Modified: pkg/quantstrat/R/signals.R =================================================================== --- pkg/quantstrat/R/signals.R 2015-11-01 17:40:34 UTC (rev 1708) +++ pkg/quantstrat/R/signals.R 2015-11-01 21:36:29 UTC (rev 1709) @@ -477,7 +477,7 @@ if(verbose)cat("Applying Parameter Set: ",toString(param.combo),'\n') # Attached Paramset to Strategy Object - strategy <- quantstrat:::install.param.combo(strategy, param.combo, paramset.label) + strategy <- install.param.combo(strategy, param.combo, paramset.label) # Generate Indicators and Signals for Given Paramset name.ref = paste('paramset.',gsub(", ",".",toString(param.combo)),sep='') @@ -522,6 +522,7 @@ #' @param portfolio text name of the portfolio to associate the order book with #' @param mktdata market data #' @param sigcol String name of signal to use for analysis +#' @param ... any other passthru parameters #' @author Michael Guan #' @return \code{xts} object with columns representing signals for each symbol #' @seealso @@ -595,7 +596,7 @@ #' This function collects and aggregates post signal price changes for N days forward. #' #' @param signals xts object with signals, one column -#' @param sigvals signal value to match against +#' @param sigval signal value to match against #' @param on the periods endpoints to find as a character string #' @param forward.days number of days to look forward after signal (days to exit post signal) #' @param cum.sum \code{TRUE},\code{FALSE}; cumulative sum of price changes @@ -776,7 +777,7 @@ #' there are lots paramsets, it is best to plot a smaller portion so the #' information can be displayed clearly. #' -#' @param signal list of paramset forward looking price changes by asset +#' @param signals list of paramset forward looking price changes by asset #' @param rows number of rows for plot #' @param columns number of columns for plot #' @param mai A numerical vector of the form c(bottom, left, top, right) which gives the margin size specified in inches. @@ -787,7 +788,8 @@ #' @param xaxt A character which specifies the x axis type. Specifying "n" suppresses plotting of the axis. The standard value is "s": for compatibility with S values "l" and "t" are accepted but are equivalent to "s": any value other than "n" implies plotting. #' @param cex.axis The magnification to be used for axis annotation relative to the current setting of cex. #' @param h the y-value(s) for horizontal line(s). -#' @param hlinecol A specification for the default plotting color. See section ?Color Specification?. +#' @param hlinecol A specification for the default plotting color. See section \sQuote{Color Specification}. +#' @param ... any other passthru parameters #' @author Michael Guan #' @export @@ -817,10 +819,10 @@ #' Visualization of Signal Across Lookback with Beanplots #' -#' This function is similar to \code{plot.signals} but uses beanplots +#' This function is similar to \code{signal.plot} but uses beanplots #' instead of barplots. Requires 'beanplot' package #' -#' @param signal list of paramset forward looking price changes by asset +#' @param signals list of paramset forward looking price changes by asset #' @param rows number of rows for plot #' @param columns number of columns for plot #' @param mai A numerical vector of the form c(bottom, left, top, right) which gives the margin size specified in inches. @@ -831,7 +833,8 @@ #' @param xaxt A character which specifies the x axis type. Specifying "n" suppresses plotting of the axis. The standard value is "s": for compatibility with S values "l" and "t" are accepted but are equivalent to "s": any value other than "n" implies plotting. #' @param cex.axis The magnification to be used for axis annotation relative to the current setting of cex. #' @param h the y-value(s) for horizontal line(s). -#' @param hlinecol A specification for the default plotting color. See section ?Color Specification?. +#' @param hlinecol A specification for the default plotting color. See section \sQuote{Color Specification}. +#' @param ... any other passthru parameters #' @author Michael Guan #' @return plot #' @export @@ -871,6 +874,7 @@ #' @param xlim the x limits in the plot #' @param mai A numerical vector of the form c(bottom, left, top, right) which gives the margin size specified in inches. #' @param h the y-value(s) for horizontal line(s). +#' @param ... any other passthru parameters #' @author Michael Guan #' @return plot #' @export @@ -924,7 +928,7 @@ #' @examples #' \dontrun{ #' # signalAnalysisExample1.R -#' plot.signal.path(results$sigret.by.asset$RTH$paramset.1.5[1:10,]) +#' signal.plot.path(results$sigret.by.asset$RTH$paramset.1.5[1:10,]) #' } #' @export signal.path.plot<-function(data,main='Cumulative Return Paths'){ Modified: pkg/quantstrat/R/tradeOrderStats.R =================================================================== --- pkg/quantstrat/R/tradeOrderStats.R 2015-11-01 17:40:34 UTC (rev 1708) +++ pkg/quantstrat/R/tradeOrderStats.R 2015-11-01 21:36:29 UTC (rev 1709) @@ -1,7 +1,7 @@ #' get order information associated with closing positions #' +#' Combine perTradeStats output with closed order information. #' -#' #' TODO: decide which of these columns are actually important #' TODO: add option for opening order/trade pairing rather than closing #' Modified: pkg/quantstrat/R/walk.forward.R =================================================================== --- pkg/quantstrat/R/walk.forward.R 2015-11-01 17:40:34 UTC (rev 1708) +++ pkg/quantstrat/R/walk.forward.R 2015-11-01 21:36:29 UTC (rev 1709) @@ -146,7 +146,7 @@ } # configure strategy to use selected param.combo - strategy <- quantstrat:::install.param.combo(strategy, param.combo, paramset.label) + strategy <- install.param.combo(strategy, param.combo, paramset.label) result$testing.timespan <- testing.timespan Modified: pkg/quantstrat/demo/signal.SMA.R =================================================================== --- pkg/quantstrat/demo/signal.SMA.R 2015-11-01 17:40:34 UTC (rev 1708) +++ pkg/quantstrat/demo/signal.SMA.R 2015-11-01 21:36:29 UTC (rev 1709) @@ -127,7 +127,7 @@ x.val=seq(1, 10, 2),val=10,ylim=c(-20, 20), xlim=c(0, 10),mai=c(1,1,0.3,0.5),h=0) -plot.signals(results.w$sigret.by.asset$XLE, rows=5, columns = 4) +signal.plot(results.w$sigret.by.asset$XLE, rows=5, columns = 4) beanplot.signals(results.w$sigret.by.asset$XLE, rows=5, columns = 4) @@ -148,7 +148,7 @@ x.val=seq(1, 5, 1),val=10,ylim=c(-30, 30), xlim=c(0, 5),mai=c(1,1,0.3,0.5),h=0) -plot.signals(results.m$sigret.by.asset$XLE, rows=5, columns = 4) +signal.plot(results.m$sigret.by.asset$XLE, rows=5, columns = 4) beanplot.signals(results.m$sigret.by.asset$XLE, rows=5, columns = 4) ############################################################################### Deleted: pkg/quantstrat/man/add.constraint.Rd =================================================================== --- pkg/quantstrat/man/add.constraint.Rd 2015-11-01 17:40:34 UTC (rev 1708) +++ pkg/quantstrat/man/add.constraint.Rd 2015-11-01 21:36:29 UTC (rev 1709) @@ -1,44 +0,0 @@ -\name{add.constraint} -\alias{add.constraint} -\title{Adds a constraint on 2 distributions within a paramset} -\usage{ - add.constraint(strategy, paramset.label, - distribution.label.1, distribution.label.2, operator, - label, store = TRUE) -} -\arguments{ - \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{distribution.label.1}{a label identifying the first - distribution} - - \item{distribution.label.2}{a label identifying the - second distribution} - - \item{operator}{an operator specifying the relational - constraint between the 2 distributions} - - \item{label}{a label uniquely identifying the constraint - within the paramset} - - \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. -} -\author{ - Jan Humme -} -\seealso{ - \code{\link{add.distribution}}, - \code{\link{delete.paramset}}, - \code{\link{apply.paramset}} -} - Modified: pkg/quantstrat/man/add.distribution.Rd =================================================================== --- pkg/quantstrat/man/add.distribution.Rd 2015-11-01 17:40:34 UTC (rev 1708) +++ pkg/quantstrat/man/add.distribution.Rd 2015-11-01 21:36:29 UTC (rev 1709) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/paramsets.R \name{add.distribution} \alias{add.distribution} \title{Adds a distribution to a paramset in a strategy} Modified: pkg/quantstrat/man/add.distribution.constraint.Rd =================================================================== --- pkg/quantstrat/man/add.distribution.constraint.Rd 2015-11-01 17:40:34 UTC (rev 1708) +++ pkg/quantstrat/man/add.distribution.constraint.Rd 2015-11-01 21:36:29 UTC (rev 1709) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/paramsets.R \name{add.distribution.constraint} \alias{add.distribution.constraint} \title{Adds a constraint on 2 distributions within a paramset} Modified: pkg/quantstrat/man/add.indicator.Rd =================================================================== --- pkg/quantstrat/man/add.indicator.Rd 2015-11-01 17:40:34 UTC (rev 1708) +++ pkg/quantstrat/man/add.indicator.Rd 2015-11-01 21:36:29 UTC (rev 1709) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/indicators.R \name{add.indicator} \alias{add.indicator} \title{add an indicator to a strategy} @@ -30,43 +31,43 @@ 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, +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 applied before signals and rules, and the output of indicators +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. +\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}. -\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, +\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. +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 +\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. +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 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 +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{ Modified: pkg/quantstrat/man/add.init.Rd =================================================================== --- pkg/quantstrat/man/add.init.Rd 2015-11-01 17:40:34 UTC (rev 1708) +++ pkg/quantstrat/man/add.init.Rd 2015-11-01 21:36:29 UTC (rev 1709) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/initialize.R \name{add.init} \alias{add.init} \title{add arbitrary initialization functions to a strategy} @@ -29,8 +30,8 @@ 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 +\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{ @@ -38,8 +39,8 @@ 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 +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 2015-11-01 17:40:34 UTC (rev 1708) +++ pkg/quantstrat/man/add.rule.Rd 2015-11-01 21:36:29 UTC (rev 1709) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/rules.R \name{add.rule} \alias{add.rule} \title{add a rule to a strategy} @@ -44,9 +45,9 @@ 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 +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, +\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: @@ -57,47 +58,47 @@ \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 +} + +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 +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 +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, +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 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 +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 2015-11-01 17:40:34 UTC (rev 1708) +++ pkg/quantstrat/man/add.signal.Rd 2015-11-01 21:36:29 UTC (rev 1709) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/signals.R \name{add.signal} \alias{add.signal} \title{add a signal to a strategy} @@ -32,15 +33,15 @@ 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 +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 +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{ Modified: pkg/quantstrat/man/addOrder.Rd =================================================================== --- pkg/quantstrat/man/addOrder.Rd 2015-11-01 17:40:34 UTC (rev 1708) +++ pkg/quantstrat/man/addOrder.Rd 2015-11-01 21:36:29 UTC (rev 1709) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/orders.R \name{addOrder} \alias{addOrder} \title{add an order to the order book} @@ -53,28 +54,28 @@ \description{ It is important to understand that all the order functionality included in \code{quantstrat} exists to more closely model a real trading environment both in backtesting and in production. -Many backtesting systems make a set of assumptions about instant execution, -and we have chosen not to do this in quantstrat, because real quantitative -trading systems do not have instant execution. They make decisions +Many backtesting systems make a set of assumptions about instant execution, +and we have chosen not to do this in quantstrat, because real quantitative +trading systems do not have instant execution. They make decisions (the Rules) and then enter orders (the province of this function in backtesting), -during which there is some \code{delay} between receiving the data that fires the -Signal and Rule, and the time the order reaches the market, and then those orders +during which there is some \code{delay} between receiving the data that fires the +Signal and Rule, and the time the order reaches the market, and then those orders \emph{MAY} become transactions if market prices and liquidity cooperate. } \details{ -By default, this function will locate and replace any 'open' order(s) -on the requested portfolio/symbol that have the same order +By default, this function will locate and replace any 'open' order(s) +on the requested portfolio/symbol that have the same order type and side. If an orderset is also specified and replace=TRUE, -\emph{all open orders} for the orderset will be replaced. +\emph{all open orders} for the orderset will be replaced. If you do not want open orders to be canceled and replaced with the new order, set \code{replace=FALSE}. - + We have modeled a 'limit' order, used to enter or exit a position at a specific price, determined by the prefered price (see \code{prefer}) plus \code{threshold} (see below). We have modeled two types of stop orders, which should be sufficient to model most types of stops. -We have modeled the simplest type, a 'stoplimit' order, which is just a limit order used to enter +We have modeled the simplest type, a 'stoplimit' order, which is just a limit order used to enter or exit a position at a specific price, determined by the prefered price (see \code{prefer}) plus \code{threshold} (see below). The stoplimit order type can be used to implement both stop-enter (long/buy or short/sell) and stop-loss (long/sell or short/buy) style limit orders. There is no functional difference between a @@ -86,20 +87,20 @@ of the order. In this way, a 10 pct trailing exit will not change in size from the current price as the price changes. Be aware that a stoptrailing order may be moved ("replaced") frequently. -Some markets and brokers recognize a stop that triggers a market order, when the stop is triggered, +Some markets and brokers recognize a stop that triggers a market order, when the stop is triggered, a market order will be executed at the then-prevailing price. We have not modeled this type of order. We have also added the 'iceberg' order type. This order type should -most often be paired with \code{delay} and \code{\link{osMaxPos}}. The -iceberg order when initially entered is treated like a limit -order, with an optional \code{threshold} (which is applied at initial order +most often be paired with \code{delay} and \code{\link{osMaxPos}}. The +iceberg order when initially entered is treated like a limit +order, with an optional \code{threshold} (which is applied at initial order entry, so be careful). Right now, they will enter a new order at price+threshold -upon any execution of the prior iceberg order. This process could -be infinite if \code{\link{osMaxPos}} or an equivalent order sizing +upon any execution of the prior iceberg order. This process could +be infinite if \code{\link{osMaxPos}} or an equivalent order sizing function is not used to limit total position size. An order \code{delay} -is also advisable to model the delay that occurs between getting the trade +is also advisable to model the delay that occurs between getting the trade confirmation of the previous trade and entering the new order into the order book. - + The 'limit', 'stoplimit', 'stoptrailing' and 'iceberg' order types are the only order types that make use of the order \code{threshold}. Thresholds may be specified in one of 2 ways: as a scalar (\code{tmult=FALSE}) or as a multiplier for the current price (\code{tmult=TRUE}). If \code{tmult=TRUE}, \code{threshold} is converted to a @@ -111,10 +112,10 @@ provide all thresholds as a positive number, and the software will automagically figure out whether to add or subtract the threshold amount from the price. -If you ever wanted to move from a backtesting mode to a production mode, -this function (and the linked funtion \code{\link{ruleOrderProc}}) would -need to be replaced by functions that worked against your execution environment. -Basically, the execution environment must provide three interfaces in a live +If you ever wanted to move from a backtesting mode to a production mode, +this function (and the linked funtion \code{\link{ruleOrderProc}}) would +need to be replaced by functions that worked against your execution environment. +Basically, the execution environment must provide three interfaces in a live trading environment: \enumerate{ @@ -122,10 +123,10 @@ \item an order interface for sending orders (and canceling or updating them) to the market -\item a fill interface that reports the transaction details when an order has been filled +\item a fill interface that reports the transaction details when an order has been filled } -Conversion to a live trading environment will also likely require a new version of +Conversion to a live trading environment will also likely require a new version of \code{\link{applyStrategy}} to provide the event loop interface and interact with \code{mktdata}. } \seealso{ Modified: pkg/quantstrat/man/addPosLimit.Rd =================================================================== --- pkg/quantstrat/man/addPosLimit.Rd 2015-11-01 17:40:34 UTC (rev 1708) +++ pkg/quantstrat/man/addPosLimit.Rd 2015-11-01 21:36:29 UTC (rev 1709) @@ -1,4 +1,5 @@ -% Generated by roxygen2 (4.0.2): do not edit by hand +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/osFUNs.R \name{addPosLimit} \alias{addPosLimit} \title{add position and level limits at timestamp} @@ -26,32 +27,32 @@ Typically, constraints will include position sizing limits. } \details{ -\code{addPosLimit} works with \code{\link{osMaxPos}} to set +\code{addPosLimit} works with \code{\link{osMaxPos}} to set and enforce position sizing limits. If \code{levels=1}, then all order sizing will be in the complete control of the strategy rules, up to the maximum position specified -using \code{addPosLimit}'s \code{maxpos} and \code{minpos} +using \code{addPosLimit}'s \code{maxpos} and \code{minpos} arguments. - + Simply setting a position limit will not do anything. The strategy entry rules also need to specify an -the use of order sizing function \code{\link{osMaxPos}}, +the use of order sizing function \code{\link{osMaxPos}}, most typically as an argument to \code{\link{ruleSignal}}. -levels are a simplification of more complex (proprietary) -techniques sometimes used for order sizing. [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/blotter -r 1709 From noreply at r-forge.r-project.org Mon Nov 2 00:26:51 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 2 Nov 2015 00:26:51 +0100 (CET) Subject: [Blotter-commits] r1710 - in pkg/quantstrat: R man Message-ID: <20151101232651.D169818658A@r-forge.r-project.org> Author: bodanker Date: 2015-11-02 00:26:50 +0100 (Mon, 02 Nov 2015) New Revision: 1710 Modified: pkg/quantstrat/R/chart.forward.R pkg/quantstrat/R/chart.forward.training.R pkg/quantstrat/R/orders.R pkg/quantstrat/man/getOrderBook.Rd Log: Fix minor issues caught by R CMD check Remove unneeded require(xtsExtra) call from chart.forward and chart.forward.training. Correct getOrderBook alias (was getOrderbook). Modified: pkg/quantstrat/R/chart.forward.R =================================================================== --- pkg/quantstrat/R/chart.forward.R 2015-11-01 21:36:29 UTC (rev 1709) +++ pkg/quantstrat/R/chart.forward.R 2015-11-01 23:26:50 UTC (rev 1710) @@ -6,8 +6,6 @@ chart.forward <- function(audit.filename) { - if(!require(xtsExtra, quietly=TRUE)) stop('The "xtsExtra" package is required to use this function') - #.audit <- NULL if(is.null(.audit)) stop ('You need to run a walk forward test first to create the .audit environment') Modified: pkg/quantstrat/R/chart.forward.training.R =================================================================== --- pkg/quantstrat/R/chart.forward.training.R 2015-11-01 21:36:29 UTC (rev 1709) +++ pkg/quantstrat/R/chart.forward.training.R 2015-11-01 23:26:50 UTC (rev 1710) @@ -6,8 +6,6 @@ chart.forward.training <- function(audit.filename) { - if(!require(xtsExtra, quietly=TRUE)) stop('The "xtsExtra" package is required to use this function') - .audit <- NULL load(audit.filename) Modified: pkg/quantstrat/R/orders.R =================================================================== --- pkg/quantstrat/R/orders.R 2015-11-01 21:36:29 UTC (rev 1709) +++ pkg/quantstrat/R/orders.R 2015-11-01 23:26:50 UTC (rev 1710) @@ -23,7 +23,7 @@ #' } #' @aliases #' get.orderbook -#' getOrderbook +#' getOrderBook #' @rdname getOrderBook #' @export get.orderbook #' @export getOrderBook Modified: pkg/quantstrat/man/getOrderBook.Rd =================================================================== --- pkg/quantstrat/man/getOrderBook.Rd 2015-11-01 21:36:29 UTC (rev 1709) +++ pkg/quantstrat/man/getOrderBook.Rd 2015-11-01 23:26:50 UTC (rev 1710) @@ -2,7 +2,7 @@ % Please edit documentation in R/orders.R \name{get.orderbook} \alias{get.orderbook} -\alias{getOrderbook} +\alias{getOrderBook} \title{get the order book object} \usage{ get.orderbook(portfolio, envir = .strategy) From noreply at r-forge.r-project.org Mon Nov 2 02:37:39 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 2 Nov 2015 02:37:39 +0100 (CET) Subject: [Blotter-commits] r1711 - pkg/quantstrat/demo Message-ID: <20151102013739.7AA97187CBD@r-forge.r-project.org> Author: bodanker Date: 2015-11-02 02:37:38 +0100 (Mon, 02 Nov 2015) New Revision: 1711 Modified: pkg/quantstrat/demo/00Index pkg/quantstrat/demo/luxor.6.paramset.stoploss.R pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R pkg/quantstrat/demo/luxor.getSymbols.R pkg/quantstrat/demo/luxor.sample.MAE.stoploss.R pkg/quantstrat/demo/luxor.sample.MAE.stoptrailing.R pkg/quantstrat/demo/luxor.sample.MFE.takeprofit.R pkg/quantstrat/demo/luxor.sample.tradeGraphs.sma.R pkg/quantstrat/demo/luxor.sample.tradeGraphs.timespan.R pkg/quantstrat/demo/luxor.sample.walk.forward.R Log: Fix demo/00Index and file permissions Demo names should not contain the .R extension. Add missing demos. Ensure all hash-bang (#!) demos have the correct permissions to run. Modified: pkg/quantstrat/demo/00Index =================================================================== --- pkg/quantstrat/demo/00Index 2015-11-01 23:26:50 UTC (rev 1710) +++ pkg/quantstrat/demo/00Index 2015-11-02 01:37:38 UTC (rev 1711) @@ -9,23 +9,26 @@ bee Milktrader's Bumblebee FastMA/BBands cross system bbandParameters example of parameter test on bbands demo strategy macdParameters example of parameter test on macd demo strategy -luxor.1.strategy.basic.R Jaekle & Tomasini; Sections 3.2: basic luxor strategy not using ordersets or orderchains -luxor.2.add.paramsets.R Jaekle & Tomasini; Sections 3.3: variation of the input parameters -luxor.3.paramset.sma.R Jaekle & Tomasini; Sections 3.3: variation of the input parameters -luxor.4.paramset.timespan.R Jaekle & Tomasini; Sections 3.4: inserting an intraday time filter -luxor.5.strategy.ordersets.R Jaekle & Tomasini; Sections 3.5: strategy implementation using ordersets and orderchains -luxor.6.paramset.stoploss.R Jaekle & Tomasini; Sections 3.5: paramset implementation for stoploss optimization -luxor.6.paramset.stoptrailing.R Jaekle & Tomasini; Sections 3.5: paramset implementation for stop trailing optimization -luxor.6.paramset.takeprofit.R Jaekle & Tomasini; Sections 3.5: paramset implementation for take profit optimization -luxor.7.exit.and.risk.R Jaekle & Tomasini; Sections 3.5: running with stoploss and/or stoptrailing and/or takeprofit -luxor.8.walk.forward.R Jaekle & Tomasini; Sections 6: walk forward analysis -luxor.getSymbols.R Jaekle & Tomasini; reading symbols -luxor.include.R Jaekle & Tomasini; Sections constants -luxor.sample.MAE.stoploss.R Jaekle & Tomasini; sample MAE stoploss graph -luxor.sample.MAE.stoptrailing.R Jaekle & Tomasini; sample MAE stoptrailing graph -luxor.sample.MFE.takeprofit.R Jaekle & Tomasini; sample MFE take profit graph -luxor.sample.tradeGraphs.sma.R Jaekle & Tomasini; sample 3D SMA graph -luxor.sample.tradeGraphs.timespan.R Jaekle & Tomasini; sample 3D timespan graph -signal.SMA.R SMA Cross Strategy with Signal Analysis Example; See maCross.R -signal.RSI.R RSI Cross Strategy with Signal Analysis Example; See rsi.R +macdRebalancing example of applyStrategy.rebalancing on macd demo strategy +rocema Rate-of-Change EMA strategy: demonstrating ternary indicator, ordersets to handle simultaneous stop-loss and take-profit orders +luxor.1.strategy.basic Jaekle & Tomasini; Sections 3.2: basic luxor strategy not using ordersets or orderchains +luxor.2.add.paramsets Jaekle & Tomasini; Sections 3.3: variation of the input parameters +luxor.3.paramset.sma Jaekle & Tomasini; Sections 3.3: variation of the input parameters +luxor.4.paramset.timespan Jaekle & Tomasini; Sections 3.4: inserting an intraday time filter +luxor.5.strategy.ordersets Jaekle & Tomasini; Sections 3.5: strategy implementation using ordersets and orderchains +luxor.6.paramset.stoploss Jaekle & Tomasini; Sections 3.5: paramset implementation for stoploss optimization +luxor.6.paramset.stoptrailing Jaekle & Tomasini; Sections 3.5: paramset implementation for stop trailing optimization +luxor.6.paramset.takeprofit Jaekle & Tomasini; Sections 3.5: paramset implementation for take profit optimization +luxor.7.exit.and.risk Jaekle & Tomasini; Sections 3.5: running with stoploss and/or stoptrailing and/or takeprofit +luxor.8.walk.forward Jaekle & Tomasini; Sections 6: walk forward analysis +luxor.getSymbols Jaekle & Tomasini; reading symbols +luxor.include Jaekle & Tomasini; Sections constants +luxor.sample.MAE.stoploss Jaekle & Tomasini; sample MAE stoploss graph +luxor.sample.MAE.stoptrailing Jaekle & Tomasini; sample MAE stoptrailing graph +luxor.sample.MFE.takeprofit Jaekle & Tomasini; sample MFE take profit graph +luxor.sample.tradeGraphs.sma Jaekle & Tomasini; sample 3D SMA graph +luxor.sample.tradeGraphs.timespan Jaekle & Tomasini; sample 3D timespan graph +luxor.sample.walk.forward Jaekle & Tomasini; walk forward chart sample +signal.SMA SMA Cross Strategy with Signal Analysis Example; See maCross.R +signal.RSI RSI Cross Strategy with Signal Analysis Example; See rsi.R Property changes on: pkg/quantstrat/demo/luxor.6.paramset.stoploss.R ___________________________________________________________________ Added: svn:executable + * Property changes on: pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R ___________________________________________________________________ Added: svn:executable + * Property changes on: pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R ___________________________________________________________________ Added: svn:executable + * Property changes on: pkg/quantstrat/demo/luxor.getSymbols.R ___________________________________________________________________ Added: svn:executable + * Property changes on: pkg/quantstrat/demo/luxor.sample.MAE.stoploss.R ___________________________________________________________________ Added: svn:executable + * Property changes on: pkg/quantstrat/demo/luxor.sample.MAE.stoptrailing.R ___________________________________________________________________ Added: svn:executable + * Property changes on: pkg/quantstrat/demo/luxor.sample.MFE.takeprofit.R ___________________________________________________________________ Added: svn:executable + * Property changes on: pkg/quantstrat/demo/luxor.sample.tradeGraphs.sma.R ___________________________________________________________________ Added: svn:executable + * Property changes on: pkg/quantstrat/demo/luxor.sample.tradeGraphs.timespan.R ___________________________________________________________________ Added: svn:executable + * Property changes on: pkg/quantstrat/demo/luxor.sample.walk.forward.R ___________________________________________________________________ Added: svn:executable + * From noreply at r-forge.r-project.org Mon Nov 2 18:48:46 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 2 Nov 2015 18:48:46 +0100 (CET) Subject: [Blotter-commits] r1712 - pkg/quantstrat/R Message-ID: <20151102174846.1388E18747C@r-forge.r-project.org> Author: bodanker Date: 2015-11-02 18:48:45 +0100 (Mon, 02 Nov 2015) New Revision: 1712 Modified: pkg/quantstrat/R/orders.R pkg/quantstrat/R/ruleOrderProc.R Log: Fix TIF handling when mktdata index is Date Calling as.Date on an xts object does not work, because as.Date.default is dispatched and doesn't know how to handle xts objects. Use coredata to extract the TIF string from the xts object before calling as.Date. Address Brian's TODO FIXME to convert timestamp to POSIXct before adding the numeric time.in.force (documented to be in seconds). Modified: pkg/quantstrat/R/orders.R =================================================================== --- pkg/quantstrat/R/orders.R 2015-11-02 01:37:38 UTC (rev 1711) +++ pkg/quantstrat/R/orders.R 2015-11-02 17:48:45 UTC (rev 1712) @@ -386,11 +386,10 @@ else { if(is.numeric(time.in.force)) - time.in.force <- timestamp + time.in.force + time.in.force <- as.POSIXct(timestamp) + time.in.force time.in.force <- format(time.in.force, "%Y-%m-%d %H:%M:%OS") - #TODO FIXME this line probably needs to be sensitive to the index of the market data, Date vs POSIXct - } + } } #set up the other parameters Modified: pkg/quantstrat/R/ruleOrderProc.R =================================================================== --- pkg/quantstrat/R/ruleOrderProc.R 2015-11-02 01:37:38 UTC (rev 1711) +++ pkg/quantstrat/R/ruleOrderProc.R 2015-11-02 17:48:45 UTC (rev 1712) @@ -69,13 +69,13 @@ if(any(!tif.xts=='')) { if (any(indexClass(ordersubset)=='Date')) - tif <- as.Date(tif.xts) + tif <- as.Date(coredata(tif.xts)) else { - tif <- strptime(tif.xts, format='%Y-%m-%d %H:%M:%OS') + tif <- strptime(coredata(tif.xts), format='%Y-%m-%d %H:%M:%OS') tif.na <- is.na(tif) if(any(tif.na)) - tif[tif.na] <- strptime(tif.xts[tif.na], format='%Y-%m-%d %H:%M:%S') + tif[tif.na] <- strptime(coredata(tif.xts[tif.na]), format='%Y-%m-%d %H:%M:%S') } #check which ones should be expired From noreply at r-forge.r-project.org Wed Nov 11 20:49:55 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 11 Nov 2015 20:49:55 +0100 (CET) Subject: [Blotter-commits] r1713 - pkg/quantstrat/demo Message-ID: <20151111194955.CE71B1869C4@r-forge.r-project.org> Author: bodanker Date: 2015-11-11 20:49:55 +0100 (Wed, 11 Nov 2015) New Revision: 1713 Modified: pkg/quantstrat/demo/luxor.8.walk.forward.R Log: Get luxor.8 closer to running It seems unlikely this demo ever worked as committed. Even after ensuring robustbase and PerformanceAnalytics are installed, changing period="days" (since there isn't enough data for period="months"), and running the luxor.5 demo before running luxor.8, there's still an error caused by an attempt to calculate a 40+ period SMA on ~20 observations. I'm not sure how to fix that last issue, but these seem like enough changes for one commit. :) See R-Forge issue #6258. Modified: pkg/quantstrat/demo/luxor.8.walk.forward.R =================================================================== --- pkg/quantstrat/demo/luxor.8.walk.forward.R 2015-11-02 17:48:45 UTC (rev 1712) +++ pkg/quantstrat/demo/luxor.8.walk.forward.R 2015-11-11 19:49:55 UTC (rev 1713) @@ -12,6 +12,7 @@ source(paste0(path.package("quantstrat"),"/demo/luxor.include.R")) source(paste0(path.package("quantstrat"),"/demo/luxor.getSymbols.R")) +source(paste0(path.package("quantstrat"),"/demo/luxor.5.strategy.ordersets.R")) ### foreach and doMC @@ -19,6 +20,13 @@ require(doMC) registerDoMC(cores=8) +### robustbase and PerformanceAnalytics + +if (!requireNamespace("robustbase", quietly=TRUE)) + stop("package 'robustbase' required, but not installed") +if (!requireNamespace("PerformanceAnalytics", quietly=TRUE)) + stop("package 'PerformanceAnalytics' required, but not installed") + ### blotter initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD') @@ -68,7 +76,20 @@ ### walk.forward -r <- walk.forward(strategy.st, paramset.label='WFA', portfolio.st=portfolio.st, account.st=account.st, period='months', k.training=3, k.testing=1, obj.func=my.obj.func, obj.args=list(x=quote(result$apply.paramset)), user.func=ess, user.args=list('account.st'=account.st, 'portfolio.st'=portfolio.st), audit.prefix='wfa', anchored=FALSE, verbose=TRUE) +r <- walk.forward(strategy.st, + paramset.label='WFA', + portfolio.st=portfolio.st, + account.st=account.st, + period='days', + k.training=3, + k.testing=1, + obj.func=my.obj.func, + obj.args=list(x=quote(result$apply.paramset)), + user.func=ess, + user.args=list('account.st'=account.st, 'portfolio.st'=portfolio.st), + audit.prefix='wfa', + anchored=FALSE, + verbose=TRUE) ### analyse From noreply at r-forge.r-project.org Sat Nov 14 16:57:11 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 14 Nov 2015 16:57:11 +0100 (CET) Subject: [Blotter-commits] r1714 - pkg/quantstrat/R Message-ID: <20151114155711.1475318772D@r-forge.r-project.org> Author: bodanker Date: 2015-11-14 16:57:10 +0100 (Sat, 14 Nov 2015) New Revision: 1714 Modified: pkg/quantstrat/R/rules.R Log: Check for sigcol before dindex loop If 'sigcol' either doesn't exist or is named incorrectly, xts throws an uninformative error. Add a one-time check to ensure sigcol exists in mktdata before starting the dindex loop. See R-Forge issue #5101. Thanks to Evelyn Mitchell for the report. Modified: pkg/quantstrat/R/rules.R =================================================================== --- pkg/quantstrat/R/rules.R 2015-11-11 19:49:55 UTC (rev 1713) +++ pkg/quantstrat/R/rules.R 2015-11-14 15:57:10 UTC (rev 1714) @@ -302,9 +302,15 @@ # check if there's anything to do if(length(strategy$rules[[type]])>=1){ for (rule in strategy$rules[[type]]){ + sigcol <- rule$arguments$sigcol + sigval <- rule$arguments$sigval + # ensure mktdata contains sigcol + if (!is.null(sigcol) && !sigcol %in% colnames(mktdata)) { + stop("mktdata does not contain 'sigcol': ", sigcol) + } if(isTRUE(rule$path.dep)){ # only apply to path dependent rule # check for sigcol, sigval, otherwise use all - if(is.null(rule$arguments$sigcol) | is.null(rule$arguments$sigval) ){ + if(is.null(sigcol) || is.null(sigval)) { if(is.null(rule$timespan)) { assign.dindex(1:length(Dates)) } else { @@ -312,9 +318,9 @@ } } else { if(is.null(rule$timespan)) { - assign.dindex(c(get.dindex(),which(mktdata[,rule$arguments$sigcol] == rule$arguments$sigval))) + assign.dindex(c(get.dindex(),which(mktdata[, sigcol] == sigval))) } else { - assign.dindex(c(get.dindex(),which(merge(.xts(,.index(mktdata)),mktdata[rule$timespan,rule$arguments$sigcol]) == rule$arguments$sigval))) + assign.dindex(c(get.dindex(),which(merge(.xts(,.index(mktdata)),mktdata[rule$timespan, sigcol]) == sigval))) } } } From noreply at r-forge.r-project.org Sun Nov 15 00:36:50 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 15 Nov 2015 00:36:50 +0100 (CET) Subject: [Blotter-commits] r1715 - in pkg/quantstrat: . R Message-ID: <20151114233650.59641187E01@r-forge.r-project.org> Author: bodanker Date: 2015-11-15 00:36:49 +0100 (Sun, 15 Nov 2015) New Revision: 1715 Modified: pkg/quantstrat/DESCRIPTION pkg/quantstrat/NAMESPACE pkg/quantstrat/R/paramsets.R Log: Import iterators::iter And remove now-unnecessary require() calls. See R-Forge issue #5795. Modified: pkg/quantstrat/DESCRIPTION =================================================================== --- pkg/quantstrat/DESCRIPTION 2015-11-14 15:57:10 UTC (rev 1714) +++ pkg/quantstrat/DESCRIPTION 2015-11-14 23:36:49 UTC (rev 1715) @@ -11,6 +11,7 @@ FinancialInstrument(>= 0.12.5), foreach(>= 1.4.0) Imports: + iterators, zoo Suggests: PerformanceAnalytics, Modified: pkg/quantstrat/NAMESPACE =================================================================== --- pkg/quantstrat/NAMESPACE 2015-11-14 15:57:10 UTC (rev 1714) +++ pkg/quantstrat/NAMESPACE 2015-11-14 23:36:49 UTC (rev 1715) @@ -67,4 +67,5 @@ import(quantmod) import(xts) import(zoo) +importFrom(iterators,iter) useDynLib(quantstrat) Modified: pkg/quantstrat/R/paramsets.R =================================================================== --- pkg/quantstrat/R/paramsets.R 2015-11-14 15:57:10 UTC (rev 1714) +++ pkg/quantstrat/R/paramsets.R 2015-11-14 23:36:49 UTC (rev 1715) @@ -40,12 +40,6 @@ # TODO: fix expand.grid # TODO: "and" multiple constraints i.o. "or" - -#require(foreach, quietly=TRUE) -require('foreach') -#require(iterators, quietly=TRUE) -require('iterators') - # creates a copy of a portfolio, stripping all history (transactions etc) clone.portfolio <- function(portfolio.st, cloned.portfolio.st, strip.history=TRUE) @@ -367,6 +361,7 @@ #' @author Jan Humme #' @export #' @seealso \code{\link{add.distribution.constraint}}, \code{\link{add.distribution.constraint}}, \code{\link{delete.paramset}} +#' @importFrom iterators iter apply.paramset <- function(strategy.st, paramset.label, portfolio.st, account.st, mktdata=NULL, nsamples=0, user.func=NULL, user.args=NULL, calc='slave', audit=NULL, packages=NULL, verbose=FALSE, paramsets, ...) { From noreply at r-forge.r-project.org Sun Nov 15 00:45:08 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 15 Nov 2015 00:45:08 +0100 (CET) Subject: [Blotter-commits] r1716 - pkg/quantstrat/R Message-ID: <20151114234508.1EA32187DFE@r-forge.r-project.org> Author: bodanker Date: 2015-11-15 00:45:07 +0100 (Sun, 15 Nov 2015) New Revision: 1716 Modified: pkg/quantstrat/R/tradeGraphs.R Log: Ensure rgl and reshape2 are available... ...via CRAN-approved method (requireNamespace). Clean up formatting. See R-Forge issue #5795. Thanks to Jonathan Owen. Modified: pkg/quantstrat/R/tradeGraphs.R =================================================================== --- pkg/quantstrat/R/tradeGraphs.R 2015-11-14 23:36:49 UTC (rev 1715) +++ pkg/quantstrat/R/tradeGraphs.R 2015-11-14 23:45:07 UTC (rev 1716) @@ -11,7 +11,7 @@ #' tradeGraphs ( #' stats = stats, #' free.params = c("Param.indicator.1.nFast", "Param.indicator.2.nSlow"), -#' params.filter = "Param.indicator.2.nSlow < 40 & Param.indicator.1.nFast > 5" +#' params.filter = "Param.indicator.2.nSlow < 40 & Param.indicator.1.nFast > 5" #' statistics = c("Net.Trading.PL", "maxDrawdown", "Avg.Trade.PL", "Num.Trades") #' title = 'Luxor' #' ) @@ -24,9 +24,11 @@ # TODO: fix axes to use non scientific notation # TODO: fix use of full rainbow for small fractions (eg. Profit.Factor, now only uses red) - if(!require(rgl, quietly=TRUE)) stop('The "rgl" package is required to use this function') + if(!requireNamespace("rgl", quietly=TRUE)) + stop('The "rgl" package is required to use this function') - if(!require(reshape2, quietly=TRUE)) stop('The "reshape2" package is required to use this function') + if(!requireNamespace("reshape2", quietly=TRUE)) + stop('The "reshape2" package is required to use this function') if(missing(stats)) stop('stats undefined') @@ -34,35 +36,27 @@ if(length(free.params) != 2) stop('free.params must be a vector of length 2') if(missing(statistics)) stop('must specify at least one statistics column to draw graph') - - + var1 <- free.params[1] var2 <- free.params[2] - - - for(statistic in statistics) { - - var3 <- statistic - + + for(var3 in statistics) { if (length(params.filter) == 0 ) { data <- stats[,c(var1, var2, var3)] } else { data <- subset(stats, eval(parse(text=params.filter)), select = c(var1, var2, var3)) } - data_r = recast(data, as.formula(paste0(var1, " ~ ", var2)), id.var=c(var1,var2), measure.var=c(var3)) + data_r <- reshape2::recast(data, as.formula(paste0(var1, " ~ ", var2)), + id.var=c(var1,var2), measure.var=c(var3)) x <- data_r[, 1] - y <- as.numeric(colnames(data_r)[-1]) -z <- unlist(data_r[, -1]) + y <- as.numeric(colnames(data_r)[-1]) + z <- unlist(data_r[, -1]) - # x <- recast(data, as.formula(paste0(var1, " ~ ", var2)) , id.var=c(var1,var2), measure.var=c(var3))$labels[[1]][,1] - # y <- recast(data, as.formula(paste0(var1, " ~ ", var2)) , id.var=c(var1,var2), measure.var=c(var3))$labels[[2]][,1] - # z <- recast(data, as.formula(paste0(var1, " ~ ", var2)) , id.var=c(var1,var2), measure.var=c(var3))$data - col <- heat.colors(length(z))[rank(z)] - open3d() - persp3d(x,y,z, color=col, xlab=var1, ylab=var2, zlab=var3, main = title) + rgl::open3d() + rgl::persp3d(x,y,z, color=col, xlab=var1, ylab=var2, zlab=var3, main = title) } } From noreply at r-forge.r-project.org Sun Nov 15 01:23:07 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 15 Nov 2015 01:23:07 +0100 (CET) Subject: [Blotter-commits] r1717 - pkg/FinancialInstrument/R Message-ID: <20151115002307.9CA58187797@r-forge.r-project.org> Author: bodanker Date: 2015-11-15 01:23:07 +0100 (Sun, 15 Nov 2015) New Revision: 1717 Modified: pkg/FinancialInstrument/R/load.instruments.R Log: Update file names in load.instruments examples R CMD build --resave-data=gzip has been the default since 2011-02-08 (in R-devel), so add .gz to file extensions in examples. Modified: pkg/FinancialInstrument/R/load.instruments.R =================================================================== --- pkg/FinancialInstrument/R/load.instruments.R 2015-11-14 23:45:07 UTC (rev 1716) +++ pkg/FinancialInstrument/R/load.instruments.R 2015-11-15 00:23:07 UTC (rev 1717) @@ -50,9 +50,9 @@ #' \code{\link{getSymbols.FI}} #' @examples #' \dontrun{ -#' load.instruments(system.file('data/currencies.csv',package='FinancialInstrument')) -#' load.instruments(system.file('data/root_contracts.csv',package='FinancialInstrument')) -#' load.instruments(system.file('data/future_series.csv',package='FinancialInstrument')) +#' load.instruments(system.file('data/currencies.csv.gz',package='FinancialInstrument')) +#' load.instruments(system.file('data/root_contracts.csv.gz',package='FinancialInstrument')) +#' load.instruments(system.file('data/future_series.csv.gz',package='FinancialInstrument')) #' #' } #' @export From noreply at r-forge.r-project.org Sun Nov 15 18:08:44 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 15 Nov 2015 18:08:44 +0100 (CET) Subject: [Blotter-commits] r1718 - in pkg/quantstrat: R demo Message-ID: <20151115170844.92A46187E2C@r-forge.r-project.org> Author: bodanker Date: 2015-11-15 18:08:44 +0100 (Sun, 15 Nov 2015) New Revision: 1718 Modified: pkg/quantstrat/R/chart.forward.R pkg/quantstrat/R/chart.forward.training.R pkg/quantstrat/demo/luxor.sample.walk.forward.R Log: Use xts:::plot.xts for walk-forward analysis The chart.forward.* functions still used the plot.xts API from xtsExtra from before Ross Bennett's GSoC work. Update them to use the current API defined by xts:::plot.xts. Thanks to Alex Alias for the report and patch. Modified: pkg/quantstrat/R/chart.forward.R =================================================================== --- pkg/quantstrat/R/chart.forward.R 2015-11-15 00:23:07 UTC (rev 1717) +++ pkg/quantstrat/R/chart.forward.R 2015-11-15 17:08:44 UTC (rev 1718) @@ -47,20 +47,11 @@ CumMax <- cummax(PL.xts) Drawdowns.xts <- -(CumMax - PL.xts) data.to.plot <- as.xts(cbind(PL.xts, Drawdowns.xts)) - - # now plot it - dev.new() - plot.xts( - data.to.plot, - screens=rep(1:2,each=n+1), - col=c(rep('grey',n), 'blue'), - minor.ticks=FALSE, - main=NA - ) - title( - main='Walk Forward Analysis', - sub=audit.filename - ) - + + p <- plot(PL.xts, col=c("blue", rep("grey", n-1)), main="Walk Forward Analysis") + # set on=NA so it is drawn on a new panel + p <- lines(Drawdowns.xts, col=c("blue", rep("grey", n-1)), on=NA, main="Drawdowns") + print(p) + .audit <- NULL } Modified: pkg/quantstrat/R/chart.forward.training.R =================================================================== --- pkg/quantstrat/R/chart.forward.training.R 2015-11-15 00:23:07 UTC (rev 1717) +++ pkg/quantstrat/R/chart.forward.training.R 2015-11-15 17:08:44 UTC (rev 1718) @@ -29,10 +29,11 @@ PL.xts <- cbind(PL.xts, R) } - # add a column for the chosen portfolio, doubling it + # .audit$param.combo.nr contains the rowname of the best portfolio chosen.one <- .audit$param.combo.nr chosen.portfolio.st = ls(name=.audit, pattern=glob2rx(paste('portfolio', '*', chosen.one, sep='.'))) - + # add a column for the chosen portfolio, doubling it and + # making it plot last, so it's not over-plotted by other portfolios R <- PL.xts[,chosen.portfolio.st] PL.xts <- cbind(PL.xts, R) @@ -42,21 +43,15 @@ CumMax <- cummax(PL.xts) Drawdowns.xts <- -(CumMax - PL.xts) data.to.plot <- as.xts(cbind(PL.xts, Drawdowns.xts)) - - # now plot it - dev.new() - plot.xts( - data.to.plot, - screens=rep(1:2,each=n+1), - col=c(rep('grey',n), 'blue'), - minor.ticks=FALSE, - main=NA - ) - title( - main='Walk Forward Analysis', - sub=audit.filename - ) - + + # based on the suggestion by Ross, note that the number of + # lines is increased by 1 since the 'chosen' portfolio is added as the last one + # and highlighted using the blue color + p <- plot(PL.xts, col=c("blue", rep("grey", n)), main="Walk Forward Analysis") + # set on=NA so it is drawn on a new panel + p <- lines(Drawdowns.xts, col=c("blue", rep("grey", n)), on=NA, main="Drawdowns") + print(p) + .audit <- NULL } Modified: pkg/quantstrat/demo/luxor.sample.walk.forward.R =================================================================== --- pkg/quantstrat/demo/luxor.sample.walk.forward.R 2015-11-15 00:23:07 UTC (rev 1717) +++ pkg/quantstrat/demo/luxor.sample.walk.forward.R 2015-11-15 17:08:44 UTC (rev 1718) @@ -10,7 +10,7 @@ require('quantstrat') -chart.forward.testing('../data/luxor.wfa.ples.GBPUSD.2003-01-02 05:30:00.2003-03-31 23:30:00.RData') +chart.forward.training(paste0(path.package("quantstrat"),'/data/luxor.wfa.ples.RData')) ##### PLACE DEMO AND TEST DATES HERE ################# # From noreply at r-forge.r-project.org Mon Nov 16 17:56:24 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 16 Nov 2015 17:56:24 +0100 (CET) Subject: [Blotter-commits] r1719 - in pkg/quantstrat: R man Message-ID: <20151116165624.8116A1874AD@r-forge.r-project.org> Author: bodanker Date: 2015-11-16 17:56:24 +0100 (Mon, 16 Nov 2015) New Revision: 1719 Modified: pkg/quantstrat/R/chart.forward.R pkg/quantstrat/R/chart.forward.training.R pkg/quantstrat/man/chart.forward.Rd pkg/quantstrat/man/chart.forward.training.Rd Log: Make chart.forward.* more robust Attempt to ensure the audit.filename parameter is pointing to the correct file generated by walk.forward(). Add file name pattern (as generated by walk.forward) to the docs. Ensure file exists before trying to load. Remove the hard-coded portfolio string in chart.forward, and replace it with the result portfolio (which doesn't end in a digit) from the .audit environment. Only select the first .audit$param.combo.nr, in case there is more than one in the file. Roxygenize docs. Modified: pkg/quantstrat/R/chart.forward.R =================================================================== --- pkg/quantstrat/R/chart.forward.R 2015-11-15 17:08:44 UTC (rev 1718) +++ pkg/quantstrat/R/chart.forward.R 2015-11-16 16:56:24 UTC (rev 1719) @@ -1,20 +1,25 @@ #' Chart to analyse walk.forward() objective function #' -#' @param audit.filename name of .audit environment file as produced by walk.forward() +#' @param audit.filename name of .audit environment file as produced by walk.forward(). +#' Filename will match pattern [audit.prefix].results.RData. #' #' @export chart.forward <- function(audit.filename) { - #.audit <- NULL - if(is.null(.audit)) stop ('You need to run a walk forward test first to create the .audit environment') - - if(!is.null(audit.filename)) - load(audit.filename) - else - stop('You need to provide an audit.filename.') + .audit <- NULL # keep codetools happy + # ensure correct file written by walk.forward() is provided + if (!grepl("\\.results\\.RData$", audit.filename[1L])) { + stop("'audit.filename' should match pattern:\n [audit.prefix].results.RData") + } + if (file.exists(audit.filename)) { + load(audit.filename) + } else { + stop("'audit.filename', ", audit.filename, " not found.") + } - # extract all portfolio names from the audit environment, except wfa portfolio + # extract all portfolio names from the audit environment, + # except result portfolio (which doesn't end with a digit) portfolios.st = ls(name=.audit, pattern='portfolio.*.[0-9]+') n <- length(portfolios.st) @@ -33,8 +38,8 @@ PL.xts <- cbind(PL.xts, R) } - # now for the result portfolio - portfolio.st <- 'portfolio.forex' + # now for the result portfolio (which doesn't end with a digit) + portfolio.st <- ls(name=.audit, pattern='portfolio.*[^.0-9]$') p <- getPortfolio(portfolio.st, envir=.audit) from <- index(p$summary[2]) R <- cumsum(p$summary[paste(from, '/', sep=''),'Net.Trading.PL']) @@ -52,6 +57,4 @@ # set on=NA so it is drawn on a new panel p <- lines(Drawdowns.xts, col=c("blue", rep("grey", n-1)), on=NA, main="Drawdowns") print(p) - - .audit <- NULL } Modified: pkg/quantstrat/R/chart.forward.training.R =================================================================== --- pkg/quantstrat/R/chart.forward.training.R 2015-11-15 17:08:44 UTC (rev 1718) +++ pkg/quantstrat/R/chart.forward.training.R 2015-11-16 16:56:24 UTC (rev 1719) @@ -1,16 +1,26 @@ #' Chart to analyse walk.forward() objective function #' -#' @param audit.filename name of .audit environment file as produced by walk.forward() +#' @param audit.filename name of .audit environment file as produced by walk.forward(). +#' Filename will match pattern [audit.prefix].[symbol].[start timestamp].[end timestamp].RData. #' #' @export chart.forward.training <- function(audit.filename) { - .audit <- NULL + .audit <- NULL # keep codetools happy + # ensure correct file written by walk.forward() is provided + datePattern <- "[[:digit:]]{4}.[[:digit:]]{2}.[[:digit:]]{2}(.[[:digit:]]{2}.[[:digit:]]{2}.[[:digit:]]{2})?" + if (!grepl(paste0(datePattern, "\\.", datePattern, "\\.RData$"), audit.filename[1L])) { + stop("'audit.filename' should match pattern:\n [audit.prefix].[symbol].[start timestamp].[end timestamp].RData.") + } + if (file.exists(audit.filename)) { + load(audit.filename) + } else { + stop("'audit.filename', ", audit.filename, " not found.") + } - load(audit.filename) - # extract all portfolio names from the audit environment + # NB: training data only has portfolios that end in digits portfolios.st = ls(name=.audit, pattern='portfolio.*') n <- length(portfolios.st) @@ -30,7 +40,7 @@ } # .audit$param.combo.nr contains the rowname of the best portfolio - chosen.one <- .audit$param.combo.nr + chosen.one <- .audit$param.combo.nr[1L] chosen.portfolio.st = ls(name=.audit, pattern=glob2rx(paste('portfolio', '*', chosen.one, sep='.'))) # add a column for the chosen portfolio, doubling it and # making it plot last, so it's not over-plotted by other portfolios @@ -51,7 +61,4 @@ # set on=NA so it is drawn on a new panel p <- lines(Drawdowns.xts, col=c("blue", rep("grey", n)), on=NA, main="Drawdowns") print(p) - - .audit <- NULL } - Modified: pkg/quantstrat/man/chart.forward.Rd =================================================================== --- pkg/quantstrat/man/chart.forward.Rd 2015-11-15 17:08:44 UTC (rev 1718) +++ pkg/quantstrat/man/chart.forward.Rd 2015-11-16 16:56:24 UTC (rev 1719) @@ -7,7 +7,8 @@ chart.forward(audit.filename) } \arguments{ -\item{audit.filename}{name of .audit environment file as produced by walk.forward()} +\item{audit.filename}{name of .audit environment file as produced by walk.forward() +Filename will match pattern [audit.prefix].results.RData.} } \description{ Chart to analyse walk.forward() objective function Modified: pkg/quantstrat/man/chart.forward.training.Rd =================================================================== --- pkg/quantstrat/man/chart.forward.training.Rd 2015-11-15 17:08:44 UTC (rev 1718) +++ pkg/quantstrat/man/chart.forward.training.Rd 2015-11-16 16:56:24 UTC (rev 1719) @@ -7,7 +7,8 @@ chart.forward.training(audit.filename) } \arguments{ -\item{audit.filename}{name of .audit environment file as produced by walk.forward()} +\item{audit.filename}{name of .audit environment file as produced by walk.forward(). +Filename will match pattern [audit.prefix].[symbol].[start timestamp].[end timestamp].RData.} } \description{ Chart to analyse walk.forward() objective function