Unbalanced or Unexpected Paranthesis or Bracket Error

İs there any problem with that cod; [theta,se,t]=qreg(tb_26wk,(ones(2585(tb_26wk));_13wk); q(0.1));
Because ı have unbalanced or... error in that command.
Thanks.

2 Comments

What is the goal of that code? It has a few problems:
  1. Arguments should be separated by commas, not semicolons (;).
  2. What are you trying to do with the expression 2585(tb_26wk)? Variables and functions can't start with a letter, so this expression makes no sense.
If you can answer these questions or provide other clarifications you may get some more helpful answers.
First, thanks your feedback.
Second, that cod for the Quantile Cointegration which is the one of analysis in time series. So, that expression we could imagine as a mathematical function which is F(x(a)). Actually, i am writing all the cod under the line;
% Empirical Study: Term structure of interest rates.
% Data: US daily rates (missing obs deleted).
% CUSUM test of quantile cointegration.
clear;
% Load the matlab data files
load d_tb.mat % T_data=2585
load d_tb_date.mat % 1/2/2002 to 4/30/2012
load d_fcp.mat % T_data=3748
load d_fcp_date.mat % 1997-01-02 to 2012-04-30
load d_tcmnom.mat % T_data=7584*
load d_tcmnom_date.mat % 1982-01-04* to 2012-04-30
% Compute the size of data for the number of observations, if needed
% [T_data N_data]=size(tb);
% Rename the variables from the data set
% Treasury bill rates (yields: 4, 13, 26 weeks)
tb_4wk=tb(:,1); % bank discount
tb_13wk=tb(:,3);
tb_26wk=tb(:,5);
tb_4wk_ce=tb(:,2); % coupon equivalent
tb_13wk_ce=tb(:,4);
tb_26wk_ce=tb(:,6);
% Financial commercial paper rates (yields: 30, 60, 90 days)
fcp_30d=fcp(:,1);
fcp_60d=fcp(:,2);
fcp_90d=fcp(:,3);
% Treasury constant maturity rates (yields: 3, 6, 12 months)
% One month rate is not used due to large number of missing observations.
% tcmnom=tcmnom(4896:7584,:); % 2001-07-31 to 2012-04-30, T=2689 for one month rate
% tcmnom_1=tcmnom(:,1); % obs 4896:7584, 2001-07-31 to 2012-04-30 for one month rate
tcmnom_3=tcmnom(:,2); % obs 1:7584, 1982-01-04 to 2012-04-30
tcmnom_6=tcmnom(:,3); % obs 1:7584, 1982-01-04 to 2012-04-30
tcmnom_12=tcmnom(:,4); % obs 1:7584, 1982-01-04 to 2012-04-30
% For regression results using different pairs of interest rates,
% replace y and x variables.
% e.g. To compute for the results in the last two rows of Table 3,
% consier y=tcmnom_12 and x=tcmnom_6;
% y=tb_26wk;
% x=tb_13wk;
% y=tb_26wk_ce;
% x=tb_13wk_ce;
% y=fcp_90d;
% x=fcp_60d;
y=tcmnom_12;
x=tcmnom_6;
% Compute the quantile regression coefficients and residuals
q =[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9]; % nine quantiles
Lq=length(q);
[T N]=size(x);
xlag=[zeros(1,N);x(1:T-1,:)];
v=x-xlag;
vlag=[zeros(1,N); v(1:T-1,:)];
for n=1:N
[rho_2,se_v,t_v]=ols(v(:,n), [ones(T,1) vlag(:,n)]); % for calculation of the kernel estimator later
rho_v(n,1)=rho_2(2,1); % rho_v is N-by-1
res_v=v(:,n)-[ones(T,1) vlag(:,n)]*rho_2; % ols residuals
ss_v(n,1)=res_v'*res_v/(T-1); % s^2=SSR/(n-k), ss_v is N-by-1
end
beta0=zeros(N,1);
D_T_tail=[1 zeros(1,N); zeros(N,1) eye(N)*sqrt(T)];
[theta_ols,se_ols,t_ols]=ols(y,[ones(size(y)) x]);
u_hat=y-[ones(size(y)) x]*theta_ols;
for k=1:Lq
[theta,se,t]=qreg(tb_26wk,(ones(2585(tb_26wk));tb_13wk); q(0.1));
alpha = theta(1,1);
beta = theta(2:(N+1),1);
se_beta=se(2:(N+1),1);
u_tau=y-[ones(size(y)) x]*theta;
psi=q(k)-(u_tau<0);
% Compute the density funtion
F_inv_tau=quantile(u_hat,q(k));
M_f=1.364*((2*sqrt(pi))^(-1/5))*sqrt(var(u_hat))*(T^(-1/5)); % bandwidth (Silverman's rule of thumb)
f_hat=sum(normpdf((F_inv_tau-u_hat)/M_f))/(T*M_f); % using Gaussian kernel to calculate the density function
% Choose kernel function and bandwidth to compute the fully-modified estimator
psilag=[0; psi(1:T-1)];
[rho_1,se_psi,t_psi]=ols(psi, [ones(size(psilag)) psilag]); % for kernel estimator
rho_psi=rho_1(2,1);
res_psi=psi-[ones(size(psilag)) psilag]*rho_1; % residuals
ss_psi=res_psi'*res_psi/(T-1); % scalar s^2=SSR/(n-k)
%% Using the Bartlett kernel function:
a1=4*(rho_psi^2*ss_psi/(((1-rho_psi)^6)*((1+rho_psi)^2))+sum(((rho_v.^2).*ss_v)./(((1-rho_v).^6).*((1+rho_v).^2))))/(ss_psi/((1-rho_psi)^4)+sum(ss_v./((1-rho_v).^4))); % for Bartlett kernel
M=2*T^(1/3); % bandwidth
M=ceil(M);
h_set=0:M;
K=bartlett(h_set/M); % Bartlett kernel function, row vector
psi_th_1=zeros(T,M);
v_th_1=zeros(T,M,N);
v_th=zeros(T,M+1,N);
for h=1:M
psi_th_1(:,h)=[psi((h+1):T);zeros(h,1)]; % column vector
for n=1:N
v_th_1(:,h,n)=[v((h+1):T,n);zeros(h,1)];
end
end
K_1=K(1,2:M+1);
psi_th=[psi psi_th_1];
Delta_psipsi=K*(psi'*psi_th)'/T; % for (omega_psi.v)^2
Lambda_psipsi_prim=K_1*(psi'*psi_th_1)'/T; % for (omega_psi.v)^2
Delta_vpsi=(K*(v'*psi_th)')'/T; % N-by-1
for n=1:N
v_th(:,:,n)=[v(:,n) v_th_1(:,:,n)];
Delta_vv(:,n)=(K*(v'*v_th(:,:,n))')'/T; % N-by-N
Lambda_vpsi_prim(n,1)=K_1*(psi'*v_th_1(:,:,n))'/T; % Lambda_vpsi_prim is N-by-1
Lambda_vv_prim(n,:)=K_1*(v'*v_th_1(:,:,n))'/T; % Lambda_vv_prim is N-by-N
end
Omega_vpsi=Delta_vpsi+Lambda_vpsi_prim;
Omega_vv=Delta_vv+Lambda_vv_prim;
omega2_psi=Delta_psipsi+Lambda_psipsi_prim; % for (omega_psi.v)^2
Omega_psiv=Omega_vpsi'; % for (omega_psi.v)^2, which is 1-by-N
Delta_vpsi_plus=Delta_vpsi-Delta_vv*inv(Omega_vv)*Omega_vpsi;
omega2_psiv=omega2_psi-Omega_psiv*inv(Omega_vv)*Omega_vpsi; % for (omega_psi.v)^2
beta_fm=beta-inv((x-ones(size(y))*mean(x))'*(x-ones(size(y))*mean(x))*f_hat)*((x-ones(size(y))*mean(x))'*v*inv(Omega_vv)*Omega_vpsi+T*Delta_vpsi_plus); % beta_fm is N-by-1
beta_set_fm(:,k)=beta_fm;
se_beta_fm=diag(inv(sqrt((x-ones(size(y))*mean(x))'*(x-ones(size(y))*mean(x)))*f_hat)*sqrt(omega2_psiv));
t_beta_fm=(beta_fm-beta0)./se_beta_fm;
t_beta_set_fm(:,k)=t_beta_fm;
theta_fm=[alpha;beta_fm];
% CUSUM cointegration test:
y_plus=y-(Omega_psiv*inv(Omega_vv)*v')'; % fm residual
u_tau_plus=y_plus-[ones(size(y_plus)) x]*theta_fm; % fm residual
psi_plus=q(k)-(u_tau_plus<0); % psi of fm residual
cs=max(abs(cumsum(psi_plus))/sqrt(T*omega2_psiv)); % CS test statistic of the CUSUM test
cs_set(1,k)=cs;
end
% The critical values are from Hao+Inder (1996) Table 1 (# of regressors=1, excl. constant):
% cv[10% 5% 1%]= [1.0477 1.1684 1.4255]
rej_cointeg_hi1_05=abs(cs_set)>1.1684; % 1-by-9, 5% level
rej_cointeg_hi1_01=abs(cs_set)>1.4255; % 1-by-9, 1% level
% Display the result: fully modified slope coefficient estimator, test statistic, and inference
% where 1 denotes significance at the level considered and 0 denotes insignificance.
table=[beta_set_fm; cs_set; rej_cointeg_hi1_05; rej_cointeg_hi1_01]

Sign in to comment.

Answers (1)

Anil - look carefully at this line of code
[theta,se,t]=qreg(tb_26wk,(ones(2585(tb_26wk));tb_13wk); q(0.1));
As Nathan has already pointed out, there are problems with the above line of code. Why are some parameters (?) separated by semi-colons? What is the signature for the qreg function? Break this down - presumably
  • tb_26wk is the first input parameter to this function - is this correct?
  • ones(2585(tb_26wk)) are you trying to create an array of ones that is 2585xtb_26wk? Is tb_26wk an integer or something else?
  • (ones(2585(tb_26wk));tb_13wk) or are you trying to concatenate some numbers into an array. If that is the case, then use [] instead of ()
  • q(0.1) since q is an array, what are you attempting with q(0.1)? This will fail since 0.1 is not an integer (or logical) index into the array...what do you really want to do here?
If you post the function signature for qreg then we can help you further...

1 Comment

Thanks for the answer. I solved the problem. I appreciate your helping me.

Sign in to comment.

Categories

Tags

Asked:

on 13 Feb 2019

Commented:

on 14 Feb 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!