[R-SIG-Finance] style.fit by month
René Naarmann
rene.naarmann at mnet-online.de
Tue Mar 16 16:06:34 CET 2010
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
>>
>> _______________________________________________
>> R-SIG-Finance at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> -- Subscriber-posting only. If you want to post, subscribe first.
>> -- Also note that this is not the r-help list where general R
>> questions should go.
>>
>
>
>
--
René Naarmann
Eckentaler Str. 16
90542 Eckental
---
Tel.: (09126)-294069
Mobil: (0170)-8100941
E-Mail: rene.naarmann at mnet-online.de
More information about the R-SIG-Finance
mailing list