function f=function_1_2(x)
r0=.02;
sigma=.04;
gamma=5;
delta=.4;
mu0=.06;
N=60;
T=60;
dt=T/N;
R=40;
A0=50;
p=.16;
b=.7;
utility0=0;
asset=A0*ones(1,N+1);
L=A0;
b0=b*ones(1,N+1);
contri=p;
S=0*ones(1,N+1);
r=r0;
mu=mu0;
utility=utility0*ones(1,N+1);
t=0:dt:T;
for j=1:N
S(1,j)=asset(1,j)-L;
contri(1,j)=x(1)-x(2)*S(1,j)/R;
asset(1,j+1)=asset(1,j)+((asset(1,j).*(r+x(3)*(mu-r)))+40*contri(1,j)-15*b0(1,j))*dt+x(2)*sigma*asset(1,j)*sqrt(dt).*randn(1);
if j<R
C(1,j)=ones(1,1)-(contri(1,j)-x(1)*S(1,j)/R);
elseif j>=R & j<=N
C(1,j)=b;
end
utility(1,j+1)=utility(1,j)+exp(-delta*j)*(C(1,j).^(1-gamma))/(1-gamma);
end
f=(-1)*mean(utility(1,N+1))
clear
clc
lb=zeros(3,1);lb(2)=.02;
ub=inf(3,1);ub(2)=1;ub(3)=1;
x0=[0,0.02,0];
[x,fval]=fmincon(@function_1_2,x0,[],[],[],[],[],[],lb,ub)