Quantstrat faber_rebal.R demo error

343 views Asked by At

I have been going through the demos in quantstrat. I have a problem running faber_rebal.r. It fails with the following error:

> out<-applyStrategy.rebalancing(strategy='faber' , portfolios='faber')
Error in `colnames<-`(`*tmp*`, value = c("MaxPos", "LongLevels", "MinPos",  : 
length of 'dimnames' [2] not equal to array extent

Here is the output of sessionInfo():

R version 3.0.1 (2013-05-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_South Africa.1252  LC_CTYPE=English_South Africa.1252   
[3] LC_MONETARY=English_South Africa.1252 LC_NUMERIC=C                         
[5] LC_TIME=English_South Africa.1252    

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

other attached packages:
 [1] quantstrat_0.7.8           foreach_1.4.1              blotter_0.8.15            
 [4] PerformanceAnalytics_1.1.0 FinancialInstrument_1.1    quantmod_0.4-0            
 [7] Defaults_1.1-1             TTR_0.22-0                 xts_0.9-5                 
[10] zoo_1.7-10                 lattice_0.20-23           

loaded via a namespace (and not attached):
[1] codetools_0.2-8 grid_3.0.1      iterators_1.0.6 tools_3.0.1

The problem occurs within the function applyStrategy.rebalancing when it calls the private function ruleProc.

I also get the same error on my Ubuntu 12.04 Machine with R 3.0.1.

Any help to get it working would be appreciated.

Thanks Charles

2

There are 2 answers

0
pmichaels On BEST ANSWER

I had some problems getting the faber_rebal.R demo to work as well.

First, you have to set the timezone:

ttz<-Sys.getenv('TZ')
Sys.setenv(TZ='UTC')

Second, I could get the following line in the add.rule rebalance to work:

refprice=quote(last(getPrice(mktdata)[paste('::',timestamp,sep='')][,1])),

so I changed it to:

refprice=quote(last(getPrice(mktdata)[paste('::','20140119',sep='')][,1])),

I hope that helps.

Best, Peter

0
giminey On

It looks like demo was fixed in the latest update to the package. Try updating to Rev.: 1595 or later