Message-ID: <971536df1003050830w1907a3c6tf6eda44e072a585e@mail.gmail.com>
Date: 2010-03-05T16:30:53Z
From: Gabor Grothendieck
Subject: Subject: Re: Standard Deviations using Sliding window?
In-Reply-To: <6F7C22A3-AC2E-4D24-AA6F-89CFF0F2BD1C@gmail.com>
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.
>