From noreply at r-forge.r-project.org Sat Feb 2 22:44:39 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 2 Feb 2013 22:44:39 +0100 (CET) Subject: [Blotter-commits] r1386 - in pkg/FinancialInstrument: . R inst/tests Message-ID: <20130202214439.79133184BAE@r-forge.r-project.org> Author: gsee Date: 2013-02-02 22:44:39 +0100 (Sat, 02 Feb 2013) New Revision: 1386 Added: pkg/FinancialInstrument/inst/tests/test-getSymbols.FI.R Modified: pkg/FinancialInstrument/NEWS pkg/FinancialInstrument/R/load.instruments.R Log: - if a Symbol was the same as the end of a directory, e.g. "BID" and "/data/BID" getSymbols.FI would assume the data are in "/data/BID" instead of "/data/BID/BID". I'm not sure why we were doing that; hopefully this doesn't break anything. - updated NEWS - added regression test Modified: pkg/FinancialInstrument/NEWS =================================================================== --- pkg/FinancialInstrument/NEWS 2013-01-28 22:04:22 UTC (rev 1385) +++ pkg/FinancialInstrument/NEWS 2013-02-02 21:44:39 UTC (rev 1386) @@ -1,6 +1,12 @@ Changes in Version 1.2 ====================== +BUG FIXES +--------- + +* If the end of dir was the same as Symbol, getSymbols.FI had trouble finding + the files. Test added. + TESTS ----- Modified: pkg/FinancialInstrument/R/load.instruments.R =================================================================== --- pkg/FinancialInstrument/R/load.instruments.R 2013-01-28 22:04:22 UTC (rev 1385) +++ pkg/FinancialInstrument/R/load.instruments.R 2013-02-02 21:44:39 UTC (rev 1386) @@ -399,8 +399,7 @@ Symbol <- ifelse(is.na(instr_str), make.names(Symbols[[i]]), instr_str) ndc<-nchar(dir) if(substr(dir,ndc,ndc)=='/') dir <- substr(dir,1,ndc-1) #remove trailing forward slash - ssd <- strsplit(dir,"/")[[1]] - if (identical(character(0), ssd) || (!identical(character(0), ssd) && ssd[length(ssd)] != Symbol)) dir <- paste(dir,Symbol,sep="/") + dir <- paste(dir, Symbol, sep="/") if(!dir=="" && !file.exists(dir)) { if (verbose) cat("\ndirectory ",dir," does not exist, skipping\n") Added: pkg/FinancialInstrument/inst/tests/test-getSymbols.FI.R =================================================================== --- pkg/FinancialInstrument/inst/tests/test-getSymbols.FI.R (rev 0) +++ pkg/FinancialInstrument/inst/tests/test-getSymbols.FI.R 2013-02-02 21:44:39 UTC (rev 1386) @@ -0,0 +1,15 @@ +context("getSymbols.FI") + +from <- as.Date('2012-01-01') +to <- from + 9 +BID <- xts(1:10, as.Date(from:to)) +tmpdir <- file.path(tempdir(), "BID") +saveSymbols.days("BID", tmpdir, extension="RData") +rm(BID) +# make sure getSymbols.FI works if the directory has the same name as the Symbol +test_that("getSymbols.FI base_dir=Symbol", { + expect_identical(NROW(getSymbols("BID", dir=tmpdir, + extension="RData", auto.assign=FALSE, + from=from, to=to, days_to_omit=NULL, + verbose=FALSE)), 10L) +}) From noreply at r-forge.r-project.org Sat Feb 2 22:54:11 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 2 Feb 2013 22:54:11 +0100 (CET) Subject: [Blotter-commits] r1387 - pkg/FinancialInstrument/inst/tests Message-ID: <20130202215411.75C9018491A@r-forge.r-project.org> Author: gsee Date: 2013-02-02 22:54:11 +0100 (Sat, 02 Feb 2013) New Revision: 1387 Modified: pkg/FinancialInstrument/inst/tests/test-getSymbols.FI.R Log: - add src=FI to getSymbols call in getSymbols.FI test. - put data in a its own environment in test - bump version Modified: pkg/FinancialInstrument/inst/tests/test-getSymbols.FI.R =================================================================== --- pkg/FinancialInstrument/inst/tests/test-getSymbols.FI.R 2013-02-02 21:44:39 UTC (rev 1386) +++ pkg/FinancialInstrument/inst/tests/test-getSymbols.FI.R 2013-02-02 21:54:11 UTC (rev 1387) @@ -2,13 +2,14 @@ from <- as.Date('2012-01-01') to <- from + 9 -BID <- xts(1:10, as.Date(from:to)) +tmpenv <- new.env() +tmpenv$BID <- xts(1:10, as.Date(from:to)) tmpdir <- file.path(tempdir(), "BID") -saveSymbols.days("BID", tmpdir, extension="RData") -rm(BID) +dir.create(tmpdir, showWarnings=FALSE) +saveSymbols.days("BID", tmpdir, extension="RData", env=tmpenv) # make sure getSymbols.FI works if the directory has the same name as the Symbol test_that("getSymbols.FI base_dir=Symbol", { - expect_identical(NROW(getSymbols("BID", dir=tmpdir, + expect_identical(NROW(getSymbols("BID", src="FI", dir=tmpdir, extension="RData", auto.assign=FALSE, from=from, to=to, days_to_omit=NULL, verbose=FALSE)), 10L) From noreply at r-forge.r-project.org Sat Feb 2 22:54:50 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 2 Feb 2013 22:54:50 +0100 (CET) Subject: [Blotter-commits] r1388 - pkg/FinancialInstrument Message-ID: <20130202215450.21E781842FC@r-forge.r-project.org> Author: gsee Date: 2013-02-02 22:54:49 +0100 (Sat, 02 Feb 2013) New Revision: 1388 Modified: pkg/FinancialInstrument/DESCRIPTION Log: bump version (forgot to save DESCRIPTION file in last commit) Modified: pkg/FinancialInstrument/DESCRIPTION =================================================================== --- pkg/FinancialInstrument/DESCRIPTION 2013-02-02 21:54:11 UTC (rev 1387) +++ pkg/FinancialInstrument/DESCRIPTION 2013-02-02 21:54:49 UTC (rev 1388) @@ -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.2 +Version: 1.1.3 URL: https://r-forge.r-project.org/projects/blotter/ -Date: 2012-12-12 +Date: 2013-02-02 Depends: R (>= 2.12.0), quantmod(>= 0.3-17), From noreply at r-forge.r-project.org Tue Feb 5 02:14:43 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 5 Feb 2013 02:14:43 +0100 (CET) Subject: [Blotter-commits] r1389 - in pkg/FinancialInstrument: . R Message-ID: <20130205011443.CA557184C57@r-forge.r-project.org> Author: gsee Date: 2013-02-05 02:14:43 +0100 (Tue, 05 Feb 2013) New Revision: 1389 Modified: pkg/FinancialInstrument/DESCRIPTION pkg/FinancialInstrument/NEWS pkg/FinancialInstrument/R/load.instruments.R Log: setSymbolLookup.FI does not append Symbol to file path. Please test. Modified: pkg/FinancialInstrument/DESCRIPTION =================================================================== --- pkg/FinancialInstrument/DESCRIPTION 2013-02-02 21:54:49 UTC (rev 1388) +++ pkg/FinancialInstrument/DESCRIPTION 2013-02-05 01:14:43 UTC (rev 1389) @@ -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.3 +Version: 1.1.4 URL: https://r-forge.r-project.org/projects/blotter/ Date: 2013-02-02 Depends: Modified: pkg/FinancialInstrument/NEWS =================================================================== --- pkg/FinancialInstrument/NEWS 2013-02-02 21:54:49 UTC (rev 1388) +++ pkg/FinancialInstrument/NEWS 2013-02-05 01:14:43 UTC (rev 1389) @@ -4,8 +4,12 @@ BUG FIXES --------- -* If the end of dir was the same as Symbol, getSymbols.FI had trouble finding - the files. Test added. +* setSymbolLookup.FI was appending the Symbol to the directory, and + getSymbols.FI was only adding the Symbol to the file path if the end of the + path was not the same as the Symbol. That meant that getSymbols.FI could not + be used to get data for a Symbol that was the same as the base directory. + getSymbols.FI now always appends the Symbol to the file path and + setSymbolLookup.FI does not append it to the base_dir. Test added. TESTS ----- Modified: pkg/FinancialInstrument/R/load.instruments.R =================================================================== --- pkg/FinancialInstrument/R/load.instruments.R 2013-02-02 21:54:49 UTC (rev 1388) +++ pkg/FinancialInstrument/R/load.instruments.R 2013-02-05 01:14:43 UTC (rev 1389) @@ -202,7 +202,7 @@ symbol<-list() symbol[[1]]<-params # construct $dir - symbol[[1]]$dir<-paste(base_dir,instr_str,sep=sepch) + symbol[[1]]$dir<-base_dir names(symbol)[1]<-instr new.symbols<-c(new.symbols,symbol) } From noreply at r-forge.r-project.org Thu Feb 7 18:26:39 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 7 Feb 2013 18:26:39 +0100 (CET) Subject: [Blotter-commits] r1390 - pkg/quantstrat/inst/tests Message-ID: <20130207172640.078CD184443@r-forge.r-project.org> Author: milktrader Date: 2013-02-07 18:26:39 +0100 (Thu, 07 Feb 2013) New Revision: 1390 Added: pkg/quantstrat/inst/tests/test_blotter_break.R Log: blotter test added to quantstrat framework for now Added: pkg/quantstrat/inst/tests/test_blotter_break.R =================================================================== --- pkg/quantstrat/inst/tests/test_blotter_break.R (rev 0) +++ pkg/quantstrat/inst/tests/test_blotter_break.R 2013-02-07 17:26:39 UTC (rev 1390) @@ -0,0 +1,62 @@ +# test_blotter_break.R +# test for breaking trade with another trade that day in blotter +# Author: Brian M Bielinski + +Sys.setenv(TZ = "GMT") +require(blotter) +require(testthat) + +port = "testBreak" +acct = "testBreak" +symbol = c("IBM") + +data(IBM) + +startDate = first(index(IBM)) +endDate = last(index(IBM)) + +lines = "date,shrs,price,symbol +2007-01-10,100,98.0,IBM +2007-01-16,-200,99.5,IBM +2007-01-16,150,99.45,IBM +2007-01-18,-50,99.0,IBM" +con = textConnection(lines) +tt.trades = read.csv(con, as.is = TRUE) + +tt.trades[,"date"] = make.time.unique(as.POSIXct(tt.trades[,"date"])) + +currency("USD") +stock(symbol,"USD") + +initPortf(port, + symbol, + initDate = startDate) +initAcct(port, + portfolios = c(port), + initDate = startDate, + initEq=10^6) + +for(i in 1:nrow(tt.trades)){ + addTxn(port,Symbol = tt.trades[i,"symbol"], + TxnDate = tt.trades[i,"date"], + TxnPrice = tt.trades[i,"price"], + TxnQty = tt.trades[i,"shrs"]) +} + +updatePortf(port) +updateAcct(acct) +updateEndEq(acct) + +context("check that breaking trade with another trade that day is accounted for correctly.") + +# should be flat +test_that("input trades position is flat", + expect_that(sum(tt.trades[,"shrs"]) == 0, is_true())) +test_that("recorded trades position in Txns is flat", + expect_that(sum(getTxns(port,"IBM")[,"Txn.Qty"]) == 0, is_true())) +test_that("times of the trades are unique", + expect_that(length(tt.trades[,"date"]) == length(unique(tt.trades[,"date"])),is_true())) +test_that("calculated position is flat", + expect_that(getPosQty(port,"IBM",Date = endDate) == 0, is_true())) + +#chart.Posn(port,"IBM") From noreply at r-forge.r-project.org Sun Feb 10 21:19:02 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 10 Feb 2013 21:19:02 +0100 (CET) Subject: [Blotter-commits] r1391 - in pkg/FinancialInstrument: . R inst/tests man Message-ID: <20130210201902.8F9B41847E3@r-forge.r-project.org> Author: gsee Date: 2013-02-10 21:19:02 +0100 (Sun, 10 Feb 2013) New Revision: 1391 Added: pkg/FinancialInstrument/inst/tests/test-redenominate.R Modified: pkg/FinancialInstrument/DESCRIPTION pkg/FinancialInstrument/NEWS pkg/FinancialInstrument/R/redenominate.R pkg/FinancialInstrument/man/redenominate.Rd Log: - redenominate will use old_base if provided; instrument's currency otherwise (instead of always using instrument's currency) - updated docs and NEWS - added tests Modified: pkg/FinancialInstrument/DESCRIPTION =================================================================== --- pkg/FinancialInstrument/DESCRIPTION 2013-02-07 17:26:39 UTC (rev 1390) +++ pkg/FinancialInstrument/DESCRIPTION 2013-02-10 20:19:02 UTC (rev 1391) @@ -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.4 +Version: 1.1.5 URL: https://r-forge.r-project.org/projects/blotter/ -Date: 2013-02-02 +Date: 2013-02-10 Depends: R (>= 2.12.0), quantmod(>= 0.3-17), Modified: pkg/FinancialInstrument/NEWS =================================================================== --- pkg/FinancialInstrument/NEWS 2013-02-07 17:26:39 UTC (rev 1390) +++ pkg/FinancialInstrument/NEWS 2013-02-10 20:19:02 UTC (rev 1391) @@ -11,6 +11,10 @@ getSymbols.FI now always appends the Symbol to the file path and setSymbolLookup.FI does not append it to the base_dir. Test added. +* In redenominate, if the object was a defined instrument, the currency in the + instrument object would be used even if the user passed a different currency + in the old_base argument. + TESTS ----- Modified: pkg/FinancialInstrument/R/redenominate.R =================================================================== --- pkg/FinancialInstrument/R/redenominate.R 2013-02-07 17:26:39 UTC (rev 1390) +++ pkg/FinancialInstrument/R/redenominate.R 2013-02-10 20:19:02 UTC (rev 1391) @@ -280,9 +280,10 @@ #' #' Redenominate (change the base of) an instrument #' -#' If \code{x} is the name of an instrument, old_base is not required -#' and will become whatever is in the currency slot of the instrument. -#' Otherwise, old_base must be provided. +#' If \code{old_base} is not provided, \code{x} must be the name of an +#' instrument (or an object with the name of a defined instrument) so that the +#' currency attribute of the instrument can be used. Otherwise, \code{old_base} +#' must be provided. #' #' If you want to convert to JPY something that is denominated in EUR, #' you must have data for the EURJPY (or JPYEUR) exchange rate. If you don't have @@ -327,7 +328,7 @@ if (is.null(old_base)) stop(paste("If old_base is not provided, ", Symbol, ' must be defined.', sep="")) mult <- 1 } else { - old_base <- instr$currency + if (is.null(old_base)) old_base <- instr$currency mult <- as.numeric(instr$multiplier) } if (is.character(x)) x <- get(Symbol,pos=env) Added: pkg/FinancialInstrument/inst/tests/test-redenominate.R =================================================================== --- pkg/FinancialInstrument/inst/tests/test-redenominate.R (rev 0) +++ pkg/FinancialInstrument/inst/tests/test-redenominate.R 2013-02-10 20:19:02 UTC (rev 1391) @@ -0,0 +1,45 @@ +context("redenominate") + +.dat <- new.env() + +currency(c("USD", "CCY")) +exchange_rate("USDCCY") +stock("xus", "USD") +stock("xcy", "CCY") + +with(.dat, { + xus <- xts(1:5, as.Date("2010-01-01")-5:1) + xcy <- xts(c(40, 45), as.Date("2010-01-01")-2:1) + USDCCY <- xts(c(10, 11, 9, 10, 12), as.Date("2010-01-01")-5:1) +}) + +test_that("convert TO USD", { + expect_equal(as.numeric(redenominate("xcy", "USD", env=.dat)), c(4.00, 3.75)) +}) +test_that("convert FROM USD", { + expect_equal(as.numeric(redenominate("xus", "CCY", env=.dat)), c(10, 22, 27, 40, 60)) +}) +test_that("xts instead of name", { + expect_equal(as.numeric(redenominate(.dat$xcy, "USD", "CCY", env=.dat)), c(4.00, 3.75)) +}) +test_that("uses currency from instrument if old_base is missing", { + expect_equal(as.numeric(redenominate("xus", "CCY", env=.dat)), c(10, 22, 27, 40, 60)) +}) +test_that("provided old_base overrides instrument", { + expect_equal(as.numeric(redenominate("xus", "CCY", "USD", env=.dat)), c(10, 22, 27, 40, 60)) +}) +test_that("no instrument defined", { + rm_instruments("xus") + expect_equal(as.numeric(redenominate("xus", "CCY", "USD", env=.dat)), c(10, 22, 27, 40, 60)) + expect_error(redenominate("xus", "CCY", env=.dat), "old_base is not provided") +}) +test_that("inverts FX if necessary", { + with.usdccy <- redenominate("xus", "CCY", "USD", env=.dat) + with(.dat, { + CCYUSD <- 1 / USDCCY + rm(USDCCY) + }) + expect_equal(with.usdccy, redenominate("xus", "CCY", "USD", env=.dat)) +}) + +# TODO: test mixing intraday and daily data \ No newline at end of file Modified: pkg/FinancialInstrument/man/redenominate.Rd =================================================================== --- pkg/FinancialInstrument/man/redenominate.Rd 2013-02-07 17:26:39 UTC (rev 1390) +++ pkg/FinancialInstrument/man/redenominate.Rd 2013-02-10 20:19:02 UTC (rev 1391) @@ -31,9 +31,11 @@ Redenominate (change the base of) an instrument } \details{ - If \code{x} is the name of an instrument, old_base is not - required and will become whatever is in the currency slot - of the instrument. Otherwise, old_base must be provided. + If \code{old_base} is not provided, \code{x} must be the + name of an instrument (or an object with the name of a + defined instrument) so that the currency attribute of the + instrument can be used. Otherwise, \code{old_base} must + be provided. If you want to convert to JPY something that is denominated in EUR, you must have data for the EURJPY (or From noreply at r-forge.r-project.org Sun Feb 10 23:22:31 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 10 Feb 2013 23:22:31 +0100 (CET) Subject: [Blotter-commits] r1392 - pkg/quantstrat/R Message-ID: <20130210222231.D1552184932@r-forge.r-project.org> Author: opentrades Date: 2013-02-10 23:22:31 +0100 (Sun, 10 Feb 2013) New Revision: 1392 Modified: pkg/quantstrat/R/parameters.R Log: - typo fix Modified: pkg/quantstrat/R/parameters.R =================================================================== --- pkg/quantstrat/R/parameters.R 2013-02-10 20:19:02 UTC (rev 1391) +++ pkg/quantstrat/R/parameters.R 2013-02-10 22:22:31 UTC (rev 1392) @@ -721,7 +721,7 @@ #} -#' Internal function used in applyParameter function for process constraints on relationship between two parameter values. Basicly is the same as sigComparison function in signal.R written by Brian, with miner change. +#' Internal function used in applyParameter function for process constraints on relationship between two parameter values. Basicly is the same as sigComparison function in signal.R written by Brian, with minor change. #' #' Currently, this function compares two columns. #' Patches to compare an arbitrary number of columns would be gladly accepted. From noreply at r-forge.r-project.org Tue Feb 12 17:37:51 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 12 Feb 2013 17:37:51 +0100 (CET) Subject: [Blotter-commits] r1393 - pkg/quantstrat/R Message-ID: <20130212163751.A2BB9183EBA@r-forge.r-project.org> Author: braverock Date: 2013-02-12 17:37:51 +0100 (Tue, 12 Feb 2013) New Revision: 1393 Modified: pkg/quantstrat/R/rules.R Log: - fix stoptrailing where order just needs to be moved, but does not cross - minor cleanup where lookups not needed - patch kudos to Joseph Dunn Modified: pkg/quantstrat/R/rules.R =================================================================== --- pkg/quantstrat/R/rules.R 2013-02-10 22:22:31 UTC (rev 1392) +++ pkg/quantstrat/R/rules.R 2013-02-12 16:37:51 UTC (rev 1393) @@ -470,7 +470,6 @@ trailorders<-grep('^stoptrailing$', ordersubset[oo.idx,'Order.Type']) for(torder in trailorders) { - dindex<-get.dindex() firsttime<-NULL neworders<-NULL onum<-oo.idx[torder] @@ -532,12 +531,10 @@ } tmpidx<-NULL if(any(move_order)){ - dindex<-get.dindex() #print(firsttime) # find first index where we would move an order orderidx<-first(which(move_order)) - if(is.null(tmpidx)) - tmpidx <- format(index(move_order[orderidx,]), "%Y-%m-%d %H:%M:%OS6") + tmpidx <- format(index(move_order[orderidx,]), "%Y-%m-%d %H:%M:%OS6") trailspan <- paste(format(firsttime, "%Y-%m-%d %H:%M:%OS6"),"::",tmpidx,sep='') #make sure we don't cross before then # use sigThreshold @@ -550,7 +547,7 @@ assign.dindex(c(get.dindex(),newidx)) } else { #if we don't cross, do this - moveidx<-index(mktdata[index(move_order[orderidx,]),which.i=TRUE]) + moveidx <- curIndex + orderidx - 1 assign.dindex(c(get.dindex(),moveidx)) } } # end any(move_order) check @@ -561,7 +558,6 @@ if(curIndex){ if(hasmktord) { curIndex <- curIndex+1 - dindex<-get.dindex() } else { dindex<-get.dindex() if (any(dindex > curIndex)) { From noreply at r-forge.r-project.org Tue Feb 12 19:55:56 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 12 Feb 2013 19:55:56 +0100 (CET) Subject: [Blotter-commits] r1394 - pkg/quantstrat/demo Message-ID: <20130212185556.C68F11802C8@r-forge.r-project.org> Author: braverock Date: 2013-02-12 19:55:56 +0100 (Tue, 12 Feb 2013) New Revision: 1394 Modified: pkg/quantstrat/demo/rocema.R Log: - fix ES definition for the demo, thanks to Joseph Dunn for noticing Modified: pkg/quantstrat/demo/rocema.R =================================================================== --- pkg/quantstrat/demo/rocema.R 2013-02-12 16:37:51 UTC (rev 1393) +++ pkg/quantstrat/demo/rocema.R 2013-02-12 18:55:56 UTC (rev 1394) @@ -62,7 +62,7 @@ currency('USD') -future('ES', "USD", multiplier=1000, tick_size=.25, exchange="Comex", description="SP500 Future") +future('ES', "USD", multiplier=50, tick_size=.25, exchange="CME Globex", description="SP500 Future") #setSymbolLookup.FI('~/R.symbols/', 'ES') setSymbolLookup.FI('../sandbox/', 'ES') From noreply at r-forge.r-project.org Tue Feb 12 20:21:19 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 12 Feb 2013 20:21:19 +0100 (CET) Subject: [Blotter-commits] r1395 - pkg/FinancialInstrument/R Message-ID: <20130212192119.36894183CA0@r-forge.r-project.org> Author: braverock Date: 2013-02-12 20:21:18 +0100 (Tue, 12 Feb 2013) New Revision: 1395 Modified: pkg/FinancialInstrument/R/saveInstruments.R Log: - change to use bzip2 compression, 10-20x improvement in size of stored file, loads correspondingly faster Modified: pkg/FinancialInstrument/R/saveInstruments.R =================================================================== --- pkg/FinancialInstrument/R/saveInstruments.R 2013-02-12 18:55:56 UTC (rev 1394) +++ pkg/FinancialInstrument/R/saveInstruments.R 2013-02-12 19:21:18 UTC (rev 1395) @@ -82,7 +82,7 @@ sink() #system(paste("cat", file.name)) #for debugging } - } else save(.instrument, file = file.name) + } else save(.instrument, file = file.name, compress='bzip2') } From noreply at r-forge.r-project.org Tue Feb 12 22:12:52 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 12 Feb 2013 22:12:52 +0100 (CET) Subject: [Blotter-commits] r1396 - in pkg/FinancialInstrument: . R man Message-ID: <20130212211252.33FCF184B1B@r-forge.r-project.org> Author: gsee Date: 2013-02-12 22:12:51 +0100 (Tue, 12 Feb 2013) New Revision: 1396 Modified: pkg/FinancialInstrument/DESCRIPTION pkg/FinancialInstrument/NEWS pkg/FinancialInstrument/R/saveInstruments.R pkg/FinancialInstrument/man/saveInstruments.Rd Log: saveInstruments gains a "compress" argument Modified: pkg/FinancialInstrument/DESCRIPTION =================================================================== --- pkg/FinancialInstrument/DESCRIPTION 2013-02-12 19:21:18 UTC (rev 1395) +++ pkg/FinancialInstrument/DESCRIPTION 2013-02-12 21:12:51 UTC (rev 1396) @@ -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.5 +Version: 1.1.6 URL: https://r-forge.r-project.org/projects/blotter/ -Date: 2013-02-10 +Date: 2013-02-12 Depends: R (>= 2.12.0), quantmod(>= 0.3-17), Modified: pkg/FinancialInstrument/NEWS =================================================================== --- pkg/FinancialInstrument/NEWS 2013-02-12 19:21:18 UTC (rev 1395) +++ pkg/FinancialInstrument/NEWS 2013-02-12 21:12:51 UTC (rev 1396) @@ -1,5 +1,9 @@ Changes in Version 1.2 ====================== +USER VISIBLE CHANGES +-------------------- +* saveInstruments() gains a "compress" argument to allow for different + compression than the default ("gzip") BUG FIXES --------- Modified: pkg/FinancialInstrument/R/saveInstruments.R =================================================================== --- pkg/FinancialInstrument/R/saveInstruments.R 2013-02-12 19:21:18 UTC (rev 1395) +++ pkg/FinancialInstrument/R/saveInstruments.R 2013-02-12 21:12:51 UTC (rev 1396) @@ -39,6 +39,7 @@ #' As an experimental feature, a \code{list} or \code{environment} can be passed #' to \code{file_name}. #' @param dir Directory of file (defaults to current working directory. ie. "") +#' @param compress argument passed to \code{\link{save}}, default is "gzip" #' @return Called for side-effect #' @author Garrett See #' @seealso save, load load.instrument define_stocks, define_futures, @@ -59,7 +60,7 @@ #' } #' @export #' @rdname saveInstruments -saveInstruments <- function(file_name="MyInstruments", dir="") { +saveInstruments <- function(file_name="MyInstruments", dir="", compress="gzip") { if (!is.null(dir) && !dir == "" && substr(dir,nchar(dir),nchar(dir)) != "/") dir <- paste(dir,"/",sep="") .instrument <- FinancialInstrument:::.instrument @@ -82,7 +83,7 @@ sink() #system(paste("cat", file.name)) #for debugging } - } else save(.instrument, file = file.name, compress='bzip2') + } else save(.instrument, file = file.name, compress=compress) } Modified: pkg/FinancialInstrument/man/saveInstruments.Rd =================================================================== --- pkg/FinancialInstrument/man/saveInstruments.Rd 2013-02-12 19:21:18 UTC (rev 1395) +++ pkg/FinancialInstrument/man/saveInstruments.Rd 2013-02-12 21:12:51 UTC (rev 1396) @@ -4,7 +4,8 @@ \alias{saveInstruments} \title{Save and Load all instrument definitions} \usage{ - saveInstruments(file_name = "MyInstruments", dir = "") + saveInstruments(file_name = "MyInstruments", dir = "", + compress = "gzip") loadInstruments(file_name = "MyInstruments", dir = "") @@ -18,6 +19,9 @@ \item{dir}{Directory of file (defaults to current working directory. ie. "")} + + \item{compress}{argument passed to \code{\link{save}}, + default is "gzip"} } \value{ Called for side-effect From noreply at r-forge.r-project.org Tue Feb 12 22:14:33 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 12 Feb 2013 22:14:33 +0100 (CET) Subject: [Blotter-commits] r1397 - pkg/quantstrat/R Message-ID: <20130212211433.CB7211847E6@r-forge.r-project.org> Author: gsee Date: 2013-02-12 22:14:33 +0100 (Tue, 12 Feb 2013) New Revision: 1397 Modified: pkg/quantstrat/R/initialize.R Log: typo fix in roxygen block (docs will be fixed on next roxygenize) Modified: pkg/quantstrat/R/initialize.R =================================================================== --- pkg/quantstrat/R/initialize.R 2013-02-12 21:12:51 UTC (rev 1396) +++ pkg/quantstrat/R/initialize.R 2013-02-12 21:14:33 UTC (rev 1397) @@ -14,7 +14,7 @@ #' on all symbols included in the \code{symbols} vector} #' \item{init.Portf}{if TRUE, will call \code{\link[blotter]{initPortf}} #' to initialize the portfolio object} -#' \item{init.Acct}{if TRUE, will call \code{\link[blotter]{initAccount}} +#' \item{init.Acct}{if TRUE, will call \code{\link[blotter]{initAcct}} #' to initialize the account object} #' \item{init.Orders}{if TRUE, will call \code{\link{initOrders}} #' to initialize the order book for this test} From noreply at r-forge.r-project.org Tue Feb 19 21:40:08 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 19 Feb 2013 21:40:08 +0100 (CET) Subject: [Blotter-commits] r1398 - pkg/blotter/R Message-ID: <20130219204008.1B90E184DFF@r-forge.r-project.org> Author: opentrades Date: 2013-02-19 21:40:06 +0100 (Tue, 19 Feb 2013) New Revision: 1398 Modified: pkg/blotter/R/perTradeStats.R Log: - removed format() in computing perTradeStats() timespan, now directly pasting 2 POSIXct objects i.o. unnecessary string conversion Modified: pkg/blotter/R/perTradeStats.R =================================================================== --- pkg/blotter/R/perTradeStats.R 2013-02-12 21:14:33 UTC (rev 1397) +++ pkg/blotter/R/perTradeStats.R 2013-02-19 20:40:06 UTC (rev 1398) @@ -71,8 +71,9 @@ # calculate information about each trade for(i in 1:length(trades$End)) { - timespan <- paste(format(trades$Start[[i]], "%Y-%m-%d %H:%M:%OS6"), - format(trades$End[[i]], "%Y-%m-%d %H:%M:%OS6"), sep="::") + #timespan <- paste(format(trades$Start[[i]], "%Y-%m-%d %H:%M:%OS6"), + #format(trades$End[[i]], "%Y-%m-%d %H:%M:%OS6"), sep="::") + timespan <- paste(trades$Start[[i]], trades$End[[i]], sep="/") trade <- posPL[timespan] From noreply at r-forge.r-project.org Thu Feb 21 10:57:58 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 21 Feb 2013 10:57:58 +0100 (CET) Subject: [Blotter-commits] r1399 - in pkg/quantstrat: R man Message-ID: <20130221095758.9AC32184E4C@r-forge.r-project.org> Author: opentrades Date: 2013-02-21 10:57:58 +0100 (Thu, 21 Feb 2013) New Revision: 1399 Modified: pkg/quantstrat/R/tradeGraphs.R pkg/quantstrat/man/tradeGraphs.Rd Log: - rewrite of tradeGraphs.R by Chinmay Patil - renamed fixed.params to params.filter and implemented as regular expression by Chinmay Patil Modified: pkg/quantstrat/R/tradeGraphs.R =================================================================== --- pkg/quantstrat/R/tradeGraphs.R 2013-02-19 20:40:06 UTC (rev 1398) +++ pkg/quantstrat/R/tradeGraphs.R 2013-02-21 09:57:58 UTC (rev 1399) @@ -2,7 +2,7 @@ #' #' @param stats a data frame generated by tradeStats() #' @param free.params a vector of length 2, containing the column names for the data to use on the x and z axes -#' @param fixed.params - not yet implemented +#' @param params.filter - a regular expression to reduce dimensions by filtering on certain columns #' @param statistics a vector containing the column names to produce graphs for #' @param title an optional title to be printed above each graph #' @return invisible -- called for side-effect @@ -11,70 +11,51 @@ #' tradeGraphs ( #' stats = stats, #' free.params = c("Param.indicator.1.nFast", "Param.indicator.2.nSlow"), -#' fixed.params = NULL, +#' params.filter = "Param.indicator.2.nSlow < 40 & Param.indicator.1.nFast > 5" #' statistics = c("Net.Trading.PL", "maxDrawdown", "Avg.Trade.PL", "Num.Trades") #' title = 'Luxor' #' ) #' } +#' @author Jan Humme, rewritten by Chinmay Patil #' @export -tradeGraphs <- function(stats, free.params, fixed.params = NULL, statistics, title = NULL) +tradeGraphs <- function(stats, free.params, params.filter = NULL, statistics, title = NULL) { - # TODO: implement fixed.params - # TODO: fix axes to use non scientific notation - # TODO: fix use of full rainbow for small fractions (eg. Profit.Factor, now only uses red) + # TODO: fix axes to use non scientific notation + # TODO: fix use of full rainbow for small fractions (eg. Profit.Factor, now only uses red) - if(!require(rgl, quietly=TRUE)) stop('The "rgl" package is required to use this function') + if(!require(reshape2, quietly=TRUE)) stop('The "reshape2" package is required to use this function') + + if(missing(stats)) stop('stats undefined') + + if(missing(free.params)) stop('free.params undefined') + if(length(free.params) != 2) stop('free.params must be a vector of length 2') + + if(missing(statistics)) stop('must specify at least one statistics column to draw graph') + + + var1 <- free.params[1] + var2 <- free.params[2] + + + for(statistic in statistics) { + + var3 <- statistic + + if (length(params.filter) == 0 ) { + data <- stats[,c(var1, var2, var3)] + } else { + data <- subset(stats, eval(parse(text=params.filter)), select = c(var1, var2, var3)) + } + x <- recast(data, as.formula(paste0(var1, " ~ ", var2)) , id.var=c(var1,var2), measure.var=c(var3))$labels[[1]][,1] + y <- recast(data, as.formula(paste0(var1, " ~ ", var2)) , id.var=c(var1,var2), measure.var=c(var3))$labels[[2]][,1] + z <- recast(data, as.formula(paste0(var1, " ~ ", var2)) , id.var=c(var1,var2), measure.var=c(var3))$data - if(missing(stats)) stop('stats undefined') + col <- heat.colors(length(z))[rank(z)] - if(missing(free.params)) stop('free.params undefined') - if(length(free.params) != 2) stop('free.params must be a vector of length 2') - - if(missing(statistics)) stop('must specify at least one statistics column to draw graph') - - # derive sizes from free parameters - - range.free.param.1 = range(stats[[free.params[1]]]) - min.free.param.1 = range.free.param.1[1] - max.free.param.1 = range.free.param.1[2] - - range.free.param.2 = range(stats[[free.params[2]]]) - min.free.param.2 = range.free.param.2[1] - max.free.param.2 = range.free.param.2[2] - - nrows = range.free.param.1[2] - range.free.param.1[1] + 1 - ncols = range.free.param.2[2] - range.free.param.2[1] + 1 - - # draw graph for each statistic - - for(statistic in statistics) - { - # fill data matrix - - graph.data <- matrix(NA, nrows, ncols) - - graph.data[cbind( - stats[[free.params[1]]] - min.free.param.1 + 1, - stats[[free.params[2]]] - min.free.param.2 + 1)] <- stats[[statistic]] - - # set up color vector - - range.statistic = range(stats[[statistic]]) - span.statistic = range.statistic[2] - range.statistic[1] + 1 - - colors <- rainbow(span.statistic)[graph.data - range.statistic[1] + 1] - - # draw graph - - rgl.open() - rgl.surface(x=min.free.param.1:max.free.param.1, z=min.free.param.2:max.free.param.2, y=graph.data, color=colors) - rgl.planes(a=1, alpha=0.7) - - aspect3d(1,1,1) - axes3d() - title3d(title, NULL, free.params[1], statistic, free.params[2]) - } + open3d() + persp3d(x,y,z, color=col, xlab=var1, ylab=var2, zlab=var3, main = title) + } } ############################################################################### Modified: pkg/quantstrat/man/tradeGraphs.Rd =================================================================== --- pkg/quantstrat/man/tradeGraphs.Rd 2013-02-19 20:40:06 UTC (rev 1398) +++ pkg/quantstrat/man/tradeGraphs.Rd 2013-02-21 09:57:58 UTC (rev 1399) @@ -2,7 +2,7 @@ \alias{tradeGraphs} \title{Draw 3D graphs from tradeStats results using rgl} \usage{ - tradeGraphs(stats, free.params, fixed.params = NULL, + tradeGraphs(stats, free.params, params.filter = NULL, statistics, title = NULL) } \arguments{ @@ -11,7 +11,8 @@ \item{free.params}{a vector of length 2, containing the column names for the data to use on the x and z axes} - \item{fixed.params}{- not yet implemented} + \item{params.filter}{- a regular expression to reduce + dimensions by filtering on certain columns} \item{statistics}{a vector containing the column names to produce graphs for} @@ -30,10 +31,13 @@ tradeGraphs ( stats = stats, free.params = c("Param.indicator.1.nFast", "Param.indicator.2.nSlow"), - fixed.params = NULL, + params.filter = "Param.indicator.2.nSlow < 40 & Param.indicator.1.nFast > 5" statistics = c("Net.Trading.PL", "maxDrawdown", "Avg.Trade.PL", "Num.Trades") title = 'Luxor' ) } } +\author{ + Jan Humme, rewritten by Chinmay Patil +} From noreply at r-forge.r-project.org Thu Feb 21 11:30:53 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 21 Feb 2013 11:30:53 +0100 (CET) Subject: [Blotter-commits] r1400 - pkg/quantstrat/R Message-ID: <20130221103053.D03A8184617@r-forge.r-project.org> Author: opentrades Date: 2013-02-21 11:30:53 +0100 (Thu, 21 Feb 2013) New Revision: 1400 Modified: pkg/quantstrat/R/tradeGraphs.R Log: - now checks if rgl can be loaded Modified: pkg/quantstrat/R/tradeGraphs.R =================================================================== --- pkg/quantstrat/R/tradeGraphs.R 2013-02-21 09:57:58 UTC (rev 1399) +++ pkg/quantstrat/R/tradeGraphs.R 2013-02-21 10:30:53 UTC (rev 1400) @@ -24,6 +24,8 @@ # TODO: fix axes to use non scientific notation # TODO: fix use of full rainbow for small fractions (eg. Profit.Factor, now only uses red) + if(!require(rgl, quietly=TRUE)) stop('The "rgl" package is required to use this function') + if(!require(reshape2, quietly=TRUE)) stop('The "reshape2" package is required to use this function') if(missing(stats)) stop('stats undefined') From noreply at r-forge.r-project.org Thu Feb 21 19:41:00 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 21 Feb 2013 19:41:00 +0100 (CET) Subject: [Blotter-commits] r1401 - pkg/quantstrat/R Message-ID: <20130221184100.4B92E1844AE@r-forge.r-project.org> Author: opentrades Date: 2013-02-21 19:40:59 +0100 (Thu, 21 Feb 2013) New Revision: 1401 Modified: pkg/quantstrat/R/rules.R Log: - bug fix by Joseph Dunn to execute order at next bar if a new order was opened Modified: pkg/quantstrat/R/rules.R =================================================================== --- pkg/quantstrat/R/rules.R 2013-02-21 10:30:53 UTC (rev 1400) +++ pkg/quantstrat/R/rules.R 2013-02-21 18:40:59 UTC (rev 1401) @@ -647,15 +647,13 @@ exit = , enter = { if(isTRUE(hold)) next() + if(isTRUE(path.dep)) openOrdersLen <- length(getOrders(portfolio=portfolio, symbol=symbol, status="open", timespan=timestamp,which.i=TRUE)) + if(length(strategy$rules[[type]])>=1) { ruleProc(strategy$rules[[type]],timestamp=timestamp, path.dep=path.dep, mktdata=mktdata,portfolio=portfolio, symbol=symbol, ruletype=type, mktinstr=mktinstr, parameters=parameters, ...) } - if(isTRUE(path.dep) && length(getOrders(portfolio=portfolio, symbol=symbol, status="open", timespan=timestamp,which.i=TRUE))) { - ## TODO FIXME this doesn't appear to work correctly - # we opened orders in this timestamp, make sure to increment dindex w/ curIndex+1 so the order slot gets checked next index ? - #browser() - #assign.dindex(c(get.dindex(),curIndex+1)) - # + if(isTRUE(path.dep) && length(getOrders(portfolio=portfolio, symbol=symbol, status="open", timespan=timestamp,which.i=TRUE)) != openOrdersLen) { + assign.dindex(c(get.dindex(),curIndex+1)) } }, post = { From noreply at r-forge.r-project.org Sun Feb 24 14:48:32 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 24 Feb 2013 14:48:32 +0100 (CET) Subject: [Blotter-commits] r1402 - pkg/quantstrat/R Message-ID: <20130224134832.37A78184972@r-forge.r-project.org> Author: opentrades Date: 2013-02-24 14:48:31 +0100 (Sun, 24 Feb 2013) New Revision: 1402 Modified: pkg/quantstrat/R/indicators.R pkg/quantstrat/R/signals.R Log: - applyIndicators() and applySignals() now force label names if provided in add.indicator() and add.signal() Modified: pkg/quantstrat/R/indicators.R =================================================================== --- pkg/quantstrat/R/indicators.R 2013-02-21 18:40:59 UTC (rev 1401) +++ pkg/quantstrat/R/indicators.R 2013-02-24 13:48:31 UTC (rev 1402) @@ -192,7 +192,7 @@ .formals$... <- NULL tmp_val<-do.call(fun,.formals) - if(is.null(colnames(tmp_val))) { + if(is.null(colnames(tmp_val)) || !is.null(indicator$label)) { if (ncol(tmp_val)==1) { #no names, only one column colnames(tmp_val)<-indicator$label } else { #no names, more than one column Modified: pkg/quantstrat/R/signals.R =================================================================== --- pkg/quantstrat/R/signals.R 2013-02-21 18:40:59 UTC (rev 1401) +++ pkg/quantstrat/R/signals.R 2013-02-24 13:48:31 UTC (rev 1402) @@ -133,7 +133,7 @@ .formals$... <- NULL tmp_val<-do.call(fun,.formals) - if(is.null(colnames(tmp_val))) { + if(is.null(colnames(tmp_val)) || !is.null(signal$label)) { if (ncol(tmp_val)==1) { #no names, only one column colnames(tmp_val)<-signal$label } else { #no names, more than one column From noreply at r-forge.r-project.org Mon Feb 25 23:33:57 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 25 Feb 2013 23:33:57 +0100 (CET) Subject: [Blotter-commits] r1403 - in pkg/quantstrat: R man Message-ID: <20130225223357.870C4184DCE@r-forge.r-project.org> Author: opentrades Date: 2013-02-25 23:33:57 +0100 (Mon, 25 Feb 2013) New Revision: 1403 Modified: pkg/quantstrat/R/ruleSignal.R pkg/quantstrat/R/rules.R pkg/quantstrat/man/ruleSignal.Rd Log: - bug fix: fill price of parent order is now passed down the chain to children, so eg. stop-loss can be calculated correctly relative to fill price Modified: pkg/quantstrat/R/ruleSignal.R =================================================================== --- pkg/quantstrat/R/ruleSignal.R 2013-02-24 13:48:31 UTC (rev 1402) +++ pkg/quantstrat/R/ruleSignal.R 2013-02-25 22:33:57 UTC (rev 1403) @@ -48,10 +48,11 @@ #' @param prefer price method for getPrice #' @param sethold boolean, puts entry Rule processing on hold, default FALSE #' @param label rule label, default '', added by \code{\link{applyRules}} +#' @param orderprice a fixed order price, will overrule all mktdata lookup, only meant for internal use really, default NULL #' @seealso \code{\link{osNoOp}} , \code{\link{add.rule}} #' @export -ruleSignal <- function(mktdata=mktdata, timestamp, sigcol, sigval, orderqty=0, ordertype, orderside=NULL, orderset=NULL, threshold=NULL, tmult=FALSE, replace=TRUE, delay=0.0001, osFUN='osNoOp', pricemethod=c('market','opside','active'), portfolio, symbol, ..., ruletype, TxnFees=0, prefer=NULL, sethold=FALSE, label='') +ruleSignal <- function(mktdata=mktdata, timestamp, sigcol, sigval, orderqty=0, ordertype, orderside=NULL, orderset=NULL, threshold=NULL, tmult=FALSE, replace=TRUE, delay=0.0001, osFUN='osNoOp', pricemethod=c('market','opside','active'), portfolio, symbol, ..., ruletype, TxnFees=0, prefer=NULL, sethold=FALSE, label='', orderprice=NULL) { if(!is.function(osFUN)) osFUN<-match.fun(osFUN) @@ -116,71 +117,74 @@ } else { tmpqty <- orderqty } - - switch(pricemethod, - market = , - opside = , - active = { - if(is.BBO(mktdata)){ - if (tmpqty>0) - prefer='ask' # we're buying, so pay what they're asking - else - prefer='bid' # we're selling, so give it to them for what they're bidding - } - orderprice <- try(getPrice(x=mktdata, prefer=prefer))[timestamp] - }, - passive =, - work =, - join = { - if(is.BBO(mktdata)){ - if (tmpqty>0) - prefer='bid' # we're buying, so work the bid price - else - prefer='ask' # we're selling, so work the ask price - } - orderprice <- try(getPrice(x=mktdata, prefer=prefer))[timestamp] - }, - maker = { - if(hasArg(price) & length(match.call(expand.dots=TRUE)$price)>1) { - # we have prices, just use them - orderprice <- try(match.call(expand.dots=TRUE)$price) - } else { - if(!is.null(threshold)) { - baseprice<- last(getPrice(x=mktdata)[timestamp]) # this should get either the last trade price or the Close - if(hasArg(tmult) & isTRUE(match.call(expand.dots=TRUE)$tmult)) { - baseprice<- last(getPrice(x=mktdata)[timestamp]) # this should get either the last trade price or the Close - # threshold is a multiplier of current price - if (length(threshold)>1){ - orderprice <- baseprice * threshold # assume the user has set proper threshold multipliers for each side - } else { - orderprice <- c(baseprice*threshold,baseprice*(1+1-threshold)) #just bracket on both sides - } - } else { - # tmult is FALSE or NULL, threshold is numeric - if (length(threshold)>1){ - orderprice <- baseprice + threshold # assume the user has set proper threshold numerical offsets for each order - } else { - orderprice <- c(baseprice+threshold,baseprice+(-threshold)) #just bracket on both sides - } - } - } else{ - # no threshold, put it on the averages? - stop('maker orders without specified prices and without threholds not (yet?) supported') - if(is.BBO(mktdata)){ - } else { + if(is.null(orderprice)) + { + switch(pricemethod, + market = , + opside = , + active = { + if(is.BBO(mktdata)){ + if (tmpqty>0) + prefer='ask' # we're buying, so pay what they're asking + else + prefer='bid' # we're selling, so give it to them for what they're bidding + } + orderprice <- try(getPrice(x=mktdata, prefer=prefer))[timestamp] + }, + passive =, + work =, + join = { + if(is.BBO(mktdata)){ + if (tmpqty>0) + prefer='bid' # we're buying, so work the bid price + else + prefer='ask' # we're selling, so work the ask price + } + orderprice <- try(getPrice(x=mktdata, prefer=prefer))[timestamp] + }, + maker = { + if(hasArg(price) & length(match.call(expand.dots=TRUE)$price)>1) { + # we have prices, just use them + orderprice <- try(match.call(expand.dots=TRUE)$price) + } else { + if(!is.null(threshold)) { + baseprice<- last(getPrice(x=mktdata)[timestamp]) # this should get either the last trade price or the Close + if(hasArg(tmult) & isTRUE(match.call(expand.dots=TRUE)$tmult)) { + baseprice<- last(getPrice(x=mktdata)[timestamp]) # this should get either the last trade price or the Close + # threshold is a multiplier of current price + if (length(threshold)>1){ + orderprice <- baseprice * threshold # assume the user has set proper threshold multipliers for each side + } else { + orderprice <- c(baseprice*threshold,baseprice*(1+1-threshold)) #just bracket on both sides + } + } else { + # tmult is FALSE or NULL, threshold is numeric + if (length(threshold)>1){ + orderprice <- baseprice + threshold # assume the user has set proper threshold numerical offsets for each order + } else { + orderprice <- c(baseprice+threshold,baseprice+(-threshold)) #just bracket on both sides + } + } + } else{ + # no threshold, put it on the averages? + stop('maker orders without specified prices and without threholds not (yet?) supported') + if(is.BBO(mktdata)){ - } - } - } - if(length(orderqty)==1) orderqty <- c(orderqty,-orderqty) #create paired market maker orders at the same size - } - ) # end switch + } else { - if(inherits(orderprice,'try-error')) orderprice<-NULL - if(length(orderprice>1) && !pricemethod=='maker') orderprice<-last(orderprice[timestamp]) - if(!is.null(orderprice) && !is.null(ncol(orderprice))) orderprice <- orderprice[,1] + } + } + } + if(length(orderqty)==1) orderqty <- c(orderqty,-orderqty) #create paired market maker orders at the same size + } + ) # end switch + if(inherits(orderprice,'try-error')) orderprice<-NULL + if(length(orderprice>1) && !pricemethod=='maker') orderprice<-last(orderprice[timestamp]) + if(!is.null(orderprice) && !is.null(ncol(orderprice))) orderprice <- orderprice[,1] + } + if(is.null(orderset)) orderset=NA Modified: pkg/quantstrat/R/rules.R =================================================================== --- pkg/quantstrat/R/rules.R 2013-02-24 13:48:31 UTC (rev 1402) +++ pkg/quantstrat/R/rules.R 2013-02-25 22:33:57 UTC (rev 1403) @@ -639,7 +639,7 @@ } if(length(rules) > 0) { - ruleProc(rules, timestamp=timestamp, path.dep=path.dep, mktdata=mktdata, portfolio=portfolio, symbol=symbol, ruletype=type, mktinstr=mktinstr, parameters=parameters, ...) + ruleProc(rules, timestamp=timestamp, path.dep=path.dep, mktdata=mktdata, portfolio=portfolio, symbol=symbol, ruletype=type, mktinstr=mktinstr, parameters=list('orderprice'=as.numeric(closed.orders$Order.Price), ...)) } } } Modified: pkg/quantstrat/man/ruleSignal.Rd =================================================================== --- pkg/quantstrat/man/ruleSignal.Rd 2013-02-24 13:48:31 UTC (rev 1402) +++ pkg/quantstrat/man/ruleSignal.Rd 2013-02-25 22:33:57 UTC (rev 1403) @@ -5,10 +5,11 @@ ruleSignal(mktdata = mktdata, timestamp, sigcol, sigval, orderqty = 0, ordertype, orderside = NULL, orderset = NULL, threshold = NULL, tmult = FALSE, - replace = TRUE, delay = 0.0001, osFUN = "osNoOp", + replace = TRUE, delay = 1e-04, osFUN = "osNoOp", pricemethod = c("market", "opside", "active"), portfolio, symbol, ..., ruletype, TxnFees = 0, - prefer = NULL, sethold = FALSE, label = "") + prefer = NULL, sethold = FALSE, label = "", + orderprice = NULL) } \arguments{ \item{mktdata}{an xts object containing market data. @@ -79,6 +80,10 @@ \item{label}{rule label, default '', added by \code{\link{applyRules}}} + + \item{orderprice}{a fixed order price, will overrule all + mktdata lookup, only meant for internal use really, + default NULL} } \description{ As described elsewhere in the documentation, quantstrat From noreply at r-forge.r-project.org Tue Feb 26 16:05:57 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 26 Feb 2013 16:05:57 +0100 (CET) Subject: [Blotter-commits] r1404 - in pkg/quantstrat: R man Message-ID: <20130226150557.2D668183FBE@r-forge.r-project.org> Author: opentrades Date: 2013-02-26 16:05:56 +0100 (Tue, 26 Feb 2013) New Revision: 1404 Modified: pkg/quantstrat/R/ruleSignal.R pkg/quantstrat/R/rules.R pkg/quantstrat/man/ruleSignal.Rd Log: - renamed ruleSignal() order.price parameter to chain.price (to pass fill price in chained orders) - added new order.price parameter to ruleSignal() to force the order.price, ignoring mktdata etc, to allow for stop prices that are not related to chain order fill price Modified: pkg/quantstrat/R/ruleSignal.R =================================================================== --- pkg/quantstrat/R/ruleSignal.R 2013-02-25 22:33:57 UTC (rev 1403) +++ pkg/quantstrat/R/ruleSignal.R 2013-02-26 15:05:56 UTC (rev 1404) @@ -48,11 +48,12 @@ #' @param prefer price method for getPrice #' @param sethold boolean, puts entry Rule processing on hold, default FALSE #' @param label rule label, default '', added by \code{\link{applyRules}} -#' @param orderprice a fixed order price, will overrule all mktdata lookup, only meant for internal use really, default NULL +#' @param order.price the order price to use, will overrule any mktdata lookup as well as chain.price (see below), meant to specify eg. a stop-loss price that is unrelated to the fill price (see chain.price) +#' @param chain.price the price that the parent order got filled for, used to pass to children in the order chain, will overrule all mktdata lookup, only meant for internal use really, default NULL #' @seealso \code{\link{osNoOp}} , \code{\link{add.rule}} #' @export -ruleSignal <- function(mktdata=mktdata, timestamp, sigcol, sigval, orderqty=0, ordertype, orderside=NULL, orderset=NULL, threshold=NULL, tmult=FALSE, replace=TRUE, delay=0.0001, osFUN='osNoOp', pricemethod=c('market','opside','active'), portfolio, symbol, ..., ruletype, TxnFees=0, prefer=NULL, sethold=FALSE, label='', orderprice=NULL) +ruleSignal <- function(mktdata=mktdata, timestamp, sigcol, sigval, orderqty=0, ordertype, orderside=NULL, orderset=NULL, threshold=NULL, tmult=FALSE, replace=TRUE, delay=0.0001, osFUN='osNoOp', pricemethod=c('market','opside','active'), portfolio, symbol, ..., ruletype, TxnFees=0, prefer=NULL, sethold=FALSE, label='', order.price=NULL, chain.price=NULL) { if(!is.function(osFUN)) osFUN<-match.fun(osFUN) @@ -118,8 +119,17 @@ tmpqty <- orderqty } - if(is.null(orderprice)) + if(!is.null(order.price)) { +print(paste('--- order.price =', order.price)) + orderprice <- order.price + } + else if(!is.null(chain.price)) + { + orderprice <- chain.price + } + else + { switch(pricemethod, market = , opside = , @@ -186,7 +196,7 @@ } if(is.null(orderset)) orderset=NA - +print(paste('=== orderprice =', orderprice)) ## now size the order #TODO add fancy formals matching for osFUN Modified: pkg/quantstrat/R/rules.R =================================================================== --- pkg/quantstrat/R/rules.R 2013-02-25 22:33:57 UTC (rev 1403) +++ pkg/quantstrat/R/rules.R 2013-02-26 15:05:56 UTC (rev 1404) @@ -639,7 +639,7 @@ } if(length(rules) > 0) { - ruleProc(rules, timestamp=timestamp, path.dep=path.dep, mktdata=mktdata, portfolio=portfolio, symbol=symbol, ruletype=type, mktinstr=mktinstr, parameters=list('orderprice'=as.numeric(closed.orders$Order.Price), ...)) + ruleProc(rules, timestamp=timestamp, path.dep=path.dep, mktdata=mktdata, portfolio=portfolio, symbol=symbol, ruletype=type, mktinstr=mktinstr, parameters=list('chain.price'=as.numeric(closed.orders$Order.Price), ...)) } } } Modified: pkg/quantstrat/man/ruleSignal.Rd =================================================================== --- pkg/quantstrat/man/ruleSignal.Rd 2013-02-25 22:33:57 UTC (rev 1403) +++ pkg/quantstrat/man/ruleSignal.Rd 2013-02-26 15:05:56 UTC (rev 1404) @@ -9,7 +9,7 @@ pricemethod = c("market", "opside", "active"), portfolio, symbol, ..., ruletype, TxnFees = 0, prefer = NULL, sethold = FALSE, label = "", - orderprice = NULL) + order.price = NULL, chain.price = NULL) } \arguments{ \item{mktdata}{an xts object containing market data. @@ -81,9 +81,15 @@ \item{label}{rule label, default '', added by \code{\link{applyRules}}} - \item{orderprice}{a fixed order price, will overrule all - mktdata lookup, only meant for internal use really, - default NULL} + \item{order.price}{the order price to use, will overrule + any mktdata lookup as well as chain.price (see below), + meant to specify eg. a stop-loss price that is unrelated + to the fill price (see chain.price)} + + \item{chain.price}{the price that the parent order got + filled for, used to pass to children in the order chain, + will overrule all mktdata lookup, only meant for internal + use really, default NULL} } \description{ As described elsewhere in the documentation, quantstrat From noreply at r-forge.r-project.org Tue Feb 26 16:07:51 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 26 Feb 2013 16:07:51 +0100 (CET) Subject: [Blotter-commits] r1405 - pkg/quantstrat/R Message-ID: <20130226150751.8F8E01813A1@r-forge.r-project.org> Author: opentrades Date: 2013-02-26 16:07:51 +0100 (Tue, 26 Feb 2013) New Revision: 1405 Modified: pkg/quantstrat/R/ruleSignal.R Log: - removed debugging prints (oops) Modified: pkg/quantstrat/R/ruleSignal.R =================================================================== --- pkg/quantstrat/R/ruleSignal.R 2013-02-26 15:05:56 UTC (rev 1404) +++ pkg/quantstrat/R/ruleSignal.R 2013-02-26 15:07:51 UTC (rev 1405) @@ -121,7 +121,6 @@ if(!is.null(order.price)) { -print(paste('--- order.price =', order.price)) orderprice <- order.price } else if(!is.null(chain.price)) @@ -196,7 +195,6 @@ } if(is.null(orderset)) orderset=NA -print(paste('=== orderprice =', orderprice)) ## now size the order #TODO add fancy formals matching for osFUN