Hi,
Currently I am stuck on an error with updatePortf function in blotter. The
error message is same as the issue mentioned on R-sig-finance previously
i.e.,
http://r.789695.n4.nabble.com/blotter-updatePortf-issues-tp4635933.html

>
> updatePortf(Portfolio=portfolio,Dates=paste('::',as.Date(Sys.time()),sep=''))
> Error in if (length(c(year, month, day, hour, min, sec)) == 6 && c(year,
>  :
>   missing value where TRUE/FALSE needed
> In addition: Warning message:
> In as_numeric(YYYY) : NAs introduced by coercion


I don't think the problem is in updatePortf code though as I can execute
without errors all 3 demos as well as the "IBM"  updatePortf test case that
come with blotter. I tried various ways of providing dates and also did
line by line comparisons with samples but cannot figure out what is
different in my program that is causing the error. I appreciate any help.
(Note: I am bit new to R and this is my 1st post on R-sig. So please let me
know if I am supposed to include any other info. Thx)

Following are the details:

*Session Info:*

> > sessionInfo()
> R version 2.15.1 (2012-06-22)
> Platform: x86_64-pc-mingw32/x64 (64-bit)
> locale:
> [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
> States.1252
> [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
>
> [5] LC_TIME=English_United States.1252
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
> other attached packages:
> [1] PerformanceAnalytics_1.0.4.4 blotter_0.8.10
> [3] FinancialInstrument_1.0      quantmod_0.3-17
> [5] TTR_0.21-1                   xts_0.8-6
> [7] zoo_1.7-7                    Defaults_1.1-1
> loaded via a namespace (and not attached):
> [1] grid_2.15.1     lattice_0.20-10 tools_2.15.1


*Program:*

> library(quantmod)
> library(TTR)
> library(blotter)
> library(PerformanceAnalytics)
> if (!exists('.blotter')) .blotter <- new.env()
>


> print("Cleaning environment and accounts..........................")
>
> try(rm("account.assetGrpAcct","portfolio.assetGrpPort",pos=.blotter),silent=TRUE)
> try(rm("account","portfolio","symbols","initDate","initEq", "txns",
> "trades"),silent=TRUE)
>


> # Read the data
> trades_csv = "Temp/AFolioGrp.csv"
> trades = as.xts(read.zoo(file = trades_csv, index.column="Time",
> format="%m/%d/%Y", header=TRUE, sep=",", FUN=as.POSIXct))
> trades = head(trades[, c(1:4)], n=10)
> dput(trades)
> print(trades)
>


> symbols = unique(trades$Instrument)
> currency("USD")
> for(symbol in symbols){ # establish tradable instruments
>   stock(symbol, currency="USD",multiplier=1)
> }
> getSymbols(symbols, src='yahoo',
> index.class=c("POSIXt","POSIXct"),from='2001-01-01')
>


> #Convert to weekly
> for(symbol in symbols) {
>   x <- get(symbol)
>   x <- to.weekly(x,indexAt='lastof',drop.time=FALSE)
>   indexFormat(x) <- '%Y-%m-%d'
>   colnames(x) <- gsub("x",symbol,colnames(x))
>   assign(symbol,x)
> }
> print("Symbols setup completed..................................")
>


> print("Initializing Portfolio and Account........................")
> # Initialize portfolio and account
> # Set initial values
> initDate='2000-12-31'
> initEq=100000
> portfolio="assetGrpPort"
> account="assetGrpAcct"
>


> initPortf(portfolio, symbols=symbols, initDate=initDate)
> initAcct(account, portfolios=portfolio, initDate=initDate, initEq=initEq)
> print("Portfolio and Account initialization completed...............")
> verbose=TRUE
>


> print("Creating transactions........................................")
> for(i in 1:NROW(trades))
> {
>   row = trades[i,]
>   symbol = as.character(row$Instrument)
>   txnDate = index(row)
>   price = as.numeric(row$Price)
>   qty = as.numeric(row$Qty)
>   if(row$Action=="Sell") qty = -qty
>
>   addTxn(portfolio, Symbol=symbol, TxnDate=txnDate, TxnPrice=price, TxnQty
> = qty, TxnFees=0, verbose=verbose)
> }
> txns = getTxns(Portfolio=portfolio, Symbol="QQQ")
> print(txns)
> print("Transaction Creation complete..........................")
>


>
> updatePortf(Portfolio=portfolio,Dates=paste('::',as.Date(Sys.time()),sep=''))
> updateAcct(account, Dates=paste('::',as.Date(Sys.time()),sep=''))
> updateEndEq(account, Dates=paste('::',as.Date(Sys.time()),sep=''))


*Execution*

> dput(trades)
> structure(c("QQQ", "QQQ", "IWM", "IWM", "QQQ", "QQQ", "QQQ",
> "QQQ", "QQQ", "QQQ", "Buy", "Sell", "Buy", "Sell", "Buy", "Sell",
> "Buy", "Sell", "Buy", "Sell", "1", "1", "1", "1", "1", "1", "1",
> "1", "1", "1", " 48.40", " 45.15", " 48.82", " 50.65", " 33.06",
> " 36.01", " 37.73", " 39.28", " 40.45", " 41.67"), class = c("xts",
> "zoo"), .indexCLASS = c("POSIXct", "POSIXt"), tclass = c("POSIXct",
> "POSIXt"), .indexTZ = "", tzone = "", index = structure(c(988354800,
> 988959600, 990169200, 991378800, 1004688000, 1004688000, 1005897600,
> 1007107200, 1008921600, 1010736000), tzone = "", tclass = c("POSIXct",
> "POSIXt")), .Dim = c(10L, 4L), .Dimnames = list(NULL, c("Instrument",
> "Action", "Qty", "Price")))
> > print(trades)
>            Instrument Action Qty Price
> 2001-04-27 "QQQ"      "Buy"  "1" " 48.40"
> 2001-05-04 "QQQ"      "Sell" "1" " 45.15"
> 2001-05-18 "IWM"      "Buy"  "1" " 48.82"
> 2001-06-01 "IWM"      "Sell" "1" " 50.65"
> 2001-11-02 "QQQ"      "Buy"  "1" " 33.06"
> 2001-11-02 "QQQ"      "Sell" "1" " 36.01"
> 2001-11-16 "QQQ"      "Buy"  "1" " 37.73"
> 2001-11-30 "QQQ"      "Sell" "1" " 39.28"
> 2001-12-21 "QQQ"      "Buy"  "1" " 40.45"
> 2002-01-11 "QQQ"      "Sell" "1" " 41.67"
> > symbols = unique(trades$Instrument)
> >
> > currency("USD")
> [1] "USD"
> > for(symbol in symbols){ # establish tradable instruments
> +   stock(symbol, currency="USD",multiplier=1)
> + }
> > getSymbols(symbols, src='yahoo',
> index.class=c("POSIXt","POSIXct"),from='2001-01-01')
> [1] "QQQ" "IWM"
> Warning messages:
> 1: In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m,  :
>   downloaded length 147933 != reported length 200
> 2: In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m,  :
>   downloaded length 147996 != reported length 200
> >
> > #Convert to weekly
> > for(symbol in symbols) {
> +   x <- get(symbol)
> +   x <- to.weekly(x,indexAt='lastof',drop.time=FALSE)
> +   indexFormat(x) <- '%Y-%m-%d'
> +   colnames(x) <- gsub("x",symbol,colnames(x))
> +   assign(symbol,x)
> + }
> > print("Symbols setup completed..................................")
> [1] "Symbols setup completed.................................."
> >
> > print("Initializing Portfolio and Account........................")
> [1] "Initializing Portfolio and Account........................"
> > # Initialize portfolio and account
> > # Set initial values
> > initDate='2000-12-31'
> > initEq=100000
> > portfolio="assetGrpPort"
> > account="assetGrpAcct"
> >
> > initPortf(portfolio, symbols=symbols, initDate=initDate)
> [1] "assetGrpPort"
> > initAcct(account, portfolios=portfolio, initDate=initDate, initEq=initEq)
> [1] "assetGrpAcct"
> > print("Portfolio and Account initialization completed...............")
> [1] "Portfolio and Account initialization completed..............."
> >
> > verbose=TRUE
> >
> > print("Creating transactions........................................")
> [1] "Creating transactions........................................"
> > for(i in 1:NROW(trades))
> + {
> +   row = trades[i,]
> +   symbol = as.character(row$Instrument)
> +   txnDate = index(row)
> +   price = as.numeric(row$Price)
> +   qty = as.numeric(row$Qty)
> +   if(row$Action=="Sell") qty = -qty
> +
> +   addTxn(portfolio, Symbol=symbol, TxnDate=txnDate, TxnPrice=price,
> TxnQty = qty, TxnFees=0, verbose=verbose)
> + }
> [1] "2001-04-27 00:00:00 QQQ 1 @ 48.4"
> [1] "2001-05-04 00:00:00 QQQ -1 @ 45.15"
> [1] "2001-05-18 00:00:00 IWM 1 @ 48.82"
> [1] "2001-06-01 00:00:00 IWM -1 @ 50.65"
> [1] "2001-11-02 00:00:00 QQQ 1 @ 33.06"
> [1] "2001-11-02 00:00:00 QQQ -1 @ 36.01"
> [1] "2001-11-16 00:00:00 QQQ 1 @ 37.73"
> [1] "2001-11-30 00:00:00 QQQ -1 @ 39.28"
> [1] "2001-12-21 00:00:00 QQQ 1 @ 40.45"
> [1] "2002-01-11 00:00:00 QQQ -1 @ 41.67"
> > txns = getTxns(Portfolio=portfolio, Symbol="QQQ")
> > print(txns)
>            Txn.Qty Txn.Price Txn.Fees Txn.Value Txn.Avg.Cost
> Net.Txn.Realized.PL
> 2000-12-31       0      0.00        0      0.00         0.00
>  0.00
> 2001-04-27       1     48.40        0     48.40        48.40
>  0.00
> 2001-05-04      -1     45.15        0    -45.15        45.15
> -3.25
> 2001-11-02       1     33.06        0     33.06        33.06
>  0.00
> 2001-11-02      -1     36.01        0    -36.01        36.01
>  2.95
> 2001-11-16       1     37.73        0     37.73        37.73
>  0.00
> 2001-11-30      -1     39.28        0    -39.28        39.28
>  1.55
> 2001-12-21       1     40.45        0     40.45        40.45
>  0.00
> 2002-01-11      -1     41.67        0    -41.67        41.67
>  1.22
> > print("Transaction Creation complete..........................")
> [1] "Transaction Creation complete.........................."
> >
>


> >
> updatePortf(Portfolio=portfolio,Dates=paste('::',as.Date(Sys.time()),sep=''))
> Error in if (length(c(year, month, day, hour, min, sec)) == 6 && c(year,
>  :
>   missing value where TRUE/FALSE needed
> In addition: Warning message:
> In as_numeric(YYYY) : NAs introduced by coercion
>


> > updateAcct(account, Dates=paste('::',as.Date(Sys.time()),sep=''))
> Error in if (last(index(Account$summary)) >
> .parseISO8601(Dates)$first.time) { :
>   missing value where TRUE/FALSE needed
>


> > updateEndEq(account, Dates=paste('::',as.Date(Sys.time()),sep=''))
> [1] "assetGrpAcct"



Regards,
Pie

	[[alternative HTML version deleted]]

