[R-SIG-Finance] moving averages on specific interval and merge

Andreas Voellenklee wotuzu17 at gmail.com
Sat May 12 14:02:43 CEST 2012


Hi,

try this:

require ("TTR")
volumeSMA <- SMA(temp[,"A.Volume"], n=10)
colnames(volumeSMA) <- c("Volume.at.current.interval")
ultimateXTS <- cbind(temp, volumeSMA)

Andreas


2012/5/12 Jim Green <student.northwestern at gmail.com>:
> the question is more of r-help on second thought. I'll post on r-help. sorry.
>
> Jim.
>
> On 10 May 2012 21:11, Jim Green <student.northwestern at gmail.com> wrote:
>> Greetings!
>>
>> I am using quantstrat and xts to do some intraday work and come up
>> with this problem. the xts object temp in the following example is
>> attached as and rda file.
>>
>>> head(temp)
>>                    A.Open A.High  A.Low A.Close A.Volume
>> 2012-02-01 08:29:00  42.47  43.76 41.410   43.76     2071
>> 2012-02-01 09:30:00  43.38  43.38 42.970   43.15    40300
>> 2012-02-01 09:31:00  43.14  43.28 43.130   43.28    14990
>> 2012-02-01 09:32:00  43.27  43.37 43.270   43.37     3300
>> 2012-02-01 09:33:00  43.37  43.50 43.370   43.48     3056
>> 2012-02-01 09:34:00  43.49  43.50 43.396   43.44    10968
>>
>>> tail(temp)
>>                     A.Open  A.High   A.Low A.Close A.Volume
>> 2012-03-27 16:07:00 45.6650 45.6650 45.6650 45.6650      170
>> 2012-03-27 16:08:00 45.6710 45.6710 45.6710 45.6710      474
>> 2012-03-27 16:10:00 45.9131 45.9131 45.9131 45.9131     1800
>> 2012-03-27 16:13:00 45.6952 45.6952 45.6952 45.6952      300
>> 2012-03-27 16:15:00 45.9368 45.9368 45.9368 45.9368      791
>> 2012-03-27 16:21:00 45.7000 45.7000 45.7000 45.7000    22000
>>
>>
>> I would like to calculate moving averages of minute volume for
>> specific interval and merge with the original minute ohlc data.
>>
>> take 09:40:00 for example, calculate the average previous 10 days
>> volume between 09:39:00 to 09:40:00 and merge with exiting data.
>>
>> ultimately I want to get an xts object with columns
>>
>> Open   High   Low   Close   Volume   Average.Volume.at.current.interval
>> 2012-03-27 16:07:00 45.6650 45.6650 45.6650 45.6650      170   177
>> 2012-03-27 16:08:00 45.6710 45.6710 45.6710 45.6710      474  500
>> ...
>> ...
>> ..
>> 2012-03-27 16:21:00 45.7000 45.7000 45.7000 45.7000    22000 1000
>>
>> any pointers are appreciated!
>>
>> Jim.
>
> _______________________________________________
> 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.



More information about the R-SIG-Finance mailing list