Re: [R] Calculating monthly var-cov matrix on non-overlapping rooling window basis

2008-02-28 Thread Henrique Dallazuanna
You can't calculate the var indeed of cov

On 28/02/2008, Megh Dal [EMAIL PROTECTED] wrote:
 Thanks Henrique for this mail. It works fine. However I need one more
 modification. When number of column is 1 then some error is coming :

  library(zoo)
  date.data = seq(as.Date(01/01/01, format =
 %m/%d/%y),as.Date(06/25/02, format = %m/%d/%y), by = 1)
  len = length(date.data)
  data1 = zoo(matrix(rnorm(len), nrow = len),  date.data )
  head(data1)

 2001-01-01 -1.5128990
 2001-01-02 -0.2939971
 2001-01-03  1.6387866
 2001-01-04 -0.8107857
 2001-01-05  0.7966224
 2001-01-06  0.6007594
 
  lapply(split(data1, format(index(data1), %m)), cov)
 Error in FUN(X[[1L]], ...) : supply both 'x' and 'y' or a matrix-like 'x'

 However I tried with an 'ifelse' condition :
  lapply(split(data1, format(index(data1), %m)), ifelse(dim(data1)[1]  1,
 cov, var))

 Still I am getting error. What to do?


 Henrique Dallazuanna [EMAIL PROTECTED] wrote:
 Perhaps something like this:

 lapply(split(data1, format(index(data1), %m)), cov)

 On 27/02/2008, Megh Dal wrote:
  let create a 'zoo' object :
 
  library(zoo)
  date.data = seq(as.Date(01/01/01, format = %m/%d/%y),
 as.Date(06/25/02, format = %m/%d/%y), by = 1)
  len = length(date.data)
  data1 = zoo(matrix(rnorm(2*len), nrow = len), date.data )
  head(data1)
 
  Now I want to create an 3 dimensional array (suppose name  var.cov)
 where, var.cov[,,i] gives the Variance-covariance matrix for i-th month of
 data1. That is I want to calculate monthly variance-covariance matrix on
 non-overlapping rolling window basis.
 
  Any suggestion?
 
 
 
  -
 
  [[alternative HTML version deleted]]
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 


 --
 Henrique Dallazuanna
 Curitiba-Paraná-Brasil
 25° 25' 40 S 49° 16' 22 O



  
 Looking for last minute shopping deals? Find them fast with Yahoo! Search.




-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Calculating monthly var-cov matrix on non-overlapping rooling window basis

2008-02-27 Thread Henrique Dallazuanna
Perhaps something like this:

lapply(split(data1, format(index(data1), %m)), cov)

On 27/02/2008, Megh Dal [EMAIL PROTECTED] wrote:
 let create a 'zoo' object :

   library(zoo)
   date.data = seq(as.Date(01/01/01, format = %m/%d/%y), 
 as.Date(06/25/02, format = %m/%d/%y), by = 1)
   len = length(date.data)
   data1 = zoo(matrix(rnorm(2*len), nrow = len),  date.data )
   head(data1)

   Now I want to create an 3 dimensional array (suppose name  var.cov) 
 where, var.cov[,,i] gives the Variance-covariance matrix for i-th month of 
 data1. That is I want to calculate monthly variance-covariance matrix on 
 non-overlapping rolling window basis.

   Any suggestion?



  -

 [[alternative HTML version deleted]]

  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Calculating monthly var-cov matrix on non-overlapping rooling window basis

2008-02-27 Thread Megh Dal
Thanks Henrique for this mail. It works fine. However I need one more 
modification. When number of column is 1 then some error is coming :
   
   library(zoo)
 date.data = seq(as.Date(01/01/01, format = %m/%d/%y),as.Date(06/25/02, 
 format = %m/%d/%y), by = 1)
 len = length(date.data)
 data1 = zoo(matrix(rnorm(len), nrow = len),  date.data )
 head(data1)
 
2001-01-01 -1.5128990
2001-01-02 -0.2939971
2001-01-03  1.6387866
2001-01-04 -0.8107857
2001-01-05  0.7966224
2001-01-06  0.6007594
 
 lapply(split(data1, format(index(data1), %m)), cov)
Error in FUN(X[[1L]], ...) : supply both 'x' and 'y' or a matrix-like 'x'

  However I tried with an 'ifelse' condition :
   lapply(split(data1, format(index(data1), %m)), ifelse(dim(data1)[1]  1, 
cov, var))

  Still I am getting error. What to do?
  

Henrique Dallazuanna [EMAIL PROTECTED] wrote:
  Perhaps something like this:

lapply(split(data1, format(index(data1), %m)), cov)

On 27/02/2008, Megh Dal wrote:
 let create a 'zoo' object :

 library(zoo)
 date.data = seq(as.Date(01/01/01, format = %m/%d/%y), as.Date(06/25/02, 
 format = %m/%d/%y), by = 1)
 len = length(date.data)
 data1 = zoo(matrix(rnorm(2*len), nrow = len), date.data )
 head(data1)

 Now I want to create an 3 dimensional array (suppose name  var.cov) where, 
 var.cov[,,i] gives the Variance-covariance matrix for i-th month of data1. 
 That is I want to calculate monthly variance-covariance matrix on 
 non-overlapping rolling window basis.

 Any suggestion?



 -

 [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O


   
-

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.