[R-SIG-Finance] Subject: Re: Standard Deviations using Sliding window?
Gabor Grothendieck
ggrothendieck at gmail.com
Fri Mar 5 17:30:53 CET 2010
You likely want just this:
diff(log(closes['2010-02-05::']))
or this:
rollapply(as.zoo(whatever), ...)
(Actually I would have thought your command would have worked since
your object inherits from zoo and will check it out.)
On Fri, Mar 5, 2010 at 11:15 AM, Robert Nicholson
<robert.nicholson at gmail.com> wrote:
> Yep that's where I am now
>
> When I try
>
> getSymbols('AAPL')
> closes = Cl(AAPL)
> change = rollapply(closes['2010-02-25::'],width=2, function(x) { log(x[2]/x[1])}, by=1, align = "right", na.pad = TRUE)
>
> I end up with
>
> Error in switch(deparse(substitute(FUN)), mean = return(rollmean(data, :
> switch: EXPR must return a length 1 vector
>
> this was what I expected
>
> rollapply(zoo(1:10), 2, sum, na.pad = TRUE, by = 1, align="right")
> 1 2 3 4 5 6 7 8 9 10
> NA 3 5 7 9 11 13 15 17 19
>
> On Mar 5, 2010, at 9:17 PM, Judson m wrote:
>
>> > Here was a naive attempt to do standard deviation with sliding window
>> >>require(quantmod)
>> >>getSymbols("AAPL")
>> >> AAPL$STDDEV = sd(Cl(AAPL), 20)
>> >> AAPL$SMA = SMA(Cl(AAPL), 10)
>> >> AAPL
>>
>> I am pretty sure that rollapply in the ZOO library would work for you.
>>
>>
>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch 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