[R-SIG-Finance] Quantmod SMA not working

Mark Harrison harrisonmark1 at gmail.com
Mon Mar 5 21:29:58 CET 2012


I will try switching the load order...

I have been using the EMA from fTrading because I can assign where the
values start and I do not get 'NAs'.  I was trying to recreate an EMA
formula that I had been using in excel.  It always did what I needed
so I just stuck with it.

I added two columns using the fTrading EMA and TTR EMA labled for the
package so you can see the difference.  Probably too much
information....

                   Open    High     Low   Close   fTrading TTR
2010-12-31 63.270 63.535 63.120 63.425 63.42500  NA
2011-01-03 63.310 63.670 63.085 63.620 63.44357  NA
2011-01-04 63.615 64.040 63.365 63.740 63.47180  NA
2011-01-05 63.770 64.495 63.430 64.415 63.56163  NA
2011-01-06 64.405 64.530 64.070 64.340 63.63576  NA
2011-01-07 64.325 64.490 63.950 64.280 63.69712  NA

On Mon, Mar 5, 2012 at 1:47 PM, Jeffrey Ryan <jeffrey.ryan at lemnica.com> wrote:
> The problem is that fTrading also has an SMA function.  You can either
> load it before loading quantmod/TTR or ... not use it??
>
> Note the conflict when you call library(fTrading) _after_ you load quantmod/TTR
>
> Is there a function in fTrading that you need that isn't in TTR
>
> Jeff
>
> On Mon, Mar 5, 2012 at 1:36 PM, Mark Harrison <harrisonmark1 at gmail.com> wrote:
>> 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
>>
>> _______________________________________________
>> R-SIG-Finance at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> -- Subscriber-posting only. If you want to post, subscribe first.
>> -- Also note that this is not the r-help list where general R questions should go.
>
>
>
> --
> Jeffrey Ryan
> jeffrey.ryan at lemnica.com
>
> www.lemnica.com
> www.esotericR.com
>
> R/Finance 2012: Applied Finance with R
> www.RinFinance.com
>
> See you in Chicago!!!!



More information about the R-SIG-Finance mailing list