I plan to solve a function matrix x(j), which want each x(j) could lead W(j) to 0. I have written a function about it, but I do not know what code I need to write to solve this function. I will be really appreciate if anyone could take some time to give me some help. Thank you very much
%%function for omega of every time period for OI scheme
function f=function_1_5_1(x)clearr0=.02;%interest rate
sigma=.15;%vatality rate of risky asset
mu0=.06;%drift rate of risky asset
gamma=5;%risk aversion rate
M=10000;%number of trajectories
N=55;%time period
T=55;%total time period
R=40;%time of retirement
R_l=T-R;%length of retiment
dt=T/N;%each time period
t=1:dt:T;omega=x;Rf=exp(r0);for j=1:N Rs(:,j+1)=exp(mu0+sigma*randn(M,1)); a(:,j)=.5*rand(M,1);endfor j=1:N-1 for i=1:M if j=1 w(:,N-j+1)=omega(N-j+1)*ones(M,1) w(i,N-j)=(Rf+omega(N-j)*a(i,N-j+1)*(Rs(i,N-j+1)-Rf))^(-gamma)*(Rs(i,N-j+1)-Rf); else if j<R_l w(i,N-j)=(a(i,N-j)*(Rf+omega(N-j)*(Rs(i,N-j+1)-Rf))-a(i,N-j+1))^(-gamma)*(Rs(i,N-j+1)-Rf); else w(i,N-j)=(a(i,N-j)*(Rf+omgea(N-j)*(Rs(i,N-j+1)-Rf))+1-a(i,N-j+1))^(-gamma)*(Rs(i,N-j+1)-Rf); end end end W(j)=sum(w(:,j));endf=W;
Best Answer