[Blotter-commits] r1243 - in pkg/quantstrat: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Nov 8 21:54:41 CET 2012
Author: braverock
Date: 2012-11-08 21:54:41 +0100 (Thu, 08 Nov 2012)
New Revision: 1243
Added:
pkg/quantstrat/R/rebalance.rules.R
pkg/quantstrat/man/rulePctEquity.Rd
Modified:
pkg/quantstrat/NAMESPACE
pkg/quantstrat/R/applyStrategy.rebalancing.R
Log:
- add rebalance rule rulePctEquity
Modified: pkg/quantstrat/NAMESPACE
===================================================================
--- pkg/quantstrat/NAMESPACE 2012-11-08 16:44:01 UTC (rev 1242)
+++ pkg/quantstrat/NAMESPACE 2012-11-08 20:54:41 UTC (rev 1243)
@@ -28,6 +28,7 @@
export(osNoOp)
export(rm.strat)
export(ruleCancel)
+export(rulePctEquity)
export(ruleOrderProc)
export(ruleSignal)
export(save.strategy)
Modified: pkg/quantstrat/R/applyStrategy.rebalancing.R
===================================================================
--- pkg/quantstrat/R/applyStrategy.rebalancing.R 2012-11-08 16:44:01 UTC (rev 1242)
+++ pkg/quantstrat/R/applyStrategy.rebalancing.R 2012-11-08 20:54:41 UTC (rev 1243)
@@ -160,7 +160,8 @@
...,
mktdata=md_subset,
parameters=parameters,
- portfolio=portfolio)
+ portfolio=portfolio,
+ symbol=symbol)
}
}
}
Copied: pkg/quantstrat/R/rebalance.rules.R (from rev 1234, pkg/quantstrat/R/ruleCancel.R)
===================================================================
--- pkg/quantstrat/R/rebalance.rules.R (rev 0)
+++ pkg/quantstrat/R/rebalance.rules.R 2012-11-08 20:54:41 UTC (rev 1243)
@@ -0,0 +1,77 @@
+#' rule to base trade size on a percentage of available equity.
+#'
+#' This rule works with \code{\link{applyStrategy.rebalancing}} to set the
+#' maximum trade size by calling \code{\link{addPosLimit}}.
+#'
+#' To use it, you need to specify it as (part of) a rule of type 'rebalance'.
+#' note that \code{\link{applyStrategy.rebalancing}} will expect a
+#' 'rebalance_on' argument to be included in the \code{arguments=list(...)}
+#' of the rule definition.
+#'
+#'
+#'
+#' @param trade.percent max percentage of equity to allow the strategy to trade in this symbol
+#' @param longlevels numeric number of levels
+#' @param shortlevels numeric number of short levels, default longlevels
+#' @param digits if not NULL(the default), will call \code{\link{round}} with specified number of digits
+#' @param refprice if not NULL(the default), will divide the calculated tra
+#' @param portfolio text name of the portfolio to place orders in, typically set automatically
+#' @param symbol identifier of the instrument to cancel orders for, typically set automatically
+#' @param timestamp timestamp coercible to POSIXct that will be the time the order will be inserted on, typically set automatically
+#' @param \dots any other passthrough parameters
+#' @seealso \code{\link{osMaxPos}} ,
+#' \code{\link{applyStrategy.rebalancing}},
+#' \code{\link{addPosLimit}},
+#' \code{\link{add.rule}}
+#'
+#' @examples
+#' # example rule definition
+#' \code{
+#' add.rule(strategy.name, 'rulePctEquity',
+#' arguments=list(rebalance_on='months',
+#' trade.percent=.02,
+#' refprice=quote(last(getPrice(mktdata)[paste('::',timestamp,sep='')])),
+#' digits=0
+#' ),
+#' type='rebalance',
+#' label='rebalance')
+#' }
+#' @export
+rulePctEquity <- function (trade.percent=.02,
+ ...,
+ longlevels=1,
+ shortlevels=1,
+ digits=NULL,
+ refprice=NULL,
+ portfolio,
+ symbol,
+ timestamp)
+{
+ dummy <- updatePortf(Portfolio=portfolio,
+ Dates=paste('::',timestamp,sep=''))
+ trading.pl <- sum(getPortfolio(portfolio)$summary$Net.Trading.PL)
+ total.equity <- initEq+trading.pl
+ tradeSize <- total.equity * trade.percent
+ if(!is.null(refprice)) tradeSize <- tradeSize/refprice
+ if(!is.null(digits)) tradeSize<-round(tradeSize,digits)
+ addPosLimit(portfolio = portfolio,
+ symbol = symbol,
+ timestamp = timestamp,
+ maxpos = tradeSize,
+ longlevels = longlevels,
+ minpos = -tradeSize,
+ shortlevels = shortlevels)
+}
+
+###############################################################################
+# R (http://r-project.org/) Quantitative Strategy Model Framework
+#
+# Copyright (c) 2009-2012
+# Peter Carl, Dirk Eddelbuettel, Brian G. Peterson, Jeffrey Ryan, and Joshua Ulrich
+#
+# This library is distributed under the terms of the GNU Public License (GPL)
+# for full details see the file COPYING
+#
+# $Id$
+#
+###############################################################################
Added: pkg/quantstrat/man/rulePctEquity.Rd
===================================================================
--- pkg/quantstrat/man/rulePctEquity.Rd (rev 0)
+++ pkg/quantstrat/man/rulePctEquity.Rd 2012-11-08 20:54:41 UTC (rev 1243)
@@ -0,0 +1,66 @@
+\name{rulePctEquity}
+\alias{rulePctEquity}
+\title{rule to base trade size on a percentage of available equity.}
+\usage{
+ rulePctEquity(trade.percent = 0.02, ..., longlevels = 1,
+ shortlevels = 1, digits = NULL, refprice = NULL,
+ portfolio, symbol, timestamp)
+}
+\arguments{
+ \item{trade.percent}{max percentage of equity to allow
+ the strategy to trade in this symbol}
+
+ \item{longlevels}{numeric number of levels}
+
+ \item{shortlevels}{numeric number of short levels,
+ default longlevels}
+
+ \item{digits}{if not NULL(the default), will call
+ \code{\link{round}} with specified number of digits}
+
+ \item{refprice}{if not NULL(the default), will divide the
+ calculated tra}
+
+ \item{portfolio}{text name of the portfolio to place
+ orders in, typically set automatically}
+
+ \item{symbol}{identifier of the instrument to cancel
+ orders for, typically set automatically}
+
+ \item{timestamp}{timestamp coercible to POSIXct that will
+ be the time the order will be inserted on, typically set
+ automatically}
+
+ \item{\dots}{any other passthrough parameters}
+}
+\description{
+ This rule works with
+ \code{\link{applyStrategy.rebalancing}} to set the
+ maximum trade size by calling \code{\link{addPosLimit}}.
+}
+\details{
+ To use it, you need to specify it as (part of) a rule of
+ type 'rebalance'. note that
+ \code{\link{applyStrategy.rebalancing}} will expect a
+ 'rebalance_on' argument to be included in the
+ \code{arguments=list(...)} of the rule definition.
+}
+\examples{
+# example rule definition
+\\code{
+add.rule(strategy.name, 'rulePctEquity',
+ arguments=list(rebalance_on='months',
+ trade.percent=.02,
+ refprice=quote(last(getPrice(mktdata)[paste('::',timestamp,sep='')])),
+ digits=0
+ ),
+ type='rebalance',
+ label='rebalance')
+}
+}
+\seealso{
+ \code{\link{osMaxPos}} ,
+ \code{\link{applyStrategy.rebalancing}},
+ \code{\link{addPosLimit}}, \code{\link{add.rule}}
+}
+
More information about the Blotter-commits
mailing list