楼主: liumin1988
4412 4

[问答] 随机动态规划 [推广有奖]

  • 0关注
  • 0粉丝

大专生

16%

还不是VIP/贵宾

-

威望
0
论坛币
252 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
109 点
帖子
20
精华
0
在线时间
54 小时
注册时间
2011-12-20
最后登录
2019-1-1

楼主
liumin1988 发表于 2012-2-19 10:42:20 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
想问一下关于随机动态规划的程序,我的目标函数是非线性的,约束条件是伊藤积分,请问各位大侠有相关的程序吗?很急
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:动态规划 请问各位大侠 约束条件 伊藤积分 各位大侠 动态

沙发
aibieli731001 发表于 2012-2-19 10:51:12
你用matlab软件试试,很简单的。

藤椅
liumin1988 发表于 2012-2-19 15:23:00
aibieli731001 发表于 2012-2-19 10:51
你用matlab软件试试,很简单的。
我是要用matlab,但是我不太会编程序,请问有相关的程序吗,想借鉴一下,谢谢

板凳
liumin1988 发表于 2012-2-20 09:44:43
有哪位大侠来显身手解答一下啊,很急啊!

报纸
matlab-007 发表于 2014-11-23 19:18:49

clear all;
close all;
% Define the structural parameters of the model,
% i.e. policy invariant preference and technology parameters
% alpha : capital's share of output
% beta  : time discount factor
% delta : depreciation rate
% sigma : risk-aversion parameter, also intertemp. subst. param.
alpha = .35;
beta  = .98;
delta = .025;
sigma = 2;

% Number of exogenous states
gz = 2;
% Values of z
z = [4.95
     5.05];
% Probabilites for z     
prh = .5;
prl = 1-prh;     
% Expected value of z
zbar = prh*z(1) + prl*z(2);

% Find the steady-state level of capital as a function of
%   the structural parameters
kstar = ((1/beta - 1 + delta)/(alpha*zbar))^(1/(alpha-1));
% Define the number of discrete values k can take
gk = 101;
k  = linspace(0.90*kstar,1.10*kstar,gk);

% Compute a (gk x gk x gz) dimensional consumption matrix c
%   for all the (gk x gk x gz) values of k_t, k_t+1 and z_t.
for h = 1 : gk
   for i = 1 : gk
       for j = 1 : gz
            c(h,i,j) = z(j)*k(h)^alpha + (1-delta)*k(h) - k(i);
            if c(h,i,j) < 0
                c(h,i,j) = 0;
            end
            % h is the counter for the endogenous state variable k_t
            % i is the counter for the control variable k_t+1
            % j is the counter for the exogenous state variable z_t
       end
   end
end
% Compute a (gk x gk x gz) dimensional consumption matrix u
%   for all the (gk x gk x gz) values of k_t, k_t+1 and z_t.
for h = 1 : gk
   for i = 1 : gk
       for j = 1 : gz
            if sigma == 1
                u(h,i,j) = log(c(h,i,j))
            else
                u(h,i,j) = (c(h,i,j)^(1-sigma) - 1)/(1-sigma);   
            end
            % h is the counter for the endogenous state variable k_t
            % i is the counter for the control variable k_t+1
            % j is the counter for the exogenous state variable z_t
       end
   end
end

% Define the initial matrix v as a matrix of zeros (could be anything)
v = zeros(gk,gz);
% Set parameters for the loop
convcrit = 1E-6;  % chosen convergence criterion
diff = 1;         % arbitrary initial value greater than convcrit
iter = 0;         % iterations counter
while diff > convcrit
    % for each combination of k_t and gamma_t
    %   find the k_t+1 that maximizes the sum of instantenous utility and
    %   discounted continuation utility
    for h = 1 : gk
        for j = 1 : gz
            Tv(h,j) = max( u(h,:,j) + beta*(prh*v(:,1)' + prl*v(:,2)') );
        end
    end
    iter = iter + 1;
    diff = norm(Tv - v);
    v = Tv;
end

% Find the implicit decision rule for k_t+1 as a function of the state
%   variables k_t and z_t
for h = 1 : gk
    for j = 1 : gz
        % Using the [ ] syntax for max does not only give the value, but
        %   also the element chosen.
        [Tv,gridpoint] = max(u(h,:,j) + beta*(prh*v(:,1)' + prl*v(:,2)'));
        % Find what grid point of the k vector which is the optimal decision
        kgridrule(h,j) = gridpoint;
        % Find what value for k_t+1 which is the optimal decision
        kdecrule(h,j) = k(gridpoint);
    end
end

% Plot it and save it as a jpg-file
figure
plot(k,kdecrule,k,k);
xlabel('k_t')
ylabel('k_{t+1}')
print -djpeg kdecrule.jpg

% Compute the optimal decision rule for c as a function of the state
%    variables
for h = 1 : gk       % counter for k_t
    for j = 1 : gz   % counter for z_t
        cdecrule(h,j) = z(j)*k(h)^alpha + (1-delta)*k(h) - kdecrule(h,j);
    end
end
figure
plot(k,cdecrule)
xlabel('k_t')
ylabel('c_t')
print -djpeg decrulec.jpg
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% Simulation
% Aribrary starting point
enostate = round(gk/2);
ksim(1) = k(enostate);
% Draw a sequence of 100 random variables and use the optimal decision rule
for i = 1 : 100
    draw = rand;
    if draw < prh
        exostate = 1;
    else
        exostate = 2;
    end
   
    kprimegrid = kgridrule(enostate,exostate);
    kprime = k(kprimegrid);
   
    zsim(i) = z(exostate);
    ksim(i+1) = kprime;
    ysim(i) = z(exostate)*ksim(i)^alpha;
    isim(i) = ksim(i+1) - (1-delta)*ksim(i);
    csim(i) = ysim(i) - isim(i);
end
figure
plot(1:100,ysim/mean(ysim),1:100,csim/mean(csim),1:100,isim/mean(isim),1:100,ksim(1:100)/mean(ksim(1:100)))
legend('y','c','i','k')
title('Simulation 100 draws, devations from mean')
print -djpeg simulation.jpg

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-9 08:34