Asked by Tommy
on 20 Jun 2012

After reading the answer of my last question, I change my code about fsolve, but there is still notification of: No solution found.

fsolve stopped because the problem appears to be locally singular.

<stopping criteria details>

Would anyone could check my code and give me some advises plz? Thanks a lot.:

%%function for omega of every time period for OI scheme

function f=function_1_5_3(x,Z)

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

dt=T/N;%each time period

t=1:dt:T;

omega=x;

Rf=exp(r0);%riskless reture

load OI_a_matrix;%set a grid of at

Rs=exp(mu0+sigma*Z);%risky market return

a=20*mat(:,N-2);

a_1=20*mat(:,N-1);

W=((a.*(Rf+omega*(Rs-Rf))-a_1).^(-gamma)).*(Rs-Rf)/M;

f=W;

and

clear

M=10000;

x0=0.4;

Z=randn(M,1);

x=fsolve(@(x)function_1_5_3(x,Z),x0)

in which the loaded matrix is a random matrix which saved at first:

mat=rand(M,N)

Answer by Sargondjani
on 25 Jun 2012

Accepted Answer

first you should try yourself to solve the equation when there is just 1 line (1 a and a_1). see what's happening... and then increase to a couple of lines.

and it seem there is no (serial) correlation between a and a_1, so why not just use their expected values??? (im not a statics expert, but if they are not correlated it think that is a fair thing to do)

i will try to help with limited time, but then i first need to understand better what you want to do in words: what is the equation? do you have documentation on it? because i still find the equation obscure. i especially want to know what 'a' and a_1 and omega are (in words)

Answer by Sargondjani
on 21 Jun 2012

first of all you should delete the /M in the objective, because this only scales your problem in a bad way. another problem could arise when Rs-Rf is very close to zero, because then the objective will get very close to zero, no matter what omega is (and will thus appear singular)

does your problem solve when you have just one random element in Z, a and a_1?

actually im also a bit confused in what you are trying to do:

- - before you had an omega for every element and then there is a solution for every element, but now with only one omega for all elements, there is no solution W(:)=0 (minimizing least squares seems more appropriate in that case)
- -also i see time variables, but you dont do anything with (R,dt,N,t,T)
- -what are 'a' and 'a_1', because I am surprised that thoser random numbers enther the objective as well (the random market return i can understand)

Tommy
on 22 Jun 2012

Actually I only have the random element in Z. for others, I want to solve an individual optimal question by envelop method, so I need a and a_1 as a group of random numbers. I change something of my code of function 1_5_3 as following:

%% function for omega of every time period for OI scheme

function f=function_1_5_3(x,Z)

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

dt=T/N;%each time period

t=1:dt:T;

omega=x;

Rf=exp(r0);%riskless reture

load OI_a_matrix;%set a grid of at

Rs=exp(mu0+sigma*Z);%risky market return

a=20*mat(:,N-2);

a_1=20*mat(:,N-1);

W=((a.*(Rf+omega*(Rs-Rf))-a_1).^(-gamma)).*(Rs-Rf);%regard as function 4

f=mean(W);

But there is still some problem which shows:

Equation solved, fsolve stalled.

fsolve stopped because the relative size of the current step is less than the

default value of the step size tolerance squared and the vector of function values

is near zero as measured by the default value of the function tolerance.

<stopping criteria details>

Thank you very much!

Sargondjani
on 23 Jun 2012

This is not a problem. Like it says the equation is solved! (any further improvements are smaller than the stopping criteria)

but i still wonder if you got what you want.... if you have properly defined the problem

what do you mean with "I want to solve an individual optimal question" because now there is still only one value for omega. and a and a_1 ARE random numbers...

... and still nothing happens with your time variables

Tommy
on 25 Jun 2012

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.