[Blotter-commits] r1230 - pkg/quantstrat/demo

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Oct 23 01:21:13 CEST 2012


Author: opentrades
Date: 2012-10-23 01:21:13 +0200 (Tue, 23 Oct 2012)
New Revision: 1230

Added:
   pkg/quantstrat/demo/luxor.StopLoss.R
   pkg/quantstrat/demo/luxor.StopTrailing.R
   pkg/quantstrat/demo/luxor.TakeProfit.R
   pkg/quantstrat/demo/luxor.exits.R
Modified:
   pkg/quantstrat/demo/luxor.orderchains.R
Log:
minor changes to orderchains.R
added some demo's:
- luxor.exits.R contains code for the paramsets
- luxor.StopLoss.R computes stop-loss paramset
- luxor.StopTrailing.R computes stop-trailing-loss paramset
- luxor.TakeProfit.R computes take-profit paramset



Added: pkg/quantstrat/demo/luxor.StopLoss.R
===================================================================
--- pkg/quantstrat/demo/luxor.StopLoss.R	                        (rev 0)
+++ pkg/quantstrat/demo/luxor.StopLoss.R	2012-10-22 23:21:13 UTC (rev 1230)
@@ -0,0 +1,23 @@
+
+source('luxor.exits.R')
+
+############################
+
+require(foreach)
+
+registerDoSEQ()
+
+#require(doMC)
+#registerDoMC(cores=2)
+
+#require(doParallel)
+#registerDoParallel(cores=2)
+
+#require(doRedis)
+#registerDoRedis('jobs')
+
+############################
+
+results <- apply.paramset(s, paramset.label='StopLoss', portfolio.st=p, verbose=TRUE)
+
+print(results$tradeStats)

Added: pkg/quantstrat/demo/luxor.StopTrailing.R
===================================================================
--- pkg/quantstrat/demo/luxor.StopTrailing.R	                        (rev 0)
+++ pkg/quantstrat/demo/luxor.StopTrailing.R	2012-10-22 23:21:13 UTC (rev 1230)
@@ -0,0 +1,23 @@
+
+source('luxor.exits.R')
+
+############################
+
+require(foreach)
+
+registerDoSEQ()
+
+#require(doMC)
+#registerDoMC(cores=2)
+
+#require(doParallel)
+#registerDoParallel(cores=2)
+
+#require(doRedis)
+#registerDoRedis('jobs')
+
+############################
+
+results <- apply.paramset(s, paramset.label='StopTrailing', portfolio.st=p, verbose=TRUE)
+
+print(results$tradeStats)

Added: pkg/quantstrat/demo/luxor.TakeProfit.R
===================================================================
--- pkg/quantstrat/demo/luxor.TakeProfit.R	                        (rev 0)
+++ pkg/quantstrat/demo/luxor.TakeProfit.R	2012-10-22 23:21:13 UTC (rev 1230)
@@ -0,0 +1,23 @@
+
+source('luxor.exits.R')
+
+############################
+
+require(foreach)
+
+registerDoSEQ()
+
+#require(doMC)
+#registerDoMC(cores=2)
+
+#require(doParallel)
+#registerDoParallel(cores=2)
+
+#require(doRedis)
+#registerDoRedis('jobs')
+
+############################
+
+results <- apply.paramset(s, paramset.label='TakeProfit', portfolio.st=p, verbose=TRUE)
+
+print(results$tradeStats)

Added: pkg/quantstrat/demo/luxor.exits.R
===================================================================
--- pkg/quantstrat/demo/luxor.exits.R	                        (rev 0)
+++ pkg/quantstrat/demo/luxor.exits.R	2012-10-22 23:21:13 UTC (rev 1230)
@@ -0,0 +1,121 @@
+#!/usr/bin/Rscript --vanilla
+
+.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
+
+#require(quantstrat)
+
+source('luxor.orderchains.R')
+
+s<-getStrategy('luxor')
+
+### SMA paramset
+
+s<-add.distribution(s,
+	paramset.label = 'SMA',
+	component.type = 'indicator',
+	component.label = 'nFast',
+	variable = list(n = .FastSMA),
+	label = 'nFAST'
+)
+
+s<-add.distribution(s,
+	paramset.label = 'SMA',
+	component.type = 'indicator',
+	component.label = 'nSlow',
+	variable = list(n = .SlowSMA),
+	label = 'nSLOW'
+)
+
+s<-add.constraint(s,
+	paramset.label = 'SMA',
+	distribution.label.1 = 'nFAST',
+	distribution.label.2 = 'nSLOW',
+	operator = '<',
+	label = 'SMA'
+)
+
+### Stop Loss paramset
+
+s<-add.distribution(s,
+	paramset.label = 'StopLoss',
+	component.type = 'chain',
+	component.label = 'StopLossLONG',
+	variable = list(threshold = .StopLoss),
+	label = 'StopLossLONG'
+)
+
+s<-add.distribution(s,
+	paramset.label = 'StopLoss',
+	component.type = 'chain',
+	component.label = 'StopLossSHORT',
+	variable = list(threshold = .StopLoss),
+	label = 'StopLossSHORT'
+)
+
+s<-add.constraint(s,
+	paramset.label = 'StopLoss',
+	distribution.label.1 = 'StopLossLONG',
+	distribution.label.2 = 'StopLossSHORT',
+	operator = '==',
+	label = 'StopLoss'
+)
+
+### Stop Trailing paramset
+
+s<-add.distribution(s,
+	paramset.label = 'StopTrailing',
+	component.type = 'chain',
+	component.label = 'StopTrailingLONG',
+	variable = list(threshold = .StopTrailing),
+	label = 'StopTrailingLONG'
+)
+
+s<-add.distribution(s,
+	paramset.label = 'StopTrailing',
+	component.type = 'chain',
+	component.label = 'StopTrailingSHORT',
+	variable = list(threshold = .StopTrailing),
+	label = 'StopTrailingSHORT'
+)
+
+s<-add.constraint(s,
+	paramset.label = 'StopTrailing',
+	distribution.label.1 = 'StopTrailingLONG',
+	distribution.label.2 = 'StopTrailingSHORT',
+	operator = '==',
+	label = 'StopTrailing'
+)
+
+### Take Profit paramset
+
+s<-add.distribution(s,
+	paramset.label = 'TakeProfit',
+	component.type = 'chain',
+	component.label = 'TakeProfitLONG',
+	variable = list(threshold = .TakeProfit),
+	label = 'TakeProfitLONG'
+)
+
+s<-add.distribution(s,
+	paramset.label = 'TakeProfit',
+	component.type = 'chain',
+	component.label = 'TakeProfitSHORT',
+	variable = list(threshold = .TakeProfit),
+	label = 'TakeProfitSHORT'
+)
+
+s<-add.constraint(s,
+	paramset.label = 'TakeProfit',
+	distribution.label.1 = 'TakeProfitLONG',
+	distribution.label.2 = 'TakeProfitSHORT',
+	operator = '==',
+	label = 'TakeProfit'
+)
+

Modified: pkg/quantstrat/demo/luxor.orderchains.R
===================================================================
--- pkg/quantstrat/demo/luxor.orderchains.R	2012-10-22 22:29:09 UTC (rev 1229)
+++ pkg/quantstrat/demo/luxor.orderchains.R	2012-10-22 23:21:13 UTC (rev 1230)
@@ -6,7 +6,6 @@
 #
 # 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
 
 options(width = 240)
 #Sys.setenv(TZ="GMT")



More information about the Blotter-commits mailing list