From noreply at r-forge.r-project.org Sun May 5 00:39:40 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 5 May 2013 00:39:40 +0200 (CEST) Subject: [Blotter-commits] r1452 - pkg/quantstrat/R Message-ID: <20130504223940.4411A18487B@r-forge.r-project.org> Author: opentrades Date: 2013-05-05 00:39:39 +0200 (Sun, 05 May 2013) New Revision: 1452 Modified: pkg/quantstrat/R/orders.R pkg/quantstrat/R/rules.R Log: - introduced enable.rule() for easy rule enabling / disabling - fixed timestamp in orderbook to print 00:00:00 when midnight Modified: pkg/quantstrat/R/orders.R =================================================================== --- pkg/quantstrat/R/orders.R 2013-04-29 11:48:30 UTC (rev 1451) +++ pkg/quantstrat/R/orders.R 2013-05-04 22:39:39 UTC (rev 1452) @@ -411,7 +411,7 @@ orderset=orderset, oldstatus="open", newstatus="replaced", - statustimestamp=timestamp) + statustimestamp=format(timestamp, "%Y-%m-%d %H:%M:%S")) } # get order book if(!is.null(orders)) Modified: pkg/quantstrat/R/rules.R =================================================================== --- pkg/quantstrat/R/rules.R 2013-04-29 11:48:30 UTC (rev 1451) +++ pkg/quantstrat/R/rules.R 2013-05-04 22:39:39 UTC (rev 1452) @@ -127,6 +127,36 @@ strategy$name } +#' enable a rule in the strategy +#' +#' function to make it easy to enable (or disable) a specific rule in a strategy +#' +#' @param strategy an object of type 'strategy' which contains the rule +#' @param type one of "risk","order","rebalance","exit","enter","chain" +#' @param label the label for the rule; grep will be used to match, so multiple rules may be enabled (disabled) as a result +#' @param enabled TRUE/FALSE whether the rule is enabled for use in applying the strategy, default TRUE +#' @param store TRUE/FALSE whether to store the updated strategy in the .strategy environment, or return it. default FALSE +#' @seealso \code{\link{add.rule}} \code{\link{applyStrategy}} +#' @export + +enable.rule <- function(strategy, type=c(NULL,"risk","order","rebalance","exit","enter","chain"), label, enabled=TRUE, store=FALSE) +{ + if (!is.strategy(strategy)) { + strategy<-try(getStrategy(strategy)) + if(inherits(strategy,"try-error")) + stop ("You must supply an object or the name of an object of type 'strategy'.") + store=TRUE + } + + for(i in 1:length(strategy$rules[[type]])) + if(grepl(label, strategy$rules[[type]][[i]]$label)) + strategy$rules[[type]][[i]]$enabled <- enabled + + if (store) assign(strategy$name,strategy,envir=as.environment(.strategy)) + else return(strategy) + strategy$name +} + #' apply the rules in the strategy to arbitrary market data #' #' In typical usage, this function will be called via \code{\link{applyStrategy}}. From noreply at r-forge.r-project.org Sun May 5 00:46:50 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 5 May 2013 00:46:50 +0200 (CEST) Subject: [Blotter-commits] r1453 - pkg/quantstrat Message-ID: <20130504224650.922BC184C14@r-forge.r-project.org> Author: opentrades Date: 2013-05-05 00:46:50 +0200 (Sun, 05 May 2013) New Revision: 1453 Modified: pkg/quantstrat/NAMESPACE Log: - NAMESPACE not uploaded after enable.rule() implementation due to some conflict here on my svn copy :-S Modified: pkg/quantstrat/NAMESPACE =================================================================== --- pkg/quantstrat/NAMESPACE 2013-05-04 22:39:39 UTC (rev 1452) +++ pkg/quantstrat/NAMESPACE 2013-05-04 22:46:50 UTC (rev 1453) @@ -2,20 +2,21 @@ export(add.distribution) export(add.indicator) export(add.init) +export(add.rule) +export(add.signal) export(addOrder) export(addPosLimit) -export(add.rule) -export(add.signal) +export(apply.paramset) export(applyIndicators) export(applyParameter) -export(apply.paramset) export(applyRules) export(applySignals) +export(applyStrategy.rebalancing) export(applyStrategy) -export(applyStrategy.rebalancing) export(chart.forward.testing) export(chart.forward.training) export(delete.paramset) +export(enable.rule) export(getOrderBook) export(getOrders) export(getParameterTable) From noreply at r-forge.r-project.org Sun May 5 00:48:51 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 5 May 2013 00:48:51 +0200 (CEST) Subject: [Blotter-commits] r1454 - pkg/quantstrat/man Message-ID: <20130504224851.851B7184C14@r-forge.r-project.org> Author: opentrades Date: 2013-05-05 00:48:51 +0200 (Sun, 05 May 2013) New Revision: 1454 Added: pkg/quantstrat/man/enable.rule.Rd Log: - and here is the docs for enable.rule(); local svn conflict solved :-) Added: pkg/quantstrat/man/enable.rule.Rd =================================================================== --- pkg/quantstrat/man/enable.rule.Rd (rev 0) +++ pkg/quantstrat/man/enable.rule.Rd 2013-05-04 22:48:51 UTC (rev 1454) @@ -0,0 +1,34 @@ +\name{enable.rule} +\alias{enable.rule} +\title{enable a rule in the strategy} +\usage{ + enable.rule(strategy, + type = c(NULL, "risk", "order", "rebalance", "exit", "enter", "chain"), + label, enabled = TRUE, store = FALSE) +} +\arguments{ + \item{strategy}{an object of type 'strategy' which + contains the rule} + + \item{type}{one of + "risk","order","rebalance","exit","enter","chain"} + + \item{label}{the label for the rule; grep will be used to + match, so multiple rules may be enabled (disabled) as a + result} + + \item{enabled}{TRUE/FALSE whether the rule is enabled for + use in applying the strategy, default TRUE} + + \item{store}{TRUE/FALSE whether to store the updated + strategy in the .strategy environment, or return it. + default FALSE} +} +\description{ + function to make it easy to enable (or disable) a + specific rule in a strategy +} +\seealso{ + \code{\link{add.rule}} \code{\link{applyStrategy}} +} + From noreply at r-forge.r-project.org Sun May 5 18:28:54 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 5 May 2013 18:28:54 +0200 (CEST) Subject: [Blotter-commits] r1455 - pkg/quantstrat/R Message-ID: <20130505162854.B04651852C2@r-forge.r-project.org> Author: opentrades Date: 2013-05-05 18:28:54 +0200 (Sun, 05 May 2013) New Revision: 1455 Modified: pkg/quantstrat/R/orders.R Log: - reverted statustimestamp format() Modified: pkg/quantstrat/R/orders.R =================================================================== --- pkg/quantstrat/R/orders.R 2013-05-04 22:48:51 UTC (rev 1454) +++ pkg/quantstrat/R/orders.R 2013-05-05 16:28:54 UTC (rev 1455) @@ -411,7 +411,7 @@ orderset=orderset, oldstatus="open", newstatus="replaced", - statustimestamp=format(timestamp, "%Y-%m-%d %H:%M:%S")) + statustimestamp=timestamp) } # get order book if(!is.null(orders)) From noreply at r-forge.r-project.org Tue May 7 22:45:41 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 7 May 2013 22:45:41 +0200 (CEST) Subject: [Blotter-commits] r1456 - pkg/quantstrat/demo Message-ID: <20130507204541.9DB1A1813CF@r-forge.r-project.org> Author: opentrades Date: 2013-05-07 22:45:41 +0200 (Tue, 07 May 2013) New Revision: 1456 Removed: pkg/quantstrat/demo/luxor.1.strategy.R pkg/quantstrat/demo/luxor.2.add.paramsets.R pkg/quantstrat/demo/luxor.3.paramset.sma.R pkg/quantstrat/demo/luxor.3.tradegraphs.sma.R pkg/quantstrat/demo/luxor.4.Timespans.R pkg/quantstrat/demo/luxor.4.Timespans.tradegraphs.R pkg/quantstrat/demo/luxor.5.orderchains.R 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.7.MAE.stoploss.R pkg/quantstrat/demo/luxor.7.MAE.stoptrailing.R pkg/quantstrat/demo/luxor.7.MFE.takeprofit.R pkg/quantstrat/demo/luxor.getSymbols.R pkg/quantstrat/demo/luxor.include.R Log: - removed luxor demos (about to be replaced) Deleted: pkg/quantstrat/demo/luxor.1.strategy.R =================================================================== --- pkg/quantstrat/demo/luxor.1.strategy.R 2013-05-05 16:28:54 UTC (rev 1455) +++ pkg/quantstrat/demo/luxor.1.strategy.R 2013-05-07 20:45:41 UTC (rev 1456) @@ -1,156 +0,0 @@ -#!/usr/bin/Rscript --vanilla -# -# Jan Humme (@opentrades) - August 2012, revised April 2013 -# -# Tested and found to work correctly using blotter r1420 -# -# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) -# -# Paragraph 3.2: luxor with $30 slippage and transaction costs - -options(width = 240) -Sys.setenv(TZ="UTC") - -### - -.fast = 10 -.slow = 30 - -##### PLACE DEMO AND TEST DATES HERE ################# -# -#if(isTRUE(options('in_test')$in_test)) -# # use test dates -# {initDate="2011-01-01" -# endDate="2012-12-31" -# } else -# # use demo defaults -# {initDate="1999-12-31" -# endDate=Sys.Date()} - -source('luxor.include.R') -source('luxor.getSymbols.R') - -### blotter - -initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD') -initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD') - -### quantstrat - -initOrders(portfolio.st, initDate=initDate) - -### define strategy - -strategy(strategy.st, store=TRUE) - -### indicators - -add.indicator(strategy.st, name = "SMA", - arguments = list( - x = quote(Cl(mktdata)[,1]), - n = .fast - ), - label="nFast" -) - -add.indicator(strategy.st, name="SMA", - arguments = list( - x = quote(Cl(mktdata)[,1]), - n = .slow - ), - label="nSlow" -) - -### signals - -add.signal(strategy.st, name='sigCrossover', - arguments = list( - columns=c("nFast","nSlow"), - relationship="gte" - ), - label='long' -) - -add.signal(strategy.st, name='sigCrossover', - arguments = list( - columns=c("nFast","nSlow"), - relationship="lt" - ), - label='short' -) - -### rules - -add.rule(strategy.st, name='ruleSignal', - arguments=list(sigcol='long' , sigval=TRUE, - orderside='short', - ordertype='market', - orderqty='all', - TxnFees=.txnfees, - replace=TRUE - ), - type='exit', - label='Exit2LONG' -) - -add.rule(strategy.st, name='ruleSignal', - arguments=list(sigcol='short', sigval=TRUE, - orderside='long' , - ordertype='market', - orderqty='all', - TxnFees=.txnfees, - replace=TRUE - ), - type='exit', - label='Exit2SHORT' -) - -add.rule(strategy.st, name='ruleSignal', - arguments=list(sigcol='long' , sigval=TRUE, - orderside='long' , - ordertype='stoplimit', prefer='High', threshold=.threshold, - orderqty=+.orderqty, - replace=FALSE - ), - type='enter', - label='EnterLONG' -) - -add.rule(strategy.st, name='ruleSignal', - arguments=list(sigcol='short', sigval=TRUE, - orderside='short', - ordertype='stoplimit', prefer='Low', threshold=-.threshold, - orderqty=-.orderqty, - replace=FALSE - ), - type='enter', - label='EnterSHORT' -) - -############################################################################### - -applyStrategy(strategy.st, portfolio.st) - -View(getOrderBook(portfolio.st)[[portfolio.st]]$GBPUSD) - -############################################################################### - -updatePortf(portfolio.st, Symbols='GBPUSD', Dates=paste('::',as.Date(Sys.time()),sep='')) - -chart.Posn(portfolio.st, "GBPUSD") - -############################################################################### - -View(tradeStats(portfolio.st, 'GBPUSD')) - -############################################################################### - -# save the strategy in an .RData object for later retrieval - -save.strategy(strategy.st) - -##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### -# book = getOrderBook(port) -# stats = tradeStats(port) -# rets = PortfReturns(acct) -################################################################ Deleted: pkg/quantstrat/demo/luxor.2.add.paramsets.R =================================================================== --- pkg/quantstrat/demo/luxor.2.add.paramsets.R 2013-05-05 16:28:54 UTC (rev 1455) +++ pkg/quantstrat/demo/luxor.2.add.paramsets.R 2013-05-07 20:45:41 UTC (rev 1456) @@ -1,147 +0,0 @@ -#!/usr/bin/Rscript --vanilla -# -# Jan Humme (@opentrades) - August 2012, revised April 2013 -# -# Tested and found to work correctly using blotter r1420 - -require(quantstrat) - -##### PLACE DEMO AND TEST DATES HERE ################# -# -#if(isTRUE(options('in_test')$in_test)) -# # use test dates -# {initDate="2011-01-01" -# endDate="2012-12-31" -# } else -# # use demo defaults -# {initDate="1999-12-31" -# endDate=Sys.Date()} - -### - -.FastSMA = (1:20) -.SlowSMA = (30:80) - -.StopLoss = seq(0.1, 2.0, length.out=20)/100 -.StopTrailing = seq(0.1, 2.0, length.out=20)/100 -.TakeProfit = seq(0.1, 2.0, length.out=20)/100 - -strategy.st <- 'luxor' - -### - -load.strategy(strategy.st) - -### SMA paramset - -add.distribution(strategy.st, - paramset.label = 'SMA', - component.type = 'indicator', - component.label = 'nFast', - variable = list(n = .FastSMA), - label = 'nFAST' -) - -add.distribution(strategy.st, - paramset.label = 'SMA', - component.type = 'indicator', - component.label = 'nSlow', - variable = list(n = .SlowSMA), - label = 'nSLOW' -) - -add.constraint(strategy.st, - paramset.label = 'SMA', - distribution.label.1 = 'nFAST', - distribution.label.2 = 'nSLOW', - operator = '<', - label = 'SMA' -) - -### Stop Loss paramset - -add.distribution(strategy.st, - paramset.label = 'StopLoss', - component.type = 'chain', - component.label = 'StopLossLONG', - variable = list(threshold = .StopLoss), - label = 'StopLossLONG' -) - -add.distribution(strategy.st, - paramset.label = 'StopLoss', - component.type = 'chain', - component.label = 'StopLossSHORT', - variable = list(threshold = .StopLoss), - label = 'StopLossSHORT' -) - -add.constraint(strategy.st, - paramset.label = 'StopLoss', - distribution.label.1 = 'StopLossLONG', - distribution.label.2 = 'StopLossSHORT', - operator = '==', - label = 'StopLoss' -) - -### Stop Trailing paramset - -add.distribution(strategy.st, - paramset.label = 'StopTrailing', - component.type = 'chain', - component.label = 'StopTrailingLONG', - variable = list(threshold = .StopTrailing), - label = 'StopTrailingLONG' -) - -add.distribution(strategy.st, - paramset.label = 'StopTrailing', - component.type = 'chain', - component.label = 'StopTrailingSHORT', - variable = list(threshold = .StopTrailing), - label = 'StopTrailingSHORT' -) - -add.constraint(strategy.st, - paramset.label = 'StopTrailing', - distribution.label.1 = 'StopTrailingLONG', - distribution.label.2 = 'StopTrailingSHORT', - operator = '==', - label = 'StopTrailing' -) - -### Take Profit paramset - -add.distribution(strategy.st, - paramset.label = 'TakeProfit', - component.type = 'chain', - component.label = 'TakeProfitLONG', - variable = list(threshold = .TakeProfit), - label = 'TakeProfitLONG' -) - -add.distribution(strategy.st, - paramset.label = 'TakeProfit', - component.type = 'chain', - component.label = 'TakeProfitSHORT', - variable = list(threshold = .TakeProfit), - label = 'TakeProfitSHORT' -) - -add.constraint(strategy.st, - paramset.label = 'TakeProfit', - distribution.label.1 = 'TakeProfitLONG', - distribution.label.2 = 'TakeProfitSHORT', - operator = '==', - label = 'TakeProfit' -) - -### - -save.strategy(strategy.st) - -##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### -# book = getOrderBook(port) -# stats = tradeStats(port) -# rets = PortfReturns(acct) -################################################################ Deleted: pkg/quantstrat/demo/luxor.3.paramset.sma.R =================================================================== --- pkg/quantstrat/demo/luxor.3.paramset.sma.R 2013-05-05 16:28:54 UTC (rev 1455) +++ pkg/quantstrat/demo/luxor.3.paramset.sma.R 2013-05-07 20:45:41 UTC (rev 1456) @@ -1,52 +0,0 @@ -#!/usr/bin/Rscript --vanilla -# -# Jan Humme (@opentrades) - August 2012, revised April 2013 -# -# Tested and found to work correctly using blotter r1420 -# -# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) -# -# Paragraph 3.2: luxor with $30 slippage and transaction costs - -options(width = 240) -Sys.setenv(TZ='UTC') - -.nsamples=80 - -### - -source('luxor.include.R') -source('luxor.getSymbols.R') - -### blotter - -initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD') -initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD') - -### quantstrat - -initOrders(portfolio.st, initDate=initDate) - -load.strategy(strategy.st) - -### doMC - -require(doMC) -registerDoMC(cores=8) - -#require(doParallel) -#registerDoParallel(cores=2) - -#require(doRedis) -#registerDoRedis('jobs') - -results <- apply.paramset(strategy.st, paramset.label='SMA', portfolio.st=portfolio.st, account.st=account.st, nsamples=.nsamples, verbose=TRUE) - -### - -stats <- results$tradeStats - -save(stats, file='luxor.3.optimize.sma.RData') - -print(results$tradeStats) - Deleted: pkg/quantstrat/demo/luxor.3.tradegraphs.sma.R =================================================================== --- pkg/quantstrat/demo/luxor.3.tradegraphs.sma.R 2013-05-05 16:28:54 UTC (rev 1455) +++ pkg/quantstrat/demo/luxor.3.tradegraphs.sma.R 2013-05-07 20:45:41 UTC (rev 1456) @@ -1,39 +0,0 @@ -#!/usr/bin/Rscript --vanilla -# -# Jan Humme (@opentrades) - August 2012, revised April 2013 -# -# Tested and found to work correctly using blotter r1420 -# -# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) - -require(quantstrat) - -### load 'stats' back into .GlobalEnv - -load('../data/luxor.parameters.1-10.30-55.RData') - -### show trade graphs from stats - -tradeGraphs ( - stats = stats, - free.params = c("Param.indicator.1.nFast", "Param.indicator.2.nSlow"), - statistics = c("Net.Trading.PL", "maxDrawdown", "Avg.Trade.PL", "Num.Trades", "Profit.Factor"), - title = 'Luxor SMA Parameter Scan' -) - -##### PLACE DEMO AND TEST DATES HERE ################# -# -#if(isTRUE(options('in_test')$in_test)) -# # use test dates -# {initDate="2011-01-01" -# endDate="2012-12-31" -# } else -# # use demo defaults -# {initDate="1999-12-31" -# endDate=Sys.Date()} - -##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### -# book = getOrderBook(port) -# stats = tradeStats(port) -# rets = PortfReturns(acct) -################################################################ Deleted: pkg/quantstrat/demo/luxor.4.Timespans.R =================================================================== --- pkg/quantstrat/demo/luxor.4.Timespans.R 2013-05-05 16:28:54 UTC (rev 1455) +++ pkg/quantstrat/demo/luxor.4.Timespans.R 2013-05-07 20:45:41 UTC (rev 1456) @@ -1,102 +0,0 @@ -#!/usr/bin/Rscript --vanilla -# -# Jan Humme (@opentrades) - August 2012 -# -# Tested and found to work correctly using blotter r1123 -# -# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) -# -# Paragraph 3.4: inserting an intraday time filter -# uses luxor.4.R - -source('luxor.4.R') - -#verbose = 0 -verbose = 1 - -method='expand' -#method='random' -#.sampleSize=20 - -# generate 24x24h ISO8601 timespan vector - -.timespans.start<-paste(sprintf("T%02d",0:23),':00',sep='') -.timespans.stop<-paste(sprintf("T%02d",0:23),':59',sep='') - -.timespans<-outer(.timespans.start, .timespans.stop, FUN=paste, sep='/') - -# in order to run the full 24x24 hour scan above, comment out the following line: -.timespans<-c('T06:00/T10:00', 'T07:00/T11:00', 'T08:00/T12:00', 'T09:00/T13:00', 'T10:00/T14:00', 'T11:00/T15:00', 'T12:00/T16:00') - -############################################################################### - -require(doMC) -require(foreach,quietly=TRUE) -# example parallel initialization for doParallel. this or doMC, or doRedis are -# most probably preferable to doSMP -#require(doParallel) -#registerDoParallel() # by default number of physical cores -1 - -require(quantstrat) - -portfolio.st = 'forex' - -s<-getStrategy('luxor') - -parameterTable<-getParameterTable(s) - -tPD2<-setParameterDistribution(strategy=s, component.type='enter', component.label='EnterLONG', distribution = list(timespan = .timespans), label = 'Timespan') - -registerDoMC(cores=2) - -if(method == 'random') -{ - laststpar.rnd<-system.time( - scan.results<-applyParameter( - strategy=s, - portfolios=portfolio.st, - parameterPool=tPD2, - method='random', - sampleSize=.sampleSize, - parameterConstraints=NULL - ) - ) - if(verbose >=1) laststpar.rnd -} - -if(method == 'expand') -{ - laststpar.exp<-system.time( - scan.results<-applyParameter( - strategy=s, - portfolios=portfolio.st, - parameterPool=tPD2, - method='expand', - parameterConstraints=NULL - ) - ) - if(verbose >=1) print(laststpar.exp) -} - -#examine the stats from this parameter run: -if(verbose >=1) print(scan.results$statsTable) - -stats <- scan.results$statsTable -save(stats, file="luxor.timespan.RData") - -##### PLACE DEMO AND TEST DATES HERE ################# -# -#if(isTRUE(options('in_test')$in_test)) -# # use test dates -# {initDate="2011-01-01" -# endDate="2012-12-31" -# } else -# # use demo defaults -# {initDate="1999-12-31" -# endDate=Sys.Date()} - -##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### -# book = getOrderBook(port) -# stats = tradeStats(port) -# rets = PortfReturns(acct) -################################################################ Deleted: pkg/quantstrat/demo/luxor.4.Timespans.tradegraphs.R =================================================================== --- pkg/quantstrat/demo/luxor.4.Timespans.tradegraphs.R 2013-05-05 16:28:54 UTC (rev 1455) +++ pkg/quantstrat/demo/luxor.4.Timespans.tradegraphs.R 2013-05-07 20:45:41 UTC (rev 1456) @@ -1,43 +0,0 @@ -#!/usr/bin/Rscript --vanilla - -require(quantstrat) - -load('../data/luxor.timespan.24x24.2002-2008.RData') - -names(stats)[names(stats)=='testPackListPRL[[k]]$parameters']<-'timespan' - -stats$tmp = strsplit(as.character(stats$timespan),'/') - -stats$from<-sapply(stats$tmp,FUN='[',1) -stats$to<-sapply(stats$tmp,FUN='[',2) - -stats$start<-as.numeric(gsub('T([0-9]+):[0-9]+',x=stats$from,'\\1')) -stats$stop<-(as.numeric(gsub('T([0-9]+):[0-9]+',x=stats$to,'\\1'))+1)%%24 - -# trading data is in EST (GMT-4): move 4 hours to adjust to GMT -#stats$start<-(stats$start+4)%%24 -#stats$stop<-(stats$stop+4)%%24 - -tradeGraphs( - stats, - free.params=c('start','stop'), - statistics=c('Net.Trading.PL','maxDrawdown',"Avg.Trade.PL",'Num.Trades',"Profit.Factor"), - title = 'Luxor Intraday TimeWindow Scan' -) - -##### PLACE DEMO AND TEST DATES HERE ################# -# -#if(isTRUE(options('in_test')$in_test)) -# # use test dates -# {initDate="2011-01-01" -# endDate="2012-12-31" -# } else -# # use demo defaults -# {initDate="1999-12-31" -# endDate=Sys.Date()} - -##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### -# book = getOrderBook(port) -# stats = tradeStats(port) -# rets = PortfReturns(acct) -################################################################ Deleted: pkg/quantstrat/demo/luxor.5.orderchains.R =================================================================== --- pkg/quantstrat/demo/luxor.5.orderchains.R 2013-05-05 16:28:54 UTC (rev 1455) +++ pkg/quantstrat/demo/luxor.5.orderchains.R 2013-05-07 20:45:41 UTC (rev 1456) @@ -1,291 +0,0 @@ -#!/usr/bin/Rscript --vanilla -# -# Jan Humme (@opentrades) - August 2012 -# -# Tested and found to work correctly using blotter r1230 -# -# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) -# - -options(width = 240) -#Sys.setenv(TZ="GMT") - -##### PLACE DEMO AND TEST DATES HERE ################# -# -#if(isTRUE(options('in_test')$in_test)) -# # use test dates -# {initDate="2011-01-01" -# endDate="2012-12-31" -# } else -# # use demo defaults -# {initDate="1999-12-31" -# endDate=Sys.Date()} - -.from='2002-10-21' -#.to='2008-07-04' -.to='2002-10-31' - -### - -source('luxor.include.R') -source('luxor.getSymbols.R') - -### blotter - -initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD') -initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD') - -### quantstrat - -initOrders(portfolio.st, initDate=initDate) - -### define strategy - -addPosLimit( - portfolio=portfolio.st, - symbol='GBPUSD', - timestamp=initDate, - maxpos=.orderqty) - -strategy(strategy.st, store=TRUE) - -### indicators - -add.indicator(strategy.st, name = "SMA", - arguments = list( - x = quote(Cl(mktdata)[,1]), - n = .fast - ), - label="nFast" -) - -add.indicator(strategy.st, name="SMA", - arguments = list( - x = quote(Cl(mktdata)[,1]), - n = .slow - ), - label="nSlow" -) - -### signals - -add.signal(strategy.st, name='sigCrossover', - arguments = list( - columns=c("nFast","nSlow"), - relationship="gte" - ), - label='long' -) - -add.signal(strategy.st, name='sigCrossover', - arguments = list( - columns=c("nFast","nSlow"), - relationship="lt" - ), - label='short' -) - -### rules ############ - -### stop-loss - -add.rule(strategy.st, name = 'ruleSignal', - arguments=list(sigcol='long' , sigval=TRUE, - replace=FALSE, - orderside='long', - ordertype='stoplimit', - tmult=TRUE, - threshold=.stoploss, - TxnFees=.txnfees, - orderqty='all', - orderset='ocolong' - ), - type='chain', parent='EnterLONG', - label='StopLossLONG', - storefun=FALSE -) - -add.rule(strategy.st, name = 'ruleSignal', - arguments=list(sigcol='short' , sigval=TRUE, - replace=FALSE, - orderside='short', - ordertype='stoplimit', - tmult=TRUE, - threshold=.stoploss, - TxnFees=.txnfees, - orderqty='all', - orderset='ocoshort' - ), - type='chain', parent='EnterSHORT', - label='StopLossSHORT', - storefun=FALSE -) - -### stop-trailing - -if(TRUE) -{ -add.rule(strategy.st, name = 'ruleSignal', - arguments=list(sigcol='long' , sigval=TRUE, - replace=FALSE, - orderside='long', - ordertype='stoptrailing', - tmult=TRUE, - threshold=.stoptrailing, - TxnFees=.txnfees, - orderqty='all', - orderset='ocolong' - ), - type='chain', parent='EnterLONG', - label='StopTrailingLONG', - storefun=FALSE -) - -add.rule(strategy.st, name = 'ruleSignal', - arguments=list(sigcol='short' , sigval=TRUE, - replace=FALSE, - orderside='short', - ordertype='stoptrailing', - tmult=TRUE, - threshold=.stoptrailing, - TxnFees=.txnfees, - orderqty='all', - orderset='ocoshort' - ), - type='chain', parent='EnterSHORT', - label='StopTrailingSHORT', - storefun=FALSE -) -} - -### take-profit - -add.rule(strategy.st, name = 'ruleSignal', - arguments=list(sigcol='long' , sigval=TRUE, - replace=FALSE, - orderside='long', - ordertype='limit', - tmult=TRUE, - threshold=.takeprofit, - TxnFees=.txnfees, - orderqty='all', - orderset='ocolong' - ), - type='chain', parent='EnterLONG', - label='TakeProfitLONG', - storefun=FALSE -) - -add.rule(strategy.st, name = 'ruleSignal', - arguments=list(sigcol='short' , sigval=TRUE, - replace=FALSE, - orderside='short', - ordertype='limit', - tmult=TRUE, - threshold=.takeprofit, - TxnFees=.txnfees, - orderqty='all', - orderset='ocoshort' - ), - type='chain', parent='EnterSHORT', - label='TakeProfitSHORT', - storefun=FALSE -) - -### - -add.rule(strategy.st, name = 'ruleSignal', - arguments=list(sigcol='long' , sigval=TRUE, - replace=TRUE, - orderside='short', - ordertype='market', - TxnFees=.txnfees, - orderqty='all', - orderset='ocoshort' - ), - type='exit', - timespan = .timespan, - label='Exit2LONG', - storefun=FALSE -) - -add.rule(strategy.st, name = 'ruleSignal', - arguments=list(sigcol='short', sigval=TRUE, - replace=TRUE, - orderside='long' , - ordertype='market', - TxnFees=.txnfees, - orderqty='all', - orderset='ocolong' - ), - type='exit', - timespan = .timespan, - label='Exit2SHORT', - storefun=FALSE -) - -add.rule(strategy.st, name = 'ruleSignal', - arguments=list(sigcol='long' , sigval=TRUE, - replace=FALSE, - orderside='long' , - ordertype='stoplimit', - prefer='High', - threshold=.threshold, - TxnFees=0, - orderqty=+.orderqty, - osFUN=osMaxPos, - orderset='ocolong' - ), - type='enter', - timespan = .timespan, - label='EnterLONG', - storefun=FALSE -) - -add.rule(strategy.st, name = 'ruleSignal', - arguments=list(sigcol='short', sigval=TRUE, - replace=FALSE, - orderside='short', - ordertype='stoplimit', - prefer='Low', - threshold=.threshold, - TxnFees=0, - orderqty=-.orderqty, - osFUN=osMaxPos, - orderset='ocoshort' - ), - type='enter', - timespan = .timespan, - label='EnterSHORT', - storefun=FALSE -) - -# - -############################################################################### - -applyStrategy(strategy.st, portfolio.st, verbose = FALSE) -#applyStrategy(strategy.st, p, prefer='Open', verbose = FALSE) - -updatePortf(portfolio.st, Symbols='GBPUSD', ,Dates=paste('::',as.Date(Sys.time()),sep='')) - -############################################################################### - -chart.Posn(portfolio.st, "GBPUSD") - -print(getOrderBook(portfolio.st)) - -#txns <- getTxns(portfolio.st, 'GBPUSD') -#txns -##txns$Net -#cat('Net profit:', sum(txns$Net.Txn.Realized.PL), '\n') - -print(tradeStats(portfolio.st, 'GBPUSD')) - -save.strategy(strategy.st) - -##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### -# book = getOrderBook(port) -# stats = tradeStats(port) -# rets = PortfReturns(acct) -################################################################ Deleted: pkg/quantstrat/demo/luxor.6.paramset.stoploss.R =================================================================== --- pkg/quantstrat/demo/luxor.6.paramset.stoploss.R 2013-05-05 16:28:54 UTC (rev 1455) +++ pkg/quantstrat/demo/luxor.6.paramset.stoploss.R 2013-05-07 20:45:41 UTC (rev 1456) @@ -1,71 +0,0 @@ -#!/usr/bin/Rscript --vanilla -# -# Jan Humme (@opentrades) - August 2012 -# -# Tested and found to work correctly using blotter r1230 -# -# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) -# -# compute StopLoss percentage for various paramsets - -require(quantstrat) - -options(width = 240) -#Sys.setenv(TZ="GMT") - -##### PLACE DEMO AND TEST DATES HERE ################# -# -#if(isTRUE(options('in_test')$in_test)) -# # use test dates -# {initDate="2011-01-01" -# endDate="2012-12-31" -# } else -# # use demo defaults -# {initDate="1999-12-31" -# endDate=Sys.Date()} - -source('luxor.include.R') -source('luxor.getSymbols.R') - -### - -initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD') -addPosLimit( - portfolio=portfolio.st, - symbol='GBPUSD', - timestamp=initDate, - maxpos=.orderqty) - -initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD') - -### - -initOrders(portfolio.st, initDate=initDate) - -load.strategy(strategy.st) - -############################ - -require(foreach) -#registerDoSEQ() - -require(doMC) -registerDoMC(cores=8) - -#require(doParallel) -#registerDoParallel(cores=2) - -#require(doRedis) -#registerDoRedis('jobs') - -############################ - -results <- apply.paramset(strategy.st, paramset.label='StopLoss', portfolio.st=portfolio.st, account.st=account.st, nsamples=80, verbose=TRUE) - -print(results$tradeStats) - -##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### -# book = getOrderBook(port) -# stats = tradeStats(port) -# rets = PortfReturns(acct) -################################################################ Deleted: pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R =================================================================== --- pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R 2013-05-05 16:28:54 UTC (rev 1455) +++ pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R 2013-05-07 20:45:41 UTC (rev 1456) @@ -1,71 +0,0 @@ -#!/usr/bin/Rscript --vanilla -# -# Jan Humme (@opentrades) - August 2012 -# -# Tested and found to work correctly using blotter r1230 -# -# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) -# -# compute StopTrailing percentage for various paramsets - -require(quantstrat) - -options(width = 240) -Sys.setenv(TZ='UTC') - -##### PLACE DEMO AND TEST DATES HERE ################# -# -#if(isTRUE(options('in_test')$in_test)) -# # use test dates -# {initDate="2011-01-01" -# endDate="2012-12-31" -# } else -# # use demo defaults -# {initDate="1999-12-31" -# endDate=Sys.Date()} - -source('luxor.include.R') -source('luxor.getSymbols.R') - -### - -initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD') -addPosLimit( - portfolio=portfolio.st, - symbol='GBPUSD', - timestamp=initDate, - maxpos=.orderqty) - -initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD') - -### - -initOrders(portfolio.st, initDate=initDate) - -load.strategy(strategy.st) - -############################ - -require(foreach) -#registerDoSEQ() - -require(doMC) -registerDoMC(cores=2) - -#require(doParallel) -#registerDoParallel(cores=2) - -#require(doRedis) -#registerDoRedis('jobs') - -############################ - -results <- apply.paramset(strategy.st, paramset.label='StopTrailing', portfolio.st=portfolio.st, account.st=account.st, nsamples=80, verbose=TRUE) - -print(results$tradeStats) - -##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### -# book = getOrderBook(port) -# stats = tradeStats(port) -# rets = PortfReturns(acct) -################################################################ Deleted: pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R =================================================================== --- pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R 2013-05-05 16:28:54 UTC (rev 1455) +++ pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R 2013-05-07 20:45:41 UTC (rev 1456) @@ -1,71 +0,0 @@ -#!/usr/bin/Rscript --vanilla -# -# Jan Humme (@opentrades) - August 2012 -# -# Tested and found to work correctly using blotter r1230 -# -# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) -# -# compute TakeProfit percentage for various paramsets - -require(quantstrat) - -options(width = 240) -Sys.setenv(TZ='UTC') - -##### PLACE DEMO AND TEST DATES HERE ################# -# -#if(isTRUE(options('in_test')$in_test)) -# # use test dates -# {initDate="2011-01-01" -# endDate="2012-12-31" -# } else -# # use demo defaults -# {initDate="1999-12-31" -# endDate=Sys.Date()} - -source('luxor.include.R') -source('luxor.getSymbols.R') - -### - -initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD') -addPosLimit( - portfolio=portfolio.st, - symbol='GBPUSD', - timestamp=initDate, - maxpos=.orderqty) - -initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD') - -### - -initOrders(portfolio.st, initDate=initDate) - -load.strategy(strategy.st) - -############################ - -require(foreach) -#registerDoSEQ() - -require(doMC) -registerDoMC(cores=8) - -#require(doParallel) -#registerDoParallel(cores=2) - -#require(doRedis) -#registerDoRedis('jobs') - -############################ - -results <- apply.paramset(strategy.st, paramset.label='TakeProfit', portfolio.st=portfolio.st, account.st=account.st, nsamples=80, verbose=TRUE) - -print(results$tradeStats) - -##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### -# book = getOrderBook(port) -# stats = tradeStats(port) -# rets = PortfReturns(acct) -################################################################ Deleted: pkg/quantstrat/demo/luxor.7.MAE.stoploss.R =================================================================== --- pkg/quantstrat/demo/luxor.7.MAE.stoploss.R 2013-05-05 16:28:54 UTC (rev 1455) +++ pkg/quantstrat/demo/luxor.7.MAE.stoploss.R 2013-05-07 20:45:41 UTC (rev 1456) @@ -1,35 +0,0 @@ -#!/usr/bin/Rscript --vanilla -# -# Jan Humme (@opentrades) - August 2012 -# -# Tested and found to work correctly using blotter r1143 -# -# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) -# -# Figure 3.11: MAE graph of Luxor system - -require('blotter') - -data('luxor-p066', package='quantstrat', envir=.blotter) - -currency(c('GBP', 'USD')) -exchange_rate(c('GBPUSD'), tick_size=0.0001) - -chart.ME('luxor', 'GBPUSD', type='MAE', scale='cash') - -##### PLACE DEMO AND TEST DATES HERE ################# -# -#if(isTRUE(options('in_test')$in_test)) -# # use test dates -# {initDate="2011-01-01" -# endDate="2012-12-31" -# } else -# # use demo defaults -# {initDate="1999-12-31" -# endDate=Sys.Date()} - -##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### -# book = getOrderBook(port) -# stats = tradeStats(port) -# rets = PortfReturns(acct) -################################################################ Deleted: pkg/quantstrat/demo/luxor.7.MAE.stoptrailing.R =================================================================== --- pkg/quantstrat/demo/luxor.7.MAE.stoptrailing.R 2013-05-05 16:28:54 UTC (rev 1455) +++ pkg/quantstrat/demo/luxor.7.MAE.stoptrailing.R 2013-05-07 20:45:41 UTC (rev 1456) @@ -1,35 +0,0 @@ -#!/usr/bin/Rscript --vanilla -# -# Jan Humme (@opentrades) - August 2012 -# -# Tested and found to work correctly using blotter r1143 -# -# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) -# -# Figure 3.12: MAE graph in percentage terms - -require('blotter') - -data('luxor-p066', package='quantstrat', envir=.blotter) - -currency(c('GBP', 'USD')) -exchange_rate(c('GBPUSD'), tick_size=0.0001) - -chart.ME('luxor', type='MAE', scale='percent') - -##### PLACE DEMO AND TEST DATES HERE ################# -# -#if(isTRUE(options('in_test')$in_test)) -# # use test dates -# {initDate="2011-01-01" -# endDate="2012-12-31" -# } else -# # use demo defaults -# {initDate="1999-12-31" -# endDate=Sys.Date()} - -##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### -# book = getOrderBook(port) -# stats = tradeStats(port) -# rets = PortfReturns(acct) -################################################################ Deleted: pkg/quantstrat/demo/luxor.7.MFE.takeprofit.R =================================================================== --- pkg/quantstrat/demo/luxor.7.MFE.takeprofit.R 2013-05-05 16:28:54 UTC (rev 1455) +++ pkg/quantstrat/demo/luxor.7.MFE.takeprofit.R 2013-05-07 20:45:41 UTC (rev 1456) @@ -1,35 +0,0 @@ -#!/usr/bin/Rscript --vanilla -# -# Jan Humme (@opentrades) - August 2012 -# -# Tested and found to work correctly using blotter r1143 -# -# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) -# -# Figure 3.16: MFE graph in percentage terms - -require('blotter') - -data('luxor-p066', package='quantstrat', envir=.blotter) - -currency(c('GBP', 'USD')) -exchange_rate(c('GBPUSD'), tick_size=0.0001) - -chart.ME('luxor', type='MFE', scale='percent') - -##### PLACE DEMO AND TEST DATES HERE ################# -# -#if(isTRUE(options('in_test')$in_test)) -# # use test dates -# {initDate="2011-01-01" -# endDate="2012-12-31" -# } else -# # use demo defaults -# {initDate="1999-12-31" -# endDate=Sys.Date()} - -##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### -# book = getOrderBook(port) -# stats = tradeStats(port) -# rets = PortfReturns(acct) -################################################################ Deleted: pkg/quantstrat/demo/luxor.getSymbols.R =================================================================== --- pkg/quantstrat/demo/luxor.getSymbols.R 2013-05-05 16:28:54 UTC (rev 1455) +++ pkg/quantstrat/demo/luxor.getSymbols.R 2013-05-07 20:45:41 UTC (rev 1456) @@ -1,45 +0,0 @@ -#!/usr/bin/Rscript --vanilla -# -# Jan Humme (@opentrades) - August 2012, revised April 2013 -# -# Tested and found to work correctly using blotter r1420 -# -# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) -# -# Paragraph 3.2: luxor with $30 slippage and transaction costs - -Sys.setenv(TZ="UTC") - -.from='2002-10-21' -#.to='2008-07-04' -.to='2002-10-31' - -### packages -# -# quantstrat package will pull in some other packages: -# FinancialInstrument, quantmod, blotter, xts - -require(quantstrat) - -### FinancialInstrument - -currency(c('GBP', 'USD')) - -exchange_rate('GBPUSD', tick_size=0.0001) - -### quantmod - -getSymbols.FI(Symbols='GBPUSD', - dir=system.file('extdata',package='quantstrat'), - from=.from, to=.to -) - -# ALTERNATIVE WAY TO FETCH SYMBOL DATA -#setSymbolLookup.FI(system.file('extdata',package='quantstrat'), 'GBPUSD') -#getSymbols('GBPUSD', from=.from, to=.to, verbose=FALSE) - -### xts - -GBPUSD = to.minutes30(GBPUSD) -GBPUSD = align.time(to.minutes30(GBPUSD), 1800) - Deleted: pkg/quantstrat/demo/luxor.include.R =================================================================== --- pkg/quantstrat/demo/luxor.include.R 2013-05-05 16:28:54 UTC (rev 1455) +++ pkg/quantstrat/demo/luxor.include.R 2013-05-07 20:45:41 UTC (rev 1456) @@ -1,27 +0,0 @@ -### - -initDate = '2002-10-21' - -strategy.st = 'luxor' -portfolio.st = 'forex' -account.st = 'IB1' - -### - -.fast = 1 -.slow = 44 - -.timespan = 'T08:00/T12:00' -.timespan = 'T00:00/T23:59' - -.stoploss = 0.001 -.stoptrailing = 0.0015 -.takeprofit = 0.003 - -### - -.orderqty = 100000 -.threshold = 0.0005 -.txnfees = -30 - -### From noreply at r-forge.r-project.org Tue May 7 22:46:47 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 7 May 2013 22:46:47 +0200 (CEST) Subject: [Blotter-commits] r1457 - pkg/quantstrat/demo Message-ID: <20130507204647.77BA21813CF@r-forge.r-project.org> Author: opentrades Date: 2013-05-07 22:46:47 +0200 (Tue, 07 May 2013) New Revision: 1457 Added: pkg/quantstrat/demo/luxor.1.strategy.basic.R pkg/quantstrat/demo/luxor.2.add.paramsets.R pkg/quantstrat/demo/luxor.3.paramset.sma.R pkg/quantstrat/demo/luxor.4.paramset.timespan.R pkg/quantstrat/demo/luxor.5.strategy.ordersets.R 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.7.exit+risk.R pkg/quantstrat/demo/luxor.getSymbols.R pkg/quantstrat/demo/luxor.include.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 Modified: pkg/quantstrat/demo/00Index Log: - updated luxor demos Modified: pkg/quantstrat/demo/00Index =================================================================== --- pkg/quantstrat/demo/00Index 2013-05-07 20:45:41 UTC (rev 1456) +++ pkg/quantstrat/demo/00Index 2013-05-07 20:46:47 UTC (rev 1457) @@ -8,23 +8,19 @@ 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 Tomasini & Jaekle: Section 3.2: luxor without any optimizations -luxor.2 Tomasini & Jaekle: Section 3.2: luxor with $30 slippage and transaction costs -luxor.3 Tomasini & Jaekle: Section 3.3 Variation of the input parameters: optimization and stability diagrams -luxor.3.Parameters Tomasini & Jaekle: Section 3.3 Variation of the input parameters: optimization and stability diagrams / scan -luxor.3.Parameters.tradegraphs Tomasini & Jaekle: 3D graphs of results for SMA scan -luxor.4 Tomasini & Jaekle: Section 3.4: inserting an intraday time filter -luxor.4.Timespans Tomasini & Jaekle: Section 3.4: inserting an intraday time filter / scan -luxor.4.Timespans.tradegraphs Tomasini & Jaekle: 3D graphs of results for timespan scan -luxor.orderchains Tomasini & Jaekle: adding order chain logic conditional on fills -luxor.Stop -luxor-3.11 -luxor-3.12 -luxor-3.16 -luxor.3 -luxor.4 -luxor.StopLoss -luxor.StopTrailing -luxor.TakeProfit -luxor.exits -luxor.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+risk.R Jaekle & Tomasini; Sections 3.5: running with stoploss and/or stoptrailing and/or takeprofit +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 Added: pkg/quantstrat/demo/luxor.1.strategy.basic.R =================================================================== --- pkg/quantstrat/demo/luxor.1.strategy.basic.R (rev 0) +++ pkg/quantstrat/demo/luxor.1.strategy.basic.R 2013-05-07 20:46:47 UTC (rev 1457) @@ -0,0 +1,151 @@ +#!/usr/bin/Rscript --vanilla +# +# Jan Humme (@opentrades) - August 2012, revised April 2013 +# +# Tested and found to work correctly using blotter r1420 +# +# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) +# +# Paragraph 3.2: luxor with $30 slippage and transaction costs + +##### PLACE DEMO AND TEST DATES HERE ################# +# +#if(isTRUE(options('in_test')$in_test)) +# # use test dates +# {initDate="2011-01-01" +# endDate="2012-12-31" +# } else +# # use demo defaults +# {initDate="1999-12-31" +# endDate=Sys.Date()} + +source('luxor.include.R') +.fast = 10 +.slow = 30 + +source('luxor.getSymbols.R') + +### blotter + +initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD') +initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD') + +### quantstrat + +initOrders(portfolio.st, initDate=initDate) + +### define strategy + +strategy(strategy.st, store=TRUE) + +### indicators + +add.indicator(strategy.st, name = "SMA", + arguments = list( + x = quote(Cl(mktdata)[,1]), + n = .fast + ), + label="nFast" +) + +add.indicator(strategy.st, name="SMA", + arguments = list( + x = quote(Cl(mktdata)[,1]), + n = .slow + ), + label="nSlow" +) + +### signals + +add.signal(strategy.st, name='sigCrossover', + arguments = list( + columns=c("nFast","nSlow"), + relationship="gte" + ), + label='long' +) + +add.signal(strategy.st, name='sigCrossover', + arguments = list( + columns=c("nFast","nSlow"), + relationship="lt" + ), + label='short' +) + +### rules + +add.rule(strategy.st, name='ruleSignal', + arguments=list(sigcol='long' , sigval=TRUE, + orderside='short', + ordertype='market', + orderqty='all', + TxnFees=.txnfees, + replace=TRUE + ), + type='exit', + label='Exit2LONG' +) + +add.rule(strategy.st, name='ruleSignal', + arguments=list(sigcol='short', sigval=TRUE, + orderside='long' , + ordertype='market', + orderqty='all', + TxnFees=.txnfees, + replace=TRUE + ), + type='exit', + label='Exit2SHORT' +) + +add.rule(strategy.st, name='ruleSignal', + arguments=list(sigcol='long' , sigval=TRUE, + orderside='long' , + ordertype='stoplimit', prefer='High', threshold=.threshold, + orderqty=+.orderqty, + replace=FALSE + ), + type='enter', + label='EnterLONG' +) + +add.rule(strategy.st, name='ruleSignal', + arguments=list(sigcol='short', sigval=TRUE, + orderside='short', + ordertype='stoplimit', prefer='Low', threshold=-.threshold, + orderqty=-.orderqty, + replace=FALSE + ), + type='enter', + label='EnterSHORT' +) + +############################################################################### + +applyStrategy(strategy.st, portfolio.st) + +View(getOrderBook(portfolio.st)[[portfolio.st]]$GBPUSD) + +############################################################################### + +updatePortf(portfolio.st, Symbols='GBPUSD', Dates=paste('::',as.Date(Sys.time()),sep='')) + +chart.Posn(portfolio.st, "GBPUSD") + +############################################################################### + +View(tradeStats(portfolio.st, 'GBPUSD')) + +############################################################################### + +# save the strategy in an .RData object for later retrieval + +save.strategy(strategy.st) + +##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### +# book = getOrderBook(port) +# stats = tradeStats(port) +# rets = PortfReturns(acct) +################################################################ Property changes on: pkg/quantstrat/demo/luxor.1.strategy.basic.R ___________________________________________________________________ Added: svn:executable + * Added: pkg/quantstrat/demo/luxor.2.add.paramsets.R =================================================================== --- pkg/quantstrat/demo/luxor.2.add.paramsets.R (rev 0) +++ pkg/quantstrat/demo/luxor.2.add.paramsets.R 2013-05-07 20:46:47 UTC (rev 1457) @@ -0,0 +1,74 @@ +#!/usr/bin/Rscript --vanilla +# +# Jan Humme (@opentrades) - August 2012, revised April 2013 +# +# Tested and found to work correctly using blotter r1420 + +require(quantstrat) + +##### PLACE DEMO AND TEST DATES HERE ################# +# +#if(isTRUE(options('in_test')$in_test)) +# # use test dates +# {initDate="2011-01-01" +# endDate="2012-12-31" +# } else +# # use demo defaults +# {initDate="1999-12-31" +# endDate=Sys.Date()} + +source('luxor.include.R') + +### + +strategy.st <- 'luxor' + +### + +load.strategy(strategy.st) + +### SMA paramset + +add.distribution(strategy.st, + paramset.label = 'SMA', + component.type = 'indicator', + component.label = 'nFast', + variable = list(n = .FastSMA), + label = 'nFAST' +) + +add.distribution(strategy.st, + paramset.label = 'SMA', + component.type = 'indicator', + component.label = 'nSlow', + variable = list(n = .SlowSMA), + label = 'nSLOW' +) + +add.constraint(strategy.st, + paramset.label = 'SMA', + distribution.label.1 = 'nFAST', + distribution.label.2 = 'nSLOW', + operator = '<', + label = 'SMA' +) + +### Timespan paramset + +add.distribution(strategy.st, + paramset.label = 'Timespan', + component.type = 'rule', + component.label = 'timespan', + variable = list(n = .timespans), + label = 'Timespan' +) + +### + +save.strategy(strategy.st) + +##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### +# book = getOrderBook(port) +# stats = tradeStats(port) +# rets = PortfReturns(acct) +################################################################ Property changes on: pkg/quantstrat/demo/luxor.2.add.paramsets.R ___________________________________________________________________ Added: svn:executable + * Added: pkg/quantstrat/demo/luxor.3.paramset.sma.R =================================================================== --- pkg/quantstrat/demo/luxor.3.paramset.sma.R (rev 0) +++ pkg/quantstrat/demo/luxor.3.paramset.sma.R 2013-05-07 20:46:47 UTC (rev 1457) @@ -0,0 +1,47 @@ +#!/usr/bin/Rscript --vanilla +# +# Jan Humme (@opentrades) - August 2012, revised April 2013 +# +# Tested and found to work correctly using blotter r1420 +# +# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) +# +# Paragraph 3.2: luxor with $30 slippage and transaction costs + +### + +source('luxor.include.R') +source('luxor.getSymbols.R') + +### blotter + +initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD') +initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD') + +### quantstrat + +initOrders(portfolio.st, initDate=initDate) + +load.strategy(strategy.st) + +### doMC + +require(doMC) +registerDoMC(cores=8) + +#require(doParallel) +#registerDoParallel(cores=2) + +#require(doRedis) +#registerDoRedis('jobs') + +results <- apply.paramset(strategy.st, paramset.label='SMA', portfolio.st=portfolio.st, account.st=account.st, nsamples=.nsamples, verbose=TRUE) + +### + +stats <- results$tradeStats + +print(stats) + +save(stats, file='luxor.3.paramset.SMA.RData') + Property changes on: pkg/quantstrat/demo/luxor.3.paramset.sma.R ___________________________________________________________________ Added: svn:executable + * Added: pkg/quantstrat/demo/luxor.4.paramset.timespan.R =================================================================== --- pkg/quantstrat/demo/luxor.4.paramset.timespan.R (rev 0) +++ pkg/quantstrat/demo/luxor.4.paramset.timespan.R 2013-05-07 20:46:47 UTC (rev 1457) @@ -0,0 +1,45 @@ +#!/usr/bin/Rscript --vanilla +# +# Jan Humme (@opentrades) - August 2012, revised April 2013 +# +# Tested and found to work correctly using blotter r1420 +# +# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) + +stop('#### DEMO BROKEN - BEING FIXED ###') + +source('luxor.include.R') +source('luxor.getSymbols.R') + +### blotter + +initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD') +initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD') + +### quantstrat + +initOrders(portfolio.st, initDate=initDate) + +load.strategy(strategy.st) + +### doMC + +require(doMC) +registerDoMC(cores=8) + +#require(doParallel) +#registerDoParallel(cores=2) + +#require(doRedis) +#registerDoRedis('jobs') + +results <- apply.paramset(strategy.st, paramset.label='Timespan', portfolio.st=portfolio.st, account.st=account.st, nsamples=.nsamples, verbose=TRUE) + +### + +stats <- results$tradeStats + +print(stats) + +save(stats, file='luxor.4.paramset.Timespan.RData') + Property changes on: pkg/quantstrat/demo/luxor.4.paramset.timespan.R ___________________________________________________________________ Added: svn:executable + * Added: pkg/quantstrat/demo/luxor.5.strategy.ordersets.R =================================================================== --- pkg/quantstrat/demo/luxor.5.strategy.ordersets.R (rev 0) +++ pkg/quantstrat/demo/luxor.5.strategy.ordersets.R 2013-05-07 20:46:47 UTC (rev 1457) @@ -0,0 +1,306 @@ +#!/usr/bin/Rscript --vanilla +# +# Jan Humme (@opentrades) - May 2013 +# +# Tested and found to work correctly using blotter r1448 +# +# After Jaekle & Tomasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) +# +# Advanced luxor strategy implementation including exit management using ordersets and orderchains + +require(quantstrat) + +##### PLACE DEMO AND TEST DATES HERE ################# +# +#if(isTRUE(options('in_test')$in_test)) +# # use test dates +# {initDate="2011-01-01" +# endDate="2012-12-31" +# } else +# # use demo defaults +# {initDate="1999-12-31" +# endDate=Sys.Date()} + +source('luxor.include.R') + +### define strategy + +strategy(strategy.st, store=TRUE) + +### indicators + +add.indicator(strategy.st, name = "SMA", + arguments = list( + x = quote(Cl(mktdata)[,1]), + n = .fast + ), + label="nFast" +) + +add.indicator(strategy.st, name="SMA", + arguments = list( + x = quote(Cl(mktdata)[,1]), + n = .slow + ), + label="nSlow" +) + +### signals + +add.signal(strategy.st, name='sigCrossover', + arguments = list( + columns=c("nFast","nSlow"), + relationship="gte" + ), + label='long' +) + +add.signal(strategy.st, name='sigCrossover', + arguments = list( + columns=c("nFast","nSlow"), + relationship="lt" + ), + label='short' +) + +### rules ############ + +# normal exit rules + +add.rule(strategy.st, name = 'ruleSignal', + arguments=list(sigcol='long' , sigval=TRUE, + replace=TRUE, + orderside='short', + ordertype='market', + TxnFees=.txnfees, + orderqty='all', + orderset='ocoshort' + ), + type='exit', + timespan = .timespan, + label='Exit2LONG' +) + +add.rule(strategy.st, name = 'ruleSignal', + arguments=list(sigcol='short', sigval=TRUE, + replace=TRUE, + orderside='long' , + ordertype='market', + TxnFees=.txnfees, + orderqty='all', + orderset='ocolong' + ), + type='exit', + timespan = .timespan, + label='Exit2SHORT' +) + +# normal entry rules + +add.rule(strategy.st, name = 'ruleSignal', + arguments=list(sigcol='long' , sigval=TRUE, + replace=FALSE, + orderside='long' , + ordertype='stoplimit', + prefer='High', + threshold=.threshold, + TxnFees=0, + orderqty=+.orderqty, + osFUN=osMaxPos, + orderset='ocolong' + ), + type='enter', + timespan = .timespan, + label='EnterLONG' +) + +add.rule(strategy.st, name = 'ruleSignal', + arguments=list(sigcol='short', sigval=TRUE, + replace=FALSE, + orderside='short', + ordertype='stoplimit', + prefer='Low', + threshold=.threshold, + TxnFees=0, + orderqty=-.orderqty, + osFUN=osMaxPos, + orderset='ocoshort' + ), + type='enter', + timespan = .timespan, + label='EnterSHORT' +) + +### stoploss, stoptrailing and takeprofit + +# stop-loss + +add.rule(strategy.st, name = 'ruleSignal', + arguments=list(sigcol='long' , sigval=TRUE, + replace=FALSE, + orderside='long', + ordertype='stoplimit', tmult=TRUE, threshold=quote(.stoploss), + TxnFees=.txnfees, + orderqty='all', + orderset='ocolong' + ), + type='chain', parent='EnterLONG', + label='StopLossLONG', + enabled=FALSE +) + +add.rule(strategy.st, name = 'ruleSignal', + arguments=list(sigcol='short' , sigval=TRUE, + replace=FALSE, + orderside='short', + ordertype='stoplimit', tmult=TRUE, threshold=quote(.stoploss), + TxnFees=.txnfees, + orderqty='all', + orderset='ocoshort' + ), + type='chain', parent='EnterSHORT', + label='StopLossSHORT', + enabled=FALSE +) + +add.distribution(strategy.st, + paramset.label = 'StopLoss', + component.type = 'chain', + component.label = 'StopLossLONG', + variable = list(threshold = .StopLoss), + label = 'StopLossLONG' +) + +add.distribution(strategy.st, + paramset.label = 'StopLoss', + component.type = 'chain', + component.label = 'StopLossSHORT', + variable = list(threshold = .StopLoss), + label = 'StopLossSHORT' +) + +add.constraint(strategy.st, + paramset.label = 'StopLoss', + distribution.label.1 = 'StopLossLONG', + distribution.label.2 = 'StopLossSHORT', + operator = '==', + label = 'StopLoss' +) + +# stop-trailing + +add.rule(strategy.st, name = 'ruleSignal', + arguments=list(sigcol='long' , sigval=TRUE, + replace=FALSE, + orderside='long', + ordertype='stoptrailing', tmult=TRUE, threshold=quote(.stoptrailing), + TxnFees=.txnfees, + orderqty='all', + orderset='ocolong' + ), + type='chain', parent='EnterLONG', + label='StopTrailingLONG', + enabled=FALSE +) + +add.rule(strategy.st, name = 'ruleSignal', + arguments=list(sigcol='short' , sigval=TRUE, + replace=FALSE, + orderside='short', + ordertype='stoptrailing', tmult=TRUE, threshold=quote(.stoptrailing), + TxnFees=.txnfees, + orderqty='all', + orderset='ocoshort' + ), + type='chain', parent='EnterSHORT', + label='StopTrailingSHORT', + enabled=FALSE +) + +add.distribution(strategy.st, + paramset.label = 'StopTrailing', + component.type = 'chain', + component.label = 'StopTrailingLONG', + variable = list(threshold = .StopTrailing), + label = 'StopTrailingLONG' +) + +add.distribution(strategy.st, + paramset.label = 'StopTrailing', + component.type = 'chain', + component.label = 'StopTrailingSHORT', + variable = list(threshold = .StopTrailing), + label = 'StopTrailingSHORT' +) + +add.constraint(strategy.st, + paramset.label = 'StopTrailing', + distribution.label.1 = 'StopTrailingLONG', + distribution.label.2 = 'StopTrailingSHORT', + operator = '==', + label = 'StopTrailing' +) + +# take-profit + +add.rule(strategy.st, name = 'ruleSignal', + arguments=list(sigcol='long' , sigval=TRUE, + replace=FALSE, + orderside='long', + ordertype='limit', tmult=TRUE, threshold=quote(.takeprofit), + TxnFees=.txnfees, + orderqty='all', + orderset='ocolong' + ), + type='chain', parent='EnterLONG', + label='TakeProfitLONG', + enabled=FALSE +) + +add.rule(strategy.st, name = 'ruleSignal', + arguments=list(sigcol='short' , sigval=TRUE, + replace=FALSE, + orderside='short', + ordertype='limit', tmult=TRUE, threshold=quote(.takeprofit), + TxnFees=.txnfees, + orderqty='all', + orderset='ocoshort' + ), + type='chain', parent='EnterSHORT', + label='TakeProfitSHORT', + enabled=FALSE +) + +add.distribution(strategy.st, + paramset.label = 'TakeProfit', + component.type = 'chain', + component.label = 'TakeProfitLONG', + variable = list(threshold = .TakeProfit), + label = 'TakeProfitLONG' +) + +add.distribution(strategy.st, + paramset.label = 'TakeProfit', + component.type = 'chain', + component.label = 'TakeProfitSHORT', + variable = list(threshold = .TakeProfit), + label = 'TakeProfitSHORT' +) + +add.constraint(strategy.st, + paramset.label = 'TakeProfit', + distribution.label.1 = 'TakeProfitLONG', + distribution.label.2 = 'TakeProfitSHORT', + operator = '==', + label = 'TakeProfit' +) + +############################################################################### + +save.strategy(strategy.st) + +##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### +# book = getOrderBook(port) +# stats = tradeStats(port) +# rets = PortfReturns(acct) +################################################################ Property changes on: pkg/quantstrat/demo/luxor.5.strategy.ordersets.R ___________________________________________________________________ Added: svn:executable + * Added: pkg/quantstrat/demo/luxor.6.paramset.stoploss.R =================================================================== --- pkg/quantstrat/demo/luxor.6.paramset.stoploss.R (rev 0) +++ pkg/quantstrat/demo/luxor.6.paramset.stoploss.R 2013-05-07 20:46:47 UTC (rev 1457) @@ -0,0 +1,78 @@ +#!/usr/bin/Rscript --vanilla +# +# Jan Humme (@opentrades) - August 2012 +# +# Tested and found to work correctly using blotter r1230 +# +# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) +# +# compute StopLoss percentage for various paramsets + +require(quantstrat) + +##### PLACE DEMO AND TEST DATES HERE ################# +# +#if(isTRUE(options('in_test')$in_test)) +# # use test dates +# {initDate="2011-01-01" +# endDate="2012-12-31" +# } else +# # use demo defaults +# {initDate="1999-12-31" +# endDate=Sys.Date()} + +source('luxor.include.R') +source('luxor.getSymbols.R') + +### + +initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD') +addPosLimit( + portfolio=portfolio.st, + symbol='GBPUSD', + timestamp=initDate, + maxpos=.orderqty) + +initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD') + +### + +initOrders(portfolio.st, initDate=initDate) + +load.strategy(strategy.st) + +### BEGIN uncomment lines to activate StopLoss and/or StopTrailing and/or TakeProfit rules + +enable.rule('luxor', 'chain', 'StopLoss') +#enable.rule('luxor', 'chain', 'StopTrailing') +#enable.rule('luxor', 'chain', 'TakeProfit') + +### END uncomment lines to activate StopLoss and/or StopTrailing and/or TakeProfit rules + +require(foreach) +#registerDoSEQ() + +require(doMC) +registerDoMC(cores=8) + +#require(doParallel) +#registerDoParallel(cores=2) + +#require(doRedis) +#registerDoRedis('jobs') + +############################ + +results <- apply.paramset(strategy.st, paramset.label='StopLoss', portfolio.st=portfolio.st, account.st=account.st, nsamples=80, verbose=TRUE) + +stats <- results$tradeStats + +print(stats) + +plot(100*stats$StopLossLONG, stats$Net.Trading.PL, type='b', xlab='Stoploss %', ylab='Net.Trading.PL', main='Luxor') + +##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### +# book = getOrderBook(port) +# stats = tradeStats(port) +# rets = PortfReturns(acct) +################################################################ Added: pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R =================================================================== --- pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R (rev 0) +++ pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R 2013-05-07 20:46:47 UTC (rev 1457) @@ -0,0 +1,78 @@ +#!/usr/bin/Rscript --vanilla +# +# Jan Humme (@opentrades) - August 2012 +# +# Tested and found to work correctly using blotter r1230 +# +# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) +# +# compute StopTrailing percentage for various paramsets + +require(quantstrat) + +##### PLACE DEMO AND TEST DATES HERE ################# +# +#if(isTRUE(options('in_test')$in_test)) +# # use test dates +# {initDate="2011-01-01" +# endDate="2012-12-31" +# } else +# # use demo defaults +# {initDate="1999-12-31" +# endDate=Sys.Date()} + +source('luxor.include.R') +source('luxor.getSymbols.R') + +### + +initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD') +addPosLimit( + portfolio=portfolio.st, + symbol='GBPUSD', + timestamp=initDate, + maxpos=.orderqty) + +initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD') + +### + +initOrders(portfolio.st, initDate=initDate) + +load.strategy(strategy.st) + +### BEGIN uncomment lines to activate StopLoss and/or StopTrailing and/or TakeProfit rules + +enable.rule('luxor', 'chain', 'StopLoss') +enable.rule('luxor', 'chain', 'StopTrailing') +#enable.rule('luxor', 'chain', 'TakeProfit') + +### END uncomment lines to activate StopLoss and/or StopTrailing and/or TakeProfit rules + +require(foreach) +#registerDoSEQ() + +require(doMC) +registerDoMC(cores=2) + +#require(doParallel) +#registerDoParallel(cores=2) + +#require(doRedis) +#registerDoRedis('jobs') + +############################ + +results <- apply.paramset(strategy.st, paramset.label='StopTrailing', portfolio.st=portfolio.st, account.st=account.st, nsamples=80, verbose=TRUE) + +stats <- results$tradeStats + +print(stats) + +plot(100*stats$StopTrailingLONG, stats$Net.Trading.PL, type='b', xlab='StopTrailing %', ylab='Net.Trading.PL', main='Luxor') + +##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### +# book = getOrderBook(port) +# stats = tradeStats(port) +# rets = PortfReturns(acct) +################################################################ Added: pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R =================================================================== --- pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R (rev 0) +++ pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R 2013-05-07 20:46:47 UTC (rev 1457) @@ -0,0 +1,78 @@ +#!/usr/bin/Rscript --vanilla +# +# Jan Humme (@opentrades) - August 2012 +# +# Tested and found to work correctly using blotter r1230 +# +# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) +# +# compute TakeProfit percentage for various paramsets + +require(quantstrat) + +##### PLACE DEMO AND TEST DATES HERE ################# +# +#if(isTRUE(options('in_test')$in_test)) +# # use test dates +# {initDate="2011-01-01" +# endDate="2012-12-31" +# } else +# # use demo defaults +# {initDate="1999-12-31" +# endDate=Sys.Date()} + +source('luxor.include.R') +source('luxor.getSymbols.R') + +### + +initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD') +addPosLimit( + portfolio=portfolio.st, + symbol='GBPUSD', + timestamp=initDate, + maxpos=.orderqty) + +initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD') + +### + +initOrders(portfolio.st, initDate=initDate) + +load.strategy(strategy.st) + +### BEGIN uncomment lines to activate StopLoss and/or StopTrailing and/or TakeProfit rules + +enable.rule('luxor', 'chain', 'StopLoss') +enable.rule('luxor', 'chain', 'StopTrailing') +enable.rule('luxor', 'chain', 'TakeProfit') + +### END uncomment lines to activate StopLoss and/or StopTrailing and/or TakeProfit rules + +require(foreach) +#registerDoSEQ() + +require(doMC) +registerDoMC(cores=8) + +#require(doParallel) +#registerDoParallel(cores=2) + +#require(doRedis) +#registerDoRedis('jobs') + +############################ + +results <- apply.paramset(strategy.st, paramset.label='TakeProfit', portfolio.st=portfolio.st, account.st=account.st, nsamples=80, verbose=TRUE) + +stats <- results$tradeStats + +print(stats) + +plot(100*stats$TakeProfitLONG, stats$Net.Trading.PL, type='b', xlab='TakeProfit %', ylab='Net.Trading.PL', main='Luxor') + +##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### +# book = getOrderBook(port) +# stats = tradeStats(port) +# rets = PortfReturns(acct) +################################################################ Added: pkg/quantstrat/demo/luxor.7.exit+risk.R =================================================================== --- pkg/quantstrat/demo/luxor.7.exit+risk.R (rev 0) +++ pkg/quantstrat/demo/luxor.7.exit+risk.R 2013-05-07 20:46:47 UTC (rev 1457) @@ -0,0 +1,80 @@ +#!/usr/bin/Rscript --vanilla +# +# Jan Humme (@opentrades) - April 2013 +# +# Tested and found to work correctly using blotter r1420 +# +# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) +# +# Paragraph 3.5: determination of appropriate exit and risk management + +source('luxor.include.R') + +##### PLACE DEMO AND TEST DATES HERE ################# +# +#if(isTRUE(options('in_test')$in_test)) +# # use test dates +# {initDate="2011-01-01" +# endDate="2012-12-31" +# } else +# # use demo defaults +# {initDate="1999-12-31" +# endDate=Sys.Date()} + +source('luxor.getSymbols.R') + +### blotter + +initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD') +initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD') + +### quantstrat + +load.strategy('luxor') + +### BEGIN uncomment lines to activate StopLoss and/or StopTrailing and/or TakeProfit rules + +#enable.rule('luxor', 'chain', 'StopLoss') +#enable.rule('luxor', 'chain', 'StopTrailing') +#enable.rule('luxor', 'chain', 'TakeProfit') + +### END uncomment lines to activate StopLoss and/or StopTrailing and/or TakeProfit rules + +addPosLimit( + portfolio=portfolio.st, + symbol='GBPUSD', + timestamp=initDate, + maxpos=.orderqty) + +initOrders(portfolio.st, initDate=initDate) + +applyStrategy(strategy.st, portfolio.st, prefer='Open') + +View(getOrderBook(portfolio.st)[[portfolio.st]]$GBPUSD) + +############################################################################### + +updatePortf(portfolio.st, Symbols='GBPUSD', Dates=paste('::',as.Date(Sys.time()),sep='')) + +chart.Posn(portfolio.st, "GBPUSD") + +############################################################################### + +View(tradeStats(portfolio.st, 'GBPUSD')) + +############################################################################### + +print(tradeQuantiles('forex', 'GBPUSD')) + +dev.new() + +### Uncomment to choose appropriate MAE of MFE graph + +chart.ME(portfolio.st, 'GBPUSD', scale='percent', type='MAE') +#chart.ME(portfolio.st, 'GBPUSD', scale='percent', type='MFE') + +##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### +# book = getOrderBook(port) +# stats = tradeStats(port) +# rets = PortfReturns(acct) +################################################################ Property changes on: pkg/quantstrat/demo/luxor.7.exit+risk.R ___________________________________________________________________ Added: svn:executable + * Added: pkg/quantstrat/demo/luxor.getSymbols.R =================================================================== --- pkg/quantstrat/demo/luxor.getSymbols.R (rev 0) +++ pkg/quantstrat/demo/luxor.getSymbols.R 2013-05-07 20:46:47 UTC (rev 1457) @@ -0,0 +1,42 @@ +#!/usr/bin/Rscript --vanilla +# +# Jan Humme (@opentrades) - August 2012, revised April 2013 +# +# Tested and found to work correctly using blotter r1420 +# +# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) +# +# Paragraph 3.2: luxor with $30 slippage and transaction costs + +Sys.setenv(TZ="UTC") + +### packages +# +# quantstrat package will pull in some other packages: +# FinancialInstrument, quantmod, blotter, xts + +require(quantstrat) + +### FinancialInstrument + +currency(c('GBP', 'USD')) + +exchange_rate('GBPUSD', tick_size=0.0001) + +### quantmod + +getSymbols.FI(Symbols='GBPUSD', +# dir=system.file('extdata',package='quantstrat'), + dir='~/R/OHLC', + from=.from, to=.to +) + +# ALTERNATIVE WAY TO FETCH SYMBOL DATA +#setSymbolLookup.FI(system.file('extdata',package='quantstrat'), 'GBPUSD') +#getSymbols('GBPUSD', from=.from, to=.to, verbose=FALSE) + +### xts + +GBPUSD = to.minutes30(GBPUSD) +GBPUSD = align.time(to.minutes30(GBPUSD), 1800) + Added: pkg/quantstrat/demo/luxor.include.R =================================================================== --- pkg/quantstrat/demo/luxor.include.R (rev 0) +++ pkg/quantstrat/demo/luxor.include.R 2013-05-07 20:46:47 UTC (rev 1457) @@ -0,0 +1,60 @@ +### + +options(width = 240) +Sys.setenv(TZ="UTC") + +### + +initDate = '2002-10-21' + +.from=initDate + +.to='2008-07-04' +#.to='2002-12-31' +.to='2002-10-31' + +### + +strategy.st = 'luxor' +portfolio.st = 'forex' +account.st = 'IB1' + +### + +.orderqty = 100000 +.threshold = 0.0005 +.txnfees = -6 # round-trip fee + +### Distributions for paramset analysis + +.nsamples=80 + +.FastSMA = (1:20) +.SlowSMA = (30:80) + +.StopLoss = seq(0.02, 0.48, length.out=24)/100 +.StopTrailing = seq(0.05, 0.4, length.out=8)/100 +.TakeProfit = seq(0.1, 1.0, length.out=10)/100 + +# generate 24x24h ISO8601 timespan vector + +.timespans.start<-paste(sprintf("T%02d",0:23),':00',sep='') +.timespans.stop<-paste(sprintf("T%02d",0:23),':59',sep='') + +.timespans<-outer(.timespans.start, .timespans.stop, FUN=paste, sep='/') + +# in order to run the full 24x24 hour scan above, comment out the following line: +.timespans<-c('T06:00/T10:00', 'T07:00/T11:00', 'T08:00/T12:00', 'T09:00/T13:00', 'T10:00/T14:00', 'T11:00/T15:00', 'T12:00/T16:00') + +### Actual arameters + +.fast = 6 +.slow = 44 + +#.timespan = 'T08:00/T12:00' +.timespan = 'T00:00/T23:59' + +.stoploss <- 0.0025 +.stoptrailing <- 0.008 +.takeprofit <- 0.019 + Added: pkg/quantstrat/demo/luxor.sample.MAE.stoploss.R =================================================================== --- pkg/quantstrat/demo/luxor.sample.MAE.stoploss.R (rev 0) +++ pkg/quantstrat/demo/luxor.sample.MAE.stoploss.R 2013-05-07 20:46:47 UTC (rev 1457) @@ -0,0 +1,40 @@ +#!/usr/bin/Rscript --vanilla +# +# Jan Humme (@opentrades) - August 2012 +# +# Tested and found to work correctly using blotter r1143 +# +# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) +# +# Figure 3.11: MAE graph of Luxor system + +require('blotter') + +data('luxor-p066', package='quantstrat', envir=.blotter) + +currency(c('GBP', 'USD')) +exchange_rate(c('GBPUSD'), tick_size=0.0001) + +chart.ME( + Portfolio='luxor', + Symbol='GBPUSD', + type='MAE', + scale='cash' +) + +##### PLACE DEMO AND TEST DATES HERE ################# +# +#if(isTRUE(options('in_test')$in_test)) +# # use test dates +# {initDate="2011-01-01" +# endDate="2012-12-31" +# } else +# # use demo defaults +# {initDate="1999-12-31" +# endDate=Sys.Date()} + +##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### +# book = getOrderBook(port) +# stats = tradeStats(port) +# rets = PortfReturns(acct) +################################################################ Added: pkg/quantstrat/demo/luxor.sample.MAE.stoptrailing.R =================================================================== [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/blotter -r 1457 From noreply at r-forge.r-project.org Tue May 7 23:07:08 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 7 May 2013 23:07:08 +0200 (CEST) Subject: [Blotter-commits] r1458 - pkg/quantstrat/demo Message-ID: <20130507210708.1AAAB183B50@r-forge.r-project.org> Author: opentrades Date: 2013-05-07 23:07:07 +0200 (Tue, 07 May 2013) New Revision: 1458 Modified: pkg/quantstrat/demo/luxor.1.strategy.basic.R pkg/quantstrat/demo/luxor.2.add.paramsets.R pkg/quantstrat/demo/luxor.3.paramset.sma.R pkg/quantstrat/demo/luxor.4.paramset.timespan.R pkg/quantstrat/demo/luxor.5.strategy.ordersets.R 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.7.exit+risk.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 Log: - updated luxor demo headers Modified: pkg/quantstrat/demo/luxor.1.strategy.basic.R =================================================================== --- pkg/quantstrat/demo/luxor.1.strategy.basic.R 2013-05-07 20:46:47 UTC (rev 1457) +++ pkg/quantstrat/demo/luxor.1.strategy.basic.R 2013-05-07 21:07:07 UTC (rev 1458) @@ -2,11 +2,11 @@ # # Jan Humme (@opentrades) - August 2012, revised April 2013 # -# Tested and found to work correctly using blotter r1420 +# Tested and found to work correctly using blotter r1457 # -# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) +# After Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) # -# Paragraph 3.2: luxor with $30 slippage and transaction costs +# Paragraph 3.2: luxor with slippage and transaction costs ##### PLACE DEMO AND TEST DATES HERE ################# # Modified: pkg/quantstrat/demo/luxor.2.add.paramsets.R =================================================================== --- pkg/quantstrat/demo/luxor.2.add.paramsets.R 2013-05-07 20:46:47 UTC (rev 1457) +++ pkg/quantstrat/demo/luxor.2.add.paramsets.R 2013-05-07 21:07:07 UTC (rev 1458) @@ -2,7 +2,9 @@ # # Jan Humme (@opentrades) - August 2012, revised April 2013 # -# Tested and found to work correctly using blotter r1420 +# Tested and found to work correctly using blotter r1457 +# +# After Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) require(quantstrat) Modified: pkg/quantstrat/demo/luxor.3.paramset.sma.R =================================================================== --- pkg/quantstrat/demo/luxor.3.paramset.sma.R 2013-05-07 20:46:47 UTC (rev 1457) +++ pkg/quantstrat/demo/luxor.3.paramset.sma.R 2013-05-07 21:07:07 UTC (rev 1458) @@ -2,11 +2,11 @@ # # Jan Humme (@opentrades) - August 2012, revised April 2013 # -# Tested and found to work correctly using blotter r1420 +# Tested and found to work correctly using blotter r1457 # -# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) +# After Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) # -# Paragraph 3.2: luxor with $30 slippage and transaction costs +# Paragraph 3.3: luxor SMA paramset optimization ### Modified: pkg/quantstrat/demo/luxor.4.paramset.timespan.R =================================================================== --- pkg/quantstrat/demo/luxor.4.paramset.timespan.R 2013-05-07 20:46:47 UTC (rev 1457) +++ pkg/quantstrat/demo/luxor.4.paramset.timespan.R 2013-05-07 21:07:07 UTC (rev 1458) @@ -2,9 +2,11 @@ # # Jan Humme (@opentrades) - August 2012, revised April 2013 # -# Tested and found to work correctly using blotter r1420 +# Tested and found to work correctly using blotter r1457 # -# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) +# After Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) +# +# Paragraph 3.4: luxor timespan paramset optimization stop('#### DEMO BROKEN - BEING FIXED ###') Modified: pkg/quantstrat/demo/luxor.5.strategy.ordersets.R =================================================================== --- pkg/quantstrat/demo/luxor.5.strategy.ordersets.R 2013-05-07 20:46:47 UTC (rev 1457) +++ pkg/quantstrat/demo/luxor.5.strategy.ordersets.R 2013-05-07 21:07:07 UTC (rev 1458) @@ -2,7 +2,7 @@ # # Jan Humme (@opentrades) - May 2013 # -# Tested and found to work correctly using blotter r1448 +# Tested and found to work correctly using blotter r1457 # # After Jaekle & Tomasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) # Modified: pkg/quantstrat/demo/luxor.6.paramset.stoploss.R =================================================================== --- pkg/quantstrat/demo/luxor.6.paramset.stoploss.R 2013-05-07 20:46:47 UTC (rev 1457) +++ pkg/quantstrat/demo/luxor.6.paramset.stoploss.R 2013-05-07 21:07:07 UTC (rev 1458) @@ -2,9 +2,9 @@ # # Jan Humme (@opentrades) - August 2012 # -# Tested and found to work correctly using blotter r1230 +# Tested and found to work correctly using blotter r1457 # -# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) +# After Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) # # compute StopLoss percentage for various paramsets Modified: pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R =================================================================== --- pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R 2013-05-07 20:46:47 UTC (rev 1457) +++ pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R 2013-05-07 21:07:07 UTC (rev 1458) @@ -2,9 +2,9 @@ # # Jan Humme (@opentrades) - August 2012 # -# Tested and found to work correctly using blotter r1230 +# Tested and found to work correctly using blotter r1457 # -# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) +# After Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) # # compute StopTrailing percentage for various paramsets Modified: pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R =================================================================== --- pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R 2013-05-07 20:46:47 UTC (rev 1457) +++ pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R 2013-05-07 21:07:07 UTC (rev 1458) @@ -2,9 +2,9 @@ # # Jan Humme (@opentrades) - August 2012 # -# Tested and found to work correctly using blotter r1230 +# Tested and found to work correctly using blotter r1457 # -# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) +# After Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) # # compute TakeProfit percentage for various paramsets Modified: pkg/quantstrat/demo/luxor.7.exit+risk.R =================================================================== --- pkg/quantstrat/demo/luxor.7.exit+risk.R 2013-05-07 20:46:47 UTC (rev 1457) +++ pkg/quantstrat/demo/luxor.7.exit+risk.R 2013-05-07 21:07:07 UTC (rev 1458) @@ -2,9 +2,9 @@ # # Jan Humme (@opentrades) - April 2013 # -# Tested and found to work correctly using blotter r1420 +# Tested and found to work correctly using blotter r1457 # -# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) +# After Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) # # Paragraph 3.5: determination of appropriate exit and risk management Modified: pkg/quantstrat/demo/luxor.getSymbols.R =================================================================== --- pkg/quantstrat/demo/luxor.getSymbols.R 2013-05-07 20:46:47 UTC (rev 1457) +++ pkg/quantstrat/demo/luxor.getSymbols.R 2013-05-07 21:07:07 UTC (rev 1458) @@ -2,11 +2,11 @@ # # Jan Humme (@opentrades) - August 2012, revised April 2013 # -# Tested and found to work correctly using blotter r1420 +# Tested and found to work correctly using blotter r1457 # -# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) +# After Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) # -# Paragraph 3.2: luxor with $30 slippage and transaction costs +# loading symbol data Sys.setenv(TZ="UTC") Modified: pkg/quantstrat/demo/luxor.sample.MAE.stoploss.R =================================================================== --- pkg/quantstrat/demo/luxor.sample.MAE.stoploss.R 2013-05-07 20:46:47 UTC (rev 1457) +++ pkg/quantstrat/demo/luxor.sample.MAE.stoploss.R 2013-05-07 21:07:07 UTC (rev 1458) @@ -2,9 +2,9 @@ # # Jan Humme (@opentrades) - August 2012 # -# Tested and found to work correctly using blotter r1143 +# Tested and found to work correctly using blotter r1457 # -# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) +# After Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) # # Figure 3.11: MAE graph of Luxor system Modified: pkg/quantstrat/demo/luxor.sample.MAE.stoptrailing.R =================================================================== --- pkg/quantstrat/demo/luxor.sample.MAE.stoptrailing.R 2013-05-07 20:46:47 UTC (rev 1457) +++ pkg/quantstrat/demo/luxor.sample.MAE.stoptrailing.R 2013-05-07 21:07:07 UTC (rev 1458) @@ -2,9 +2,9 @@ # # Jan Humme (@opentrades) - August 2012 # -# Tested and found to work correctly using blotter r1143 +# Tested and found to work correctly using blotter r1457 # -# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) +# After Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) # # Figure 3.12: MAE graph in percentage terms Modified: pkg/quantstrat/demo/luxor.sample.MFE.takeprofit.R =================================================================== --- pkg/quantstrat/demo/luxor.sample.MFE.takeprofit.R 2013-05-07 20:46:47 UTC (rev 1457) +++ pkg/quantstrat/demo/luxor.sample.MFE.takeprofit.R 2013-05-07 21:07:07 UTC (rev 1458) @@ -2,9 +2,9 @@ # # Jan Humme (@opentrades) - August 2012 # -# Tested and found to work correctly using blotter r1143 +# Tested and found to work correctly using blotter r1457 # -# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) +# After Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) # # Figure 3.16: MFE graph in percentage terms Modified: pkg/quantstrat/demo/luxor.sample.tradeGraphs.sma.R =================================================================== --- pkg/quantstrat/demo/luxor.sample.tradeGraphs.sma.R 2013-05-07 20:46:47 UTC (rev 1457) +++ pkg/quantstrat/demo/luxor.sample.tradeGraphs.sma.R 2013-05-07 21:07:07 UTC (rev 1458) @@ -2,9 +2,11 @@ # # Jan Humme (@opentrades) - August 2012, revised April 2013 # -# Tested and found to work correctly using blotter r1420 +# Tested and found to work correctly using blotter r1457 # -# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) +# After Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) +# +# 3D SMA graph example require(quantstrat) Modified: pkg/quantstrat/demo/luxor.sample.tradeGraphs.timespan.R =================================================================== --- pkg/quantstrat/demo/luxor.sample.tradeGraphs.timespan.R 2013-05-07 20:46:47 UTC (rev 1457) +++ pkg/quantstrat/demo/luxor.sample.tradeGraphs.timespan.R 2013-05-07 21:07:07 UTC (rev 1458) @@ -1,4 +1,12 @@ #!/usr/bin/Rscript --vanilla +# +# Jan Humme (@opentrades) - August 2012, revised April 2013 +# +# Tested and found to work correctly using blotter r1457 +# +# After Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) +# +# 3D timespan graph example require(quantstrat) From noreply at r-forge.r-project.org Tue May 7 23:27:03 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 7 May 2013 23:27:03 +0200 (CEST) Subject: [Blotter-commits] r1459 - pkg/quantstrat/demo Message-ID: <20130507212703.ADD391855D0@r-forge.r-project.org> Author: opentrades Date: 2013-05-07 23:27:03 +0200 (Tue, 07 May 2013) New Revision: 1459 Modified: pkg/quantstrat/demo/luxor.getSymbols.R Log: - corrected default data dir Modified: pkg/quantstrat/demo/luxor.getSymbols.R =================================================================== --- pkg/quantstrat/demo/luxor.getSymbols.R 2013-05-07 21:07:07 UTC (rev 1458) +++ pkg/quantstrat/demo/luxor.getSymbols.R 2013-05-07 21:27:03 UTC (rev 1459) @@ -26,8 +26,8 @@ ### quantmod getSymbols.FI(Symbols='GBPUSD', -# dir=system.file('extdata',package='quantstrat'), - dir='~/R/OHLC', + dir=system.file('extdata',package='quantstrat'), +# dir='~/R/OHLC', from=.from, to=.to ) From noreply at r-forge.r-project.org Wed May 8 00:07:51 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 8 May 2013 00:07:51 +0200 (CEST) Subject: [Blotter-commits] r1460 - pkg/quantstrat/demo Message-ID: <20130507220751.AD549185347@r-forge.r-project.org> Author: opentrades Date: 2013-05-08 00:07:51 +0200 (Wed, 08 May 2013) New Revision: 1460 Modified: pkg/quantstrat/demo/luxor.1.strategy.basic.R 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.7.exit+risk.R pkg/quantstrat/demo/luxor.getSymbols.R pkg/quantstrat/demo/luxor.include.R Log: - prettified tradeStats() using View(t(tradeStats(...))) Modified: pkg/quantstrat/demo/luxor.1.strategy.basic.R =================================================================== --- pkg/quantstrat/demo/luxor.1.strategy.basic.R 2013-05-07 21:27:03 UTC (rev 1459) +++ pkg/quantstrat/demo/luxor.1.strategy.basic.R 2013-05-07 22:07:51 UTC (rev 1460) @@ -136,7 +136,7 @@ ############################################################################### -View(tradeStats(portfolio.st, 'GBPUSD')) +View(t(tradeStats(portfolio.st, 'GBPUSD'))) ############################################################################### Modified: pkg/quantstrat/demo/luxor.6.paramset.stoploss.R =================================================================== --- pkg/quantstrat/demo/luxor.6.paramset.stoploss.R 2013-05-07 21:27:03 UTC (rev 1459) +++ pkg/quantstrat/demo/luxor.6.paramset.stoploss.R 2013-05-07 22:07:51 UTC (rev 1460) @@ -67,7 +67,7 @@ stats <- results$tradeStats -print(stats) +View(t(stats)) plot(100*stats$StopLossLONG, stats$Net.Trading.PL, type='b', xlab='Stoploss %', ylab='Net.Trading.PL', main='Luxor') Modified: pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R =================================================================== --- pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R 2013-05-07 21:27:03 UTC (rev 1459) +++ pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R 2013-05-07 22:07:51 UTC (rev 1460) @@ -67,7 +67,7 @@ stats <- results$tradeStats -print(stats) +View(t(stats)) plot(100*stats$StopTrailingLONG, stats$Net.Trading.PL, type='b', xlab='StopTrailing %', ylab='Net.Trading.PL', main='Luxor') Modified: pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R =================================================================== --- pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R 2013-05-07 21:27:03 UTC (rev 1459) +++ pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R 2013-05-07 22:07:51 UTC (rev 1460) @@ -67,7 +67,7 @@ stats <- results$tradeStats -print(stats) +View(t(stats)) plot(100*stats$TakeProfitLONG, stats$Net.Trading.PL, type='b', xlab='TakeProfit %', ylab='Net.Trading.PL', main='Luxor') Modified: pkg/quantstrat/demo/luxor.7.exit+risk.R =================================================================== --- pkg/quantstrat/demo/luxor.7.exit+risk.R 2013-05-07 21:27:03 UTC (rev 1459) +++ pkg/quantstrat/demo/luxor.7.exit+risk.R 2013-05-07 22:07:51 UTC (rev 1460) @@ -34,9 +34,9 @@ ### BEGIN uncomment lines to activate StopLoss and/or StopTrailing and/or TakeProfit rules -#enable.rule('luxor', 'chain', 'StopLoss') -#enable.rule('luxor', 'chain', 'StopTrailing') -#enable.rule('luxor', 'chain', 'TakeProfit') +enable.rule('luxor', 'chain', 'StopLoss') +enable.rule('luxor', 'chain', 'StopTrailing') +enable.rule('luxor', 'chain', 'TakeProfit') ### END uncomment lines to activate StopLoss and/or StopTrailing and/or TakeProfit rules @@ -60,7 +60,7 @@ ############################################################################### -View(tradeStats(portfolio.st, 'GBPUSD')) +View(t(tradeStats(portfolio.st, 'GBPUSD'))) ############################################################################### @@ -71,7 +71,8 @@ ### Uncomment to choose appropriate MAE of MFE graph chart.ME(portfolio.st, 'GBPUSD', scale='percent', type='MAE') -#chart.ME(portfolio.st, 'GBPUSD', scale='percent', type='MFE') +dev.new() +chart.ME(portfolio.st, 'GBPUSD', scale='percent', type='MFE') ##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### # book = getOrderBook(port) Modified: pkg/quantstrat/demo/luxor.getSymbols.R =================================================================== --- pkg/quantstrat/demo/luxor.getSymbols.R 2013-05-07 21:27:03 UTC (rev 1459) +++ pkg/quantstrat/demo/luxor.getSymbols.R 2013-05-07 22:07:51 UTC (rev 1460) @@ -26,8 +26,8 @@ ### quantmod getSymbols.FI(Symbols='GBPUSD', - dir=system.file('extdata',package='quantstrat'), -# dir='~/R/OHLC', +# dir=system.file('extdata',package='quantstrat'), + dir='~/R/OHLC', from=.from, to=.to ) Modified: pkg/quantstrat/demo/luxor.include.R =================================================================== --- pkg/quantstrat/demo/luxor.include.R 2013-05-07 21:27:03 UTC (rev 1459) +++ pkg/quantstrat/demo/luxor.include.R 2013-05-07 22:07:51 UTC (rev 1460) @@ -11,7 +11,7 @@ .to='2008-07-04' #.to='2002-12-31' -.to='2002-10-31' +#.to='2002-10-31' ### From noreply at r-forge.r-project.org Wed May 8 00:09:11 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 8 May 2013 00:09:11 +0200 (CEST) Subject: [Blotter-commits] r1461 - pkg/quantstrat/demo Message-ID: <20130507220911.EAD64180803@r-forge.r-project.org> Author: opentrades Date: 2013-05-08 00:09:11 +0200 (Wed, 08 May 2013) New Revision: 1461 Modified: pkg/quantstrat/demo/luxor.getSymbols.R pkg/quantstrat/demo/luxor.include.R Log: - reset data dir and range to defaults Modified: pkg/quantstrat/demo/luxor.getSymbols.R =================================================================== --- pkg/quantstrat/demo/luxor.getSymbols.R 2013-05-07 22:07:51 UTC (rev 1460) +++ pkg/quantstrat/demo/luxor.getSymbols.R 2013-05-07 22:09:11 UTC (rev 1461) @@ -26,8 +26,8 @@ ### quantmod getSymbols.FI(Symbols='GBPUSD', -# dir=system.file('extdata',package='quantstrat'), - dir='~/R/OHLC', + dir=system.file('extdata',package='quantstrat'), +# dir='~/R/OHLC', from=.from, to=.to ) Modified: pkg/quantstrat/demo/luxor.include.R =================================================================== --- pkg/quantstrat/demo/luxor.include.R 2013-05-07 22:07:51 UTC (rev 1460) +++ pkg/quantstrat/demo/luxor.include.R 2013-05-07 22:09:11 UTC (rev 1461) @@ -10,8 +10,7 @@ .from=initDate .to='2008-07-04' -#.to='2002-12-31' -#.to='2002-10-31' +.to='2002-10-31' ### From noreply at r-forge.r-project.org Wed May 8 17:02:00 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 8 May 2013 17:02:00 +0200 (CEST) Subject: [Blotter-commits] r1462 - in pkg/FinancialInstrument: . R Message-ID: <20130508150200.B5E1C184C93@r-forge.r-project.org> Author: gsee Date: 2013-05-08 17:02:00 +0200 (Wed, 08 May 2013) New Revision: 1462 Modified: pkg/FinancialInstrument/DESCRIPTION pkg/FinancialInstrument/R/update_instruments.morningstar.R Log: patches for changes in package:XML Modified: pkg/FinancialInstrument/DESCRIPTION =================================================================== --- pkg/FinancialInstrument/DESCRIPTION 2013-05-07 22:09:11 UTC (rev 1461) +++ pkg/FinancialInstrument/DESCRIPTION 2013-05-08 15:02:00 UTC (rev 1462) @@ -9,7 +9,7 @@ Contributors: Dirk Eddelbuettel, Alexis Petit, Jeffrey Ryan, Joshua Ulrich Description: Infrastructure for defining meta-data and relationships for financial instruments. -Version: 1.1.7 +Version: 1.1.8 URL: https://r-forge.r-project.org/projects/blotter/ Date: 2013-03-03 Depends: @@ -19,7 +19,7 @@ zoo(>= 1.7-5) Suggests: foreach, - XML, + XML (>= 3.96.1.1), testthat Collate: 'buildHierarchy.R' Modified: pkg/FinancialInstrument/R/update_instruments.morningstar.R =================================================================== --- pkg/FinancialInstrument/R/update_instruments.morningstar.R 2013-05-07 22:09:11 UTC (rev 1461) +++ pkg/FinancialInstrument/R/update_instruments.morningstar.R 2013-05-08 15:02:00 UTC (rev 1462) @@ -28,9 +28,9 @@ x <- readHTMLTable(paste("http://news.morningstar.com/etf/Lists/ETFReturn", "s.html?topNum=All&lastRecNum=1000&curField=8&ca", "tegory=0", sep=""), stringsAsFactors=FALSE) - x <- x[[which.max(sapply(x, nrow))]] - colnames(x) <- x[2, ] - x <- x[-c(1:3), -1] + x <- x[[which.max(sapply(x, NROW))]] + colnames(x) <- x[1, ] + x <- x[-c(1:2), -1] x <- x[!is.na(x[, 1]), ] x <- x[!duplicated(x[, 1]), ] tickers <- gsub(".*\\(|*\\)", "", x[,1]) From noreply at r-forge.r-project.org Wed May 8 19:11:48 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 8 May 2013 19:11:48 +0200 (CEST) Subject: [Blotter-commits] r1463 - pkg/quantstrat/man Message-ID: <20130508171148.CAFBE1813CA@r-forge.r-project.org> Author: opentrades Date: 2013-05-08 19:11:48 +0200 (Wed, 08 May 2013) New Revision: 1463 Modified: pkg/quantstrat/man/delete.paramset.Rd Log: - fixed typo Modified: pkg/quantstrat/man/delete.paramset.Rd =================================================================== --- pkg/quantstrat/man/delete.paramset.Rd 2013-05-08 15:02:00 UTC (rev 1462) +++ pkg/quantstrat/man/delete.paramset.Rd 2013-05-08 17:11:48 UTC (rev 1463) @@ -21,8 +21,8 @@ Jan Humme } \seealso{ + \code{\link{add.distibution}}, \code{\link{add.constraint}}, - \code{\link{add.constraint}}, \code{\link{apply.paramset}} } From noreply at r-forge.r-project.org Wed May 8 22:43:14 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 8 May 2013 22:43:14 +0200 (CEST) Subject: [Blotter-commits] r1464 - in pkg/quantstrat: R data demo Message-ID: <20130508204314.D4D631854C6@r-forge.r-project.org> Author: opentrades Date: 2013-05-08 22:43:14 +0200 (Wed, 08 May 2013) New Revision: 1464 Added: pkg/quantstrat/data/luxor.wfa.ples.GBPUSD.2003-01-02 05:30:00.2003-03-31 23:30:00.RData pkg/quantstrat/demo/luxor.sample.walk.forward.R Modified: pkg/quantstrat/R/chart.forward.testing.R pkg/quantstrat/R/chart.forward.training.R pkg/quantstrat/R/paramsets.R pkg/quantstrat/demo/luxor.5.strategy.ordersets.R pkg/quantstrat/demo/luxor.7.exit+risk.R pkg/quantstrat/demo/luxor.include.R Log: - addde WFA paramset to luxor.5 strategy - added luxor WFA (Walk Forward Analysis) demo - fixed some small issues with walk forward implementation - added sample walk forward chart demo Modified: pkg/quantstrat/R/chart.forward.testing.R =================================================================== --- pkg/quantstrat/R/chart.forward.testing.R 2013-05-08 17:11:48 UTC (rev 1463) +++ pkg/quantstrat/R/chart.forward.testing.R 2013-05-08 20:43:14 UTC (rev 1464) @@ -22,20 +22,24 @@ { p <- getPortfolio(portfolio.st, envir=.audit) - R <- cumsum(p$summary['2004-01-01/','Net.Trading.PL']) + from <- index(p$summary[2]) + + #R <- cumsum(p$summary['2004-01-01/','Net.Trading.PL']) + R <- cumsum(p$summary[paste(from, '/', sep=''),'Net.Trading.PL']) names(R) <- portfolio.st PL.xts <- cbind(PL.xts, R) } # add a column for the chosen portfolio, doubling it - #chosen.one <- .audit$param.combo.nr - #chosen.portfolio.st = ls(name=.audit, pattern=glob2rx(paste('portfolio', '*', chosen.one, sep='.'))) - testing.portfolio.st = 'portfolio.futures' + chosen.one <- .audit$param.combo.nr + testing.portfolio.st <- ls(env=.audit, pattern=glob2rx(paste('portfolio', '*', chosen.one, sep='.'))) R <- PL.xts[,testing.portfolio.st] PL.xts <- cbind(PL.xts, R) + PL.xts <- na.locf(PL.xts) + # add drawdown columns for all portfolio columns CumMax <- cummax(PL.xts) Drawdowns.xts <- -(CumMax - PL.xts) Modified: pkg/quantstrat/R/chart.forward.training.R =================================================================== --- pkg/quantstrat/R/chart.forward.training.R 2013-05-08 17:11:48 UTC (rev 1463) +++ pkg/quantstrat/R/chart.forward.training.R 2013-05-08 20:43:14 UTC (rev 1464) @@ -21,8 +21,11 @@ for(portfolio.st in portfolios.st) { p <- getPortfolio(portfolio.st, envir=.audit) - - R <- cumsum(p$summary['2004-01-01/','Net.Trading.PL']) + + from <- index(p$summary[2]) + + #R <- cumsum(p$summary['2004-01-01/','Net.Trading.PL']) + R <- cumsum(p$summary[paste(from, '/', sep=''),'Net.Trading.PL']) names(R) <- portfolio.st PL.xts <- cbind(PL.xts, R) @@ -31,9 +34,12 @@ # add a column for the chosen portfolio, doubling it chosen.one <- .audit$param.combo.nr chosen.portfolio.st = ls(name=.audit, pattern=glob2rx(paste('portfolio', '*', chosen.one, sep='.'))) + R <- PL.xts[,chosen.portfolio.st] PL.xts <- cbind(PL.xts, R) + PL.xts <- na.locf(PL.xts) + # add drawdown columns for all portfolio columns CumMax <- cummax(PL.xts) Drawdowns.xts <- -(CumMax - PL.xts) Modified: pkg/quantstrat/R/paramsets.R =================================================================== --- pkg/quantstrat/R/paramsets.R 2013-05-08 17:11:48 UTC (rev 1463) +++ pkg/quantstrat/R/paramsets.R 2013-05-08 20:43:14 UTC (rev 1464) @@ -216,7 +216,7 @@ #' #' @author Jan Humme #' @export -#' @seealso \code{\link{add.constraint}}, \code{\link{add.constraint}}, \code{\link{apply.paramset}} +#' @seealso \code{\link{add.distibution}}, \code{\link{add.constraint}}, \code{\link{apply.paramset}} delete.paramset <- function(strategy, paramset.label, store=TRUE) { Added: pkg/quantstrat/data/luxor.wfa.ples.GBPUSD.2003-01-02 05:30:00.2003-03-31 23:30:00.RData =================================================================== (Binary files differ) Property changes on: pkg/quantstrat/data/luxor.wfa.ples.GBPUSD.2003-01-02 05:30:00.2003-03-31 23:30:00.RData ___________________________________________________________________ Added: svn:mime-type + application/x-gzip Modified: pkg/quantstrat/demo/luxor.5.strategy.ordersets.R =================================================================== --- pkg/quantstrat/demo/luxor.5.strategy.ordersets.R 2013-05-08 17:11:48 UTC (rev 1463) +++ pkg/quantstrat/demo/luxor.5.strategy.ordersets.R 2013-05-08 20:43:14 UTC (rev 1464) @@ -131,8 +131,34 @@ label='EnterSHORT' ) -### stoploss, stoptrailing and takeprofit +### parameter sets +# SMA + +add.distribution(strategy.st, + paramset.label = 'SMA', + component.type = 'indicator', + component.label = 'nFast', + variable = list(n = .FastSMA), + label = 'nFAST' +) + +add.distribution(strategy.st, + paramset.label = 'SMA', + component.type = 'indicator', + component.label = 'nSlow', + variable = list(n = .SlowSMA), + label = 'nSLOW' +) + +add.constraint(strategy.st, + paramset.label = 'SMA', + distribution.label.1 = 'nFAST', + distribution.label.2 = 'nSLOW', + operator = '<', + label = 'SMA' +) + # stop-loss add.rule(strategy.st, name = 'ruleSignal', @@ -295,6 +321,32 @@ label = 'TakeProfit' ) +# Walk Forward Analysis + +add.distribution(strategy.st, + paramset.label = 'WFA', + component.type = 'indicator', + component.label = 'nFast', + variable = list(n = .FastWFA), + label = 'nFAST' +) + +add.distribution(strategy.st, + paramset.label = 'WFA', + component.type = 'indicator', + component.label = 'nSlow', + variable = list(n = .SlowWFA), + label = 'nSLOW' +) + +add.constraint(strategy.st, + paramset.label = 'WFA', + distribution.label.1 = 'nFAST', + distribution.label.2 = 'nSLOW', + operator = '<', + label = 'WFA' +) + ############################################################################### save.strategy(strategy.st) Modified: pkg/quantstrat/demo/luxor.7.exit+risk.R =================================================================== --- pkg/quantstrat/demo/luxor.7.exit+risk.R 2013-05-08 17:11:48 UTC (rev 1463) +++ pkg/quantstrat/demo/luxor.7.exit+risk.R 2013-05-08 20:43:14 UTC (rev 1464) @@ -35,8 +35,8 @@ ### BEGIN uncomment lines to activate StopLoss and/or StopTrailing and/or TakeProfit rules enable.rule('luxor', 'chain', 'StopLoss') -enable.rule('luxor', 'chain', 'StopTrailing') -enable.rule('luxor', 'chain', 'TakeProfit') +#enable.rule('luxor', 'chain', 'StopTrailing') +#enable.rule('luxor', 'chain', 'TakeProfit') ### END uncomment lines to activate StopLoss and/or StopTrailing and/or TakeProfit rules Modified: pkg/quantstrat/demo/luxor.include.R =================================================================== --- pkg/quantstrat/demo/luxor.include.R 2013-05-08 17:11:48 UTC (rev 1463) +++ pkg/quantstrat/demo/luxor.include.R 2013-05-08 20:43:14 UTC (rev 1464) @@ -1,16 +1,20 @@ ### options(width = 240) +#options(warn=1) + Sys.setenv(TZ="UTC") ### initDate = '2002-10-21' +#initDate = '2003-01-01' .from=initDate -.to='2008-07-04' +#.to='2008-07-04' .to='2002-10-31' +#.to='2003-07-31' ### @@ -31,10 +35,15 @@ .FastSMA = (1:20) .SlowSMA = (30:80) -.StopLoss = seq(0.02, 0.48, length.out=24)/100 +#.StopLoss = seq(0.02, 0.48, length.out=24)/100 +#.StopLoss = seq(0.01, 0.24, length.out=24)/100 +.StopLoss = seq(0.002, 0.048, length.out=24)/100 .StopTrailing = seq(0.05, 0.4, length.out=8)/100 .TakeProfit = seq(0.1, 1.0, length.out=10)/100 +.FastWFA = c(1, 3, 5, 7, 9) +.SlowWFA = c(42, 44, 46) + # generate 24x24h ISO8601 timespan vector .timespans.start<-paste(sprintf("T%02d",0:23),':00',sep='') Added: pkg/quantstrat/demo/luxor.sample.walk.forward.R =================================================================== --- pkg/quantstrat/demo/luxor.sample.walk.forward.R (rev 0) +++ pkg/quantstrat/demo/luxor.sample.walk.forward.R 2013-05-08 20:43:14 UTC (rev 1464) @@ -0,0 +1,30 @@ +#!/usr/bin/Rscript --vanilla +# +# Jan Humme (@opentrades) - August 2012 +# +# Tested and found to work correctly using blotter r1457 +# +# After Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) +# +# Walk forward chart sample + +require('quantstrat') + +chart.forward.testing('../data/luxor.wfa.ples.GBPUSD.2003-01-02 05:30:00.2003-03-31 23:30:00.RData') + +##### PLACE DEMO AND TEST DATES HERE ################# +# +#if(isTRUE(options('in_test')$in_test)) +# # use test dates +# {initDate="2011-01-01" +# endDate="2012-12-31" +# } else +# # use demo defaults +# {initDate="1999-12-31" +# endDate=Sys.Date()} + +##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### +# book = getOrderBook(port) +# stats = tradeStats(port) +# rets = PortfReturns(acct) +################################################################ From noreply at r-forge.r-project.org Fri May 10 15:51:22 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 10 May 2013 15:51:22 +0200 (CEST) Subject: [Blotter-commits] r1465 - pkg/quantstrat/R Message-ID: <20130510135122.AF1C7185162@r-forge.r-project.org> Author: opentrades Date: 2013-05-10 15:51:22 +0200 (Fri, 10 May 2013) New Revision: 1465 Modified: pkg/quantstrat/R/ruleOrderProc.R Log: - ohlc stoplimit orders can no longer transact on price out of bar; now limited to Hi() or Lo() of bar Modified: pkg/quantstrat/R/ruleOrderProc.R =================================================================== --- pkg/quantstrat/R/ruleOrderProc.R 2013-05-08 20:43:14 UTC (rev 1464) +++ pkg/quantstrat/R/ruleOrderProc.R 2013-05-10 13:51:22 UTC (rev 1465) @@ -165,7 +165,7 @@ if( (has.Lo(mktdata) && orderPrice > as.numeric(Lo(mktdataTimestamp))) || (!has.Lo(mktdata) && orderPrice > as.numeric(getPrice(mktdataTimestamp, prefer=prefer)))) { - txnprice = orderPrice + txnprice = min(orderPrice, Hi(mktdataTimestamp)) txntime = timestamp } else next() # price did not move through my order, should go to next order } else if((orderQty < 0 && orderType != 'stoplimit') || (orderQty > 0 && (orderType=='stoplimit'))) { @@ -173,7 +173,7 @@ if ( (has.Hi(mktdata) && orderPrice < as.numeric(Hi(mktdataTimestamp))) || (!has.Hi(mktdata) && orderPrice < as.numeric(getPrice(mktdataTimestamp,prefer=prefer))) ) { - txnprice = orderPrice + txnprice = max(orderPrice, Lo(mktdataTimestamp)) txntime = timestamp } else next() # price did not move through my order, should go to next order } else { From noreply at r-forge.r-project.org Fri May 10 16:40:03 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 10 May 2013 16:40:03 +0200 (CEST) Subject: [Blotter-commits] r1466 - in pkg/quantstrat: R demo man Message-ID: <20130510144003.7AC4718486D@r-forge.r-project.org> Author: opentrades Date: 2013-05-10 16:40:03 +0200 (Fri, 10 May 2013) New Revision: 1466 Added: pkg/quantstrat/demo/luxor.8.walk.forward.R Modified: pkg/quantstrat/R/walk.forward.R pkg/quantstrat/demo/00Index pkg/quantstrat/man/walk.forward.Rd Log: - added "anchored" parameter to walk.forward - included luxor.8.walk.forward.R in the demos Modified: pkg/quantstrat/R/walk.forward.R =================================================================== --- pkg/quantstrat/R/walk.forward.R 2013-05-10 13:51:22 UTC (rev 1465) +++ pkg/quantstrat/R/walk.forward.R 2013-05-10 14:40:03 UTC (rev 1466) @@ -39,6 +39,7 @@ #' @param k.testing the number of periods to use for testing, eg. '1 month' #' @param obj.func a user provided function returning the best param.combo from the paramset, based on training results; defaults to 'max' #' @param obj.args a user provided argument to obj.func, defaults to quote(tradeStats.list$Net.Trading.PL) +#' @param anchored whether to use a fixed start for the training window (TRUE), or a sliding start (FALSE); defaults to FALSE #' @param include.insamples will optionally run a full backtest for each param.combo in the paramset, and add the resulting in-sample portfolios and orderbooks to the file '.results.RData'; default TRUE #' @param ... optional parameters to pass to apply.paramset() #' @param verbose dumps a lot of info during the run if set to TRUE, defaults to FALSE @@ -55,7 +56,7 @@ period, k.training, nsamples=0, audit.prefix=NULL, k.testing, obj.func=function(x){which(x==max(x))}, obj.args=list(x=quote(tradeStats.list$Net.Trading.PL)), - include.insamples=TRUE, + anchored=FALSE, include.insamples=TRUE, ..., verbose=FALSE) { must.have.args(match.call(), c('portfolio.st', 'strategy.st', 'paramset.label', 'k.training')) @@ -76,12 +77,16 @@ total.start <- ep[1 + k.training] + 1 total.timespan <- paste(index(symbol[total.start]), '', sep='/') + if(anchored) + training.start <- ep[1] + 1 + k <- 1; while(TRUE) { result <- list() # start and end of training window - training.start <- ep[k] + 1 + if(!anchored) + training.start <- ep[k] + 1 training.end <- ep[k + k.training] # stop if training.end is beyond last data Modified: pkg/quantstrat/demo/00Index =================================================================== --- pkg/quantstrat/demo/00Index 2013-05-10 13:51:22 UTC (rev 1465) +++ pkg/quantstrat/demo/00Index 2013-05-10 14:40:03 UTC (rev 1466) @@ -17,6 +17,7 @@ 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+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 Added: pkg/quantstrat/demo/luxor.8.walk.forward.R =================================================================== --- pkg/quantstrat/demo/luxor.8.walk.forward.R (rev 0) +++ pkg/quantstrat/demo/luxor.8.walk.forward.R 2013-05-10 14:40:03 UTC (rev 1466) @@ -0,0 +1,82 @@ +#!/usr/bin/Rscript --vanilla +# +# Jan Humme (@opentrades) - April 2013 +# +# Tested and found to work correctly using blotter r1457 +# +# After Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) +# +# Paragraph 3.5: determination of appropriate exit and risk management + +source('luxor.include.R') +initDate <- '2003-01-01' +.from <- initDate +.to <- '2003-12-31' + +source('luxor.getSymbols.R') + +### foreach and doMC + +require(foreach) +require(doMC) +registerDoMC(cores=8) + +### blotter + +initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD') +initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD', initEq=100000) + +### quantstrat + +require(quantstrat) + +initOrders(portfolio.st, initDate=initDate) + +load.strategy(strategy.st) + +enable.rule(strategy.st, 'chain', 'StopLoss') +#enable.rule(strategy.st, 'chain', 'StopTrailing') +enable.rule(strategy.st, 'chain', 'TakeProfit') + +addPosLimit( + portfolio=portfolio.st, + symbol='GBPUSD', + timestamp=initDate, + maxpos=.orderqty) + +### objective function + +ess <- function(a.st, p.st) +{ + require(robustbase, quietly=TRUE) + require(PerformanceAnalytics, quietly=TRUE) + + portfolios.st <- ls(pos=.blotter, pattern=paste('portfolio', p.st, '[0-9]*',sep='.')) + + pr <- PortfReturns(Account = a.st, Portfolios=portfolios.st) + + my.es <- ES(R=pr, clean='boudt') + + return(my.es) +} + +my.obj.func <- function(x) +{ + #return(which(max(x$Net.Trading.PL) == x$Net.Trading.PL)) + #return(which(max(x$GBPUSD) == x$GBPUSD)) + return(which(max(x$tradeStats$Net.Trading.PL/x$user.func$GBPUSD) == x$tradeStats$Net.Trading.PL/x$user.func$GBPUSD)) +} + +### 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('a.st'=account.st, 'p.st'=portfolio.st), audit.prefix='wfa.ples', anchored=FALSE, verbose=TRUE) + +### analyse + +pdf(paste('GBPUSD', .from, .to, 'pdf', sep='.')) +chart.Posn(portfolio.st) +dev.off() + +ts <- tradeStats(portfolio.st) +save(ts, file=paste('GBPUSD', .from, .to, 'RData', sep='.')) + Property changes on: pkg/quantstrat/demo/luxor.8.walk.forward.R ___________________________________________________________________ Added: svn:executable + * Modified: pkg/quantstrat/man/walk.forward.Rd =================================================================== --- pkg/quantstrat/man/walk.forward.Rd 2013-05-10 13:51:22 UTC (rev 1465) +++ pkg/quantstrat/man/walk.forward.Rd 2013-05-10 14:40:03 UTC (rev 1466) @@ -7,7 +7,8 @@ audit.prefix = NULL, k.testing, obj.func = function(x) { which(x == max(x)) }, obj.args = list(x = quote(tradeStats.list$Net.Trading.PL)), - include.insamples = TRUE, ..., verbose = FALSE) + anchored = FALSE, include.insamples = TRUE, ..., + verbose = FALSE) } \arguments{ \item{portfolio.st}{the name of the portfolio object} @@ -51,6 +52,10 @@ \item{obj.args}{a user provided argument to obj.func, defaults to quote(tradeStats.list$Net.Trading.PL)} + \item{anchored}{whether to use a fixed start for the + training window (TRUE), or a sliding start (FALSE); + defaults to FALSE} + \item{include.insamples}{will optionally run a full backtest for each param.combo in the paramset, and add the resulting in-sample portfolios and orderbooks to the From noreply at r-forge.r-project.org Mon May 13 21:30:22 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 13 May 2013 21:30:22 +0200 (CEST) Subject: [Blotter-commits] r1467 - in pkg/quantstrat: . R demo man Message-ID: <20130513193022.771E7184F70@r-forge.r-project.org> Author: opentrades Date: 2013-05-13 21:30:22 +0200 (Mon, 13 May 2013) New Revision: 1467 Added: pkg/quantstrat/R/chart.forward.R pkg/quantstrat/man/chart.forward.Rd Removed: pkg/quantstrat/R/chart.forward.testing.R pkg/quantstrat/man/chart.forward.testing.Rd Modified: pkg/quantstrat/DESCRIPTION pkg/quantstrat/NAMESPACE pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R pkg/quantstrat/demo/luxor.7.exit+risk.R pkg/quantstrat/demo/luxor.8.walk.forward.R pkg/quantstrat/demo/luxor.include.R Log: - chart.forward() improvements - several small luxor improvements Modified: pkg/quantstrat/DESCRIPTION =================================================================== --- pkg/quantstrat/DESCRIPTION 2013-05-10 14:40:03 UTC (rev 1466) +++ pkg/quantstrat/DESCRIPTION 2013-05-13 19:30:22 UTC (rev 1467) @@ -22,7 +22,6 @@ ByteCompile: TRUE Collate: 'applyStrategy.rebalancing.R' - 'chart.forward.testing.R' 'chart.forward.training.R' 'indicators.R' 'initialize.R' @@ -43,3 +42,4 @@ 'walk.forward.R' 'wrapup.R' 'tradeOrderStats.R' + 'chart.forward.R' Modified: pkg/quantstrat/NAMESPACE =================================================================== --- pkg/quantstrat/NAMESPACE 2013-05-10 14:40:03 UTC (rev 1466) +++ pkg/quantstrat/NAMESPACE 2013-05-13 19:30:22 UTC (rev 1467) @@ -13,8 +13,8 @@ export(applySignals) export(applyStrategy.rebalancing) export(applyStrategy) -export(chart.forward.testing) export(chart.forward.training) +export(chart.forward) export(delete.paramset) export(enable.rule) export(getOrderBook) Copied: pkg/quantstrat/R/chart.forward.R (from rev 1466, pkg/quantstrat/R/chart.forward.testing.R) =================================================================== --- pkg/quantstrat/R/chart.forward.R (rev 0) +++ pkg/quantstrat/R/chart.forward.R 2013-05-13 19:30:22 UTC (rev 1467) @@ -0,0 +1,64 @@ +#' Chart to analyse walk.forward() objective function +#' +#' @param audit.filename name of .audit environment file as produced by walk.forward() +#' +#' @export + +chart.forward <- function(audit.filename) +{ + if(!require(xtsExtra, quietly=TRUE)) stop('The "xtsExtra" package is required to use this function') + + .audit <- NULL + + load(audit.filename) + + # extract all portfolio names from the audit environment, except wfa portfolio + portfolios.st = ls(name=.audit, pattern='portfolio.*.[0-9]+') + n <- length(portfolios.st) + + # calculate Net.Trading.PL for each portfolio, one xts col per portfolio + PL.xts <- xts() + for(portfolio.st in portfolios.st) + { + p <- getPortfolio(portfolio.st, envir=.audit) + + from <- index(p$summary[2]) + + #R <- cumsum(p$summary['2004-01-01/','Net.Trading.PL']) + R <- cumsum(p$summary[paste(from, '/', sep=''),'Net.Trading.PL']) + names(R) <- portfolio.st + + PL.xts <- cbind(PL.xts, R) + } + + # now for the result portfolio + portfolio.st <- 'portfolio.forex' + p <- getPortfolio(portfolio.st, envir=.audit) + from <- index(p$summary[2]) + R <- cumsum(p$summary[paste(from, '/', sep=''),'Net.Trading.PL']) + names(R) <- portfolio.st + + #PL.xts <- na.locf(PL.xts) + PL.xts <- na.locf(cbind(PL.xts, R)) + + # add drawdown columns for all portfolio columns + 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 + ) + + .audit <- NULL +} Deleted: pkg/quantstrat/R/chart.forward.testing.R =================================================================== --- pkg/quantstrat/R/chart.forward.testing.R 2013-05-10 14:40:03 UTC (rev 1466) +++ pkg/quantstrat/R/chart.forward.testing.R 2013-05-13 19:30:22 UTC (rev 1467) @@ -1,63 +0,0 @@ -#' Chart to analyse walk.forward() objective function -#' -#' @param audit.filename name of .audit environment file as produced by walk.forward() -#' -#' @export - -chart.forward.testing <- function(audit.filename) -{ - if(!require(xtsExtra, quietly=TRUE)) stop('The "xtsExtra" package is required to use this function') - - .audit <- NULL - - load(audit.filename) - - # extract all portfolio names from the audit environment - portfolios.st = ls(name=.audit, pattern='portfolio.*') - n <- length(portfolios.st) - - # calculate Net.Trading.PL for each portfolio, one xts col per portfolio - PL.xts <- xts() - for(portfolio.st in portfolios.st) - { - p <- getPortfolio(portfolio.st, envir=.audit) - - from <- index(p$summary[2]) - - #R <- cumsum(p$summary['2004-01-01/','Net.Trading.PL']) - R <- cumsum(p$summary[paste(from, '/', sep=''),'Net.Trading.PL']) - names(R) <- portfolio.st - - PL.xts <- cbind(PL.xts, R) - } - - # add a column for the chosen portfolio, doubling it - chosen.one <- .audit$param.combo.nr - testing.portfolio.st <- ls(env=.audit, pattern=glob2rx(paste('portfolio', '*', chosen.one, sep='.'))) - - R <- PL.xts[,testing.portfolio.st] - PL.xts <- cbind(PL.xts, R) - - PL.xts <- na.locf(PL.xts) - - # add drawdown columns for all portfolio columns - 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 - ) - - .audit <- NULL -} Modified: pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R =================================================================== --- pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R 2013-05-10 14:40:03 UTC (rev 1466) +++ pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R 2013-05-13 19:30:22 UTC (rev 1467) @@ -44,7 +44,7 @@ ### BEGIN uncomment lines to activate StopLoss and/or StopTrailing and/or TakeProfit rules enable.rule('luxor', 'chain', 'StopLoss') -enable.rule('luxor', 'chain', 'StopTrailing') +#enable.rule('luxor', 'chain', 'StopTrailing') enable.rule('luxor', 'chain', 'TakeProfit') ### END uncomment lines to activate StopLoss and/or StopTrailing and/or TakeProfit rules Modified: pkg/quantstrat/demo/luxor.7.exit+risk.R =================================================================== --- pkg/quantstrat/demo/luxor.7.exit+risk.R 2013-05-10 14:40:03 UTC (rev 1466) +++ pkg/quantstrat/demo/luxor.7.exit+risk.R 2013-05-13 19:30:22 UTC (rev 1467) @@ -34,7 +34,7 @@ ### BEGIN uncomment lines to activate StopLoss and/or StopTrailing and/or TakeProfit rules -enable.rule('luxor', 'chain', 'StopLoss') +#enable.rule('luxor', 'chain', 'StopLoss') #enable.rule('luxor', 'chain', 'StopTrailing') #enable.rule('luxor', 'chain', 'TakeProfit') Modified: pkg/quantstrat/demo/luxor.8.walk.forward.R =================================================================== --- pkg/quantstrat/demo/luxor.8.walk.forward.R 2013-05-10 14:40:03 UTC (rev 1466) +++ pkg/quantstrat/demo/luxor.8.walk.forward.R 2013-05-13 19:30:22 UTC (rev 1467) @@ -6,13 +6,9 @@ # # After Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6) # -# Paragraph 3.5: determination of appropriate exit and risk management +# Paragraph 3.7 walk forward analysis source('luxor.include.R') -initDate <- '2003-01-01' -.from <- initDate -.to <- '2003-12-31' - source('luxor.getSymbols.R') ### foreach and doMC @@ -46,15 +42,14 @@ ### objective function -ess <- function(a.st, p.st) +ess <- function(account.st, portfolio.st) { require(robustbase, quietly=TRUE) require(PerformanceAnalytics, quietly=TRUE) - portfolios.st <- ls(pos=.blotter, pattern=paste('portfolio', p.st, '[0-9]*',sep='.')) + portfolios.st <- ls(pos=.blotter, pattern=paste('portfolio', portfolio.st, '[0-9]*',sep='.')) + pr <- PortfReturns(Account = account.st, Portfolios=portfolios.st) - pr <- PortfReturns(Account = a.st, Portfolios=portfolios.st) - my.es <- ES(R=pr, clean='boudt') return(my.es) @@ -62,14 +57,18 @@ my.obj.func <- function(x) { - #return(which(max(x$Net.Trading.PL) == x$Net.Trading.PL)) - #return(which(max(x$GBPUSD) == x$GBPUSD)) - return(which(max(x$tradeStats$Net.Trading.PL/x$user.func$GBPUSD) == x$tradeStats$Net.Trading.PL/x$user.func$GBPUSD)) + # pick one of the following objective functions (uncomment) + + #return(max(x$tradeStats$Max.Drawdown) == x$tradeStats$Max.Drawdown) + + #return(max(x$tradeStats$Net.Trading.PL) == x$tradeStats$Net.Trading.PL) + + return(max(x$user.func$GBPUSD.DailyEndEq) == x$user.func$GBPUSD.DailyEndEq) } ### 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('a.st'=account.st, 'p.st'=portfolio.st), audit.prefix='wfa.ples', anchored=FALSE, verbose=TRUE) +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) ### analyse Modified: pkg/quantstrat/demo/luxor.include.R =================================================================== --- pkg/quantstrat/demo/luxor.include.R 2013-05-10 14:40:03 UTC (rev 1466) +++ pkg/quantstrat/demo/luxor.include.R 2013-05-13 19:30:22 UTC (rev 1467) @@ -8,13 +8,11 @@ ### initDate = '2002-10-21' -#initDate = '2003-01-01' .from=initDate -#.to='2008-07-04' .to='2002-10-31' -#.to='2003-07-31' +.to='2008-07-04' ### @@ -35,11 +33,9 @@ .FastSMA = (1:20) .SlowSMA = (30:80) -#.StopLoss = seq(0.02, 0.48, length.out=24)/100 -#.StopLoss = seq(0.01, 0.24, length.out=24)/100 -.StopLoss = seq(0.002, 0.048, length.out=24)/100 -.StopTrailing = seq(0.05, 0.4, length.out=8)/100 -.TakeProfit = seq(0.1, 1.0, length.out=10)/100 +.StopLoss = seq(0.05, 2.4, length.out=48)/100 +.StopTrailing = seq(0.05, 2.4, length.out=48)/100 +.TakeProfit = seq(0.1, 4.8, length.out=48)/100 .FastWFA = c(1, 3, 5, 7, 9) .SlowWFA = c(42, 44, 46) @@ -59,10 +55,10 @@ .fast = 6 .slow = 44 -#.timespan = 'T08:00/T12:00' +#.timespan = 'T09:00/T13:00' .timespan = 'T00:00/T23:59' -.stoploss <- 0.0025 -.stoptrailing <- 0.008 -.takeprofit <- 0.019 +.stoploss <- 0.40/100 +.stoptrailing <- 0.8/100 +.takeprofit <- 2.0/100 Added: pkg/quantstrat/man/chart.forward.Rd =================================================================== --- pkg/quantstrat/man/chart.forward.Rd (rev 0) +++ pkg/quantstrat/man/chart.forward.Rd 2013-05-13 19:30:22 UTC (rev 1467) @@ -0,0 +1,14 @@ +\name{chart.forward} +\alias{chart.forward} +\title{Chart to analyse walk.forward() objective function} +\usage{ + chart.forward(audit.filename) +} +\arguments{ + \item{audit.filename}{name of .audit environment file as + produced by walk.forward()} +} +\description{ + Chart to analyse walk.forward() objective function +} + Deleted: pkg/quantstrat/man/chart.forward.testing.Rd =================================================================== --- pkg/quantstrat/man/chart.forward.testing.Rd 2013-05-10 14:40:03 UTC (rev 1466) +++ pkg/quantstrat/man/chart.forward.testing.Rd 2013-05-13 19:30:22 UTC (rev 1467) @@ -1,14 +0,0 @@ -\name{chart.forward.testing} -\alias{chart.forward.testing} -\title{Chart to analyse walk.forward() objective function} -\usage{ - chart.forward.testing(audit.filename) -} -\arguments{ - \item{audit.filename}{name of .audit environment file as - produced by walk.forward()} -} -\description{ - Chart to analyse walk.forward() objective function -} - From noreply at r-forge.r-project.org Mon May 13 22:01:43 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 13 May 2013 22:01:43 +0200 (CEST) Subject: [Blotter-commits] r1468 - pkg/quantstrat/demo Message-ID: <20130513200144.0D75418552E@r-forge.r-project.org> Author: opentrades Date: 2013-05-13 22:01:43 +0200 (Mon, 13 May 2013) New Revision: 1468 Modified: pkg/quantstrat/demo/luxor.include.R Log: - small typo fix Modified: pkg/quantstrat/demo/luxor.include.R =================================================================== --- pkg/quantstrat/demo/luxor.include.R 2013-05-13 19:30:22 UTC (rev 1467) +++ pkg/quantstrat/demo/luxor.include.R 2013-05-13 20:01:43 UTC (rev 1468) @@ -12,7 +12,7 @@ .from=initDate .to='2002-10-31' -.to='2008-07-04' +#.to='2008-07-04' ### From noreply at r-forge.r-project.org Thu May 16 17:28:47 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 16 May 2013 17:28:47 +0200 (CEST) Subject: [Blotter-commits] r1469 - pkg/quantstrat/demo Message-ID: <20130516152847.DC6AF1849B7@r-forge.r-project.org> Author: opentrades Date: 2013-05-16 17:28:47 +0200 (Thu, 16 May 2013) New Revision: 1469 Modified: pkg/quantstrat/demo/luxor.getSymbols.R Log: - to.minutes30() was called twice Modified: pkg/quantstrat/demo/luxor.getSymbols.R =================================================================== --- pkg/quantstrat/demo/luxor.getSymbols.R 2013-05-13 20:01:43 UTC (rev 1468) +++ pkg/quantstrat/demo/luxor.getSymbols.R 2013-05-16 15:28:47 UTC (rev 1469) @@ -38,5 +38,5 @@ ### xts GBPUSD = to.minutes30(GBPUSD) -GBPUSD = align.time(to.minutes30(GBPUSD), 1800) +GBPUSD = align.time(GBPUSD, 1800) From noreply at r-forge.r-project.org Thu May 16 20:08:43 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 16 May 2013 20:08:43 +0200 (CEST) Subject: [Blotter-commits] r1470 - pkg/quantstrat/data Message-ID: <20130516180843.161C9185511@r-forge.r-project.org> Author: opentrades Date: 2013-05-16 20:08:42 +0200 (Thu, 16 May 2013) New Revision: 1470 Added: pkg/quantstrat/data/luxor.wfa.ples.RData Removed: pkg/quantstrat/data/luxor.wfa.ples.GBPUSD.2003-01-02 05:30:00.2003-03-31 23:30:00.RData Log: - renamed luxor wfa data file because r-forge does not build anymore - TODO fix demo/luxor.sample.wfa.R - (broken) Deleted: pkg/quantstrat/data/luxor.wfa.ples.GBPUSD.2003-01-02 05:30:00.2003-03-31 23:30:00.RData =================================================================== (Binary files differ) Copied: pkg/quantstrat/data/luxor.wfa.ples.RData (from rev 1469, pkg/quantstrat/data/luxor.wfa.ples.GBPUSD.2003-01-02 05:30:00.2003-03-31 23:30:00.RData) =================================================================== (Binary files differ) From noreply at r-forge.r-project.org Tue May 21 19:18:49 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 21 May 2013 19:18:49 +0200 (CEST) Subject: [Blotter-commits] r1471 - pkg/quantstrat/sandbox Message-ID: <20130521171849.859AF183E7A@r-forge.r-project.org> Author: opentrades Date: 2013-05-21 19:18:49 +0200 (Tue, 21 May 2013) New Revision: 1471 Added: pkg/quantstrat/sandbox/QuantstratWorkshop.pdf Log: - added quantstrat workshop sheets Added: pkg/quantstrat/sandbox/QuantstratWorkshop.pdf =================================================================== (Binary files differ) Property changes on: pkg/quantstrat/sandbox/QuantstratWorkshop.pdf ___________________________________________________________________ Added: svn:mime-type + application/pdf From noreply at r-forge.r-project.org Sun May 26 16:22:56 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 26 May 2013 16:22:56 +0200 (CEST) Subject: [Blotter-commits] r1472 - pkg/quantstrat/R Message-ID: <20130526142256.334C2184F54@r-forge.r-project.org> Author: opentrades Date: 2013-05-26 16:22:55 +0200 (Sun, 26 May 2013) New Revision: 1472 Modified: pkg/quantstrat/R/paramsets.R Log: - doRedis timeout patch, thanks to Kent Huxsey Modified: pkg/quantstrat/R/paramsets.R =================================================================== --- pkg/quantstrat/R/paramsets.R 2013-05-21 17:18:49 UTC (rev 1471) +++ pkg/quantstrat/R/paramsets.R 2013-05-26 14:22:55 UTC (rev 1472) @@ -460,9 +460,31 @@ clone.portfolio(portfolio.st, result$portfolio.st) clone.orderbook(portfolio.st, result$portfolio.st) + if(exists('redisGetContext')) + { + # assume we are using a doRedis parallel backend + # store the context, and close the connection + # patch to prevent timeout on large data sets + # + # thanks to Kent Hoxsey for this workaround + + redisContext <- redisGetContext() + redisClose() + } + strategy <- install.param.combo(strategy, param.combo, paramset.label) applyStrategy(strategy, portfolios=result$portfolio.st, mktdata=mktdata, verbose=verbose) + if(exists('redisContext')) + { + # assume redisContext contains preserved context + # restore doRedis connection + # + # thanks to Kent Hoxsey for this workaround + + redisConnect(host=redisContext$host) + } + if(calc == 'slave') { updatePortf(result$portfolio.st, Dates=paste('::',as.Date(Sys.time()),sep=''), Prices=mktdata) From noreply at r-forge.r-project.org Mon May 27 01:30:38 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 27 May 2013 01:30:38 +0200 (CEST) Subject: [Blotter-commits] r1473 - in pkg/FinancialInstrument: . R man Message-ID: <20130526233038.B9375184D17@r-forge.r-project.org> Author: gsee Date: 2013-05-27 01:30:38 +0200 (Mon, 27 May 2013) New Revision: 1473 Modified: pkg/FinancialInstrument/DESCRIPTION pkg/FinancialInstrument/NEWS pkg/FinancialInstrument/R/instrument.R pkg/FinancialInstrument/R/load.instruments.R pkg/FinancialInstrument/R/synthetic.R pkg/FinancialInstrument/man/exchange_rate.Rd pkg/FinancialInstrument/man/instrument.Rd pkg/FinancialInstrument/man/load.instruments.Rd pkg/FinancialInstrument/man/option_series.yahoo.Rd pkg/FinancialInstrument/man/synthetic.instrument.Rd Log: - instrument() and most wrappers gain an overwrite argument to allow the user to ensure that an instrument is not overwritten. - load.instruments() gains an overwrite argument that is passed through to the instrument() wrapper functions. Therefore, load.instruments() no longer checks to see if an instrument already exists. Thanks to Charlie Friedemann for the patch. - load.instruments() gains an "identifier_cols" argument that can be used to pass the names of columns that are to be used as identifiers instead of as normal instrument attributes. Thanks to Charlie Friedemann for the patch - minor code formatting; tabs to spaces, etc. Modified: pkg/FinancialInstrument/DESCRIPTION =================================================================== --- pkg/FinancialInstrument/DESCRIPTION 2013-05-26 14:22:55 UTC (rev 1472) +++ pkg/FinancialInstrument/DESCRIPTION 2013-05-26 23:30:38 UTC (rev 1473) @@ -9,9 +9,9 @@ Contributors: Dirk Eddelbuettel, Alexis Petit, Jeffrey Ryan, Joshua Ulrich Description: Infrastructure for defining meta-data and relationships for financial instruments. -Version: 1.1.8 +Version: 1.1.9 URL: https://r-forge.r-project.org/projects/blotter/ -Date: 2013-03-03 +Date: 2013-05-26 Depends: R (>= 2.12.0), quantmod(>= 0.3-17), Modified: pkg/FinancialInstrument/NEWS =================================================================== --- pkg/FinancialInstrument/NEWS 2013-05-26 14:22:55 UTC (rev 1472) +++ pkg/FinancialInstrument/NEWS 2013-05-26 23:30:38 UTC (rev 1473) @@ -1,10 +1,29 @@ Changes in Version 1.2 ====================== + USER VISIBLE CHANGES -------------------- + * saveInstruments() gains a "compress" argument to allow for different compression than the default ("gzip") +* instrument() and most of its wrappers gain an "overwrite" argument. The + default is TRUE to match previous behavior -- if you try to create an + instrument that already exists, the old one will be replaced by + the new definition. If overwrite=FALSE is used, there will be an error + if you try to define an instrument that has a primary_id that is already + in use. Thanks to Charlie Friedemann for the suggestion and discussions. + +* load.instruments() gains an overwrite argument that is passed through to the + instrument() wrapper functions. Therefore, load.instruments() no longer + checks to see if an instrument already exists. Thanks to Charlie Friedemann + for the patch. + +* load.instruments() gains an "identifier_cols" argument that can be used to + pass the names of columns that are to be used as identifiers instead of as + normal instrument attributes. Thanks to Charlie Friedemann for the patch. + + BUG FIXES --------- Modified: pkg/FinancialInstrument/R/instrument.R =================================================================== --- pkg/FinancialInstrument/R/instrument.R 2013-05-26 14:22:55 UTC (rev 1472) +++ pkg/FinancialInstrument/R/instrument.R 2013-05-26 23:30:38 UTC (rev 1473) @@ -104,6 +104,9 @@ #' \code{instrument} prior to further processing (and presumably assignment) or #' to test your parameters before assignment. #' +#' If \code{overwrite=FALSE} is used, an error will be thrown if any +#' \code{primary_id}s are already in use. +#' #' As of version 0.10.0, the .instrument environment is located at the top level #' of the package. i.e. \code{FinancialInstrument:::.instrument}. #' @@ -135,6 +138,9 @@ #' @param assign_i TRUE/FALSE. Should the instrument be assigned to the #' \code{.instrument} environment? Default is FALSE for \code{instrument}, #' TRUE for wrappers. +#' @param overwrite TRUE/FALSE. Should existing instruments with the same +#' primary_id be overwritten? Default is TRUE. If FALSE, an error will be +#' thrown and the instrument will not be created. #' @aliases #' stock #' bond @@ -151,8 +157,9 @@ #' \code{\link{spread}}, #' \code{\link{load.instruments}} #' @export -instrument<-function(primary_id , ..., currency , multiplier , tick_size=NULL, - identifiers = NULL, type=NULL, assign_i=FALSE ){ +instrument <- function(primary_id , ..., currency , multiplier , tick_size=NULL, + identifiers = NULL, type=NULL, assign_i=FALSE, + overwrite=TRUE) { if(is.null(primary_id)) { stop("you must specify a primary_id for the instrument") } @@ -198,7 +205,6 @@ identifiers <- c(identifiers, arg[pos_arg]) arg[pos_arg] <- NULL - ## TODO note that multiplier could be a time series, probably add code here to check if(!is.numeric(multiplier) || length(multiplier) > 1) { stop("multiplier must be a single number") @@ -209,13 +215,21 @@ if(is.null(type)) { tclass="instrument" } else tclass = unique(c(type,"instrument")) - - if (is.currency.name(primary_id)) { + + if (is.currency.name(primary_id) && + !inherits(getInstrument(primary_id, type="currency"), + "exchange_rate")) { oid <- primary_id primary_id <- tail(make.names(c(ls_instruments(), oid), unique=TRUE), 1) warning(paste(oid, "is the name of a currency. Using", primary_id, "for the primary_id of this", type)) identifiers <- c(identifiers, ticker=oid) + } else if ((primary_id %in% ls_instruments()) && !overwrite && + isTRUE(assign_i)) { + # primary_id already exists and we are not overwriting + stop(paste("an instrument with primary_id", primary_id, + "already exists in the .instrument environment.", + "Set overwrite=TRUE to overwrite.")) } tmpinstr <- list(primary_id = primary_id, currency = currency, @@ -238,11 +252,22 @@ #' @export #' @rdname instrument stock <- function(primary_id , currency=NULL , multiplier=1 , tick_size=.01, - identifiers = NULL, assign_i=TRUE, ...){ + identifiers = NULL, assign_i=TRUE, overwrite=TRUE, ...){ if (is.null(currency)) stop ("'currency' is a required argument") - if (length(primary_id) > 1) return(unname(sapply(primary_id, stock, - currency=currency, multiplier=multiplier, tick_size=tick_size, - identifiers=identifiers, ...=...))) + if (!isTRUE(overwrite) && isTRUE(assign_i) && + any(in.use <- primary_id %in% (li <- ls_instruments()))) { + stop(paste(paste0("In stock(...) : ", + "overwrite is FALSE and primary_id", + if (sum(in.use) > 1) "s are" else " is", + " already in use:\n"), + paste(intersect(primary_id, li), collapse=", ")), + call.=FALSE) + } + if (length(primary_id) > 1) { + return(unname(sapply(primary_id, stock, currency=currency, + multiplier=multiplier, tick_size=tick_size, + identifiers=identifiers, ...=...))) + } instrument(primary_id=primary_id, currency=currency, multiplier=multiplier, tick_size=tick_size, identifiers = identifiers, ..., type="stock", assign_i=assign_i) @@ -251,8 +276,17 @@ #' @export #' @rdname instrument fund <- function(primary_id , currency=NULL , multiplier=1 , tick_size=.01, - identifiers = NULL, assign_i=TRUE, ...){ + identifiers = NULL, assign_i=TRUE, overwrite=TRUE, ...){ if (is.null(currency)) stop ("'currency' is a required argument") + if (!isTRUE(overwrite) && isTRUE(assign_i) && + any(in.use <- primary_id %in% (li <- ls_instruments()))) { + stop(paste(paste0("In fund(...) : ", + "overwrite is FALSE and primary_id", + if (sum(in.use) > 1) "s are" else " is", + " already in use:\n"), + paste(intersect(primary_id, li), collapse=", ")), + call.=FALSE) + } if (length(primary_id) > 1) return(unname(sapply(primary_id, fund, currency=currency, multiplier=multiplier, tick_size=tick_size, identifiers=identifiers, ...=...))) @@ -264,9 +298,14 @@ #' @export #' @rdname instrument future <- function(primary_id , currency , multiplier , tick_size=NULL, - identifiers = NULL, assign_i=TRUE, ..., underlying_id=NULL){ + identifiers = NULL, assign_i=TRUE, overwrite=TRUE, ..., + underlying_id=NULL){ if(missing(primary_id)) primary_id <- paste("..",underlying_id,sep="") if (length(primary_id) > 1) stop('primary_id must be of length 1') + if (!isTRUE(overwrite) && assign_i==TRUE && + primary_id %in% ls_instruments()) { + stop(sQuote(primary_id), " already in use and overwrite=FALSE") + } if (missing(currency) && !is.null(underlying_id)) { uinstr <- getInstrument(underlying_id,silent=TRUE) if (is.instrument(uinstr)) { @@ -358,6 +397,9 @@ future_series <- function(primary_id, root_id=NULL, suffix_id=NULL, first_traded=NULL, expires=NULL, identifiers = NULL, assign_i=TRUE, overwrite=TRUE, ...){ + # if overwrite==FALSE and assign_i==TRUE, we'll need to know what instruments + # are already defined. Don't bother doing this if we're overwriting anyway + if (!isTRUE(overwrite) && isTRUE(assign_i)) li <- ls_instruments() if (missing(primary_id)) { if (all(is.null(c(root_id,suffix_id)))) { stop(paste('must provide either a primary_id or', @@ -378,6 +420,15 @@ stop(paste("'first_traded' and 'expires' must be NULL", "if calling with multiple primary_ids")) } + if (!isTRUE(overwrite) && isTRUE(assign_i) && + any(in.use <- primary_id %in% li)) { + stop(paste(paste("In future_series(...) : ", + "overwrite is FALSE and primary_id", + if (sum(in.use) > 1) "s are" else " is", + " already in use:\n", sep=""), + paste(intersect(primary_id, li), collapse=", ")), + call.=FALSE) + } return(unname(sapply(primary_id, future_series, root_id=root_id, suffix_id=suffix_id, first_traded=first_traded, expires=expires, identifiers = identifiers, assign_i=assign_i, @@ -389,8 +440,10 @@ #need to replace primary_id root_id <- primary_id primary_id <- paste(root_id, suffix_id, sep="_") - } - + } + if (!isTRUE(overwrite) && isTRUE(assign_i) && primary_id %in% li) { + stop(sQuote(primary_id), " already in use and overwrite=FALSE") + } pid <- parse_id(primary_id) if (is.null(root_id)) root_id <- pid$root if (is.null(suffix_id)) suffix_id <- pid$suffix @@ -462,15 +515,20 @@ #' @export #' @rdname instrument option <- function(primary_id , currency , multiplier , tick_size=NULL, - identifiers = NULL, assign_i=TRUE, ..., underlying_id=NULL){ + identifiers = NULL, assign_i=TRUE, overwrite=TRUE, + ..., underlying_id=NULL){ if (missing(primary_id)) primary_id <- paste(".",underlying_id,sep="") if (length(primary_id) > 1) stop("'primary_id' must be of length 1") + if (!isTRUE(overwrite) && assign_i==TRUE && + primary_id %in% ls_instruments()) { + stop(sQuote(primary_id), " already in use and overwrite=FALSE") + } if (missing(currency) && !is.null(underlying_id)) { uinstr <- getInstrument(underlying_id,silent=TRUE) if (is.instrument(uinstr)) { currency <- uinstr$currency } else stop("'currency' is a required argument") - } + } if(is.null(underlying_id)) { warning("underlying_id should only be NULL for cash-settled options") } else { @@ -496,6 +554,7 @@ first_traded=NULL, expires=NULL, callput=c("call","put"), strike=NULL, identifiers=NULL, assign_i=TRUE, overwrite=TRUE, ...){ + if (!isTRUE(overwrite) && isTRUE(assign_i)) li <- ls_instruments() if (missing(primary_id) ) { if (all(is.null(c(root_id,suffix_id)))) { stop(paste('must provide either a primary_id or', @@ -525,6 +584,15 @@ primary_id <- paste(gsub("\\.","",root_id), suffix_id, sep="_") } } else if (length(primary_id) > 1) { + if (!isTRUE(overwrite) && isTRUE(assign_i) && + any(in.use <- primary_id %in% li)) { + stop(paste(paste("In option_series(...) : ", + "overwrite is FALSE and primary_id", + if (sum(in.use) > 1) "s are" else " is", + " already in use:\n", sep=""), + paste(intersect(primary_id, li), collapse=", ")), + call.=FALSE) + } if (!is.null(expires) || !is.null(first_traded)) { stop(paste("'first_traded' and 'expires' must be NULL", "if calling with multiple primary_ids")) @@ -540,7 +608,10 @@ #root_id and we need to replace primary_id root_id <- primary_id primary_id <- paste(root_id, suffix_id, sep="_") - } + } + if (!isTRUE(overwrite) && isTRUE(assign_i) && primary_id %in% li) { + stop(sQuote(primary_id), " already in use and overwrite=FALSE") + } pid <- parse_id(primary_id) if (is.null(root_id)) root_id <- pid$root if (is.null(suffix_id)) suffix_id <- pid$suffix @@ -624,6 +695,7 @@ #' @param first_traded first date that contracts are tradeable. Probably not #' applicable if defining several chains. #' @param tick_size minimum price change of options. +#' @param overwrite if an instrument already exists, should it be overwritten? #' @return Called for side-effect. The instrument that is created and stored #' will inherit option_series, option, and instrument classes. #' @references Yahoo \url{http://finance.yahoo.com} @@ -640,13 +712,8 @@ #' } #' @export option_series.yahoo <- function(symbol, Exp, currency="USD", multiplier=100, - first_traded=NULL, tick_size=NULL) { + first_traded=NULL, tick_size=NULL, overwrite=TRUE) { #FIXME: identifiers? - - if (!("package:quantmod" %in% search() || - require("quantmod",quietly=TRUE))) { - stop("Please install quantmod before using this function.") - } opts <- getOptionChain(Symbols=symbol,Exp=Exp, src="yahoo") @@ -657,19 +724,37 @@ optnames <- unname(do.call(c, led)) #FIXME: Is this a reasonable way to get rownames? } else optnames <- locals(opts) #c(rownames(opts$calls),rownames(opts$puts)) + + CleanID <- function(x, symbol) { + si <- gsub(symbol, "", x) #suffix_id + out <- list(root_id = symbol, + expiry = substr(si, 1, 6), + right = substr(si, 7, 7), + strike = as.numeric(substr(si, 8, 15))/1000) + clean.si <- with(out, paste(expiry, right, strike, sep="")) + c(out, list(clean.si=clean.si, + primary_id = paste(symbol, "_", clean.si, sep=""))) + } + + CleanID(optnames[4], "GS") + id.list <- lapply(optnames, CleanID, symbol) + + if (!isTRUE(overwrite)) { + new.ids <- unname((u <- unlist(id.list))[grep("primary_id", names(u))]) + if (any(in.use <- new.ids %in% (li <- ls_instruments()))) { + stop(paste(paste0("In option_series.yahoo(...) : ", + "overwrite is FALSE and primary_id", + if (sum(in.use) > 1) "s are" else " is", + " already in use:\n"), + paste(intersect(new.ids, li), collapse=", ")), + call.=FALSE) + } + } + idout <- NULL - for (r in optnames) { - root_id <- symbol - si <- gsub(symbol,"",r) #suffix_id - expiry <- substr(si,1,6) - right <- substr(si,7,7) - strike <- as.numeric(substr(si,8,15))/1000 -# local <- paste(symbol, si, sep=" ") - clean.si <- paste(expiry,right,strike,sep="") - primary_id <- paste(symbol, "_", clean.si, sep="") - + for (ID in id.list) { #create currency if it doesn't exist #?? Any reason not to ?? - tmpccy <- try(getInstrument(currency,silent=TRUE),silent=TRUE) + tmpccy <- try(getInstrument(currency, silent=TRUE), silent=TRUE) if (!inherits(tmpccy, "currency")) { warning(paste("Created currency", currency, "because it did not exist.")) @@ -679,34 +764,32 @@ tmpInstr <- try(getInstrument(paste('.',symbol,sep=""), silent=TRUE), silent=TRUE) if (!inherits(tmpInstr, "option")) { - warning(paste('Created option specs for root', - paste('.', symbol, sep=""))) - option(primary_id=paste('.',symbol,sep=""), currency=currency, - multiplier=multiplier, tick_size=tick_size, - underlying_id=symbol) + warning(paste('Created option specs for root', + paste('.', symbol, sep=""))) + option(primary_id=paste('.',symbol,sep=""), currency=currency, + multiplier=multiplier, tick_size=tick_size, + underlying_id=symbol) } #create specific option - tempseries = instrument(primary_id=primary_id, - suffix_id=clean.si, + tempseries = instrument(primary_id=ID[["primary_id"]], + suffix_id=ID[["clean.si"]], first_traded=first_traded, currency=currency, multiplier=multiplier, tick_size=tick_size, expires=as.Date(paste(paste('20', - substr(expiry,1,2), + substr(ID[["expiry"]], 1, 2), sep=""), - substr(expiry,3,4), - substr(expiry,5,6), - sep="-")), - callput=switch(right, C="call", P="put"), #to be consistent with the other option_series function - strike=strike, + substr(ID[["expiry"]], 3, 4), + substr(ID[["expiry"]], 5, 6), + sep="-")), + callput=switch(ID[["right"]], C="call", P="put"), #to be consistent with the other option_series function + strike=ID[["strike"]], underlying_id=symbol, type = c("option_series","option"), - defined.by='yahoo', assign_i=TRUE + defined.by='yahoo', assign_i=TRUE, overwrite=overwrite ) -#option_series(primary_id=primary_id, suffix_id=si, exires=expiry, currency=currency, -# callput = switch(right,C='call',P='put')) - idout <- c(idout, primary_id) + idout <- c(idout, ID[["primary_id"]]) } idout } @@ -714,6 +797,17 @@ #' @export #' @rdname instrument currency <- function(primary_id, identifiers = NULL, assign_i=TRUE, ...){ + if (hasArg("overwrite")) { + if (!list(...)$overwrite && isTRUE(assign_i) && + any(in.use <- primary_id %in% (li <- ls_instruments()))) { + stop(paste(paste0("In currency(...) : ", + "overwrite is FALSE and primary_id", + if (sum(in.use) > 1) "s are" else " is", + " already in use:\n"), + paste(intersect(primary_id, li), collapse=", ")), + call.=FALSE) + } + } if (length(primary_id) > 1) { return(unname(sapply(primary_id, currency, identifiers=identifiers, ...=...))) @@ -779,12 +873,16 @@ #' stored for this instrument #' @param assign_i TRUE/FALSE. Should the instrument be assigned in the #' \code{.instrument} environment? (Default TRUE) +#' @param overwrite \code{TRUE} by default. If \code{FALSE}, an error will +#' be thrown if there is already an instrument defined with the same +#' \code{primary_id}. #' @param ... any other passthru parameters #' @references http://financial-dictionary.thefreedictionary.com/Base+Currency #' @export exchange_rate <- function (primary_id = NULL, currency = NULL, counter_currency = NULL, tick_size=0.01, - identifiers = NULL, assign_i=TRUE, ...){ + identifiers = NULL, assign_i=TRUE, overwrite=TRUE, + ...){ if (is.null(primary_id) && !is.null(currency) && !is.null(counter_currency)) { primary_id <- c(outer(counter_currency,currency,paste,sep="")) same.same <- function(x) substr(x,1,3) == substr(x,4,6) @@ -794,6 +892,16 @@ stop(paste("Must provide either 'primary_id' or both", "'currency' and 'counter_currency'")) } + if (!isTRUE(overwrite) && isTRUE(assign_i) && + any(in.use <- primary_id %in% (li <- ls_instruments()))) { + stop(paste(paste0("In exchange_rate(...) : ", + "overwrite is FALSE and primary_id", + if (sum(in.use) > 1) "s are" else " is", + " already in use:\n"), + paste(intersect(primary_id, li), collapse=", ")), + call.=FALSE) + } + if (length(primary_id) > 1) { return(unname(sapply(primary_id, exchange_rate, identifiers=identifiers, ...=...))) @@ -819,9 +927,13 @@ #' @export #' @rdname instrument bond <- function(primary_id, currency, multiplier, tick_size=NULL, - identifiers = NULL, assign_i=TRUE, ...){ + identifiers = NULL, assign_i=TRUE, overwrite=TRUE, ...){ if (missing(currency)) stop ("'currency' is a required argument") if (length(primary_id) > 1) stop("'primary_id' must be of length 1 for this function") + if (!isTRUE(overwrite) && isTRUE(assign_i) && primary_id %in% ls_instruments()) { + stop("overwrite is FALSE and the primary_id ", sQuote(primary_id), + " is already in use.") + } instrument(primary_id=primary_id, currency=currency, multiplier=multiplier, tick_size=tick_size, identifiers = identifiers, ..., type="bond", assign_i=assign_i ) @@ -938,7 +1050,8 @@ #' } #' @export instrument.auto <- function(primary_id, currency=NULL, multiplier=1, silent=FALSE, - default_type='unknown', root=NULL, assign_i=TRUE, ...) { + default_type='unknown', root=NULL, assign_i=TRUE, + ...) { ##TODO: check formals against dots and remove duplicates from dots before calling constructors to avoid # 'formal argument "multiplier" matched by multiple actual arguments' if (!is.null(currency) && !is.currency.name(currency)) { Modified: pkg/FinancialInstrument/R/load.instruments.R =================================================================== --- pkg/FinancialInstrument/R/load.instruments.R 2013-05-26 14:22:55 UTC (rev 1472) +++ pkg/FinancialInstrument/R/load.instruments.R 2013-05-26 23:30:38 UTC (rev 1473) @@ -27,6 +27,8 @@ #' #' You will need to specify a \code{currency}, unless the instrument \code{type} is 'currency' #' +#' Use the \code{identifier_cols} argument to specify which fields (if any) in the CSV are to be passed to \code{\link{instrument}} as the \code{identifiers} argument +#' #' Typically, columns will exist for \code{multiplier} and \code{tick_size}. #' #' Any other columns necessary to define the specified instrument type will also be required to avoid fatal Errors. @@ -38,6 +40,8 @@ #' @param metadata optional, data.frame containing metadata, default NULL, see Details #' @param id_col numeric column containing id if primary_id isn't defined, default 1 #' @param default_type character string to use as instrument type fallback, see Details +#' @param identifier_cols character vector of field names to be passed as identifiers, see Details +#' @param overwrite TRUE/FALSE. See \code{\link{instrument}}. #' @seealso #' \code{\link{loadInstruments}}, #' \code{\link{instrument}}, @@ -52,7 +56,7 @@ #' #' } #' @export -load.instruments <- function (file=NULL, ..., metadata=NULL, id_col=1, default_type='stock') { +load.instruments <- function (file=NULL, ..., metadata=NULL, id_col=1, default_type='stock', identifier_cols=NULL, overwrite=TRUE) { if(is.null(file) && is.null(metadata)) stop("You must pass either a file identifier string or a metadata object to be converted.") if(is.null(metadata)){ @@ -87,51 +91,55 @@ #now process the data for(rn in 1:nrow(filedata)){ - if(!isTRUE(is.instrument(try(getInstrument(as.character(filedata[rn,id_col]),silent=TRUE),silent=TRUE)))){ - type=as.character(filedata[rn,'type']) - arg<-as.list(filedata[rn,]) - if(type=='spread' || type=='guaranteed_spread'){ - if(!is.null(arg$members)){ - arg$members<-unlist(strsplit(arg$members,',')) - } - if(!is.null(arg$memberratio)){ - arg$memberratio<-unlist(strsplit(arg$memberratio,',')) - } - if(!is.null(arg$ratio)){ - arg$memberratio<-unlist(strsplit(arg$ratio,',')) - } - } - arg$type<-NULL - arg<-arg[!is.na(arg)] - arg<-arg[!arg==""] - if (set_primary) { - arg$primary_id<-filedata[rn,id_col] + type <- as.character(filedata[rn,'type']) + arg <- as.list(filedata[rn,]) + if(type=='spread' || type=='guaranteed_spread'){ + if(!is.null(arg$members)){ + arg$members<-unlist(strsplit(arg$members,',')) } + if(!is.null(arg$memberratio)){ + arg$memberratio<-unlist(strsplit(arg$memberratio,',')) + } + if(!is.null(arg$ratio)){ + arg$memberratio<-unlist(strsplit(arg$ratio,',')) + } + } + arg$type <- NULL + arg <- arg[!is.na(arg)] + arg <- arg[!arg==""] + if (set_primary) { + arg$primary_id<-filedata[rn,id_col] + } + + #do some name cleanup to make up for Reuters silliness + if(substr(arg$primary_id,1,1)==1) arg$primary_id <- substr(arg$primary_id,2,nchar(arg$primary_id)) + arg$primary_id<-make.names(arg$primary_id) + if(!is.null(arg$X.RIC)){ + if(substr(arg$X.RIC,1,1)==1) arg$X.RIC <- substr(arg$X.RIC,2,nchar(arg$X.RIC)) + } + if(!is.null(arg$RIC)){ + if(substr(arg$RIC,1,1)==1) arg$RIC <- substr(arg$RIC,2,nchar(arg$RIC)) + } + if(length(dotargs)) arg<-c(arg,dotargs) + + if(!is.null(identifier_cols) && any(identifier_cols %in% names(arg))){ + arg$identifiers <- arg[names(arg) %in% identifier_cols] + arg[identifier_cols] <- NULL + } + + arg$overwrite <- overwrite + if(is.function(try(match.fun(type),silent=TRUE))){ + out <- try(do.call(type,arg)) - #do some name cleanup to make up for Reuters silliness - if(substr(arg$primary_id,1,1)==1) arg$primary_id <- substr(arg$primary_id,2,nchar(arg$primary_id)) - arg$primary_id<-make.names(arg$primary_id) - if(!is.null(arg$X.RIC)){ - if(substr(arg$X.RIC,1,1)==1) arg$X.RIC <- substr(arg$X.RIC,2,nchar(arg$X.RIC)) - } - if(!is.null(arg$RIC)){ - if(substr(arg$RIC,1,1)==1) arg$RIC <- substr(arg$RIC,2,nchar(arg$RIC)) - } - if(length(dotargs)) arg<-c(arg,dotargs) - if(is.function(try(match.fun(type),silent=TRUE))){ - out <- try(do.call(type,arg)) - #TODO recover gracefully? - } else { - # the call for a function named for type didn't work, so we'll try calling instrument as a generic - type=c(type,"instrument") - arg$type<-type # set the type - arg$assign_i<-TRUE # assign to the environment - try(do.call("instrument",arg)) - } - } else { - warning(filedata[rn,id_col]," already exists in the .instrument environment") - } # end instrument check + #TODO recover gracefully? + } else { + # the call for a function named for type didn't work, so we'll try calling instrument as a generic + type=c(type,"instrument") + arg$type<-type # set the type + arg$assign_i<-TRUE # assign to the environment + try(do.call("instrument",arg)) + } } # end loop on rows } Modified: pkg/FinancialInstrument/R/synthetic.R =================================================================== --- pkg/FinancialInstrument/R/synthetic.R 2013-05-26 14:22:55 UTC (rev 1472) +++ pkg/FinancialInstrument/R/synthetic.R 2013-05-26 23:30:38 UTC (rev 1473) @@ -14,7 +14,9 @@ #' @export #' @rdname synthetic.instrument -synthetic <- function(primary_id=NULL, currency=NULL, multiplier=1, identifiers = NULL, assign_i=TRUE, ..., members=NULL, type="synthetic") +synthetic <- function(primary_id=NULL, currency=NULL, multiplier=1, + identifiers=NULL, assign_i=TRUE, overwrite=TRUE, ..., + members=NULL, type="synthetic") { if (missing(primary_id) || (is.null(primary_id))) primary_id <- make_spread_id(members) if (missing(currency) || (is.null(currency))) { @@ -25,7 +27,10 @@ if (is.instrument(instr)) currency <- instr$currency } } - instrument(primary_id=primary_id , currency=currency , multiplier=multiplier , identifiers = identifiers, assign_i=assign_i, ...=..., type=type, members=members) + instrument(primary_id=primary_id , currency=currency , + multiplier=multiplier , identifiers = identifiers, + assign_i=assign_i, overwrite=overwrite, ...=..., type=type, + members=members) } @@ -69,7 +74,11 @@ #' @param assign_i TRUE/FALSE. Should the instrument be assigned in the \code{.instrument} environment? #' @param type type of instrument; wrappers do not require this. #' @param root_id instrument identifier for the root contract, default NULL -#' @param suffix_id identifiers for the member contract suffixes, default NULL, will be split as \code{members}, see Details +#' @param suffix_id identifiers for the member contract suffixes, default NULL, +#' will be split as \code{members}, see Details +#' @param overwrite if FALSE and an instrument with the same \code{primary_id} +#' is already defined, an error will be thrown and no instruments will be +#' created. #' @return called for side effect. stores an instrument in .instrument environment #' @author Brian Peterson, Garrett See #' @seealso instrument, future, option_series.yahoo @@ -81,8 +90,11 @@ #' spread('SPY.DIA','USD',c('SPY','DIA'),c(1,-1)) #' } #' @export -synthetic.instrument <- function (primary_id, currency, members, memberratio, ..., multiplier = 1, tick_size=NULL, - identifiers = NULL, assign_i=TRUE, type = c("synthetic.instrument", "synthetic")) +synthetic.instrument <- function (primary_id, currency, members, + memberratio, ..., multiplier = 1, + tick_size=NULL, identifiers = NULL, + assign_i=TRUE, + type = c("synthetic.instrument", "synthetic")) { dargs <- list(...) if (!is.list(members)) { @@ -93,10 +105,10 @@ currencies = vector(), memberpositions = NULL) for (member in members) { tmp_instr <- try(getInstrument(member, silent=TRUE)) - if (inherits(tmp_instr, "try-error") | !is.instrument(tmp_instr)) { + if (inherits(tmp_instr, "try-error") | !is.instrument(tmp_instr)) { if(missing(currency) || is.null(currency)) { - stop("'currency' must be provided if member instruments are not defined") - warning(paste("Instrument", member, "not found, using currency of", currency)) + stop("'currency' must be provided if member instruments are not defined") + warning(paste("Instrument", member, "not found, using currency of", currency)) } memberlist$currencies[member] <- currency } @@ -117,8 +129,7 @@ dargs$expires <- expires } } - } - else { + } else { warning("passing in members as a list not fully tested") if (all(do.call(c, lapply(members, is.instrument)))) { #if members is a list of instruments instrlist <- members @@ -143,18 +154,19 @@ primary_id <- make_spread_id(members) if (missing(currency) || is.null(currency)) currency <- as.character(memberlist$currencies[1]) - + synthetic(primary_id = primary_id, currency = currency, multiplier = multiplier, [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/blotter -r 1473 From noreply at r-forge.r-project.org Mon May 27 04:11:45 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 27 May 2013 04:11:45 +0200 (CEST) Subject: [Blotter-commits] r1474 - in pkg/FinancialInstrument: . R inst/tests Message-ID: <20130527021146.065531812A2@r-forge.r-project.org> Author: gsee Date: 2013-05-27 04:11:44 +0200 (Mon, 27 May 2013) New Revision: 1474 Added: pkg/FinancialInstrument/inst/tests/test-instrument.R Modified: pkg/FinancialInstrument/NEWS pkg/FinancialInstrument/R/instrument.R Log: - the sapply() calls in the instrument wrappers now use simplify=FALSE is assign_i is FALSE so that a list of instruments is returned. Named lists of instruments are easy to work with since they can be passed directly to (re)loadInstruments(), or coerced to an environment with as.environment() - added some tests Modified: pkg/FinancialInstrument/NEWS =================================================================== --- pkg/FinancialInstrument/NEWS 2013-05-26 23:30:38 UTC (rev 1473) +++ pkg/FinancialInstrument/NEWS 2013-05-27 02:11:44 UTC (rev 1474) @@ -43,6 +43,14 @@ uses the "%m" format in the as.Date call instead of using the month name with the (locale-specific) "%b" format. Thanks to Alexis Petit for the patch. +* when instrument() wrappers were called with vectors of symbols and + assign_i=FALSE, the symbols were being returned instead of the instrument + objects. Now, when `assign_i=FALSE` and `length(primary_id) > 1`, a + named list of instruments will be returned. Named lists of instruments are + easy to work with since they can be passed directly to (re)loadInstruments(), + or coerced to an environment with as.environment() + + TESTS ----- Modified: pkg/FinancialInstrument/R/instrument.R =================================================================== --- pkg/FinancialInstrument/R/instrument.R 2013-05-26 23:30:38 UTC (rev 1473) +++ pkg/FinancialInstrument/R/instrument.R 2013-05-27 02:11:44 UTC (rev 1474) @@ -264,9 +264,11 @@ call.=FALSE) } if (length(primary_id) > 1) { - return(unname(sapply(primary_id, stock, currency=currency, - multiplier=multiplier, tick_size=tick_size, - identifiers=identifiers, ...=...))) + out <- sapply(primary_id, stock, currency=currency, + multiplier=multiplier, tick_size=tick_size, + identifiers=identifiers, assign_i=assign_i, + ...=..., simplify=assign_i) + return(if (assign_i) unname(out) else out) } instrument(primary_id=primary_id, currency=currency, multiplier=multiplier, tick_size=tick_size, identifiers = identifiers, ..., @@ -287,9 +289,13 @@ paste(intersect(primary_id, li), collapse=", ")), call.=FALSE) } - if (length(primary_id) > 1) return(unname(sapply(primary_id, fund, - currency=currency, multiplier=multiplier, tick_size=tick_size, - identifiers=identifiers, ...=...))) + if (length(primary_id) > 1) { + out <- sapply(primary_id, fund, currency=currency, + multiplier=multiplier, tick_size=tick_size, + identifiers=identifiers, assign_i=assign_i, ...=..., + simplify=assign_i) + return(if (assign_i) unname(out) else out) + } instrument(primary_id=primary_id, currency=currency, multiplier=multiplier, tick_size=tick_size, identifiers=identifiers, ..., type="fund", assign_i=assign_i) @@ -429,10 +435,11 @@ paste(intersect(primary_id, li), collapse=", ")), call.=FALSE) } - return(unname(sapply(primary_id, future_series, - root_id=root_id, suffix_id=suffix_id, first_traded=first_traded, - expires=expires, identifiers = identifiers, assign_i=assign_i, - ...=...))) + out <- sapply(primary_id, future_series, root_id=root_id, + suffix_id=suffix_id, first_traded=first_traded, + expires=expires, identifiers = identifiers, + assign_i=assign_i, ...=..., simplify=assign_i) + return(if (assign_i) unname(out) else out) } else if (is.null(root_id) && !is.null(suffix_id) && parse_id(primary_id)$type == 'root') { #if we have primary_id, but primary_id looks like a root_id, and we have @@ -597,10 +604,12 @@ stop(paste("'first_traded' and 'expires' must be NULL", "if calling with multiple primary_ids")) } - return(unname(sapply(primary_id, option_series, - root_id=root_id, suffix_id=suffix_id, first_traded=first_traded, - expires=expires, callput=callput, strike=strike, - identifiers=identifiers, assign_i=assign_i, ...=...))) + out <- sapply(primary_id, option_series, root_id=root_id, + suffix_id=suffix_id, first_traded=first_traded, + expires=expires, callput=callput, strike=strike, + identifiers=identifiers, assign_i=assign_i, ...=..., + simplify=assign_i) + return(if (assign_i) unname(out) else out) } else if (is.null(root_id) && !is.null(suffix_id) && parse_id(primary_id)$type == 'root') { #if we have primary_id, but primary_id looks like a root_id, and we @@ -809,8 +818,9 @@ } } if (length(primary_id) > 1) { - return(unname(sapply(primary_id, currency, - identifiers=identifiers, ...=...))) + out <- sapply(primary_id, currency, identifiers=identifiers, + assign_i=assign_i, ...=..., simplify=assign_i) + return(if (assign_i) unname(out) else out) } if (is.null(identifiers)) identifiers <- list() ccy <- try(getInstrument(primary_id,type='currency',silent=TRUE)) @@ -903,8 +913,9 @@ } if (length(primary_id) > 1) { - return(unname(sapply(primary_id, exchange_rate, identifiers=identifiers, - ...=...))) + out <- sapply(primary_id, exchange_rate, identifiers=identifiers, + assign_i=assign_i, ...=..., simplify=assign_i) + return(if (assign_i) unname(out) else out) } if (is.null(currency)) currency <- substr(primary_id,4,6) if (is.null(counter_currency)) counter_currency <- substr(primary_id,1,3) Added: pkg/FinancialInstrument/inst/tests/test-instrument.R =================================================================== --- pkg/FinancialInstrument/inst/tests/test-instrument.R (rev 0) +++ pkg/FinancialInstrument/inst/tests/test-instrument.R 2013-05-27 02:11:44 UTC (rev 1474) @@ -0,0 +1,27 @@ +context("instruments") + +test_that("stock creates stock", { + # stock is created and assigned in .instrument environment and the primary_id + # of the stock is returned. + expect_is(stock("AAA", currency("USD")), "character") + expect_is(getInstrument("AAA", type="stock"), "stock") + expect_true(is.null(names(stock(c("AAA", "BBB"), "USD")))) +}) + +test_that("stock not assigned", { + # overwrite=FALSE is ignored because assign_i=FALSE + s <- c("BBB", "AAA") + ilist <- stock(s, "USD", assign_i=FALSE, overwrite=FALSE) + expect_is(ilist, "list") + expect_true(all(vapply(ilist, inherits, FUN.VALUE=TRUE, "stock"))) + expect_identical(names(ilist), s) +}) + +test_that("stock overwrite throws errors", { + expect_error(stock("AAA", "USD", overwrite=FALSE)) + rm_stocks("BBB") + expect_error(stock(c("BBB", "AAA"), "USD", overwrite=FALSE)) + # Make sure it didn't define BBB + expect_true(!getInstrument("BBB", type="stock", silent=TRUE)) +}) + From noreply at r-forge.r-project.org Mon May 27 04:43:06 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 27 May 2013 04:43:06 +0200 (CEST) Subject: [Blotter-commits] r1475 - in pkg/FinancialInstrument: . R inst/tests Message-ID: <20130527024306.DD314184EAF@r-forge.r-project.org> Author: gsee Date: 2013-05-27 04:43:06 +0200 (Mon, 27 May 2013) New Revision: 1475 Modified: pkg/FinancialInstrument/NEWS pkg/FinancialInstrument/R/saveInstruments.R pkg/FinancialInstrument/inst/tests/test-instrument.R Log: When loadInstruments() is called with a list, it now assigns instruments to their primary_ids found in the instrument instead of to the names of the list. In addition to being safer, this allows for unnamed lists to be read as easily as named lists. Modified: pkg/FinancialInstrument/NEWS =================================================================== --- pkg/FinancialInstrument/NEWS 2013-05-27 02:11:44 UTC (rev 1474) +++ pkg/FinancialInstrument/NEWS 2013-05-27 02:43:06 UTC (rev 1475) @@ -23,6 +23,8 @@ pass the names of columns that are to be used as identifiers instead of as normal instrument attributes. Thanks to Charlie Friedemann for the patch. +* loadInstruments() can now load unnamed lists of instruments because it now + uses the primary_ids directly instead of the names of the list/environment BUG FIXES --------- Modified: pkg/FinancialInstrument/R/saveInstruments.R =================================================================== --- pkg/FinancialInstrument/R/saveInstruments.R 2013-05-27 02:11:44 UTC (rev 1474) +++ pkg/FinancialInstrument/R/saveInstruments.R 2013-05-27 02:43:06 UTC (rev 1475) @@ -93,9 +93,13 @@ require("utils") if (is.environment(file_name) || is.list(file_name)) { ilist <- as.list(file_name) + if (!all(vapply(ilist, function(x) length(x[["primary_id"]]) == 1L, + TRUE))) { + stop("all instruments must have exactly one primary_id") + } for (i in seq_along(ilist)) { - assign(names(ilist)[i], ilist[[i]], - pos=FinancialInstrument:::.instrument) + assign(ilist[[i]][["primary_id"]], ilist[[i]], + pos=FinancialInstrument:::.instrument) } return(invisible(NULL)) } Modified: pkg/FinancialInstrument/inst/tests/test-instrument.R =================================================================== --- pkg/FinancialInstrument/inst/tests/test-instrument.R 2013-05-27 02:11:44 UTC (rev 1474) +++ pkg/FinancialInstrument/inst/tests/test-instrument.R 2013-05-27 02:43:06 UTC (rev 1475) @@ -25,3 +25,15 @@ expect_true(!getInstrument("BBB", type="stock", silent=TRUE)) }) +test_that("loadInstruments from list", { + rm_instruments(keep.currencies=FALSE) + stock(c("A", "B"), currency("USD")) # put some stuff in the .instrument env + L <- stock(c("DD", "EE"), "USD", assign_i=FALSE) + expect_true(!is.instrument.name("DD")) + loadInstruments(L) + expect_true(is.instrument.name("DD")) + expect_true(is.instrument.name("A")) + reloadInstruments(L) + expect_true(!is.instrument.name("A")) + expect_true(is.instrument.name("DD")) +}) \ No newline at end of file From noreply at r-forge.r-project.org Mon May 27 17:50:28 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 27 May 2013 17:50:28 +0200 (CEST) Subject: [Blotter-commits] r1476 - in pkg/FinancialInstrument: . R inst man Message-ID: <20130527155029.0363C1850D6@r-forge.r-project.org> Author: gsee Date: 2013-05-27 17:50:28 +0200 (Mon, 27 May 2013) New Revision: 1476 Added: pkg/FinancialInstrument/inst/THANKS Modified: pkg/FinancialInstrument/DESCRIPTION pkg/FinancialInstrument/R/FinancialInstrument-package.R pkg/FinancialInstrument/man/FinancialInstrument-package.Rd Log: move Contributors (which is not a valid DESCRIPTION field) to a new THANKS file. Modified: pkg/FinancialInstrument/DESCRIPTION =================================================================== --- pkg/FinancialInstrument/DESCRIPTION 2013-05-27 02:43:06 UTC (rev 1475) +++ pkg/FinancialInstrument/DESCRIPTION 2013-05-27 15:50:28 UTC (rev 1476) @@ -6,7 +6,6 @@ Type: Package LazyLoad: yes Author: Peter Carl, Brian G. Peterson, Garrett See -Contributors: Dirk Eddelbuettel, Alexis Petit, Jeffrey Ryan, Joshua Ulrich Description: Infrastructure for defining meta-data and relationships for financial instruments. Version: 1.1.9 Modified: pkg/FinancialInstrument/R/FinancialInstrument-package.R =================================================================== --- pkg/FinancialInstrument/R/FinancialInstrument-package.R 2013-05-27 02:43:06 UTC (rev 1475) +++ pkg/FinancialInstrument/R/FinancialInstrument-package.R 2013-05-27 15:50:28 UTC (rev 1476) @@ -102,13 +102,10 @@ #' @docType package #' @author #' Peter Carl, -#' Dirk Eddelbuettel, #' Brian G. Peterson, -#' Jeffrey Ryan, #' Garrett See, -#' Joshua Ulrich #' -#' Maintainer: Garrett See \email{gsee000@@gmail.com} +#' Maintainer: G See \email{gsee000@@gmail.com} #' @keywords package #' @seealso #' \code{\link[xts:xts-package]{xts}}, Added: pkg/FinancialInstrument/inst/THANKS =================================================================== --- pkg/FinancialInstrument/inst/THANKS (rev 0) +++ pkg/FinancialInstrument/inst/THANKS 2013-05-27 15:50:28 UTC (rev 1476) @@ -0,0 +1,9 @@ +The authors of FinancialInstrument would like to thank the following for their +code contributions, testing, discussions and feedback: + Dirk Eddelbuettel + Charlie Friedeman + Ilya Kipnis + Lance Levenson + Alexis Petit + Jeffrey Ryan + Joshua Ulrich \ No newline at end of file Modified: pkg/FinancialInstrument/man/FinancialInstrument-package.Rd =================================================================== --- pkg/FinancialInstrument/man/FinancialInstrument-package.Rd 2013-05-27 02:43:06 UTC (rev 1475) +++ pkg/FinancialInstrument/man/FinancialInstrument-package.Rd 2013-05-27 15:50:28 UTC (rev 1476) @@ -261,10 +261,9 @@ } } \author{ - Peter Carl, Dirk Eddelbuettel, Brian G. Peterson, Jeffrey - Ryan, Garrett See, Joshua Ulrich + Peter Carl, Brian G. Peterson, Garrett See, - Maintainer: Garrett See \email{gsee000 at gmail.com} + Maintainer: G See \email{gsee000 at gmail.com} } \seealso{ \code{\link[xts:xts-package]{xts}}, From noreply at r-forge.r-project.org Mon May 27 19:00:35 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 27 May 2013 19:00:35 +0200 (CEST) Subject: [Blotter-commits] r1477 - pkg/FinancialInstrument/R Message-ID: <20130527170035.B7F90183C2F@r-forge.r-project.org> Author: gsee Date: 2013-05-27 19:00:35 +0200 (Mon, 27 May 2013) New Revision: 1477 Modified: pkg/FinancialInstrument/R/instrument.R Log: replace paste0 with paste(..., sep="") Modified: pkg/FinancialInstrument/R/instrument.R =================================================================== --- pkg/FinancialInstrument/R/instrument.R 2013-05-27 15:50:28 UTC (rev 1476) +++ pkg/FinancialInstrument/R/instrument.R 2013-05-27 17:00:35 UTC (rev 1477) @@ -256,10 +256,10 @@ if (is.null(currency)) stop ("'currency' is a required argument") if (!isTRUE(overwrite) && isTRUE(assign_i) && any(in.use <- primary_id %in% (li <- ls_instruments()))) { - stop(paste(paste0("In stock(...) : ", + stop(paste(paste("In stock(...) : ", "overwrite is FALSE and primary_id", if (sum(in.use) > 1) "s are" else " is", - " already in use:\n"), + " already in use:\n", sep=""), paste(intersect(primary_id, li), collapse=", ")), call.=FALSE) } @@ -282,10 +282,10 @@ if (is.null(currency)) stop ("'currency' is a required argument") if (!isTRUE(overwrite) && isTRUE(assign_i) && any(in.use <- primary_id %in% (li <- ls_instruments()))) { - stop(paste(paste0("In fund(...) : ", + stop(paste(paste("In fund(...) : ", "overwrite is FALSE and primary_id", if (sum(in.use) > 1) "s are" else " is", - " already in use:\n"), + " already in use:\n", sep=""), paste(intersect(primary_id, li), collapse=", ")), call.=FALSE) } @@ -751,10 +751,10 @@ if (!isTRUE(overwrite)) { new.ids <- unname((u <- unlist(id.list))[grep("primary_id", names(u))]) if (any(in.use <- new.ids %in% (li <- ls_instruments()))) { - stop(paste(paste0("In option_series.yahoo(...) : ", + stop(paste(paste("In option_series.yahoo(...) : ", "overwrite is FALSE and primary_id", if (sum(in.use) > 1) "s are" else " is", - " already in use:\n"), + " already in use:\n", sep=""), paste(intersect(new.ids, li), collapse=", ")), call.=FALSE) } @@ -809,10 +809,10 @@ if (hasArg("overwrite")) { if (!list(...)$overwrite && isTRUE(assign_i) && any(in.use <- primary_id %in% (li <- ls_instruments()))) { - stop(paste(paste0("In currency(...) : ", + stop(paste(paste("In currency(...) : ", "overwrite is FALSE and primary_id", if (sum(in.use) > 1) "s are" else " is", - " already in use:\n"), + " already in use:\n", sep=""), paste(intersect(primary_id, li), collapse=", ")), call.=FALSE) } @@ -904,10 +904,10 @@ } if (!isTRUE(overwrite) && isTRUE(assign_i) && any(in.use <- primary_id %in% (li <- ls_instruments()))) { - stop(paste(paste0("In exchange_rate(...) : ", + stop(paste(paste("In exchange_rate(...) : ", "overwrite is FALSE and primary_id", if (sum(in.use) > 1) "s are" else " is", - " already in use:\n"), + " already in use:\n", sep=""), paste(intersect(primary_id, li), collapse=", ")), call.=FALSE) }