Subject: Re: Standard Deviations using Sliding window?
I think Josh's earlier suggestion of runSD is more along the lines of
what you want.
While you can certainly do what you want via rollapply, your original
example will work via
getSymbols('AAPL')
AAPL$STDDEV = runSD(Cl(AAPL), 20)
AAPL$SMA = SMA(Cl(AAPL), 10)
Regards,
- Brian
Robert Nicholson 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.
Brian G. Peterson http://braverock.com/brian/ Ph: 773-459-4973 IM: bgpbraverock