필터 지우기
필터 지우기

Another question about function

조회 수: 1 (최근 30일)
Tommy
Tommy 2012년 6월 14일
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
Walter Roberson
Walter Roberson 2012년 6월 14일
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 ?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 5G Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by