%  weil.m 
%  Algebra for Weil's precautionary saving model (RES 93). 
%
format compact
clear all

% Part 1:  values of k
disp('***************************************************************')
disp('Values of k (third derivative property)') 
disp(' ')
disp('Power utility') 
syms c f f1 f2 f3 alpha k 
f = c^alpha/alpha
f1 = diff(f,c)
f2 = diff(f1,c)
f3 = diff(f2,c)
k = simplify(f3*f1/(f2*f2))

disp(' ')
disp('Exponential utility') 
clear f f1 f2 f3
f = -exp(-alpha*c)
f1 = diff(f,c)
f2 = diff(f1,c)
f3 = diff(f2,c)
k = simplify(f3*f1/(f2*f2))


% Part 2:  solution of problem 
%     J(a) = A + B a
%     c  = F + G a
disp('  ') 
disp('***************************************************************')
disp('DP solution (J = A + B a, C = F + G a)') 
clear all
syms J A B 
syms alpha rho ies beta r a c mu ybar sigma 

B = ((1-beta)^(1/(1-rho))/(1-beta^(1/(1-rho))*r^(rho/(1-rho))))^((1-rho)/rho)
G = simplify(B*((1-beta)/B)^(1/(1-rho)))
zero = G - (1-beta^(1/(1-rho))*r^(rho/(1-rho)))

disp('??')



return 



mu = A + B*r*(a-c)+B*ybar - alpha*sigma^2/2

[c] = solve('mu*(beta*r*B/(1-beta))^(1/(1-rho))/c = 1')   

return 


