Mogapi O.S
2012-Feb-21 06:12 UTC
[R] BHHH algorithm on duration time models for stock prices
I am currently trying to find MLE of a function with four parameters. My codes run well but i don't get the results. I get the following message: BHHH maximisation Number of iterations: 0 Return code: 100 Initial value out of range. I don't know this is so because of the way i have written my loglikelihood or what. The loglikelihood LogLik<-function(param){ beta_1<-param[1] beta_2<-param[2] beta_3<-param[3] beta_4<-param[4] lambda.plus<-beta_1*Iplusless1 + beta_2*Iminusless1 lambda.minus<-beta_3*Iplusless1 + beta_4*Iminusless1 sum(Iplus_new*log(lambda.plus))-sum(log(lambda.plus)*x_new) + sum(Iminus_new*log(lambda.minus))-sum(log(lambda.minus)*x_new) } The gradients gradient<-function(param){ beta_1<-param[1] beta_2<-param[2] beta_3<-param[3] beta_4<-param[4] lambda.plus<-beta_1*Iplusless1 + beta_2*Iminusless1 lambda.minus<-beta_3*Iplusless1 + beta_4*Iminusless1 sum(Iplus_new*Iplusless1)-sum((lambda.plus)*Iplusless1*x_new) sum(Iplus_new*Iminusless1)-sum((lambda.plus)*Iminusless1*x_new) sum(Iminus_new*Iplusless1)-sum((lambda.minus)*Iminusless1*x_new) sum(Iminus_new*Iminusless1)-sum((lambda.minus)*Iminusless1*x_new) } In this codes the variables are Iplus_new, lambda.plus, lambda_minus, Iminus_new , Iminusless1 and Iplusless1. The variables x_new is the duration between two bid-ask occurring at times t_(i-1) and t_i. i.e. x_new=t_i -t_i-1. There are several observations for x_new. The Iplus_new and Iminus_new are the indicator variable showing whether the price was increasing or decreasing at duration x_new. Both Iminusless1 and Iplusless1 are lag variable of Iminus_new and Iplus_new respectively. aaa<- maxBHHH(LogLik, gradient, start=1) summary(aaa) [[alternative HTML version deleted]]