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:
Dear Rene,
why are you trying to circumvent the already implemented wrapper in
style.QPfit?
If I got your problem right, you could just slice your data to rolling
estimation windows and then forward it to style.QPfit. Did you already have
a look at rollapply, I didn't test it but I think this should work for your
purpose. In this case you will have to store the coefficients in each run,
so that you are able to calculate the unsystematic returns, e.g. in a loop.
Hth
Thomas
Ren? Naarmann schrieb:
Hi all,
thank you Julien for your thougts. I working with R 2.10.0 on Windows XP.
I remembered the function applySeries and fapply respectively. I tried to
calculate
a variance covariance matrix over different periods. When this works I
could go on with solve.QP which needs the Dmat.
Here is an example:
require(timeSeries)
btime <- timeSequence(from="1999-01-01", to="1999-03-31", by = "month")
etime <- timeLastDayInMonth(btime[-1])
btime <- btime[-length(btime)]
data1 <- rnorm(1:90)
data2 <- matrix(rnorm(270), ncol = 3)
colnames(data2) <- LETTERS[1:3]
datats <- timeSequence(from="1999-01-01", to="1999-03-31", by = "day")
S <- timeSeries(data2, datats)
applySeries(S, btime, etime, FUN = function(x) cov(x,
use="pairwise.complete.obs"))
cov(window(S, start="1999-01-01", end="1999-02-28"))
The result is a matrix which contains the varcov matrices for 2
subperiods which is fine,
but when I am using my real Data I receive this Message:
Fehler in midnightStandard2(charvec, format) : ?'charvec' has non-NA
entries of different number of characters
I don't understand this error message, can anyone help?
I read my datafile from a spreadsheet via readSeries(), the head looks
like this:
? ? ? ? ? ? ? ? ? R2G ? ? ? ? ?R2V ? ? ? ? ? R1G ? ? ? ? ? R1V
?MSCIWexUS
1999-01-04 -0.006477506 ?0.004066846 -0.0026417776 -0.0009521722
?0.018939565
1999-01-05 ?0.001725935 ?0.002339151 ?0.0128278433 ?0.0116685255
?0.006108505
1999-01-06 ?0.018860732 ?0.007514636 ?0.0211913231 ?0.0215123444
?0.019311270
1999-01-07 ?0.005040827 -0.004752986 -0.0028397673 ?0.0013254882
-0.005757679
1999-01-08 ?0.011525972 ?0.003911511 -0.0006109632 ?0.0101291838
?0.001059926
1999-01-11 ?0.013880501 -0.005775207 -0.0039712968 -0.0108176871
-0.011788948
Thanks in advance
Ren?
julien cuisinier schrieb:
Hi Ren?,
For quad prog algo, look for solve.QP from quadprog package in R. It
should allow you to do what you want (if I understood well). Please note I
am not too familiar with the PerformanceAnalytics package & its capabilities
(but suspect its style analysis function is a wrapper for solve.QP).
Building a rolling window analysis is quite trivial from there.
On another note, using 1 month data is probably too small to have stable
results (depending on how many factors in your style analysis - personal
rule of thumb is 10 times the number of factors gives you a benchmark of nbr
of data points needed) , I would look to include more returns in your linear
regression. One could look into applying some sort of weighting to your
regression to improve forecasting power (e.g. exponential weighting). I
guess you are also looking into the residuals for autocorrelation &
heteroskedasticity which will impact the hypothesis testing of your
betas/coefficients.
& Finally, always best to make a question as concise as possible,
include a piece of reproducible code of what you are trying to do & some
system information (what R version, what OS) ... that often makes easier for
list member to help & follow (more or less) the posting guide.
HTH
Julien
On Mar 16, 2010, at 12:04 AM, Ren? Naarmann wrote:
Hi R-users,
it is the first time for me writing to this group. I would be grateful
if somebody could help me to find
a solution to my problem.
I am working on my final thesis and I would like to analyse the impact
of return frequency
using return-based style analysis. Specifically I would like to
calculate attributable returns. An attributalbe return
is the difference between the realised return of a fund and the
forecast from using the estimated style coefficients
multiplied by the respective indexseries.
I am using the implemented functions for style analysis in the
PerformanceAnalytics Package.
I would like to use the quadratic programming algorithm just for each
day in a specific month, i.e.
use the daily returns from january to calculate the style weigths. This
should be done month by month.
In the next step the calculation should include two months of data and
calculate the style weigths month by month.
So far I tried to usw apply.month in combination with style.fit. This
returns the same results for each month.
In the next step I tried to use some code out of chart.RollingStyle. I
change it for my purpose and
receive the style weights in a rolling calculation and could enable the
by option. So I get styleweights
over a specific width and could shift the calculation by a specified
block, i.e. calculate styleweigths
for 20 days shifting this calculation by the next 20 days. What I would
like to have is a shifting by month
to use the last month realised daily returns to forecast the style
weigths for the next month.
Has somebody an idea how to handle this problem?
Thank you in advance
Ren? Naarmann
--
E-Mail: rene.naarmann at mnet-online.de