From noreply at r-forge.r-project.org Tue Aug 13 00:30:33 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 13 Aug 2013 00:30:33 +0200 (CEST) Subject: [Blotter-commits] r1486 - pkg/blotter/R Message-ID: <20130812223033.702D1185932@r-forge.r-project.org> Author: braverock Date: 2013-08-13 00:30:33 +0200 (Tue, 13 Aug 2013) New Revision: 1486 Modified: pkg/blotter/R/updatePortf.R Log: - fix bug reported by Guy Yollin where Portfolio and Accout index rows could be duplicated. Thanks to Josh Ulrich for help with the fix Modified: pkg/blotter/R/updatePortf.R =================================================================== --- pkg/blotter/R/updatePortf.R 2013-07-23 17:49:22 UTC (rev 1485) +++ pkg/blotter/R/updatePortf.R 2013-08-12 22:30:33 UTC (rev 1486) @@ -75,6 +75,25 @@ else {summary=cbind(summary,result)} } + # get rid of duplicated indices in the summary data, + # thanks to Guy Yollin for the bug report and Josh Ulrich for the elegant approach to fixing it + d <- duplicated(.index(summary)) | duplicated(.index(summary), fromLast=TRUE) + if(any(d)){ + f <- function(x) { + cLast <- c('Long.Value', 'Short.Value', 'Net.Value', 'Gross.Value') + cSums <- c('Period.Realized.PL', 'Period.Unrealized.PL', 'Gross.Trading.PL', 'Txn.Fees', 'Net.Trading.PL') + setNames(suppressWarnings( + merge(last(x[,cLast]), + xts(t(colSums(x[,cSums],na.rm=TRUE)),order.by=last(index(x)))) + ) + ,nm=colnames(x)) + } + + slist <- do.call(rbind, lapply(split(summary[d,], .index(summary[d,])), f)) + summary <- merge(summary[!d,], slist) #put it all back together + } + + if(!is.timeBased(Dates)) Dates = xts:::time.xts(Portfolio$symbols[[1]][["posPL"]][Dates]) startDate = first(xts:::.parseISO8601(Dates))$first.time-.00001 # trim summary slot to not double count, related to bug 831 on R-Forge, and rbind new summary From noreply at r-forge.r-project.org Tue Aug 13 16:22:09 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 13 Aug 2013 16:22:09 +0200 (CEST) Subject: [Blotter-commits] r1487 - pkg/blotter/R Message-ID: <20130813142209.5B6441849C3@r-forge.r-project.org> Author: braverock Date: 2013-08-13 16:22:09 +0200 (Tue, 13 Aug 2013) New Revision: 1487 Modified: pkg/blotter/R/updateAcct.R Log: - fix bug reported by Guy Yollin where Portfolio and Accout index rows could be duplicated. Thanks to Josh Ulrich for help with the fix Modified: pkg/blotter/R/updateAcct.R =================================================================== --- pkg/blotter/R/updateAcct.R 2013-08-12 22:30:33 UTC (rev 1486) +++ pkg/blotter/R/updateAcct.R 2013-08-13 14:22:09 UTC (rev 1487) @@ -75,6 +75,7 @@ #multiply by the currency multiplier psummary<-psummary*CcyMult } + # now bind it Account$portfolios[[pname]] = rbind(Account$portfolios[[pname]],psummary) } @@ -85,13 +86,9 @@ table = .getByPortf(Account, 'Net.Trading.PL', Dates) obsLength = length(index(table)) obsDates = index(table) - if(obsLength > 1) # can't estimate periodicity of one observation - on=periodicity(table)$units - else - on="none" # Now aggregate the portfolio information into the $summary slot - Attributes = c('Additions', 'Withdrawals', 'Realized.PL', 'Unrealized.PL', 'Interest', 'Gross.Trading.PL', 'Txn.Fees', 'Net.Trading.PL', 'Advisory.Fees', 'Net.Performance', 'End.Eq') + Attributes = c('Additions', 'Withdrawals', 'Realized.PL', 'Unrealized.PL', 'Int.Income', 'Gross.Trading.PL', 'Txn.Fees', 'Net.Trading.PL', 'Advisory.Fees', 'Net.Performance', 'End.Eq') for(Attribute in Attributes) { switch(Attribute, @@ -103,24 +100,9 @@ table = .getByPortf(Account, Attribute, Dates) result = xts(rowSums(table,na.rm=TRUE),order.by=index(table)) }, - Additions = { - result = if(on=="none") - as.xts(sum(Account$Additions[paste("::",obsDates, sep="")]), order.by=index(table)) - else - period.apply(Account$Additions[obsDates], endpoints(Account$Additions[obsDates], on=on), sum) # aggregates multiple account txns - }, - Withdrawals = { - result = if(on=="none") - as.xts(sum(Account$Withdrawals[paste("::",obsDates, sep="")]), order.by=index(table)) - else - period.apply(Account$Withdrawals[obsDates], endpoints(Account$Withdrawals[obsDates], on=periodicity(table)$units), sum) - }, - Interest = { - result = if(on=="none") - as.xts(sum(Account$Interest[paste("::",obsDates, sep="")]),, order.by=index(table)) - else - period.apply(Account$Interest[obsDates], endpoints(Account$Interest[obsDates], on=periodicity(table)$units), sum) - }, + Additions = , + Withdrawals = , + Int.Income = , Advisory.Fees = , Net.Performance = , End.Eq = { @@ -128,14 +110,32 @@ result = xts(rep(0,obsLength),order.by=obsDates) } ) + colnames(result) = Attribute if(is.null(summary)) {summary=result} else {summary=cbind(summary,result)} } - summary[is.na(summary)] <- 0 # replace any NA's with zero - Account$summary <- rbind(Account$summary, summary) - # This function does not calculate End.Eq + Account$summary <- rbind(Account$summary, summary) + + # get rid of duplicated indices in the summary data, + # thanks to Guy Yollin for the bug report and Josh Ulrich for the elegant approach to fixing it + d <- duplicated(.index(Account$summary)) | duplicated(.index(Account$summary), fromLast=TRUE) + if(any(d)){ + dedups <- function(x) { + suppressWarnings( + xts(t(colSums(x)),order.by=last(index(x))) + ) + } + + alist <- do.call(rbind, lapply(split(Account$summary[d,], .index(Account$summary[d,])), dedups) ) + + Account$summary <- rbind(Account$summary[!d,], alist) #put it all back together + + } + + # This function does not calculate End.Eq + assign(paste("account",name,sep='.'),Account, envir=.blotter) return(name) #not sure this is a good idea } From noreply at r-forge.r-project.org Tue Aug 13 16:42:19 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 13 Aug 2013 16:42:19 +0200 (CEST) Subject: [Blotter-commits] r1488 - pkg/blotter/R Message-ID: <20130813144219.954D1183C20@r-forge.r-project.org> Author: braverock Date: 2013-08-13 16:42:19 +0200 (Tue, 13 Aug 2013) New Revision: 1488 Modified: pkg/blotter/R/updateAcct.R Log: - merged back in changes from r 1484, not sure why svn didn't catch the conflict. Modified: pkg/blotter/R/updateAcct.R =================================================================== --- pkg/blotter/R/updateAcct.R 2013-08-13 14:22:09 UTC (rev 1487) +++ pkg/blotter/R/updateAcct.R 2013-08-13 14:42:19 UTC (rev 1488) @@ -75,7 +75,6 @@ #multiply by the currency multiplier psummary<-psummary*CcyMult } - # now bind it Account$portfolios[[pname]] = rbind(Account$portfolios[[pname]],psummary) } @@ -86,9 +85,13 @@ table = .getByPortf(Account, 'Net.Trading.PL', Dates) obsLength = length(index(table)) obsDates = index(table) + if(obsLength > 1) # can't estimate periodicity of one observation + on=periodicity(table)$units + else + on="none" # Now aggregate the portfolio information into the $summary slot - Attributes = c('Additions', 'Withdrawals', 'Realized.PL', 'Unrealized.PL', 'Int.Income', 'Gross.Trading.PL', 'Txn.Fees', 'Net.Trading.PL', 'Advisory.Fees', 'Net.Performance', 'End.Eq') + Attributes = c('Additions', 'Withdrawals', 'Realized.PL', 'Unrealized.PL', 'Interest', 'Gross.Trading.PL', 'Txn.Fees', 'Net.Trading.PL', 'Advisory.Fees', 'Net.Performance', 'End.Eq') for(Attribute in Attributes) { switch(Attribute, @@ -100,9 +103,24 @@ table = .getByPortf(Account, Attribute, Dates) result = xts(rowSums(table,na.rm=TRUE),order.by=index(table)) }, - Additions = , - Withdrawals = , - Int.Income = , + Additions = { + result = if(on=="none") + as.xts(sum(Account$Additions[paste("::",obsDates, sep="")]), order.by=index(table)) + else + period.apply(Account$Additions[obsDates], endpoints(Account$Additions[obsDates], on=on), sum) # aggregates multiple account txns + }, + Withdrawals = { + result = if(on=="none") + as.xts(sum(Account$Withdrawals[paste("::",obsDates, sep="")]), order.by=index(table)) + else + period.apply(Account$Withdrawals[obsDates], endpoints(Account$Withdrawals[obsDates], on=periodicity(table)$units), sum) + }, + Interest = { + result = if(on=="none") + as.xts(sum(Account$Interest[paste("::",obsDates, sep="")]),, order.by=index(table)) + else + period.apply(Account$Interest[obsDates], endpoints(Account$Interest[obsDates], on=periodicity(table)$units), sum) + }, Advisory.Fees = , Net.Performance = , End.Eq = { @@ -115,6 +133,9 @@ if(is.null(summary)) {summary=result} else {summary=cbind(summary,result)} } + summary[is.na(summary)] <- 0 # replace any NA's with zero + Account$summary <- rbind(Account$summary, summary) + # This function does not calculate End.Eq Account$summary <- rbind(Account$summary, summary) From noreply at r-forge.r-project.org Tue Aug 13 16:51:33 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 13 Aug 2013 16:51:33 +0200 (CEST) Subject: [Blotter-commits] r1489 - pkg/quantstrat/demo Message-ID: <20130813145133.DC0E81812A7@r-forge.r-project.org> Author: peter_carl Date: 2013-08-13 16:51:33 +0200 (Tue, 13 Aug 2013) New Revision: 1489 Modified: pkg/quantstrat/demo/faber.R Log: - added updateEndEq - also view tradestats Modified: pkg/quantstrat/demo/faber.R =================================================================== --- pkg/quantstrat/demo/faber.R 2013-08-13 14:42:19 UTC (rev 1488) +++ pkg/quantstrat/demo/faber.R 2013-08-13 14:51:33 UTC (rev 1489) @@ -129,6 +129,7 @@ start_t<-Sys.time() updatePortf(Portfolio='faber',Dates=paste('::',as.Date(Sys.time()),sep='')) updateAcct('faber') +updateEndEq('faber') end_t<-Sys.time() print("trade blotter portfolio update:") print(end_t-start_t) @@ -158,7 +159,7 @@ } faber.stats<-tradeStats('faber')[,c('Net.Trading.PL','Max.Drawdown','Num.Trades','Profit.Factor','Std.Dev.Trade.PL','Largest.Winner','Largest.Loser','Max.Equity','Min.Equity')] -faber.stats +View(faber.stats) Sys.setenv(TZ=oldtz) ############################################################################### From noreply at r-forge.r-project.org Tue Aug 13 18:39:36 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 13 Aug 2013 18:39:36 +0200 (CEST) Subject: [Blotter-commits] r1490 - pkg/blotter/R Message-ID: <20130813163936.463CA180AB3@r-forge.r-project.org> Author: peter_carl Date: 2013-08-13 18:39:36 +0200 (Tue, 13 Aug 2013) New Revision: 1490 Modified: pkg/blotter/R/updateAcct.R Log: - removed accidental row duplication - removed row deduplication code Modified: pkg/blotter/R/updateAcct.R =================================================================== --- pkg/blotter/R/updateAcct.R 2013-08-13 14:51:33 UTC (rev 1489) +++ pkg/blotter/R/updateAcct.R 2013-08-13 16:39:36 UTC (rev 1490) @@ -133,30 +133,11 @@ if(is.null(summary)) {summary=result} else {summary=cbind(summary,result)} } + browser() summary[is.na(summary)] <- 0 # replace any NA's with zero Account$summary <- rbind(Account$summary, summary) # This function does not calculate End.Eq - Account$summary <- rbind(Account$summary, summary) - - # get rid of duplicated indices in the summary data, - # thanks to Guy Yollin for the bug report and Josh Ulrich for the elegant approach to fixing it - d <- duplicated(.index(Account$summary)) | duplicated(.index(Account$summary), fromLast=TRUE) - if(any(d)){ - dedups <- function(x) { - suppressWarnings( - xts(t(colSums(x)),order.by=last(index(x))) - ) - } - - alist <- do.call(rbind, lapply(split(Account$summary[d,], .index(Account$summary[d,])), dedups) ) - - Account$summary <- rbind(Account$summary[!d,], alist) #put it all back together - - } - - # This function does not calculate End.Eq - assign(paste("account",name,sep='.'),Account, envir=.blotter) return(name) #not sure this is a good idea } From noreply at r-forge.r-project.org Tue Aug 13 19:23:04 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 13 Aug 2013 19:23:04 +0200 (CEST) Subject: [Blotter-commits] r1491 - pkg/blotter/R Message-ID: <20130813172304.E8D951842CC@r-forge.r-project.org> Author: peter_carl Date: 2013-08-13 19:23:04 +0200 (Tue, 13 Aug 2013) New Revision: 1491 Modified: pkg/blotter/R/updateAcct.R Log: - removed debugging Modified: pkg/blotter/R/updateAcct.R =================================================================== --- pkg/blotter/R/updateAcct.R 2013-08-13 16:39:36 UTC (rev 1490) +++ pkg/blotter/R/updateAcct.R 2013-08-13 17:23:04 UTC (rev 1491) @@ -133,7 +133,6 @@ if(is.null(summary)) {summary=result} else {summary=cbind(summary,result)} } - browser() summary[is.na(summary)] <- 0 # replace any NA's with zero Account$summary <- rbind(Account$summary, summary) # This function does not calculate End.Eq From noreply at r-forge.r-project.org Tue Aug 13 20:01:30 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 13 Aug 2013 20:01:30 +0200 (CEST) Subject: [Blotter-commits] r1492 - pkg/blotter/R Message-ID: <20130813180131.165701812A7@r-forge.r-project.org> Author: peter_carl Date: 2013-08-13 20:01:30 +0200 (Tue, 13 Aug 2013) New Revision: 1492 Modified: pkg/blotter/R/updateAcct.R Log: - added tests for empty account transactions - scoped Dates=NULL to ignore initDate to prevent row duplication of initDate Modified: pkg/blotter/R/updateAcct.R =================================================================== --- pkg/blotter/R/updateAcct.R 2013-08-13 17:23:04 UTC (rev 1491) +++ pkg/blotter/R/updateAcct.R 2013-08-13 18:01:30 UTC (rev 1492) @@ -14,7 +14,7 @@ Portfolios = names(Account$portfolios) - if(is.null(Dates)) Dates<-index(getPortfolio(Portfolios[1])$summary) + if(is.null(Dates)) Dates<-index(getPortfolio(Portfolios[1])$summary)[-1] #trim to only time prior to Dates if(last(index(Account$summary))>.parseISO8601(Dates)$first.time){ @@ -106,20 +106,32 @@ Additions = { result = if(on=="none") as.xts(sum(Account$Additions[paste("::",obsDates, sep="")]), order.by=index(table)) - else - period.apply(Account$Additions[obsDates], endpoints(Account$Additions[obsDates], on=on), sum) # aggregates multiple account txns + else{ + if(length(Account$Additions[obsDates])>0) # catch empty sets + period.apply(Account$Additions[obsDates], endpoints(Account$Additions[obsDates], on=on), sum) # aggregates multiple account txns + else + xts(rep(0,obsLength),order.by=obsDates) + } }, Withdrawals = { result = if(on=="none") as.xts(sum(Account$Withdrawals[paste("::",obsDates, sep="")]), order.by=index(table)) - else - period.apply(Account$Withdrawals[obsDates], endpoints(Account$Withdrawals[obsDates], on=periodicity(table)$units), sum) + else{ + if(length(Account$Additions[obsDates])>0) # catch empty sets + period.apply(Account$Withdrawals[obsDates], endpoints(Account$Withdrawals[obsDates], on=periodicity(table)$units), sum) + else + xts(rep(0,obsLength),order.by=obsDates) + } }, Interest = { result = if(on=="none") as.xts(sum(Account$Interest[paste("::",obsDates, sep="")]),, order.by=index(table)) - else - period.apply(Account$Interest[obsDates], endpoints(Account$Interest[obsDates], on=periodicity(table)$units), sum) + else{ + if(length(Account$Additions[obsDates])>0) # catch empty sets + period.apply(Account$Interest[obsDates], endpoints(Account$Interest[obsDates], on=periodicity(table)$units), sum) + else + xts(rep(0,obsLength),order.by=obsDates) + } }, Advisory.Fees = , Net.Performance = , From noreply at r-forge.r-project.org Wed Aug 14 05:08:04 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 14 Aug 2013 05:08:04 +0200 (CEST) Subject: [Blotter-commits] r1493 - pkg/blotter/R Message-ID: <20130814030804.8D10E18513B@r-forge.r-project.org> Author: bodanker Date: 2013-08-14 05:08:03 +0200 (Wed, 14 Aug 2013) New Revision: 1493 Modified: pkg/blotter/R/updatePortf.R Log: - another attempt to remove duplicate indices in summary data (also remove some of Brian's tabs... :) Modified: pkg/blotter/R/updatePortf.R =================================================================== --- pkg/blotter/R/updatePortf.R 2013-08-13 18:01:30 UTC (rev 1492) +++ pkg/blotter/R/updatePortf.R 2013-08-14 03:08:03 UTC (rev 1493) @@ -74,26 +74,22 @@ if(is.null(summary)) {summary=result} else {summary=cbind(summary,result)} } - - # get rid of duplicated indices in the summary data, - # thanks to Guy Yollin for the bug report and Josh Ulrich for the elegant approach to fixing it - d <- duplicated(.index(summary)) | duplicated(.index(summary), fromLast=TRUE) - if(any(d)){ - f <- function(x) { - cLast <- c('Long.Value', 'Short.Value', 'Net.Value', 'Gross.Value') - cSums <- c('Period.Realized.PL', 'Period.Unrealized.PL', 'Gross.Trading.PL', 'Txn.Fees', 'Net.Trading.PL') - setNames(suppressWarnings( - merge(last(x[,cLast]), - xts(t(colSums(x[,cSums],na.rm=TRUE)),order.by=last(index(x)))) - ) - ,nm=colnames(x)) - } - - slist <- do.call(rbind, lapply(split(summary[d,], .index(summary[d,])), f)) - summary <- merge(summary[!d,], slist) #put it all back together - } - - + + # get rid of duplicated indices in the summary data, + # thanks to Guy Yollin for the bug report and Josh Ulrich for the elegant approach to fixing it + d <- duplicated(.index(summary)) | duplicated(.index(summary), fromLast=TRUE) + if(any(d)){ + f <- function(x) { + cLast <- c('Long.Value', 'Short.Value', 'Net.Value', 'Gross.Value') + cSums <- c('Period.Realized.PL', 'Period.Unrealized.PL', 'Gross.Trading.PL', 'Txn.Fees', 'Net.Trading.PL') + setNames( merge(last(x[,cLast]), xts(t(colSums(x[,cSums],na.rm=TRUE)),last(index(x)))), colnames(x) ) + } + summary.dups <- summary[d,] + ds <- duplicated(.index(summary.dups)) + slist <- period.apply(summary.dups, c(0, which(ds)), f) + summary <- rbind(summary[!d,], slist) # put it all back together + } + if(!is.timeBased(Dates)) Dates = xts:::time.xts(Portfolio$symbols[[1]][["posPL"]][Dates]) startDate = first(xts:::.parseISO8601(Dates))$first.time-.00001 # trim summary slot to not double count, related to bug 831 on R-Forge, and rbind new summary From noreply at r-forge.r-project.org Wed Aug 14 05:32:02 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 14 Aug 2013 05:32:02 +0200 (CEST) Subject: [Blotter-commits] r1494 - pkg/blotter/R Message-ID: <20130814033202.247CF184FAF@r-forge.r-project.org> Author: bodanker Date: 2013-08-14 05:32:01 +0200 (Wed, 14 Aug 2013) New Revision: 1494 Modified: pkg/blotter/R/updatePortf.R Log: - correct endpoints in case a row appears more than twice Modified: pkg/blotter/R/updatePortf.R =================================================================== --- pkg/blotter/R/updatePortf.R 2013-08-14 03:08:03 UTC (rev 1493) +++ pkg/blotter/R/updatePortf.R 2013-08-14 03:32:01 UTC (rev 1494) @@ -85,7 +85,7 @@ setNames( merge(last(x[,cLast]), xts(t(colSums(x[,cSums],na.rm=TRUE)),last(index(x)))), colnames(x) ) } summary.dups <- summary[d,] - ds <- duplicated(.index(summary.dups)) + ds <- duplicated(.index(summary.dups)) & !duplicated(.index(summary.dups), fromLast=TRUE) slist <- period.apply(summary.dups, c(0, which(ds)), f) summary <- rbind(summary[!d,], slist) # put it all back together } From noreply at r-forge.r-project.org Wed Aug 14 14:01:06 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 14 Aug 2013 14:01:06 +0200 (CEST) Subject: [Blotter-commits] r1495 - pkg/blotter/R Message-ID: <20130814120106.57C3718479F@r-forge.r-project.org> Author: braverock Date: 2013-08-14 14:01:05 +0200 (Wed, 14 Aug 2013) New Revision: 1495 Modified: pkg/blotter/R/updateAcct.R pkg/blotter/R/updatePortf.R Log: - convert tabs to spaces to clean up formatting Modified: pkg/blotter/R/updateAcct.R =================================================================== --- pkg/blotter/R/updateAcct.R 2013-08-14 03:32:01 UTC (rev 1494) +++ pkg/blotter/R/updateAcct.R 2013-08-14 12:01:05 UTC (rev 1495) @@ -12,17 +12,17 @@ a.ccy.str<-attr(Account,'currency') } - Portfolios = names(Account$portfolios) - - if(is.null(Dates)) Dates<-index(getPortfolio(Portfolios[1])$summary)[-1] - - #trim to only time prior to Dates - if(last(index(Account$summary))>.parseISO8601(Dates)$first.time){ - whichi<-first(Account$summary[paste(.parseISO8601(Dates)$first.time,'::',sep=''), which.i = TRUE]) - if(!is.null(whichi)) whichi=whichi-1 - if(whichi<1) whichi=1 - Account$summary = Account$summary[1:whichi,] - } + Portfolios = names(Account$portfolios) + + if(is.null(Dates)) Dates<-index(getPortfolio(Portfolios[1])$summary)[-1] + + #trim to only time prior to Dates + if(last(index(Account$summary))>.parseISO8601(Dates)$first.time){ + whichi<-first(Account$summary[paste(.parseISO8601(Dates)$first.time,'::',sep=''), which.i = TRUE]) + if(!is.null(whichi)) whichi=whichi-1 + if(whichi<1) whichi=1 + Account$summary = Account$summary[1:whichi,] + } # Append the portfolio summary data to the portfolio slot @@ -31,52 +31,52 @@ if(!is.null(attr(Portfolio,'currency'))) { p.ccy.str<-attr(Portfolio,'currency') } - + # Test whether portfolio and account are of the same ccy - psummary = Portfolio$summary[Dates] - if( a.ccy.str != p.ccy.str ){ + psummary = Portfolio$summary[Dates] + if( a.ccy.str != p.ccy.str ){ # If not, translate the portfolio summary to the account currency - CcyMult <- NA - port_currency<-try(getInstrument(p.ccy.str), silent=TRUE) - if(inherits(port_currency,"try-error") | !is.instrument(port_currency)){ - warning("Currency",p.ccy.str," not found, using currency multiplier of 1") - CcyMult<-1 - } else { - FXrate.str<-paste(p.ccy.str,a.ccy.str,sep='') # currency quote convention is EURUSD which reads as "USD per EUR" - FXrate<-try(get(FXrate.str), silent=TRUE) - #TODO FIXME: this uses convention to sort out the rate, we should check $currency and $counter_currency and make sure directionality is correct - if(inherits(FXrate,"try-error")){ - FXrate.str<-paste(a.ccy.str,p.ccy.str,sep='') - FXrate<-try(get(FXrate.str), silent=TRUE) - if(inherits(FXrate,"try-error")){ - warning("Exchange Rate",FXrate.str," not found for symbol,',Symbol,' using currency multiplier of 1") - CcyMult<-1 - } else { - invert=TRUE - } - } - } - if(is.na(CcyMult) && !is.na(FXrate)) { - if(inherits(FXrate,'xts')){ - CcyMult <- FXrate[Dates] - CcyMult <- na.locf(merge(CcyMult,index(psummary))) - CcyMult <- drop(CcyMult[index(psummary)]) - } else { - CcyMult<-as.numeric(FXrate) - } - } else { - CcyMult<-1 - } - if(isTRUE(invert)){ - # portfolio and instrument have different currencies, and FXrate was in the wrong direction - CcyMult<-1/CcyMult - } - - #multiply by the currency multiplier - psummary<-psummary*CcyMult + CcyMult <- NA + port_currency<-try(getInstrument(p.ccy.str), silent=TRUE) + if(inherits(port_currency,"try-error") | !is.instrument(port_currency)){ + warning("Currency",p.ccy.str," not found, using currency multiplier of 1") + CcyMult<-1 + } else { + FXrate.str<-paste(p.ccy.str,a.ccy.str,sep='') # currency quote convention is EURUSD which reads as "USD per EUR" + FXrate<-try(get(FXrate.str), silent=TRUE) + #TODO FIXME: this uses convention to sort out the rate, we should check $currency and $counter_currency and make sure directionality is correct + if(inherits(FXrate,"try-error")){ + FXrate.str<-paste(a.ccy.str,p.ccy.str,sep='') + FXrate<-try(get(FXrate.str), silent=TRUE) + if(inherits(FXrate,"try-error")){ + warning("Exchange Rate",FXrate.str," not found for symbol,',Symbol,' using currency multiplier of 1") + CcyMult<-1 + } else { + invert=TRUE + } + } + } + if(is.na(CcyMult) && !is.na(FXrate)) { + if(inherits(FXrate,'xts')){ + CcyMult <- FXrate[Dates] + CcyMult <- na.locf(merge(CcyMult,index(psummary))) + CcyMult <- drop(CcyMult[index(psummary)]) + } else { + CcyMult<-as.numeric(FXrate) + } + } else { + CcyMult<-1 + } + if(isTRUE(invert)){ + # portfolio and instrument have different currencies, and FXrate was in the wrong direction + CcyMult<-1/CcyMult + } + + #multiply by the currency multiplier + psummary<-psummary*CcyMult } - # now bind it - Account$portfolios[[pname]] = rbind(Account$portfolios[[pname]],psummary) + # now bind it + Account$portfolios[[pname]] = rbind(Account$portfolios[[pname]],psummary) } summary = NULL @@ -136,11 +136,11 @@ Advisory.Fees = , Net.Performance = , End.Eq = { - ## TODO no cash handling for now, add this in later, but for now, zeroes + ## TODO no cash handling for now, add this in later, but for now, zeroes result = xts(rep(0,obsLength),order.by=obsDates) } ) - + colnames(result) = Attribute if(is.null(summary)) {summary=result} else {summary=cbind(summary,result)} Modified: pkg/blotter/R/updatePortf.R =================================================================== --- pkg/blotter/R/updatePortf.R 2013-08-14 03:32:01 UTC (rev 1494) +++ pkg/blotter/R/updatePortf.R 2013-08-14 12:01:05 UTC (rev 1495) @@ -1,16 +1,16 @@ #' update Portfilio P&L over a Dates range -#' +#' #' The \code{updatePortf} function goes through each symbol and calculates the PL for each period prices are available. #' -#' Note that the portfolio will be marked on every time stamp where prices are available. +#' Note that the portfolio will be marked on every time stamp where prices are available. #' As such, your \code{Dates} range must reflect timestamps which appear in the price stream. -#' Also note that you probably don't want to mark the portfolio on every tick, -#' -#' +#' Also note that you probably don't want to mark the portfolio on every tick, +#' +#' #' @return assigns position information and PL into the environment -#' +#' #' @param Portfolio string identifying a portfolio -#' @param Symbols character vector identifying symbols to update the portfolio for, default NULL +#' @param Symbols character vector identifying symbols to update the portfolio for, default NULL #' @param Dates xts-style ISO-8601 time range to run updatePortf over, default NULL (will use times from Prices #' @param Prices optional xts object containing prices and timestamps to mark the book on, default NULL #' @param \dots any other passthrough parameters @@ -23,59 +23,59 @@ # FUNCTION if(is.null(Symbols)){ Symbols = names(Portfolio$symbols) - } + } for(symbol in Symbols){ tmp_instr<-try(getInstrument(symbol), silent=TRUE) - .updatePosPL(Portfolio=pname, Symbol=as.character(symbol), Dates=Dates, Prices=Prices, ...=...) + .updatePosPL(Portfolio=pname, Symbol=as.character(symbol), Dates=Dates, Prices=Prices, ...=...) } - + # Calculate and store portfolio summary table Portfolio<-getPortfolio(pname) # refresh with an updated object - if(is.null(Dates)) Dates <- xts:::time.xts(Portfolio$symbols[[1]]$posPL) #not quite right, only using first symbol... + if(is.null(Dates)) Dates <- xts:::time.xts(Portfolio$symbols[[1]]$posPL) #not quite right, only using first symbol... #Symbols = names(Portfolio$symbols) Attributes = c('Long.Value', 'Short.Value', 'Net.Value', 'Gross.Value', 'Period.Realized.PL', 'Period.Unrealized.PL', 'Gross.Trading.PL', 'Txn.Fees', 'Net.Trading.PL') summary = NULL - tmp.attr=NULL + tmp.attr=NULL for(attribute in Attributes) { - result=NULL + result=NULL switch(attribute, - Net.Value =, + Net.Value =, Gross.Value =, - Long.Value =, - Short.Value =,{ - # all these use Pos.Value - if(is.null(tmp.attr)){ - table = .getBySymbol(Portfolio = Portfolio, Attribute = "Pos.Value", Dates = Dates, Symbols = Symbols) - tmp.attr="Pos.Value" - } - switch(attribute, - Gross.Value = { result = xts(rowSums(abs(table), na.rm=TRUE), order.by=index(table))}, - Long.Value = { tmat = apply(table,MARGIN=c(1,2),FUN=max,0)# comes out a matrix - result = xts(rowSums(tmat, na.rm=TRUE), order.by=index(table)) - }, - Short.Value = { tmat = apply(table,MARGIN=c(1,2),FUN=min,0) # comes out a matrix - result = xts(rowSums(tmat, na.rm=TRUE), order.by=index(table)) - }, - Net.Value = { result = xts(rowSums(table, na.rm=TRUE), order.by=index(table)) } - ) + Long.Value =, + Short.Value =,{ + # all these use Pos.Value + if(is.null(tmp.attr)){ + table = .getBySymbol(Portfolio = Portfolio, Attribute = "Pos.Value", Dates = Dates, Symbols = Symbols) + tmp.attr="Pos.Value" + } + switch(attribute, + Gross.Value = { result = xts(rowSums(abs(table), na.rm=TRUE), order.by=index(table))}, + Long.Value = { tmat = apply(table,MARGIN=c(1,2),FUN=max,0)# comes out a matrix + result = xts(rowSums(tmat, na.rm=TRUE), order.by=index(table)) }, - Period.Realized.PL =, - Period.Unrealized.PL =, - Gross.Trading.PL =, - Txn.Fees =, - Net.Trading.PL = { - table = .getBySymbol(Portfolio = Portfolio, Attribute = attribute, Dates = Dates, Symbols = Symbols) - tmp.attr = NULL - result = xts(rowSums(table, na.rm=TRUE), order.by=index(table)) + Short.Value = { tmat = apply(table,MARGIN=c(1,2),FUN=min,0) # comes out a matrix + result = xts(rowSums(tmat, na.rm=TRUE), order.by=index(table)) + }, + Net.Value = { result = xts(rowSums(table, na.rm=TRUE), order.by=index(table)) } + ) + }, + Period.Realized.PL =, + Period.Unrealized.PL =, + Gross.Trading.PL =, + Txn.Fees =, + Net.Trading.PL = { + table = .getBySymbol(Portfolio = Portfolio, Attribute = attribute, Dates = Dates, Symbols = Symbols) + tmp.attr = NULL + result = xts(rowSums(table, na.rm=TRUE), order.by=index(table)) } ) - + colnames(result) = attribute - if(is.null(summary)) {summary=result} - else {summary=cbind(summary,result)} + if(is.null(summary)) {summary=result} + else {summary=cbind(summary,result)} } - # get rid of duplicated indices in the summary data, + # get rid of duplicated indices in the summary data, # thanks to Guy Yollin for the bug report and Josh Ulrich for the elegant approach to fixing it d <- duplicated(.index(summary)) | duplicated(.index(summary), fromLast=TRUE) if(any(d)){ @@ -89,24 +89,24 @@ slist <- period.apply(summary.dups, c(0, which(ds)), f) summary <- rbind(summary[!d,], slist) # put it all back together } - - if(!is.timeBased(Dates)) Dates = xts:::time.xts(Portfolio$symbols[[1]][["posPL"]][Dates]) - startDate = first(xts:::.parseISO8601(Dates))$first.time-.00001 - # trim summary slot to not double count, related to bug 831 on R-Forge, and rbind new summary - if( as.POSIXct(attr(Portfolio,'initDate'))>=startDate || length(Portfolio$summary)==0 ){ - Portfolio$summary<-summary #changes to subset might not return a empty dimnames set of columns - }else{ - Portfolio$summary<-rbind(Portfolio$summary[paste('::',startDate,sep='')],summary) - } - # assign Portfolio to environment - assign( paste("portfolio",pname,sep='.'), Portfolio, envir=.blotter ) - + + if(!is.timeBased(Dates)) Dates = xts:::time.xts(Portfolio$symbols[[1]][["posPL"]][Dates]) + startDate = first(xts:::.parseISO8601(Dates))$first.time-.00001 + # trim summary slot to not double count, related to bug 831 on R-Forge, and rbind new summary + if( as.POSIXct(attr(Portfolio,'initDate'))>=startDate || length(Portfolio$summary)==0 ){ + Portfolio$summary<-summary #changes to subset might not return a empty dimnames set of columns + }else{ + Portfolio$summary<-rbind(Portfolio$summary[paste('::',startDate,sep='')],summary) + } + # assign Portfolio to environment + assign( paste("portfolio",pname,sep='.'), Portfolio, envir=.blotter ) + return(pname) #not sure this is a good idea } ############################################################################### # Blotter: Tools for transaction-oriented trading systems development -# for R (see http://r-project.org/) +# for R (see http://r-project.org/) # Copyright (c) 2008-2011 Peter Carl and Brian G. Peterson # # This library is distributed under the terms of the GNU Public License (GPL) From noreply at r-forge.r-project.org Wed Aug 14 14:20:22 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 14 Aug 2013 14:20:22 +0200 (CEST) Subject: [Blotter-commits] r1496 - pkg/blotter Message-ID: <20130814122022.9C5831853B3@r-forge.r-project.org> Author: peter_carl Date: 2013-08-14 14:20:21 +0200 (Wed, 14 Aug 2013) New Revision: 1496 Modified: pkg/blotter/DESCRIPTION Log: - bumped version Modified: pkg/blotter/DESCRIPTION =================================================================== --- pkg/blotter/DESCRIPTION 2013-08-14 12:01:05 UTC (rev 1495) +++ pkg/blotter/DESCRIPTION 2013-08-14 12:20:21 UTC (rev 1496) @@ -2,7 +2,7 @@ Type: Package Title: Tools for transaction-oriented trading systems development. -Version: 0.8.14 +Version: 0.8.15 Date: $Date$ Author: Peter Carl, Brian G. Peterson Maintainer: Brian G. Peterson From noreply at r-forge.r-project.org Wed Aug 14 16:40:48 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 14 Aug 2013 16:40:48 +0200 (CEST) Subject: [Blotter-commits] r1497 - pkg/blotter/R Message-ID: <20130814144048.F1DA71859A1@r-forge.r-project.org> Author: braverock Date: 2013-08-14 16:40:48 +0200 (Wed, 14 Aug 2013) New Revision: 1497 Modified: pkg/blotter/R/chart.Posn.R Log: - stop if there's nothing to chart Modified: pkg/blotter/R/chart.Posn.R =================================================================== --- pkg/blotter/R/chart.Posn.R 2013-08-14 12:20:21 UTC (rev 1496) +++ pkg/blotter/R/chart.Posn.R 2013-08-14 14:40:48 UTC (rev 1497) @@ -31,33 +31,36 @@ daily = { mult=86400 }, {mult=86400} ) - if(!isTRUE(freq$frequency*mult == round(freq$frequency,0)*mult)) { + if(!isTRUE(freq$frequency*mult == round(freq$frequency,0)*mult)) { # if the equality n=round((freq$frequency/mult),0)*mult } else { n=mult } - + tzero = xts(0,order.by=index(Prices[1,])) if(is.null(Dates)) Dates<-paste(first(index(Prices)),last(index(Prices)),sep='::') - + #scope the data by Dates Portfolio$symbols[[Symbol]]$txn<-Portfolio$symbols[[Symbol]]$txn[Dates] Portfolio$symbols[[Symbol]]$posPL<-Portfolio$symbols[[Symbol]]$posPL[Dates] - - Trades = Portfolio$symbols[[Symbol]]$txn$Txn.Qty - - Buys = Portfolio$symbols[[Symbol]]$txn$Txn.Price[which(Trades>0)] + + Trades = Portfolio$symbols[[Symbol]]$txn$Txn.Qty + + Buys = Portfolio$symbols[[Symbol]]$txn$Txn.Price[which(Trades>0)] Sells = Portfolio$symbols[[Symbol]]$txn$Txn.Price[which(Trades<0)] Position = Portfolio$symbols[[Symbol]]$txn$Pos.Qty + + if(!nrow(Position)>1) stop ('no transactions/positions to chart') + if(as.POSIXct(first(index(Prices)))1) CumPL = na.omit(na.locf(merge(CumPL,index(Prices)))) - else + else CumPL = NULL - + if(!is.null(CumPL)) { CumMax <- cummax(CumPL) Drawdown <- -(CumMax - CumPL) @@ -68,20 +71,20 @@ # # These aren't quite right, as abs(Pos.Qty) should be less than prior abs(Pos.Qty) # SellCover = Portfolio$symbols[[Symbol]]$txn$Txn.Price * (Portfolio$symbols[[Symbol]]$txn$Txn.Qty<0) * (Portfolio$symbols[[Symbol]]$txn$Pos.Qty==0) # BuyCover = Portfolio$symbols[[Symbol]]$txn$Txn.Price * (Portfolio$symbols[[Symbol]]$txn$Txn.Qty>0) * (Portfolio$symbols[[Symbol]]$txn$Pos.Qty==0) - # + # # #Symbol 24 (up) and 25 (dn) can take bkgd colors # addTA(BuyCover,pch=24,type="p",col="green", bg="orange", on=1) # addTA(SellCover,pch=25,type="p",col="red", bg="orange", on=1) # scope the Price data by Dates if(!is.null(Dates)) Prices=Prices[Dates] - + chart_Series(Prices, name=Symbol, TA=TA, ...) if(!is.null(nrow(Buys)) && nrow(Buys) >=1 ) (add_TA(Buys,pch=2,type='p',col='green', on=1)); if(!is.null(nrow(Sells)) && nrow(Sells) >= 1) (add_TA(Sells,pch=6,type='p',col='red', on=1)); if(nrow(Position)>=1) { - (add_TA(Positionfill,type='h',col='blue', lwd=2)) - (add_TA(Position,type='p',col='orange', lwd=2, on=2)) + (add_TA(Positionfill,type='h',col='blue', lwd=2)) + (add_TA(Position,type='p',col='orange', lwd=2, on=2)) } if(!is.null(CumPL)) (add_TA(CumPL, col='darkgreen', lwd=2)) if(!is.null(Drawdown)) (add_TA(Drawdown, col='darkred', lwd=2, yaxis=c(0,-max(CumMax)))) @@ -90,7 +93,7 @@ ############################################################################### # Blotter: Tools for transaction-oriented trading systems development -# for R (see http://r-project.org/) +# for R (see http://r-project.org/) # Copyright (c) 2008-2011 Peter Carl and Brian G. Peterson # # This library is distributed under the terms of the GNU Public License (GPL) From noreply at r-forge.r-project.org Sun Aug 25 02:26:39 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 25 Aug 2013 02:26:39 +0200 (CEST) Subject: [Blotter-commits] r1498 - in pkg/FinancialInstrument: R man Message-ID: <20130825002639.C2B10185C4A@r-forge.r-project.org> Author: gsee Date: 2013-08-25 02:26:39 +0200 (Sun, 25 Aug 2013) New Revision: 1498 Modified: pkg/FinancialInstrument/R/CompareInstrumentFiles.R pkg/FinancialInstrument/R/instrument.R pkg/FinancialInstrument/R/load.instruments.R pkg/FinancialInstrument/R/ls_by_currency.R pkg/FinancialInstrument/R/ls_by_expiry.R pkg/FinancialInstrument/R/ls_expiries.R pkg/FinancialInstrument/R/ls_instruments.R pkg/FinancialInstrument/R/ls_instruments_by.R pkg/FinancialInstrument/R/ls_strikes.R pkg/FinancialInstrument/R/ls_underlyings.R pkg/FinancialInstrument/R/saveInstruments.R pkg/FinancialInstrument/R/synthetic.R pkg/FinancialInstrument/R/update_instruments.yahoo.R pkg/FinancialInstrument/man/instrument.Rd Log: Remove a bunch of "FinanicalInstrument:::" for CRAN Modified: pkg/FinancialInstrument/R/CompareInstrumentFiles.R =================================================================== --- pkg/FinancialInstrument/R/CompareInstrumentFiles.R 2013-08-14 14:40:48 UTC (rev 1497) +++ pkg/FinancialInstrument/R/CompareInstrumentFiles.R 2013-08-25 00:26:39 UTC (rev 1498) @@ -44,14 +44,14 @@ CompareInstrumentFiles <- function(file1, file2, ...) { force(file1) #backup current instrument environment - bak <- as.list(FinancialInstrument:::.instrument, all.names=TRUE) + bak <- as.list(.instrument, all.names=TRUE) # load files to be compared reloadInstruments(file1) - orig <- as.list(FinancialInstrument:::.instrument, all.names=TRUE) + orig <- as.list(.instrument, all.names=TRUE) if (!missing(file2)) { force(file2) reloadInstruments(file2) - new <- as.list(FinancialInstrument:::.instrument, all.names=TRUE) + new <- as.list(.instrument, all.names=TRUE) } else new <- bak #restore user's instrument environment reloadInstruments(bak) Modified: pkg/FinancialInstrument/R/instrument.R =================================================================== --- pkg/FinancialInstrument/R/instrument.R 2013-08-14 14:40:48 UTC (rev 1497) +++ pkg/FinancialInstrument/R/instrument.R 2013-08-25 00:26:39 UTC (rev 1498) @@ -108,7 +108,7 @@ #' \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}. +#' of the package. i.e. \code{.instrument}. #' #' \code{future} and \code{option} are used to define the contract specs of a #' series of instruments. The \code{primary_id} for these can begin with 1 or @@ -244,7 +244,7 @@ if(assign_i) { assign(primary_id, tmpinstr, - envir=as.environment(FinancialInstrument:::.instrument) ) + envir=as.environment(.instrument) ) return(primary_id) } else return(tmpinstr) } @@ -321,7 +321,7 @@ if(is.null(underlying_id)) { warning("underlying_id should only be NULL for cash-settled futures") } else { - if(!exists(underlying_id, where=FinancialInstrument:::.instrument, + if(!exists(underlying_id, where=.instrument, inherits=TRUE)) { warning("underlying_id not found") # assumes that we know where to look } @@ -478,7 +478,7 @@ first_traded)) temp_series$expires<-unique(c(temp_series$expires,expires)) assign(primary_id, temp_series, - envir=as.environment(FinancialInstrument:::.instrument)) + envir=as.environment(.instrument)) return(primary_id) } else warning("No contract found to update. A new one will be created.") } @@ -539,7 +539,7 @@ if(is.null(underlying_id)) { warning("underlying_id should only be NULL for cash-settled options") } else { - if(!exists(underlying_id, where=FinancialInstrument:::.instrument, + if(!exists(underlying_id, where=.instrument, inherits=TRUE)) { warning("underlying_id not found") # assumes that we know where to look } @@ -656,7 +656,7 @@ first_traded)) temp_series$expires<-unique(c(temp_series$expires,expires)) assign(primary_id, temp_series, - envir=as.environment(FinancialInstrument:::.instrument)) + envir=as.environment(.instrument)) return(primary_id) } else { warning("No contract found to update. A new one will be created.") @@ -851,7 +851,7 @@ class(ccy)<-c("currency","instrument") if (assign_i) { assign(primary_id, ccy, - pos=as.environment(FinancialInstrument:::.instrument) ) + pos=as.environment(.instrument) ) return(primary_id) } ccy @@ -918,11 +918,11 @@ } if (is.null(currency)) currency <- substr(primary_id,4,6) if (is.null(counter_currency)) counter_currency <- substr(primary_id,1,3) - if(!exists(currency, where=FinancialInstrument:::.instrument,inherits=TRUE)) { + if(!exists(currency, where=.instrument,inherits=TRUE)) { warning(paste("currency",currency,"not found")) # assumes that we know where to look } if(!exists(counter_currency, - where=FinancialInstrument:::.instrument,inherits=TRUE)) { + where=.instrument,inherits=TRUE)) { warning(paste("counter_currency",counter_currency,"not found")) # assumes that we know where to look } @@ -971,7 +971,7 @@ temp_series$first_traded<-c(temp_series$first_traded,first_traded) temp_series$maturity<-c(temp_series$maturity,maturity) assign(id, temp_series, - envir=as.environment(FinancialInstrument:::.instrument)) + envir=as.environment(.instrument)) } else { dargs<-list(...) dargs$currency=NULL @@ -1298,12 +1298,12 @@ #' @export #' @rdname getInstrument getInstrument <- function(x, Dates=NULL, silent=FALSE, type='instrument'){ - tmp_instr <- try(get(x,pos=FinancialInstrument:::.instrument),silent=TRUE) + tmp_instr <- try(get(x,pos=.instrument),silent=TRUE) if(inherits(tmp_instr,"try-error") || !inherits(tmp_instr, type)){ xx <- make.names(x) ## First, look to see if x matches any identifiers. # unlist all instruments into a big named vector - ul.instr <- unlist(as.list(FinancialInstrument:::.instrument, + ul.instr <- unlist(as.list(.instrument, all.names=TRUE)) # subset by names that include "identifiers" ul.ident <- ul.instr[grep('identifiers', names(ul.instr))] @@ -1314,7 +1314,7 @@ if (length(tmpname) > 0) { #primary_id is everything before .identifiers id <- gsub("\\.identifiers.*", "", names(tmpname)) - tmp_instr <- try(get(id, pos=FinancialInstrument:::.instrument), + tmp_instr <- try(get(id, pos=.instrument), silent=TRUE) if (inherits(tmp_instr, type)) { #&& (x %in% tmp_instr$identifiers || x %in% make.names(tmp_instr$identifiers)) @@ -1326,14 +1326,14 @@ # to the beginning of id. char.x <- strsplit(x, "")[[1]] # split x into vector of characters x <- substr(x, grep("[^\\.]", char.x)[1], length(char.x)) # excluding leading dots - tmp_instr<-try(get(x,pos=FinancialInstrument:::.instrument),silent=TRUE) + tmp_instr<-try(get(x,pos=.instrument),silent=TRUE) if(!inherits(tmp_instr,type)) { tmp_instr<-try(get(paste(".",x,sep=""), - pos=FinancialInstrument:::.instrument), + pos=.instrument), silent=TRUE) if(!inherits(tmp_instr,type)) { tmp_instr<-try(get(paste("..",x,sep=""), - pos=FinancialInstrument:::.instrument), + pos=.instrument), silent=TRUE) } } @@ -1402,7 +1402,7 @@ if (inherits(instr, 'try-error') || !is.instrument(instr)) stop(paste('instrument ',primary_id,' must be defined first.',sep='')) if (attr == 'primary_id') { - rm(list = primary_id, pos = FinancialInstrument:::.instrument) + rm(list = primary_id, pos = .instrument) } else if (attr == 'currency') { if (!is.currency.name(value)) { stop("currency ", value, " must be an object of type 'currency'") @@ -1440,7 +1440,7 @@ } } instr[[attr]] <- value - assign(instr$primary_id, instr, pos=FinancialInstrument:::.instrument) + assign(instr$primary_id, instr, pos=.instrument) } Modified: pkg/FinancialInstrument/R/load.instruments.R =================================================================== --- pkg/FinancialInstrument/R/load.instruments.R 2013-08-14 14:40:48 UTC (rev 1497) +++ pkg/FinancialInstrument/R/load.instruments.R 2013-08-25 00:26:39 UTC (rev 1498) @@ -181,7 +181,7 @@ #load all instrument names instr_names <- if(missing(Symbols)) { - ls_non_currencies(ls(pos=FinancialInstrument:::.instrument)) #if roots begin with a dot, this will filter out roots and currencies + ls_non_currencies(ls(pos=.instrument)) #if roots begin with a dot, this will filter out roots and currencies } else Symbols #TODO add check to make sure that src is actually the name of a getSymbols function Modified: pkg/FinancialInstrument/R/ls_by_currency.R =================================================================== --- pkg/FinancialInstrument/R/ls_by_currency.R 2013-08-14 14:40:48 UTC (rev 1497) +++ pkg/FinancialInstrument/R/ls_by_currency.R 2013-08-25 00:26:39 UTC (rev 1498) @@ -81,7 +81,7 @@ tmp_symbols <- NULL for (symbol in symbols) { - tmp_instr <- try(get(symbol, pos = FinancialInstrument:::.instrument),silent=TRUE) + tmp_instr <- try(get(symbol, pos = .instrument),silent=TRUE) if (is.instrument(tmp_instr) && tmp_instr$currency == currency ){ tmp_symbols <- c(tmp_symbols,symbol) @@ -101,7 +101,7 @@ if (missing(x)) { x <- ls_by_currency(currency,show.currencies=sc) } else x <- ls_by_currency(currency,pattern=x,show.currencies=sc) - rm(list=x,pos=FinancialInstrument:::.instrument) + rm(list=x,pos=.instrument) } #AUD GBP CAD EUR JPY CHF HKD SEK NZD Modified: pkg/FinancialInstrument/R/ls_by_expiry.R =================================================================== --- pkg/FinancialInstrument/R/ls_by_expiry.R 2013-08-14 14:40:48 UTC (rev 1497) +++ pkg/FinancialInstrument/R/ls_by_expiry.R 2013-08-25 00:26:39 UTC (rev 1498) @@ -61,7 +61,7 @@ expiry <- gsub("-", "", expiry) tmp_symbols <- NULL for (symbol in symbols) { - tmp_instr <- try(get(symbol, pos = FinancialInstrument:::.instrument),silent=TRUE) + tmp_instr <- try(get(symbol, pos = .instrument),silent=TRUE) if (is.instrument(tmp_instr) ) { if ((!is.null(tmp_instr$expires) && any(gsub("-", "", tmp_instr$expires) == expiry)) || (!is.null(tmp_instr$expiry) && any(gsub("-", "", tmp_instr$expiry) == expiry)) ) { @@ -78,7 +78,7 @@ if (missing(x)) { x <- ls_by_expiry(expiry) } else x <- ls_by_expiry(expiry,pattern=x) - rm(list=x,pos=FinancialInstrument:::.instrument) + rm(list=x,pos=.instrument) } #rm_by_expiry(ls_options(),'20130119') Modified: pkg/FinancialInstrument/R/ls_expiries.R =================================================================== --- pkg/FinancialInstrument/R/ls_expiries.R 2013-08-14 14:40:48 UTC (rev 1497) +++ pkg/FinancialInstrument/R/ls_expiries.R 2013-08-25 00:26:39 UTC (rev 1498) @@ -56,7 +56,7 @@ dates <- NULL underlyings <- NULL for (symbol in symbols) { - tmp_instr <- try(get(symbol,pos=FinancialInstrument:::.instrument),silent=TRUE) + tmp_instr <- try(get(symbol,pos=.instrument),silent=TRUE) if (!is.null(tmp_instr$underlying_id) && any(tmp_instr$underlying_id==underlying_id)) { #the underlying_id of this instr mathces one of the one's we're interested in. underlying <- tmp_instr$underlying_id if (is.null(tmp_instr$expires)) { #get value for expiry; may be in 'expires' or 'expiry' slot Modified: pkg/FinancialInstrument/R/ls_instruments.R =================================================================== --- pkg/FinancialInstrument/R/ls_instruments.R 2013-08-14 14:40:48 UTC (rev 1497) +++ pkg/FinancialInstrument/R/ls_instruments.R 2013-08-25 00:26:39 UTC (rev 1498) @@ -118,12 +118,12 @@ match <- TRUE } if (!is.null(pattern) && match) { #there's a pattern and match is TRUE - symbols <- ls(FinancialInstrument:::.instrument, all.names=TRUE) + symbols <- ls(.instrument, all.names=TRUE) symbols <- symbols[match(pattern,symbols)] } else if (!match && length(pattern) == 1) { # pattern is length(1) and don't match - symbols <- ls(FinancialInstrument:::.instrument, all.names=TRUE, pattern=pattern) + symbols <- ls(.instrument, all.names=TRUE, pattern=pattern) } else if (is.null(pattern)) { #no pattern - symbols <- ls(FinancialInstrument:::.instrument, all.names=TRUE) + symbols <- ls(.instrument, all.names=TRUE) } # else pattern length > 1 & don't match is.iname <- is.instrument.name(symbols) @@ -137,7 +137,7 @@ symbols <- ls_instruments(pattern,match) tmp_symbols <- NULL for (instr in symbols) { - tmp_instr <- try(get(instr, pos = FinancialInstrument:::.instrument),silent=TRUE) + tmp_instr <- try(get(instr, pos = .instrument),silent=TRUE) if (inherits(tmp_instr, 'stock') && inherits(tmp_instr, 'instrument')) { tmp_symbols <- c(tmp_symbols,instr) } @@ -151,7 +151,7 @@ symbols <- ls_instruments(pattern,match) tmp_symbols <- NULL for (instr in symbols) { - tmp_instr <- try(get(instr, pos = FinancialInstrument:::.instrument),silent=TRUE) + tmp_instr <- try(get(instr, pos = .instrument),silent=TRUE) if (inherits(tmp_instr, 'option') && inherits(tmp_instr, 'instrument')) { if (!inherits(tmp_instr, 'option_series') || include.series) tmp_symbols <- c(tmp_symbols,instr) @@ -166,7 +166,7 @@ symbols <- ls_instruments(pattern,match) tmp_symbols <- NULL for (instr in symbols) { - tmp_instr <- try(get(instr, pos = FinancialInstrument:::.instrument),silent=TRUE) + tmp_instr <- try(get(instr, pos = .instrument),silent=TRUE) if (inherits(tmp_instr, 'option_series') && inherits(tmp_instr, 'instrument')) { tmp_symbols <- c(tmp_symbols,instr) } @@ -180,7 +180,7 @@ symbols <- ls_instruments(pattern,match) tmp_symbols <- NULL for (instr in symbols) { - tmp_instr <- try(get(instr, pos = FinancialInstrument:::.instrument),silent=TRUE) + tmp_instr <- try(get(instr, pos = .instrument),silent=TRUE) if (inherits(tmp_instr, 'future') && inherits(tmp_instr, 'instrument')) { if (!inherits(tmp_instr, 'future_series') || include.series) tmp_symbols <- c(tmp_symbols,instr) @@ -195,7 +195,7 @@ symbols <- ls_instruments(pattern,match) tmp_symbols <- NULL for (instr in symbols) { - tmp_instr <- try(get(instr, pos = FinancialInstrument:::.instrument),silent=TRUE) + tmp_instr <- try(get(instr, pos = .instrument),silent=TRUE) if (inherits(tmp_instr, 'future_series') && inherits(tmp_instr, 'instrument')) { tmp_symbols <- c(tmp_symbols,instr) } @@ -209,7 +209,7 @@ symbols <- ls_instruments(pattern=pattern, match=match) tmp_symbols <- NULL for (instr in symbols) { - tmp_instr <- try(get(instr, pos = FinancialInstrument:::.instrument), + tmp_instr <- try(get(instr, pos = .instrument), silent=TRUE) if (inherits(tmp_instr, 'currency') && inherits(tmp_instr, 'instrument')) { @@ -227,7 +227,7 @@ symbols <- ls_instruments(pattern, match) tmp_symbols <- NULL for (instr in symbols) { - tmp_instr <- try(get(instr, pos = FinancialInstrument:::.instrument), + tmp_instr <- try(get(instr, pos = .instrument), silent=TRUE) if (!inherits(tmp_instr, 'currency') || (inherits(tmp_instr, 'exchange_rate') && includeFX) ) { @@ -243,7 +243,7 @@ symbols <- ls_currencies(pattern=pattern, match=match, includeFX=TRUE) tmp_symbols <- NULL for (instr in symbols) { - tmp_instr <- try(get(instr, pos = FinancialInstrument:::.instrument), + tmp_instr <- try(get(instr, pos = .instrument), silent=TRUE) if (inherits(tmp_instr, 'exchange_rate') && inherits(tmp_instr, 'instrument')) { @@ -263,7 +263,7 @@ symbols <- ls_instruments(pattern,match) tmp_symbols <- NULL for (instr in symbols) { - tmp_instr <- try(get(instr, pos = FinancialInstrument:::.instrument),silent=TRUE) + tmp_instr <- try(get(instr, pos = .instrument),silent=TRUE) if (inherits(tmp_instr, 'bond') && inherits(tmp_instr, 'instrument')) { tmp_symbols <- c(tmp_symbols,instr) } @@ -277,7 +277,7 @@ symbols <- ls_instruments(pattern,match) tmp_symbols <- NULL for (instr in symbols) { - tmp_instr <- try(get(instr, pos = FinancialInstrument:::.instrument),silent=TRUE) + tmp_instr <- try(get(instr, pos = .instrument),silent=TRUE) if (inherits(tmp_instr, 'fund') && inherits(tmp_instr, 'instrument')) { tmp_symbols <- c(tmp_symbols,instr) } @@ -291,7 +291,7 @@ symbols <- ls_instruments(pattern,match) tmp_symbols <- NULL for (instr in symbols) { - tmp_instr <- try(get(instr, pos = FinancialInstrument:::.instrument),silent=TRUE) + tmp_instr <- try(get(instr, pos = .instrument),silent=TRUE) if (inherits(tmp_instr, 'spread') && inherits(tmp_instr, 'instrument')) { tmp_symbols <- c(tmp_symbols,instr) } @@ -305,7 +305,7 @@ symbols <- ls_instruments(pattern,match) tmp_symbols <- NULL for (instr in symbols) { - tmp_instr <- try(get(instr, pos = FinancialInstrument:::.instrument),silent=TRUE) + tmp_instr <- try(get(instr, pos = .instrument),silent=TRUE) if (inherits(tmp_instr, 'guaranteed_spread') && inherits(tmp_instr, 'instrument')) { tmp_symbols <- c(tmp_symbols,instr) } @@ -319,7 +319,7 @@ symbols <- ls_instruments(pattern,match) tmp_symbols <- NULL for (instr in symbols) { - tmp_instr <- try(get(instr, pos = FinancialInstrument:::.instrument),silent=TRUE) + tmp_instr <- try(get(instr, pos = .instrument),silent=TRUE) if (inherits(tmp_instr, 'synthetic') && inherits(tmp_instr, 'instrument')) { tmp_symbols <- c(tmp_symbols,instr) } @@ -333,7 +333,7 @@ symbols <- ls_instruments(pattern,match) tmp_symbols <- NULL for (instr in symbols) { - tmp_instr <- try(get(instr, pos = FinancialInstrument:::.instrument),silent=TRUE) + tmp_instr <- try(get(instr, pos = .instrument),silent=TRUE) if (inherits(tmp_instr, 'ICS') && inherits(tmp_instr, 'instrument')) { tmp_symbols <- c(tmp_symbols,instr) } @@ -347,7 +347,7 @@ symbols <- ls_instruments(pattern,match) tmp_symbols <- NULL for (instr in symbols) { - tmp_instr <- try(get(instr, pos = FinancialInstrument:::.instrument),silent=TRUE) + tmp_instr <- try(get(instr, pos = .instrument),silent=TRUE) if (inherits(tmp_instr, 'ICS_root') && inherits(tmp_instr, 'instrument')) { tmp_symbols <- c(tmp_symbols,instr) } @@ -361,7 +361,7 @@ # symbols <- ls_instruments(pattern) #TODO: other functions should be updated to get symbols like this too # tmp_symbols <- NULL # for (instr in symbols) { -# tmp_instr <- try(get(instr, pos = FinancialInstrument:::.instrument),silent=TRUE) +# tmp_instr <- try(get(instr, pos = .instrument),silent=TRUE) # if ( is.instrument(tmp_instr) && !is.null(tmp_instr$defined.by) ) { # dby <- unlist(strsplit( tmp_instr$defined.by,";")) # if (any(dby == "yahoo" )) @@ -376,7 +376,7 @@ # symbols <- ls_instruments(pattern) # tmp_symbols <- NULL # for (instr in symbols) { -# tmp_instr <- try(get(instr, pos = FinancialInstrument:::.instrument),silent=TRUE) +# tmp_instr <- try(get(instr, pos = .instrument),silent=TRUE) # if ( is.instrument(tmp_instr) && !is.null(tmp_instr$defined.by) ) { # dby <- unlist(strsplit( tmp_instr$defined.by,";")) # if (any(dby == "IB" )) tmp_symbols <- c(tmp_symbols,instr) @@ -390,7 +390,7 @@ # symbols <- ls_instruments(pattern) # tmp_symbols <- NULL # for (symbol in symbols) { -# tmp_instr <- try(get(symbol, pos=FinancialInstrument:::.instrument),silent=TRUE) +# tmp_instr <- try(get(symbol, pos=.instrument),silent=TRUE) # if (is.instrument(tmp_instr) && !is.null(tmp_instr$defined.by) ) { # dby <- unlist(strsplit( tmp_instr$defined.by,";")) # if (any(dby == x)) tmp_symbols <- c(tmp_symbols,symbol) @@ -407,7 +407,7 @@ #but check for it in case someone made one tmp_symbols <- NULL for (instr in symbols) { - tmp_instr <- try(get(instr, pos = FinancialInstrument:::.instrument),silent=TRUE) + tmp_instr <- try(get(instr, pos = .instrument),silent=TRUE) if (inherits(tmp_instr, 'derivative') || inherits(tmp_instr, 'option') || inherits(tmp_instr, 'future') ) { @@ -425,7 +425,7 @@ #but check for it in case someone made one tmp_symbols <- NULL for (instr in symbols) { - tmp_instr <- try(get(instr, pos = FinancialInstrument:::.instrument),silent=TRUE) + tmp_instr <- try(get(instr, pos = .instrument),silent=TRUE) if (!inherits(tmp_instr, 'derivative') && !inherits(tmp_instr, 'option') && !inherits(tmp_instr, 'future') ) { @@ -442,7 +442,7 @@ symbols <- ls_options(pattern=pattern,match=match) tmp_symbols <- NULL for (instr in symbols) { - tmp_instr <- try(get(instr, pos = FinancialInstrument:::.instrument),silent=TRUE) + tmp_instr <- try(get(instr, pos = .instrument),silent=TRUE) if (is.instrument(tmp_instr) && inherits(tmp_instr, 'option')) { if (!is.null(tmp_instr$callput)) { right <- tmp_instr$callput @@ -464,7 +464,7 @@ symbols <- ls_options(pattern=pattern,match=match) tmp_symbols <- NULL for (instr in symbols) { - tmp_instr <- try(get(instr, pos = FinancialInstrument:::.instrument),silent=TRUE) + tmp_instr <- try(get(instr, pos = .instrument),silent=TRUE) if (is.instrument(tmp_instr) && inherits(tmp_instr, 'option')) { if (!is.null(tmp_instr$callput)) { right <- tmp_instr$callput @@ -496,7 +496,7 @@ } else stop('Use keep.currencies=FALSE to delete a currency') } - rm(list=x,pos=FinancialInstrument:::.instrument) + rm(list=x,pos=.instrument) } #' @export @@ -505,7 +505,7 @@ if (missing(x)) { x <- ls_stocks() } - rm(list=x[x %in% ls_stocks()], pos=FinancialInstrument:::.instrument) + rm(list=x[x %in% ls_stocks()], pos=.instrument) } #' @export @@ -514,7 +514,7 @@ if (missing(x)) { x <- ls_options() } - rm(list=x[x %in% ls_options()], pos=FinancialInstrument:::.instrument) + rm(list=x[x %in% ls_options()], pos=.instrument) } #' @export @@ -523,7 +523,7 @@ if (missing(x)) { x <- ls_option_series() } - rm(list=x[x %in% ls_option_series()], pos=FinancialInstrument:::.instrument) + rm(list=x[x %in% ls_option_series()], pos=.instrument) } #' @export @@ -532,7 +532,7 @@ if (missing(x)) { x <- ls_futures() } - rm(list=x[x %in% ls_futures()], pos=FinancialInstrument:::.instrument) + rm(list=x[x %in% ls_futures()], pos=.instrument) } #' @export @@ -541,7 +541,7 @@ if (missing(x)) { x <- ls_future_series() } - rm(list=x[x %in% ls_future_series()], pos=FinancialInstrument:::.instrument) + rm(list=x[x %in% ls_future_series()], pos=.instrument) } #' @export @@ -550,7 +550,7 @@ if (missing(x)) { x <- ls_currencies() } - rm(list=x[x %in% ls_currencies()], pos=FinancialInstrument:::.instrument) + rm(list=x[x %in% ls_currencies()], pos=.instrument) } #' @export @@ -559,7 +559,7 @@ if (missing(x)) { x <- ls_exchange_rates() } - rm(list=x[x %in% ls_exchange_rates()], pos=FinancialInstrument:::.instrument) + rm(list=x[x %in% ls_exchange_rates()], pos=.instrument) } #' @export @@ -572,7 +572,7 @@ if (missing(x)) { x <- ls_bonds() } - rm(list=x[x %in% ls_bonds()], pos=FinancialInstrument:::.instrument) + rm(list=x[x %in% ls_bonds()], pos=.instrument) } #' @export @@ -581,7 +581,7 @@ if (missing(x)) { x <- ls_funds() } - rm(list=x[x %in% ls_funds()], pos=FinancialInstrument:::.instrument) + rm(list=x[x %in% ls_funds()], pos=.instrument) } #' @export @@ -590,7 +590,7 @@ if (missing(x)) { x <- ls_spreads() } - rm(list=x[x %in% ls_spreads()], pos=FinancialInstrument:::.instrument) + rm(list=x[x %in% ls_spreads()], pos=.instrument) } #' @export @@ -599,7 +599,7 @@ if (missing(x)) { x <- ls_synthetics() } - rm(list=x[x %in% ls_synthetics()],pos=FinancialInstrument:::.instrument) + rm(list=x[x %in% ls_synthetics()],pos=.instrument) } @@ -609,7 +609,7 @@ if (missing(x)) { x <- ls_derivatives() } - rm(list=x[x %in% ls_derivatives()],pos=FinancialInstrument:::.instrument) + rm(list=x[x %in% ls_derivatives()],pos=.instrument) } #' @export @@ -624,7 +624,7 @@ x <- x[-match(ls_currencies(),x)] #then take them out of to-be-removed } else stop('Use keep.currencies=FALSE to delete a currency') } - rm(list=x[x %in% ls_non_derivatives()],pos=FinancialInstrument:::.instrument) + rm(list=x[x %in% ls_non_derivatives()],pos=.instrument) } Modified: pkg/FinancialInstrument/R/ls_instruments_by.R =================================================================== --- pkg/FinancialInstrument/R/ls_instruments_by.R 2013-08-14 14:40:48 UTC (rev 1497) +++ pkg/FinancialInstrument/R/ls_instruments_by.R 2013-08-25 00:26:39 UTC (rev 1498) @@ -57,7 +57,7 @@ if (missing(value)) value <- NULL tmp_symbols <- NULL for (symbol in symbols) { - tmp_instr <- try(get(symbol, pos = FinancialInstrument:::.instrument),silent=TRUE) + tmp_instr <- try(get(symbol, pos = .instrument),silent=TRUE) #TODO: clean this up if (is.instrument(tmp_instr)) { if ( Modified: pkg/FinancialInstrument/R/ls_strikes.R =================================================================== --- pkg/FinancialInstrument/R/ls_strikes.R 2013-08-14 14:40:48 UTC (rev 1497) +++ pkg/FinancialInstrument/R/ls_strikes.R 2013-08-25 00:26:39 UTC (rev 1498) @@ -36,7 +36,7 @@ symbols <- ls_option_series(pattern, match=FALSE) tmp_symbols <- NULL for (symbol in symbols) { - tmp_instr <- try(get(symbol,pos=FinancialInstrument:::.instrument),silent=TRUE) + tmp_instr <- try(get(symbol,pos=.instrument),silent=TRUE) #if (is.instrument(tmp_instr)) if (!is.null(tmp_instr$strike)) tmp_symbols <- c(tmp_symbols,tmp_instr$strike) Modified: pkg/FinancialInstrument/R/ls_underlyings.R =================================================================== --- pkg/FinancialInstrument/R/ls_underlyings.R 2013-08-14 14:40:48 UTC (rev 1497) +++ pkg/FinancialInstrument/R/ls_underlyings.R 2013-08-25 00:26:39 UTC (rev 1498) @@ -38,7 +38,7 @@ symbols <- ls_derivatives(pattern, match) tmp_symbols <- NULL for (symbol in symbols) { - tmp_instr <- try(get(symbol,pos=FinancialInstrument:::.instrument),silent=TRUE) + tmp_instr <- try(get(symbol,pos=.instrument),silent=TRUE) #if (is.instrument(tmp_instr)) if (!is.null(tmp_instr$underlying_id)) tmp_symbols <- c(tmp_symbols,tmp_instr$underlying_id) Modified: pkg/FinancialInstrument/R/saveInstruments.R =================================================================== --- pkg/FinancialInstrument/R/saveInstruments.R 2013-08-14 14:40:48 UTC (rev 1497) +++ pkg/FinancialInstrument/R/saveInstruments.R 2013-08-25 00:26:39 UTC (rev 1498) @@ -63,7 +63,6 @@ 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 ssfn <- strsplit(file_name, "\\.")[[1]] extension <- if (tolower(tail(ssfn, 1)) %in% c('rda', 'rdata', 'r', 'txt')) { file_name <- paste(ssfn[1:(length(ssfn)-1)], collapse=".") @@ -76,7 +75,7 @@ "require(FinancialInstrument)\n\n", file=file.name) for (s in ls_instruments()) { sink(file.name, append=TRUE) - cat('assign("', s, '", pos=FinancialInstrument:::.instrument, ', + cat('assign("', s, '", pos=.instrument, ', 'value=\n', sep="", append=TRUE) dput(getInstrument(s)) cat(")\n\n", append=TRUE) @@ -99,7 +98,7 @@ } for (i in seq_along(ilist)) { assign(ilist[[i]][["primary_id"]], ilist[[i]], - pos=FinancialInstrument:::.instrument) + pos=.instrument) } return(invisible(NULL)) } @@ -122,7 +121,7 @@ il <- ls(tmpenv$.instrument, all.names=TRUE) for (i in il) { assign(i, tmpenv$.instrument[[i]], - pos=FinancialInstrument:::.instrument, inherits=FALSE) + pos=.instrument, inherits=FALSE) } } } Modified: pkg/FinancialInstrument/R/synthetic.R =================================================================== --- pkg/FinancialInstrument/R/synthetic.R 2013-08-14 14:40:48 UTC (rev 1497) +++ pkg/FinancialInstrument/R/synthetic.R 2013-08-25 00:26:39 UTC (rev 1498) @@ -376,7 +376,7 @@ }) # Check to make sure members exist in instrument envir. Warn if not. - defined <- sapply(members, exists, where=FinancialInstrument:::.instrument) + defined <- sapply(members, exists, where=.instrument) if (any(defined == FALSE)) warning("No instrument definition found for ", paste(members[!defined], collapse=" ")) memberratio <- suff.2 Modified: pkg/FinancialInstrument/R/update_instruments.yahoo.R =================================================================== --- pkg/FinancialInstrument/R/update_instruments.yahoo.R 2013-08-14 14:40:48 UTC (rev 1497) +++ pkg/FinancialInstrument/R/update_instruments.yahoo.R 2013-08-25 00:26:39 UTC (rev 1498) @@ -118,7 +118,7 @@ instr$defined.by=db instr$updated=Sys.time() - assign(Symbols[i], instr, pos=FinancialInstrument:::.instrument) + assign(Symbols[i], instr, pos=.instrument) } } Symbols @@ -379,7 +379,7 @@ if (isTRUE(assign_i)) { invisible(lapply(out, function(x) { if (!is.null(x)) assign(x$primary_id, x, - pos=FinancialInstrument:::.instrument) + pos=.instrument) })) } else return(out) do.call(c, lapply(out, "[[", "primary_id")) Modified: pkg/FinancialInstrument/man/instrument.Rd =================================================================== --- pkg/FinancialInstrument/man/instrument.Rd 2013-08-14 14:40:48 UTC (rev 1497) +++ pkg/FinancialInstrument/man/instrument.Rd 2013-08-25 00:26:39 UTC (rev 1498) @@ -134,7 +134,7 @@ As of version 0.10.0, the .instrument environment is located at the top level of the package. i.e. - \code{FinancialInstrument:::.instrument}. + \code{.instrument}. \code{future} and \code{option} are used to define the contract specs of a series of instruments. The From noreply at r-forge.r-project.org Mon Aug 26 11:01:15 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 26 Aug 2013 11:01:15 +0200 (CEST) Subject: [Blotter-commits] r1499 - in pkg/quantstrat: . R demo Message-ID: <20130826090115.F27AE185928@r-forge.r-project.org> Author: opentrades Date: 2013-08-26 11:01:15 +0200 (Mon, 26 Aug 2013) New Revision: 1499 Modified: pkg/quantstrat/NAMESPACE pkg/quantstrat/R/paramsets.R pkg/quantstrat/demo/luxor.2.add.paramsets.R pkg/quantstrat/demo/luxor.5.strategy.ordersets.R pkg/quantstrat/demo/luxor.include.R Log: - renamed add.constraint to add.distribution.constraint Modified: pkg/quantstrat/NAMESPACE =================================================================== --- pkg/quantstrat/NAMESPACE 2013-08-25 00:26:39 UTC (rev 1498) +++ pkg/quantstrat/NAMESPACE 2013-08-26 09:01:15 UTC (rev 1499) @@ -1,5 +1,5 @@ -export(add.constraint) export(add.distribution) +export(add.distribution.constraint) export(add.indicator) export(add.init) export(add.rule) Modified: pkg/quantstrat/R/paramsets.R =================================================================== --- pkg/quantstrat/R/paramsets.R 2013-08-25 00:26:39 UTC (rev 1498) +++ pkg/quantstrat/R/paramsets.R 2013-08-26 09:01:15 UTC (rev 1499) @@ -216,7 +216,7 @@ #' #' @author Jan Humme #' @export -#' @seealso \code{\link{add.distibution}}, \code{\link{add.constraint}}, \code{\link{apply.paramset}} +#' @seealso \code{\link{add.distibution}}, \code{\link{add.distribution.constraint}}, \code{\link{apply.paramset}} delete.paramset <- function(strategy, paramset.label, store=TRUE) { @@ -255,7 +255,7 @@ #' #' @author Jan Humme #' @export -#' @seealso \code{\link{add.constraint}}, \code{\link{delete.paramset}}, \code{\link{apply.paramset}} +#' @seealso \code{\link{add.distribution.constraint}}, \code{\link{delete.paramset}}, \code{\link{apply.paramset}} add.distribution <- function(strategy, paramset.label, component.type, component.label, variable, weight=NULL, label, store=TRUE) { @@ -303,7 +303,7 @@ #' @export #' @seealso \code{\link{add.distribution}}, \code{\link{delete.paramset}}, \code{\link{apply.paramset}} -add.constraint <- function(strategy, paramset.label, distribution.label.1, distribution.label.2, operator, label, store=TRUE) +add.distribution.constraint <- function(strategy, paramset.label, distribution.label.1, distribution.label.2, operator, label, store=TRUE) { must.have.args(match.call(), c('strategy', 'paramset.label', 'distribution.label.1', 'distribution.label.2', 'operator', 'label')) @@ -355,7 +355,7 @@ #' #' @author Jan Humme #' @export -#' @seealso \code{\link{add.constraint}}, \code{\link{add.constraint}}, \code{\link{delete.paramset}} +#' @seealso \code{\link{add.distribution.constraint}}, \code{\link{add.distribution.constraint}}, \code{\link{delete.paramset}} apply.paramset <- function(strategy.st, paramset.label, portfolio.st, account.st, mktdata=NULL, nsamples=0, user.func=NULL, user.args=NULL, calc='slave', audit=NULL, packages=NULL, verbose=FALSE) { Modified: pkg/quantstrat/demo/luxor.2.add.paramsets.R =================================================================== --- pkg/quantstrat/demo/luxor.2.add.paramsets.R 2013-08-25 00:26:39 UTC (rev 1498) +++ pkg/quantstrat/demo/luxor.2.add.paramsets.R 2013-08-26 09:01:15 UTC (rev 1499) @@ -47,7 +47,7 @@ label = 'nSLOW' ) -add.constraint(strategy.st, +add.distribution.constraint(strategy.st, paramset.label = 'SMA', distribution.label.1 = 'nFAST', distribution.label.2 = 'nSLOW', Modified: pkg/quantstrat/demo/luxor.5.strategy.ordersets.R =================================================================== --- pkg/quantstrat/demo/luxor.5.strategy.ordersets.R 2013-08-25 00:26:39 UTC (rev 1498) +++ pkg/quantstrat/demo/luxor.5.strategy.ordersets.R 2013-08-26 09:01:15 UTC (rev 1499) @@ -151,7 +151,7 @@ label = 'nSLOW' ) -add.constraint(strategy.st, +add.distribution.constraint(strategy.st, paramset.label = 'SMA', distribution.label.1 = 'nFAST', distribution.label.2 = 'nSLOW', @@ -205,7 +205,7 @@ label = 'StopLossSHORT' ) -add.constraint(strategy.st, +add.distribution.constraint(strategy.st, paramset.label = 'StopLoss', distribution.label.1 = 'StopLossLONG', distribution.label.2 = 'StopLossSHORT', @@ -259,7 +259,7 @@ label = 'StopTrailingSHORT' ) -add.constraint(strategy.st, +add.distribution.constraint(strategy.st, paramset.label = 'StopTrailing', distribution.label.1 = 'StopTrailingLONG', distribution.label.2 = 'StopTrailingSHORT', @@ -313,7 +313,7 @@ label = 'TakeProfitSHORT' ) -add.constraint(strategy.st, +add.distribution.constraint(strategy.st, paramset.label = 'TakeProfit', distribution.label.1 = 'TakeProfitLONG', distribution.label.2 = 'TakeProfitSHORT', @@ -339,7 +339,7 @@ label = 'nSLOW' ) -add.constraint(strategy.st, +add.distribution.constraint(strategy.st, paramset.label = 'WFA', distribution.label.1 = 'nFAST', distribution.label.2 = 'nSLOW', Modified: pkg/quantstrat/demo/luxor.include.R =================================================================== --- pkg/quantstrat/demo/luxor.include.R 2013-08-25 00:26:39 UTC (rev 1498) +++ pkg/quantstrat/demo/luxor.include.R 2013-08-26 09:01:15 UTC (rev 1499) @@ -11,8 +11,8 @@ .from=initDate +#.to='2008-07-04' .to='2002-10-31' -#.to='2008-07-04' ### @@ -56,7 +56,8 @@ .slow = 44 #.timespan = 'T09:00/T13:00' -.timespan = 'T00:00/T23:59' +#.timespan = 'T00:00/T23:59' +.timespan = NULL .stoploss <- 0.40/100 .stoptrailing <- 0.8/100