Skip to content

Re-Post: Performance Analytics Style Analysis

2 messages · René Naarmann, Gabor Grothendieck

#
Dear List, Dear Thomas,

thank you for your idea of using rollapply. I have already tried to use 
rollapply and I also tried to use applySeries from the timeSeries
Package but R returns an error message which I do not understand. Here 
is a brief example of what I would like to do:
require(timeSeries)
require(PerformanceAnalytics)
btime <- timeSequence(from="1999-01-01", to="1999-03-31", by = "month")
etime <- timeLastDayInMonth(btime)
#btime and etime are vectors, first element in btime is the first day of 
January and the first element of etime is the last of January

set.seed(123)
DATA <- matrix(rnorm(270), ncol = 3)
colnames(DATA) <- LETTERS[1:3]
datats <- timeSequence(from="1999-01-01", to="1999-03-31", by = "day")
S <- timeSeries(DATA, datats)
#S is a Matrix of class timeSeries with 3 columns of Data.
#In the next step I would like to use the function style.fit from the 
package PerformanceAnalytics. I use the following code:

applySeries(S, btime, etime, FUN = function(x) style.fit(x[,1], 
x[,-1])$weights)
#this returns a error message which I do not understand: "Fehler in if 
(facCol[jj]) { : Fehlender Wert, wo TRUE/FALSE n?tig ist"

Any idea, what I am doing wrong? Am I using a wrong syntax or does 
applySeries not work with style.fit?

Another idea is using rollapply but then I can not manage a specific 
time period, when using the following code
rollapply(as.zoo(S), width = 30, FUN = function(x) style.fit(x[,1], 
x[,-1])$weights)
#this returns the error message: "Fehler in switch(method, vector = { : 
Element 1 ist leer; Der Teil der Argumentliste 'class' der berechnet 
wurde war: (x)"
What is wrong with this code?

Furthermore when using chart.RollingStyle with dailyreturns, the plot 
shows a black rectangle because the space between the bars is to narrow, 
how can I circumvent this problem? I am using a Laptop with a 15'' screen.

thanks in advance
Ren? Naarmann

Thomas Etheber schrieb:

  
    
#
rollapply works on each column independently unless you use
by.column=FALSE. Also style.fit()$weights returns a data frame which
is not permitted.  Try this:

sf <- function(x) style.fit(x[,1], x[,-1])$weights[[1]]
rollapply(as.zoo(S), width = 30, FUN = sf, by.column = FALSE)

See ?rollapply for more.
On Thu, Apr 1, 2010 at 10:18 AM, Ren? Naarmann <rene.naarmann at gmx.de> wrote: