[R-SIG-Finance] Quantmod SMA not working

Mark Harrison harrisonmark1 at gmail.com
Mon Mar 5 20:36:15 CET 2012


I am trying to do some data comparisons and want to use quantmod and
the addSMA feature.  However, I keep getting errors when I try the
addSMA command.  I did try the email but nothing I saw answered or
fixed this issue.

When I run addSMA(20) on my data - examples below - I get the following error:

Error in matrix(ma.tmp[lchob at xsubset, ], nc = NCOL(ma.tmp)) :
  subscript out of bounds

If I just grab Apple data from Yahoo and run:

chartSeries(AAPL, subset='last 6 months')
addSMA(20)

The first command works and the chart appears but the addSMA command
gives me the same error as above.

MyData Example:
             Open   High    Low  Close
2010-12-31 63.270 63.535 63.120 63.425
2011-01-03 63.310 63.670 63.085 63.620
2011-01-04 63.615 64.040 63.365 63.740
2011-01-05 63.770 64.495 63.430 64.415
2011-01-06 64.405 64.530 64.070 64.340
2011-01-07 64.325 64.490 63.950 64.280

Session Info:

R version 2.14.0 (2011-10-31)
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] datasets  grDevices utils     graphics  stats     methods   base

other attached packages:
 [1] blotter_0.8.4              fTrading_2110.77
fBasics_2110.79
 [4] MASS_7.3-16                timeSeries_2140.93
timeDate_2150.95
 [7] twsInstrument_1.3-1        IBrokers_0.9-3             qmao_1.1.6
[10] FinancialInstrument_0.10.9 quantmod_0.3-17            TTR_0.21-0
[13] xts_0.8-4                  zoo_1.7-7
Defaults_1.1-1

loaded via a namespace (and not attached):
[1] grid_2.14.0      lattice_0.20-3   quantstrat_0.6.1 tools_2.14.0



More information about the R-SIG-Finance mailing list