[Blotter-commits] r352 - pkg/blotter/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Jul 14 17:44:43 CEST 2010
Author: braverock
Date: 2010-07-14 17:44:43 +0200 (Wed, 14 Jul 2010)
New Revision: 352
Modified:
pkg/blotter/R/addPortfInstr.R
pkg/blotter/R/addTxn.R
pkg/blotter/R/initPortf.R
Log:
- apply patches by Wolfgang Wu <wobwu22 [at] yahoo [dot] de>
Modified: pkg/blotter/R/addPortfInstr.R
===================================================================
--- pkg/blotter/R/addPortfInstr.R 2010-07-13 17:15:56 UTC (rev 351)
+++ pkg/blotter/R/addPortfInstr.R 2010-07-14 15:44:43 UTC (rev 352)
@@ -1,23 +1,18 @@
-addPortfInstr <- function(Portfolio,symbols,...,verbose=TRUE)
+addPortfInstr <- function(Portfolio,symbols,...)
{
pname<-Portfolio
- portfolio<-get(paste("portfolio",pname,sep='.'),envir=.blotter)
+ portfolio<-get(paste("portfolio",pname,sep='.'),envir=.blotter)
if(inherits(Portfolio,"try-error"))
stop(paste("Portfolio",pname," not found, use initPortf() to create a new portfolio"))
-
- msymbols<-match(names(portfolio),symbols)
- symbols<-symbols[which(is.na(msymbols))]
-
- if(missing(initPosQty)) initPosQty=rep(0, length(symbols))
-
+ initDate <- attr(portfolio, "initDate")
+ currency <- attr(portfolio, "currency")
for(instrument in symbols){
- i = match(instrument, symbols)
- portfolio[[instrument]]$txn = initTxn(initDate = initDate, initPosQty = initPosQty[i])
- portfolio[[instrument]]$posPL = initPosPL(initDate = initDate, initPosQty = initPosQty[i])
+ portfolio[[instrument]]$txn = initTxn(initDate = initDate, initPosQty = 0)
+ portfolio[[instrument]]$posPL = initPosPL(initDate = initDate, initPosQty = 0)
+ portfolio[[instrument]][[paste('posPL',currency,sep='.')]] = portfolio[[instrument]]$posPL
}
-
- assign(paste("portfolio",as.character(pname),sep='.'),portfolio,envir=.blotter)
-
+
+ assign(paste("portfolio",as.character(pname),sep='.'),portfolio,envir=.blotter)
}
###############################################################################
Modified: pkg/blotter/R/addTxn.R
===================================================================
--- pkg/blotter/R/addTxn.R 2010-07-13 17:15:56 UTC (rev 351)
+++ pkg/blotter/R/addTxn.R 2010-07-14 15:44:43 UTC (rev 352)
@@ -15,6 +15,7 @@
#' @export
addTxn <- function(Portfolio, Symbol, TxnDate, TxnQty, TxnPrice, ..., TxnFees=0, ConMult=NULL, verbose=TRUE)
{ # @author Peter Carl
+
pname<-Portfolio
Portfolio<-get(paste("portfolio",pname,sep='.'),envir=.blotter)
@@ -27,6 +28,15 @@
ConMult<-tmp_instr$multiplier
}
}
+
+
+
+ #If there is no table for the symbol then create a new one
+ if (is.null(Portfolio[[Symbol]])){
+ addPortfInstr(Portfolio=pname, symbols=Symbol)
+ Portfolio<-get(paste("portfolio",pname,sep='.'),envir=.blotter)
+ }
+
# Outputs:
# Portfolio: hands back the entire portfolio object with the additional
# transaction in the correct slot: Portfolio[[Symbol]]$txn
Modified: pkg/blotter/R/initPortf.R
===================================================================
--- pkg/blotter/R/initPortf.R 2010-07-13 17:15:56 UTC (rev 351)
+++ pkg/blotter/R/initPortf.R 2010-07-14 15:44:43 UTC (rev 352)
@@ -38,6 +38,7 @@
}
class(portfolio)<-c("blotter_portfolio", "portfolio")
attr(portfolio,'currency')<-currency
+ attr(portfolio,'initDate')<-initDate
#return(portfolio)
assign(paste("portfolio",as.character(name),sep='.'),portfolio,envir=.blotter)
return(name) # not sure this is a good idea
More information about the Blotter-commits
mailing list