Skip to content
Back to formatted view

Raw Message

Message-ID: <1325114967940-4241306.post@n4.nabble.com>
Date: 2011-12-28T23:29:27Z
From: S
Subject: lapply over list that has multiple xts objects

I've been going through various examples on how to use lapply when the list
in question has multiple parts but I can't seem to get things working.

I have a function that computes open_close volatility as follows:

close_open <- function (OHLC, n = 10, N = 252, ...) 
{
    Cl1 <- lag(OHLC[, 4])
    OHLC <- try.xts(OHLC, error = as.matrix)
    s2o <- 18.59 * runSD(log(OHLC[, 1]/Cl1), n)
    reclass(s2o, OHLC)
}

I have a list object stocks that has 909 xts OHLC objects:

> class(stocks)
[1] "list"

> length(stocks)
[1] 909

I want to compute the open_close volatility for every component in the list
stock by using lapply. I have tinkered with various variants of

lapply(stocks, function(x) open_close(x, n=10, N=252, ...))

I get errors like so:

Error in FUN(X[[1L]], ...) : '...' used in an incorrect context

Any guidance on how I can achieve my goal would be greatly appreciated.
THank you.

--
View this message in context: http://r.789695.n4.nabble.com/lapply-over-list-that-has-multiple-xts-objects-tp4241306p4241306.html
Sent from the Rmetrics mailing list archive at Nabble.com.