Not enough input arguments
Mostra commenti meno recenti
Dear community,
I want to calculate the loss of the following system:
%Hybrid NKM under commitment
%% Step 1 define the parameters
%same Parameters as from the script
%Parameters
gam_f = 0.5
gam_b =0.5
beta= 1
gam_x = 0.2
lambda = 0.5
phi = 0.5 % IS Parameter for interest rate
sig = 1 % IS Parameter for interest rate
AR_par = 0.8
%% Step 2
% System is: (w;v)(+1) = A*[w;v] + [ 1;0;0;0;0]*eps
A11= [AR_par 0 0;0 0 0; 0 0 0];
A12= [ 0 0; 1 0; 0 1];
A21 =[ 0 -gam_f/(beta^2*gam_b) 0; -1/(beta*gam_f) 0 -gam_b/gam_f]; %Klammern nicht vergessen
A22 =[ 1/(beta^2*gam_b) gam_x/(beta^2*lambda*gam_b); -gam_x/(beta*gam_f) 1/(beta*gam_f)];
A = [ [A11 A12] ; [A21 A22] ]
%% Step 3
% using the Schur Decomposition to solve the state equations
% solve the system
disp('Schur decomposition')
[Z, T] = schur(A, 'complex')
disp('reorder eigenvalues in increasing order along the principal diagonal')
[Z T] = ordschur(Z,T, 1:5)
if abs(sum(sum(Z*T*Z'-A))) > 0.0001 && sum(sum(Z'*Z-eye(lenght(Z)))) > 0.0001
disp('Error in Schur decomposition')
end
disp('check Blanchard-Kahn')
abs_diag_T = abs(diag(T))'
%% Calculating the solution time path for nu, x and pi using the following law of motion:
% z(+1) = E[z(+1)] + Z_11^-1 * [1;0;0] * eps
T_11 = T(1:3,1:3)
Z_11 = Z(1:3,1:3)
Z_21 = Z(4:5,1:3)
T=1000;
z_solution= zeros(3,T); % zeros because we have variables in i with t-1
w_solution= zeros(3,T); % zeros because we have variables in i with t-1
w_solution(:,1)=[ 1; 0; 0]; %initial jump
z_solution(:,1)=inv(Z_11)* w_solution(: ,1);%initial jump
v_solution= zeros(2,T);
i_solution= zeros(1,T); % nominal interest rate: IS umgestellt nach der Variable i.Hier liegt anscheinend das Problem.
for t= 2:T
z_solution(:,t)= T_11* z_solution(: ,t-1 );
w_solution(:,t)= Z_11 * z_solution(:,t);
v_solution(:,t)= Z_21 *inv(Z_11)* w_solution(:,t);
end
for t= 1:T-1
i_solution(:,t) =((1- phi)*v_solution(1,t+1)+phi*w_solution(2,t)-w_solution(2,t+1))*sig+ v_solution(2,t+1); % Jump in 1 anstatt 2. umgestellte IS-Kurve.
end;
For calculating the loss I need the v_solution that is a vector containing two variables x and pi. I need the mean of these two for my loss function.
function [ LossVal, vol_pi, vol_x ] = Loss_Fun( data, w_pi, w_x )
vol_pi = (mean(data.v_solution(2,1:T).^2));
vol_x = (mean(data.v_solution(1,1:T).^2));
LossVal = w_pi * vol_pi ...
+ w_x * vol_x;
w_pi = 0.5 ; %1;
w_x = 0.25; %0.5;
end
but something seems to be wrong here. But I dont knwo what
3 Commenti
Geoff Hayes
il 28 Mag 2019
Farah - which line of code is throwing the error? Please copy and paste the full error message to this question. Also, you have included the Loss_Fun function but I don't see how it is used with the remainder of the code. Please clarify.
Farah Shahpoor
il 26 Giu 2019
Farah Shahpoor
il 26 Giu 2019
Risposta accettata
Più risposte (1)
KALYAN ACHARJYA
il 26 Giu 2019
Modificato: KALYAN ACHARJYA
il 26 Giu 2019
# Check Commnet, this function file have no role in main script.
Save the function in different file as "Loss_Fun.m" (Same directory)
function [LossVal,vol_pi,vol_x]=Loss_Fun(data,w_pi,w_x)
vol_pi=(mean(data.v_solution(2,1:T).^2));
vol_x=(mean(data.v_solution(1,1:T).^2));
LossVal=w_pi*vol_pi+w_x*vol_x;
%w_pi = 0.5 ; %1;
%w_x = 0.25; %0.5;
end
Main Script (Run the main script)
%Hybrid NKM under commitment
%% Step 1 define the parameters
%same Parameters as from the script
%Parameters
gam_f = 0.5
gam_b =0.5
beta= 1
gam_x = 0.2
lambda = 0.5
phi = 0.5 % IS Parameter for interest rate
sig = 1 % IS Parameter for interest rate
AR_par = 0.8
%% Step 2
% System is: (w;v)(+1) = A*[w;v] + [ 1;0;0;0;0]*eps
A11= [AR_par 0 0;0 0 0; 0 0 0];
A12= [ 0 0; 1 0; 0 1];
A21 =[ 0 -gam_f/(beta^2*gam_b) 0; -1/(beta*gam_f) 0 -gam_b/gam_f]; %Klammern nicht vergessen
A22 =[ 1/(beta^2*gam_b) gam_x/(beta^2*lambda*gam_b); -gam_x/(beta*gam_f) 1/(beta*gam_f)];
A = [ [A11 A12] ; [A21 A22] ]
%% Step 3
% using the Schur Decomposition to solve the state equations
% solve the system
disp('Schur decomposition')
[Z, T] = schur(A, 'complex')
disp('reorder eigenvalues in increasing order along the principal diagonal')
[Z T] = ordschur(Z,T, 1:5)
if abs(sum(sum(Z*T*Z'-A))) > 0.0001 && sum(sum(Z'*Z-eye(lenght(Z)))) > 0.0001
disp('Error in Schur decomposition')
end
disp('check Blanchard-Kahn')
abs_diag_T = abs(diag(T))'
%% Calculating the solution time path for nu, x and pi using the following law of motion:
% z(+1) = E[z(+1)] + Z_11^-1 * [1;0;0] * eps
T_11 = T(1:3,1:3)
Z_11 = Z(1:3,1:3)
Z_21 = Z(4:5,1:3)
T=1000;
z_solution= zeros(3,T); % zeros because we have variables in i with t-1
w_solution= zeros(3,T); % zeros because we have variables in i with t-1
w_solution(:,1)=[ 1; 0; 0]; %initial jump
z_solution(:,1)=inv(Z_11)* w_solution(: ,1);%initial jump
v_solution= zeros(2,T);
i_solution= zeros(1,T); % nominal interest rate: IS umgestellt nach der Variable i.Hier liegt anscheinend das Problem.
for t= 2:T
z_solution(:,t)= T_11* z_solution(: ,t-1 );
w_solution(:,t)= Z_11 * z_solution(:,t);
v_solution(:,t)= Z_21 *inv(Z_11)* w_solution(:,t);
end
for t= 1:T-1
i_solution(:,t) =((1- phi)*v_solution(1,t+1)+phi*w_solution(2,t)-w_solution(2,t+1))*sig+ v_solution(2,t+1); % Jump in 1 anstatt 2. umgestellte IS-Kurve.
end;
Output
gam_f =
0.5000
gam_b =
0.5000
beta =
1
gam_x =
0.2000
lambda =
0.5000
phi =
0.5000
sig =
1
AR_par =
0.8000
A =
0.8000 0 0 0 0
0 0 0 1.0000 0
0 0 0 0 1.0000
0 -1.0000 0 2.0000 0.8000
-2.0000 0 -1.0000 -0.4000 2.0000
Schur decomposition
Z =
0.0000 - 0.0000i 0.0000 - 0.0000i -0.2949 + 0.0000i -0.3320 + 0.0694i 0.0258 - 0.8929i
-0.1586 - 0.3781i 0.2772 + 0.2163i 0.7860 + 0.0000i -0.0795 + 0.1836i 0.0683 - 0.2138i
0.2674 - 0.1121i 0.0822 - 0.3647i -0.1149 + 0.0000i 0.0359 + 0.8130i 0.3023 + 0.0965i
0.0856 - 0.7009i 0.5138 - 0.1167i -0.3731 + 0.0000i 0.0328 - 0.2581i -0.0960 + 0.0882i
0.4956 + 0.0605i -0.0443 - 0.6760i 0.3779 + 0.0000i -0.0505 - 0.3353i -0.1247 - 0.1357i
T =
1.4956 + 0.8535i 0.5385 + 0.0000i 0.8527 - 1.0580i 0.9668 - 0.8355i -0.4607 + 0.3907i
0.0000 + 0.0000i 1.4956 - 0.8535i -0.7757 + 1.1632i 1.2424 - 0.1948i -1.0957 - 0.3520i
0.0000 + 0.0000i 0.0000 + 0.0000i 0.8000 + 0.0000i 0.2651 - 0.3937i -0.1464 + 0.7130i
0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.5044 + 0.2878i -0.6670 + 0.0000i
0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.5044 - 0.2878i
reorder eigenvalues in increasing order along the principal diagonal
Z =
0.0000 + 0.0000i -0.0000 - 0.0000i 0.4092 + 0.2263i 0.2994 - 0.2642i 0.1468 - 0.7748i
0.1237 - 0.6952i 0.4512 - 0.2721i 0.2129 + 0.1177i 0.0988 + 0.3509i -0.1754 + 0.0321i
0.4916 + 0.0874i -0.2543 - 0.6279i -0.3849 - 0.2129i 0.1566 + 0.1010i -0.0454 - 0.2480i
-0.1377 - 0.3862i 0.3311 + 0.1184i -0.5507 - 0.3046i -0.0533 - 0.4638i 0.2349 - 0.1977i
0.2731 - 0.0974i -0.0364 - 0.3721i 0.3187 + 0.1763i -0.3534 - 0.5745i 0.2796 + 0.3322i
T =
0.5044 - 0.2878i -0.1691 + 0.0663i 0.7809 - 0.5847i 0.4891 - 0.5818i 0.0876 + 1.3505i
0.0000 + 0.0000i 0.5044 + 0.2878i -0.8802 - 0.0511i 0.4373 - 1.3339i -0.8048 - 0.1024i
0.0000 + 0.0000i 0.0000 + 0.0000i 0.8000 + 0.0000i 0.4870 + 0.8044i -0.1559 + 0.7071i
0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 1.4956 - 0.8535i -1.2778 - 0.5945i
0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 1.4956 + 0.8535i
check Blanchard-Kahn
abs_diag_T =
0.5807 0.5807 0.8000 1.7220 1.7220
T_11 =
0.5044 - 0.2878i -0.1691 + 0.0663i 0.7809 - 0.5847i
0.0000 + 0.0000i 0.5044 + 0.2878i -0.8802 - 0.0511i
0.0000 + 0.0000i 0.0000 + 0.0000i 0.8000 + 0.0000i
Z_11 =
0.0000 + 0.0000i -0.0000 - 0.0000i 0.4092 + 0.2263i
0.1237 - 0.6952i 0.4512 - 0.2721i 0.2129 + 0.1177i
0.4916 + 0.0874i -0.2543 - 0.6279i -0.3849 - 0.2129i
Z_21 =
-0.1377 - 0.3862i 0.3311 + 0.1184i -0.5507 - 0.3046i
0.2731 - 0.0974i -0.0364 - 0.3721i 0.3187 + 0.1763i
>>
7 Commenti
Farah Shahpoor
il 26 Giu 2019
Farah Shahpoor
il 26 Giu 2019
KALYAN ACHARJYA
il 26 Giu 2019
Modificato: KALYAN ACHARJYA
il 26 Giu 2019
Initially, I preassumed that Loss_Fun has been called in main script.
But there is no role of Loss_Fun in the main script
Check carefully. Just run the main script, it is executing
KALYAN ACHARJYA
il 26 Giu 2019
Modificato: KALYAN ACHARJYA
il 26 Giu 2019
Farah Shahpoor
il 26 Giu 2019
Guillaume
il 26 Giu 2019
I'm not sure how many times I can explain that like any function, a function that you write must be called with its required inputs. A function Loss_fun with 3 input arguments cannot be called with just Loss_fun the same way that the sin function cannot be called with just sin.
Farah Shahpoor
il 26 Giu 2019
Categorie
Scopri di più su Linear Algebra in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
