[R-SIG-Finance] Base R question on XTS object

R. Michael Weylandt michael.weylandt at gmail.com
Wed Apr 10 15:56:52 CEST 2013


On Wed, Apr 10, 2013 at 5:17 AM, Brian G. Peterson <brian at braverock.com> wrote:
> On 04/10/2013 04:45 AM, wlblount wrote:
>>
>> before the days of all these great packages, how would one with base R
>> access
>> only find the following assuming i have an XTS object with normal OHLC
>> price
>> data for 100 periods.
>>
>>
>> 1 - change in price from yesterday to today.  close[today] -
>> close[yesterday]
>
>
> ?diff
> (part of base)
>
>
>> 2 -rolling or moving simple ave. of close[last 30 periods]
>>
>> 3 - rolling or moving sd of close[last 30 periods]
>
>
> ?apply
> (in base)
>
> ?rollapply
> (today)
> Rollapply is basically a loop that constructs the windowed index.
>
>
>> i understand that this would all be done with quantmod /ttr etc today but
>> would just like to stay within the bounds of base R for educational
>> purposes.
>

'xts' is not part of base R, so if your students can get 'xts' they
should be able to get 'quantmod'. In fact, if you simply have them
install.packages("quantmod") that will get them zoo, TTR, and xts
automatically.

>
> Then read an old book on S.
>
> ?ts
>
> the 'ts' class has been part of the S language basically since inception.
>
> Alternatively, all this code is open source.  Look at the code.
>
> Cheers,
>
> Brian
>
>
> _______________________________________________
> 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