0

EDIT(1): This is the sessionInfo():

> sessionInfo()
R version 3.4.2 (2017-09-28)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils    
[5] datasets  methods   base     

other attached packages:
 [1] FSVBackTest_0.0.0.9000       
 [2] blotter_0.14.2               
 [3] FSVTradingRules_0.0.0.9000   
 [4] FinancialInstrument_1.2.0    
 [5] quantmod_0.4-13.1            
 [6] FSVIndicators_0.0.0.9000     
 [7] roxygen2_6.0.1               
 [8] dlm_1.1-4                    
 [9] PerformanceAnalytics_1.4.3541
[10] xts_0.10-2.1                 
[11] zoo_1.8-2                    
[12] TTR_0.23-2                   
[13] FSVPositionSizing_0.0.0.9000 
[14] FSVDataCheck_0.0.0.9000      
[15] RevoUtils_10.0.6             
[16] RevoUtilsMath_10.0.1         

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.13     xml2_1.1.1      
 [3] magrittr_1.5     rtvs_1.0.0.0    
 [5] lattice_0.20-35  R6_2.2.0        
 [7] foreach_1.4.4    stringr_1.2.0   
 [9] tools_3.4.2      grid_3.4.2      
[11] iterators_1.0.8  commonmark_1.4  
[13] codetools_0.2-15 curl_3.0        
[15] stringi_1.1.5    compiler_3.4.2  
[17] boot_1.3-20    

EDIT(2): To make this totally reproducible (hopefully), I created a new library (called DUMMY), added xts(0.10-2.1) as the only dependency, added the IBM.RData file from github blotter repo as the ONLY file (.R, .Rdata, .Rda, or otherwise), restarted R, loaded ONLY that library into the global environment, I get the following sessionInfo():

> sessionInfo()
R version 3.4.2 (2017-09-28)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

other attached packages:
[1] DUMMY_0.0.0.9000     xts_0.10-2.1         zoo_1.8-2           
[4] RevoUtils_10.0.6     RevoUtilsMath_10.0.1

loaded via a namespace (and not attached):
[1] compiler_3.4.2  grid_3.4.2      rtvs_1.0.0.0   
[4] lattice_0.20-35

My DESCRIPTION file looks like this:

Package: DUMMY
Title: What the Package Does (one line, title case)
Version: 0.0.0.9000
Authors@R: person("First", "Last", email = "first.last@example.com", role = c("aut", "cre"))
Description: What the package does (one paragraph).
Depends: R (>= 3.4.2),
         xts (>= 0.10-2.1)
License: What license is it under?
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.0.1

Now when I call specific rows of IBM xts object, I get

> class(IBM)
[1] "xts" "zoo"
> IBM[1,]
     IBM.Open IBM.High IBM.Low IBM.Close IBM.Volume IBM.Adjusted
> IBM[21,]
     IBM.Open IBM.High IBM.Low IBM.Close IBM.Volume IBM.Adjusted
> IBM[20,]
     IBM.Open IBM.High IBM.Low IBM.Close IBM.Volume IBM.Adjusted
> IBM[2,]
     IBM.Open IBM.High IBM.Low IBM.Close IBM.Volume IBM.Adjusted

ORIGINAL QUESTION:

All of a sudden, I seem to be observing bizarre behavior with xts objects, and it is causing blotter (and quantstrat) functions to no longer work correctly. Even demos fail. For reference, I'm using xts_0.10-2.1, blotter_0.14.2 & zoo_1.8-2. If I use internal data from the blotter for IBM, referencing the first row of IBM yields the column names, rather than the first row of IBM price data.

> IBM[1,]
 IBM.Open IBM.High IBM.Low IBM.Close IBM.Volume
 IBM.Adjusted

for reference,

> dim(IBM)
[1] 21  6

To get the first row of IBM price data, I need to reference the first two rows of the xts object.

> IBM[1:2,]
                IBM.Open IBM.High IBM.Low IBM.Close
2007-01-03 22:00:00    97.25    98.79   96.88     98.31
                IBM.Volume IBM.Adjusted
2007-01-03 22:00:00   10524500        94.76

When I try to reference the last row of the IBM data, I get

> IBM[nrow(IBM), ]
 IBM.Open IBM.High IBM.Low IBM.Close IBM.Volume
 IBM.Adjusted

If I try to reference the last two rows of IBM data

> IBM[20:21,]
                IBM.Open IBM.High IBM.Low IBM.Close
2007-01-31 22:00:00    98.97    99.18   97.96        99
                IBM.Volume IBM.Adjusted
2007-01-31 22:00:00    6610700        95.43

If I try using tail,

> tail(IBM, 2)
                IBM.Open IBM.High IBM.Low IBM.Close
2007-01-31 22:00:00    98.97    99.18   97.96        99
                IBM.Volume IBM.Adjusted
2007-01-31 22:00:00    6610700        95.43

When I try to run the amzn_test demo from blotter,

> demo(package = "blotter")
> demo("amzn_test")

Type  <Return>   to start : 

    demo(amzn_test)
    ---- ~~~~~~~~~



> require(blotter)

> # Remove portfolio and account data if run previously
> try(rm("portfolio.amzn_port","account.amzn_acct",pos=.blotter), silent = TRUE)

> # load the example data
> data("amzn")

> currency("USD")
[1] "USD"

> stock("amzn",currency="USD",multiplier=1)
[1] "amzn"

> # Initialize the Portfolio
> initPortf("amzn_port",symbols="amzn",initDate="2010-01-14")
[1] "amzn_port"

> initAcct("amzn_acct",portfolios="amzn_port",initDate="2010-01-14", initEq=10000)
[1] "amzn_acct"

> # look at the transactions data
> amzn.trades
                    TxnPrice TxnQty
2010-01-14 07:18:50   127.49   -400
2010-01-14 07:18:53   127.49    400
2010-01-14 07:21:50   127.26   -300
2010-01-14 07:21:53   127.26    300
2010-01-14 07:23:07   127.17    100
2010-01-14 07:23:10   127.19   -100
2010-01-14 07:37:56   127.12   -400
2010-01-14 07:37:59   127.12    400
2010-01-14 07:38:32   127.23   -500
2010-01-14 07:38:35   127.23    500
2010-01-14 07:38:37   127.27    300
2010-01-14 07:38:40   127.30   -300
2010-01-14 07:46:08   126.95  -1300
2010-01-14 07:46:11   126.95   1300

> # Add the transactions to the portfolio
> blotter:::addTxns("amzn_port","amzn",TxnData=amzn.trades,verbose=TRUE)
Error in if (TxnDate < lastTxnDate) { : argument is of length zero
In addition: Warning messages:
1: In rm("portfolio.amzn_port", "account.amzn_acct", pos = .blotter) :
  object 'portfolio.amzn_port' not found
2: In rm("portfolio.amzn_port", "account.amzn_acct", pos = .blotter) :
  object 'account.amzn_acct' not found
> 

I assume this error occurs because referencing the last row of data (where lastTxnDate comes from) yields the column names rather than the last row of data, from which index() will give us the date. Has anyone else seen this? It just started happening in the past few days, so very recent issue. Thank you for your help!

Sean Sinykin
  • 542
  • 4
  • 22
  • I can't replicate. What's the output of `sessionInfo()`? And is there a `.RData` file that's being automatically restored when you start R? – Joshua Ulrich May 13 '18 at 13:32
  • See sessionInfo() above. As for any .RData files being automatically restored, not sure about that. The IBM.RData file that is part of the library I am developing came from your blotter github repo (https://github.com/R-Finance/blotter/tree/master/data). – Sean Sinykin May 13 '18 at 15:35
  • OK, In Edit(2) above, I created a new library, added ONLY the IBM.RData file from the github blotter repo (no other .R or .RData/.Rda files), added blotter(>= 0.14.2) as the only dependency, restarted R, loaded only this new library, and called IBM[1,]. This reproduces the bizarre behavior. Can you reproduce it on your side? Thanks! – Sean Sinykin May 13 '18 at 16:12
  • Thanks for the extra details. I still can't replicate with a simple package like yours. Can you try a different console (e.g. Rterm if you're using RStudio)? – Joshua Ulrich May 13 '18 at 16:44
  • I use Visual Studio for development, so that is where the above came from. I get the exact same results from within RStudio – Sean Sinykin May 13 '18 at 21:50
  • Okay... I see you're using a development version of xts. What commit have you installed? – Joshua Ulrich May 13 '18 at 22:33
  • Good question. I just typed install_github('braverock/blotter') in my console and ended up with version 0.14.2 – Sean Sinykin May 13 '18 at 22:56
  • OK, taking your cue from above, I down-versioned to the latest CRAN version (0.10-0). The problem went away, so you may want to note this issue with the dev version. Thanks! – Sean Sinykin May 13 '18 at 23:18
  • Can you give a rough estimate of when you installed blotter, and therefore xts 0.10-2.1? Also note that the latest xts on CRAN is 0.10-2. 0.10-0 is nearing a year old. – Joshua Ulrich May 14 '18 at 13:02
  • Yes, it was last weekend (around 5/11/2018) – Sean Sinykin May 17 '18 at 02:11

0 Answers0