Thanks for the helpful comments so far. I just noticed I had made a mistake
in the code I sent that might cause confusion. The code I have attempted is
as follows:


> buildCapm <- function(u) {
>
+      Test <- dlmModReg(x, dV = exp(u[1]), dW = exp(u[2 : 3]))
+      Test$JW <- matrix(c(0,1),ncol=2,byrow=TRUE)       #This line was
incorrect in my original post
+  }
The reason for the mix up is due to the fact that I am working on a somewhat
more complicated model (including the fama, french-factors and momentum). I
figured I should simplify it to make it easier to explain my problem.

-Hubert



On Tue, Dec 15, 2009 at 8:04 PM, Patrick Burns <patrick@burns-stat.com>wrote:

> I don't know anything about the book or the
> code, but 'The R Inferno' gives some hints
> about debugging that might help you.
>
>
>
> Patrick Burns
> patrick@burns-stat.com
> +44 (0)20 8525 0696
> http://www.burns-stat.com
> (home of "The R Inferno" and "A Guide for the Unwilling S User")
>
> Hubert Colt wrote:
>
>>  Hi everyone,
>>
>> I am creating time-varying betas for a time series model testing CAPM,
>> using
>> the dlm package. However I have some problems in specifying a constant
>> alpha. I have worked with the vignette extensively and read the relevant
>> parts of Petris & co's book, Dynamic Linear Models with R, but have so far
>> not been able to get the model right. I hope one of you could spare the
>> time
>> to help me out.
>>
>> My problem arises from when I try to specify the build function that the
>> MLE
>> variances calculations are based on.
>>
>> The book utilizes the following setup to get MLE's for a simple CAPM-model
>> with time-varying alpha and beta:
>>
>> buildCapm <- function(u) {
>>>
>> +      dlmModReg(x, dV = exp(u[1]), dW = exp(u[2 : 3]))
>> +  }
>>
>>> outMLE <- dlmMLE(IBM, parm = rep(0, 3), buildCapm)
>>> mod <- buildCapm(outMLE$par)
>>>
>>
>> where x is a time series for the market premium, and IBM is a time series
>> for IBMs stock price.
>> I want to also look at the possibility of a time invariant alpha, however
>> I
>> have so far not managed to specify this in the model succesfully. I have
>> attempted to keep alpha's W constant by doing the following (for
>> simplicity
>> shown here in the same model):
>>
>> buildCapm <- function(u) {
>>>
>> +      Test <- dlmModReg(x, dV = exp(u[1]), dW = exp(u[2 : 3]))
>> +      Test$JW <- matrix(c(0,1,1,1,1),ncol=5,byrow=TRUE)
>> +  }
>>
>> And countless variations thereof, but they all end up giving me the
>> following error when I run dlmMLE on it
>> afterwards:
>>
>> Error in `*tmp*`[[i]] : subscript out of bounds
>> I have not been able to surmise what other form JW should be on, or
>> alternatively what changes I need to make in the first statement in order
>> to
>> get a constant alpha, and the most relevant other examples I have found in
>> the books assume W is already known.
>>
>> I'd be very thankful for any pointers you could give me.
>>
>> Hubert
>>
>>        [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-SIG-Finance@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.
>>
>>
>>

	[[alternative HTML version deleted]]

