Another question about function

1 vue (au cours des 30 derniers jours)
Tommy
Tommy le 14 Juin 2012
I want to calculate the omega which causes to a zero result of a function group. My function is as following, which uses command fsolve, but it does not work at present. Would you please check it and teach me which command to solve this function is appropiate? Thank you very much.
function:
%%function for omega of every time period for OI scheme
function f=function_1_5_2(x)
r0=.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)=exp(mu0+sigma*randn(M,1));
a(:,j)=.5*rand(M,1);
end
for i=1:M
w(i)=(Rf+omega*a(i,T-1)*(Rs(i,T)-Rf))^(-gamma)*(Rs(i,T)-Rf);
end
f=sum(w);
command (not correct)
clear
x0=0.5;
x=fsolve(@function_1_5_2,x0)
  1 commentaire
Walter Roberson
Walter Roberson le 14 Juin 2012
What error do you encounter, or what difference do you see between the output and your expected output ?
Is omega for the solution expected to be negative? If that sum() is expected to be 0 then you have to have some negative terms, and those can arise either by omega being negative or by Rs(i,T) - Rf being negative.
Why do you compute Rs(:,1:55) but use only Rs(i,55) and none of the other Rs(:,1:54) ? Why not just skip calculating the other Rs if you are going to only use the last of them? And what is going to happen on the day that you set N different than T ?

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Systems of Nonlinear Equations 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