Effacer les filtres
Effacer les filtres

Plot inaction/action state space

2 vues (au cours des 30 derniers jours)
Carlos Fellmann
Carlos Fellmann le 7 Mar 2023
I'm trying to plot the inaction/action state space for (A,K). The problem is that of a firm that chooses to invest or not to invest every period, based on the expected discounted profits. I solve the problem with brute-force grid search. The code is as follows.
The idea would be to plot (A,K) based on the decision of the firm to invest or not.
Any help would be much appreciated!
%% PS 4
%Housekeeping
tic
clear
close all
clc
%global A0 theta beta p gamma F_cost k0 valueFunction prob j kgrid %valueFunction_a valueFunction_i
%% 1 Calibration
tic
theta=0.592;
p=1;
beta=0.90;
gamma=0.049;
F=0.039;
prob=[0.997 0.003 0;
0.0003 0.9994 0.0003;
0 0.003 0.997];
A=[0.8134 1 1.2293]';
expectedprod=A'*prob;
expectedprod=expectedprod';
%k1=0.01;
%k2=100;
nGridCapital=500;
A_ss=sum(A)/(length(A));
tol=1*10^(-10);
%% Steady State
capitalSS=(F/A_ss)^(1/(1-theta));
kmin= 0.01; %0.1*capitalSS;
kmax=100; % 1.1*capitalSS;
%% Grid construction
vGridCapital=linspace(kmin, kmax, nGridCapital);
%vGridCapital=vGridCapital';
%% Matrices
mValueFunction=zeros(3,nGridCapital);
mValueFunctionnew=zeros(3,nGridCapital);
mValueFunctionnew_i=zeros(3,nGridCapital);
mValueFunctionnew_a=zeros(3,nGridCapital);
mPolicyFunction=zeros(3,nGridCapital);
mPolicyFunction_i=zeros(3,nGridCapital);
mPolicyFunction_a=zeros(3,nGridCapital);
valueProvisional_i=zeros(3,nGridCapital);
valueProvisional_a=zeros(3,nGridCapital);
adjcost=zeros(3,nGridCapital);
invest=zeros(3,nGridCapital);
revenue=zeros(3,nGridCapital);
vIter=mValueFunction;
%% Revenue
Pi=A*(vGridCapital.^theta); %pre-build revenue for each point in the capital grid and the different productivity levels
%% Iterations
diff_i=10;
diff_a=10;
iteration=0;
diff=max(diff_i, diff_a);
while (diff>tol)
%loop for capital values
for nCapital =1:nGridCapital
%loop for A values
for prod= 1:size(A,1)
%loop for capital in the next period
for nCapitalNext =1:nGridCapital
%loop for productivity in the next period
for prodnext =1:size(expectedprod,1)
adjcost(nCapital,nCapitalNext)=(gamma/2)*(vGridCapital(nCapitalNext)-vGridCapital(nCapital)/vGridCapital(nCapital))^2 * vGridCapital(nCapital);
invest(nCapital,nCapitalNext)=p*(vGridCapital(nCapitalNext)-vGridCapital(nCapital));
revenue(nCapital)=prod*vGridCapital(nCapital).^theta;
valueProvisional_i(prodnext,nCapitalNext)=(1-beta)*(revenue(nCapital))+beta*(mValueFunction(prodnext,nCapitalNext));
valueProvisional_a(prodnext,nCapitalNext)=(1-beta)*(revenue(nCapital)- F*vGridCapital(nCapital)-adjcost(nCapital,nCapitalNext)-invest(nCapital,nCapitalNext))+beta*(mValueFunction(prodnext,nCapitalNext));
end
end
%find capital prime and A prime that maximize the function for each,
%adjustment and inactivity, given this period's productivity
mValueFunctionnew_i(prod,nCapital)=max(valueProvisional_i(prod,nCapital));
mPolicyFunction_i(prod,nCapital)=max(valueProvisional_i(prod,nCapital));
mValueFunctionnew_a(prod,nCapital)=max(valueProvisional_a(prod,nCapital));
mPolicyFunction_a(prod,nCapital)=max(valueProvisional_a(prod,nCapital));
%chose the max between the two new value functions and policy
%functions
mValueFunctionnew=max(mValueFunctionnew_a, mValueFunctionnew_i);
mPolicyFunction=max(mPolicyFunction_i,mPolicyFunction_a);
end
end
%mPolicyFunction=vGridCapital(1,mPolicyFunction); %convert the policy function back to capital units
% find the differences
diff=norm(mValueFunctionnew-mValueFunction);
% set the new value function
mValueFunction=mValueFunctionnew;
iteration=iteration+1
fprintf('Iteration=%d, Sup=%2.8f\n', iteration, diff)
fprintf('\n')
end
%% plots
figure(2)
plot(vGridCapital, mPolicyFunction(1,:), 'red')
hold on
plot(vGridCapital, mPolicyFunction(2,:), 'blue')
hold on
plot(vGridCapital, mPolicyFunction(3,:), 'green')
legend('Low A', 'Medium A', 'High A')
toc

Réponses (1)

Sugandhi
Sugandhi le 20 Mar 2023
Hi Carlos Fellmann,
I understand that you want to make plot (A, K) based on the decision of the firm to invest or not.
>> plot(X,Y)
The above command creates a 2-D line plot of the data in Y versus the corresponding values in X.
  • To plot a set of coordinates connected by line segments, specify X and Y as vectors of the same length.
  • To plot multiple sets of coordinates on the same set of axes, specify at least one of X or Y as a matrix.
In order to better assist you, please share more details of the issue you are facing.
For more understanding kindly go through the following link –

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by