This is the function in plain text because it looked messy before:
VaRfun <- function(x, lambda = 0.94) {
#create data.frame and order returns such that the lates return is the first
df <- data.frame(weight = c(1:length(x)), return = rev(x))
K <- nrow(df)
constant <- (1-lambda)/(1-lambda^(K
You will get better help if you read the Posting Guide mentioned at the foot if
every posting including this one carefully and pay attention.
A) You need to post in plain text, as your code came through the mailing list
damaged.
B) You need to include sample data and make your code run from a
This is exactly what I want. However, with my function it produces a vector of
NAs ...
Gabor Grothendieck schrieb am 16:23 Sonntag, 28.Mai
2017:
Maybe you want this.It computes VaRfun(r[c(i-500, i-1)] for each i for
which the argument to r makes sense.
rollapply(r, width = list(c(-500, -1)
Maybe you want this.It computes VaRfun(r[c(i-500, i-1)] for each i for
which the argument to r makes sense.
rollapply(r, width = list(c(-500, -1)), FUN = VaRfun),
On Sat, May 27, 2017 at 5:29 PM, Sepp via R-help wrote:
> Hello,
> I am fairly new to R and trying to calculate value at risk with ex
Hello,
I am fairly new to R and trying to calculate value at risk with exponentially
decreasing weights.My function works for a single vector of returns but does
not work with rollapply(), which is what I want to use. The function I am
working on should assig exponentially decreasing weights to
Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Morway,
> Eric
> Sent: Thursday, May 26, 2016 5:00 PM
> To: R mailing list
> Subject: [R] rollapply and difftime
>
> Technically, the code below works and results in a column that I
What about just
diff( dts )
or
as.numeric( diff( dts ), units="days" )
?
--
Sent from my phone. Please excuse my brevity.
On May 26, 2016 5:09:20 PM PDT, "MacQueen, Don" wrote:
>You want the number of days between dates?
>Does this do the trick?
>
>dts <- Sys.Date()+ c(1,2,3,5,6,9)
>dts[-1]
You want the number of days between dates?
Does this do the trick?
dts <- Sys.Date()+ c(1,2,3,5,6,9)
dts[-1] - dts[-length(dts)]
Time differences in days
[1] 1 1 2 1 3
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
On 5/26/1
Technically, the code below works and results in a column that I'm
interested in working with for further processing. However, it is both
inefficient on lengthy (>100 yr) daily time series and is, frankly, not the
R way of doing things. Using the 'Daily' data.frame provided below, I'm
interested
On Sat, Oct 27, 2012 at 6:52 AM, R. Michael Weylandt
wrote:
> I might suggest you take a look at period.apply() in the xts package.
>
I don't think that will work because it sounds like "J" wants analysis
on overlapping intervals, and period.apply works on non-overlapping
intervals. I'd suggest u
I might suggest you take a look at period.apply() in the xts package.
Cheers,
Michael
On Fri, Oct 26, 2012 at 7:33 PM, Jaguar83 wrote:
> Hi all-
>
> Thank you for reading my post. Please bear in mind that I'm very much a
> newbie with R! My question is this:
>
> I'm trying to use rollapply() on
Hi all-
Thank you for reading my post. Please bear in mind that I'm very much a
newbie with R! My question is this:
I'm trying to use rollapply() on an irregular time series so I can't simply
use the width parameter (I don't think). Rather than last 5 entries, I'd
like to rollapply on last 6 mont
See the align= argument to rollapply.
On Mon, Mar 1, 2010 at 4:37 PM, herr dittmann wrote:
> Dear expeRts,
>
> The rollapply(tseries) function puzzles me. When applying a function over a
> rolling window, I am getting NAs at odd places:
>
> dow <- get.hist.quote(instrument="^DJI", start="2010-02
Dear expeRts,
The rollapply(tseries) function puzzles me. When applying a function over a
rolling window, I am getting NAs at odd places:
dow <- get.hist.quote(instrument="^DJI", start="2010-02-01", quote="Close")
dow.2 <- rollapply(dow, width=2, FUN=mean)
dow.3 <- rollapply(dow, width=3, FUN=me
pred2)
Thanks Gabor.
-Original Message-
From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com]
Sent: Wednesday, January 13, 2010 4:02 PM
To: Brecknock, Peter
Cc: r-help@r-project.org
Subject: Re: [R] Rollapply
See:
http://tolstoy.newcastle.edu.au/R/help/04/03/1446.html
On Wed, Jan 13,
See:
http://tolstoy.newcastle.edu.au/R/help/04/03/1446.html
On Wed, Jan 13, 2010 at 3:45 PM, Pete B wrote:
>
> Hi
>
> I would like to understand how to extend the function (FUN) I am using in
> rollapply below.
>
> ##
> With the following simplified data, test
Hi
I would like to understand how to extend the function (FUN) I am using in
rollapply below.
##
With the following simplified data, test1 yields parameters for a rolling
regression
data = data.frame(Xvar=c(70.67,70.54,69.87,69.51,70.69,72.66,72.65,73.36),
rollapply over an index. Modify this appropriately:
> z <- zoo(101:109, 11:19)
> f <- function(ix) if (ix[1] < 5) min(z[ix]) else max(z[ix])
> rollapply(zoo(seq_along(z)), 3, by = 3, f)
2 5 8
101 104 109
On Thu, Jul 31, 2008 at 3:36 PM, rcoder <[EMAIL PROTECTED]> wrote:
>
> Hi everyone,
>
Hi everyone,
I have a rollapply statement that applies a function, in steps, over a data
matrix as follows:
#Code start
testm<-rollapply(mat, 100, by=100, min, na.rm=F)
#Code end
This moves down matrix 'mat' and calculates the minimum value over a 100 row
range, every 100 rows (i.e. no overlaps
methods(rollapply)
shows which classes have rollapply methods.
On Tue, Jul 29, 2008 at 5:48 PM, rcoder <[EMAIL PROTECTED]> wrote:
>
> Hi Gabor,
>
> Thanks for your reply. Assuming I have a time series that is ready made
> (i.e. not constructed it using a zoo function) will the procedure below
> st
Hi Gabor,
Thanks for your reply. Assuming I have a time series that is ready made
(i.e. not constructed it using a zoo function) will the procedure below
still retain the dates in the matrix?
Thanks,
rcoder
quote author="Gabor Grothendieck">
rollapply along an index:
library(zoo)
z <- zoo(mat
And then lapply over out.
On Mon, Jul 28, 2008 at 6:41 PM, Gabor Grothendieck
<[EMAIL PROTECTED]> wrote:
> rollapply along an index:
>
> library(zoo)
> z <- zoo(matrix(101:110, 5), 201:205)
> tt <- time(z)
> zz <- zoo(seq_along(tt), tt)
> out <- rollapply(zz, 3, function(ix) list(z[ix,]))
> str(ou
rollapply along an index:
library(zoo)
z <- zoo(matrix(101:110, 5), 201:205)
tt <- time(z)
zz <- zoo(seq_along(tt), tt)
out <- rollapply(zz, 3, function(ix) list(z[ix,]))
str(out) # list of zoo objects
On Mon, Jul 28, 2008 at 5:03 PM, rcoder <[EMAIL PROTECTED]> wrote:
>
>
> rcoder wrote:
>>
>> H
rcoder wrote:
>
> Hi everyone,
>
> Is there a way to perform a rollapply operation on a time series data
> matrix and preserve the time frame? Currently, when I apply rollapply in
> its standart form, the date column is no longer present in the o/p matrix.
>
> Thanks,
>
> rcoder
>
--
View
Hi everyone,
Is there a way to perform a rollapply operation on a time series data matrix
and preserve the time frame? Currently, when I apply rollapply in its
standart form, the date column is no longer present in the o/p matrix.
Thanks,
rcoder
--
View this message in context:
http://www.nab
1. rollapply is for creating zoo objects from zoo objects --
not for creating lists from zoo objects. 2. The
subscripting is wrong. 3. Its possible that you need a different
representation for out but that depends on what you want to
do with it. At any rate try this and note that there is no
zoo
Dear R users.
I have zoo object "size_june" containing market-capital values:
> dim(size_june) # market-cap data of 625 firms for 20 years
[1] 20 625
> class(size_june)
[1] "zoo"
> size_june # colnames = "size.firmcode"
size.34020 size.4710 size.11050 size.10660 size.9540 size.8060
27 matches
Mail list logo