Matrix Constructed with ||...|| has Too Complicated a Type

Use this forum to post questions about syntax problems or general programming issues. Questions on implementing a particular aspect of econometrics should go in "Econometrics Issues" below.

Matrix Constructed with ||...|| has Too Complicated a Type

Unread postby AdamElderfield » Sat May 29, 2021 4:31 pm

Hi,

I am getting the following error when trying to create a matrix which I can pass to the DLM instruction:

## SX26. Matrix Constructed with ||...|| has Too Complicated a Type
>>>> ||<<<<

The matrix has one parameter estimate which is a wrapped up in a function (similar to the Nelson-Siegal model), the vector tau has some numbers in it which I want to index:

Code: Select all

dec vect tau_f(7)
dec vect tau_s(7)
dec real tenor

dofor tenor = 120 3 12 12 24 12 24
 compute tau_f(%doforpass) = tenor
end dofor tenor

dofor tenor = 0 0 0 0 12 0 12
 compute tau_s(%doforpass) = tenor
end dofor tenor



frml Cf = ||1.0,-((exp(-lambda*tau_s(1))-exp(-lambda*tau_f(1)))/(tau_f(1)-tau_s(1))),((tau_s(1)*exp(-lambda*tau_s(1))-tau_f(1)*exp(-lambda*tau_f(1)))/(tau_f(1)-tau_s(1)))+((exp(-lambda*tau_s(1))-exp(-lambda*tau_f(1)))/(tau_f(1)-tau_s(1))),0.0,0.0,0.0|$
          ||1.0,-((exp(-lambda*tau_s(2))-exp(-lambda*tau_f(2)))/(tau_f(2)-tau_s(2))),((tau_s(2)*exp(-lambda*tau_s(2))-tau_f(2)*exp(-lambda*tau_f(2)))/(tau_f(2)-tau_s(2)))+((exp(-lambda*tau_s(2))-exp(-lambda*tau_f(2)))/(tau_f(2)-tau_s(2))),0.0,0.0,0.0|$
          ||1.0,-((exp(-lambda*tau_s(3))-exp(-lambda*tau_f(3)))/(tau_f(3)-tau_s(3))),((tau_s(3)*exp(-lambda*tau_s(3))-tau_f(3)*exp(-lambda*tau_f(3)))/(tau_f(3)-tau_s(3)))+((exp(-lambda*tau_s(3))-exp(-lambda*tau_f(3)))/(tau_f(3)-tau_s(3))),0.0,0.0,0.0|$
          ||1.0,-((exp(-lambda*tau_s(4))-exp(-lambda*tau_f(4)))/(tau_f(4)-tau_s(4))),((tau_s(4)*exp(-lambda*tau_s(4))-tau_f(4)*exp(-lambda*tau_f(4)))/(tau_f(4)-tau_s(4)))+((exp(-lambda*tau_s(4))-exp(-lambda*tau_f(4)))/(tau_f(4)-tau_s(4))),0.0,0.0,0.0|$
          ||1.0,-((exp(-lambda*tau_s(5))-exp(-lambda*tau_f(5)))/(tau_f(5)-tau_s(5))),((tau_s(5)*exp(-lambda*tau_s(5))-tau_f(5)*exp(-lambda*tau_f(5)))/(tau_f(5)-tau_s(5)))+((exp(-lambda*tau_s(5))-exp(-lambda*tau_f(5)))/(tau_f(5)-tau_s(5))),0.0,0.0,0.0|$
          ||1.0,-((exp(-lambda*tau_s(6))-exp(-lambda*tau_f(6)))/(tau_f(6)-tau_s(6))),((tau_s(6)*exp(-lambda*tau_s(6))-tau_f(6)*exp(-lambda*tau_f(6)))/(tau_f(6)-tau_s(6)))+((exp(-lambda*tau_s(6))-exp(-lambda*tau_f(6)))/(tau_f(6)-tau_s(6))),0.0,0.0,0.0|$
          ||1.0,-((exp(-lambda*tau_s(7))-exp(-lambda*tau_f(7)))/(tau_f(7)-tau_s(7))),((tau_s(7)*exp(-lambda*tau_s(7))-tau_f(7)*exp(-lambda*tau_f(7)))/(tau_f(7)-tau_s(7)))+((exp(-lambda*tau_s(7))-exp(-lambda*tau_f(7)))/(tau_f(7)-tau_s(7))),0.0,0.0,0.0||





Do I need to hard enter the tau values?
AdamElderfield
 
Posts: 28
Joined: Fri Nov 20, 2020 3:37 pm

Re: Matrix Constructed with ||...|| has Too Complicated a Ty

Unread postby TomDoan » Sun May 30, 2021 12:08 pm

The problem you have is that you keep repeating the ||'s at the start of the 2nd and later lines, which adds another layer of embedded matrices. (It's trying to build a RECT[RECT[RECT[RECT[....] until it hits the nesting limit.)

It's usually better to use a FUNCTION rather than a FRML if the FRML starts to get unreadably complicated. In this case, since each row is basically the same except for the row number, the FUNCTION to compute it is fairly simple. If I'm reading this correctly, you want:

Code: Select all
dec rect cf0(7,6)
ewise cf0(i,j)=(j==1)
function cfx t
type integer t
do i=1,7
  compute cf0(i,2)=-((exp(-lambda*tau_s(i))-exp(-lambda*tau_f(i)))/(tau_f(i)-tau_s(i)))
  compute cf0(i,3)=((tau_s(i)*exp(-lambda*tau_s(i))-tau_f(i)*exp(-lambda*tau_f(i)))/(tau_f(i)-tau_s(i)))+((exp(-lambda*tau_s(i))-exp(-lambda*tau_f(i)))/(tau_f(i)-tau_s(i)))
end do i
compute cfx=cf0
end


You can then use C=CFX(T) on the DLM instruction.
TomDoan
 
Posts: 7236
Joined: Wed Nov 01, 2006 5:36 pm

Re: Matrix Constructed with ||...|| has Too Complicated a Ty

Unread postby AdamElderfield » Sun May 30, 2021 5:39 pm

Thanks for the tip Tom, I will try that in future!
AdamElderfield
 
Posts: 28
Joined: Fri Nov 20, 2020 3:37 pm

Re: Matrix Constructed with ||...|| has Too Complicated a Ty

Unread postby AdamElderfield » Tue Jun 01, 2021 5:37 pm

Hi Tom,

I've tried your function, thanks. I am getting the following error:

## SX22. Expected Type REAL, Got RECTANGULAR[REAL] Instead
>>>> compute cfx=cf0<<<<

I'm not sure how to proceed?

Thanks

Adam
AdamElderfield
 
Posts: 28
Joined: Fri Nov 20, 2020 3:37 pm


Return to Help With Programming

Who is online

Users browsing this forum: No registered users and 3 guests

cron